Bläddra i källkod

Beginning of the optim...

git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@3535 92316355-f0b4-4df1-b90c-862c8a59935f
master
sam 15 år sedan
förälder
incheckning
a81278aca8
1 ändrade filer med 34 tillägg och 7 borttagningar
  1. +34
    -7
      examples/img2twit.cpp

+ 34
- 7
examples/img2twit.cpp Visa fil

@@ -10,6 +10,11 @@
* http://sam.zoy.org/wtfpl/COPYING for more details.
*/

/* TODO:
* - remove the complicated stuff from get_point/set_point, it's only
* the final packing that really matters.
*/

#include "config.h"

#include <stdio.h>
@@ -110,6 +115,8 @@ static int MAX_ITERATIONS;
static unsigned int TOTAL_CELLS;

#define RANGE_XY (RANGE_Y*RANGE_X)
#define RANGE_XYXY (RANGE_XY*RANGE_XY)
//#define RANGE_XYXY (RANGE_Y*RANGE_X*(RANGE_Y*RANGE_X+1)/2)
#define RANGE_RXY (RANGE_Y*RANGE_X*RANGE_R)
#define RANGE_GRXY (RANGE_Y*RANGE_X*RANGE_R*RANGE_G)
#define RANGE_BGRXY (RANGE_Y*RANGE_X*RANGE_R*RANGE_G*RANGE_B)
@@ -550,6 +557,19 @@ static void add_point(float x, float y, float r, float g, float b, float s)
npoints++;
}

static uint32_t pack_coords(int x1, int y1, int x2, int y2)
{
return ((y2 * RANGE_X + x2) * RANGE_Y + y1) * RANGE_X + x1;
}

static void unpack_coords(uint32_t pack, int *x1, int *y1, int *x2, int *y2)
{
*x1 = pack % RANGE_X; pack /= RANGE_X;
*y1 = pack % RANGE_Y; pack /= RANGE_Y;
*x2 = pack % RANGE_X; pack /= RANGE_X;
*y2 = pack % RANGE_Y;
}

#if 0
static void add_random_point()
{
@@ -1273,10 +1293,16 @@ int main(int argc, char *argv[])
for(int i = 0; i < npoints; i += POINTS_PER_CELL)
{
#if POINTS_PER_CELL == 2
int x1, y1, x2, y2;
x1 = (points[i] / RANGE_Y) % RANGE_X;
y1 = points[i] % RANGE_Y;
x2 = (points[i + 1] / RANGE_Y) % RANGE_X;
y2 = points[i + 1] % RANGE_Y;
uint32_t pack = pack_coords(x1, y1, x2, y2);

b.push(points[i] / RANGE_XY, RANGE_SBGR);
b.push(points[i] % RANGE_XY, RANGE_XY);
b.push(points[i + 1] / RANGE_XY, RANGE_SBGR);
b.push(points[i + 1] % RANGE_XY, RANGE_XY);
b.push(pack, RANGE_XYXY);
#else
b.push(points[i], RANGE_SBGRXY);
#endif
@@ -1295,12 +1321,13 @@ int main(int argc, char *argv[])
for(int i = dw * dh; i--; )
{
#if POINTS_PER_CELL == 2
uint32_t c1 = b.pop(RANGE_XY);
uint32_t p1 = b.pop(RANGE_SBGR);
uint32_t c2 = b.pop(RANGE_XY);
uint32_t pack = b.pop(RANGE_XYXY);
uint32_t p2 = b.pop(RANGE_SBGR);
points[i * 2 + 1] = p1 * RANGE_XY + c1;
points[i * 2] = p2 * RANGE_XY + c2;
uint32_t p1 = b.pop(RANGE_SBGR);
int x1, y1, x2, y2;
unpack_coords(pack, &x1, &y1, &x2, &y2);
points[i * 2] = p1 * RANGE_XY + x1 * RANGE_Y + y1;
points[i * 2 + 1] = p2 * RANGE_XY + x2 * RANGE_Y + y2;
#else
points[i] = b.pop(RANGE_SBGRXY);
#endif


Laddar…
Avbryt
Spara