Changeset 3535


Ignore:
Timestamp:
May 28, 2009 3:54:50 AM (5 years ago)
Author:
sam
Message:

Beginning of the optim...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libpipi/trunk/examples/img2twit.cpp

    r3533 r3535  
    99 *  To Public License, Version 2, as published by Sam Hocevar. See
    1010 *  http://sam.zoy.org/wtfpl/COPYING for more details.
     11 */
     12
     13/* TODO:
     14 * - remove the complicated stuff from get_point/set_point, it's only
     15 *   the final packing that really matters.
    1116 */
    1217
     
    111116
    112117#define RANGE_XY (RANGE_Y*RANGE_X)
     118#define RANGE_XYXY (RANGE_XY*RANGE_XY)
     119//#define RANGE_XYXY (RANGE_Y*RANGE_X*(RANGE_Y*RANGE_X+1)/2)
    113120#define RANGE_RXY (RANGE_Y*RANGE_X*RANGE_R)
    114121#define RANGE_GRXY (RANGE_Y*RANGE_X*RANGE_R*RANGE_G)
     
    549556    set_point(npoints, x, y, r, g, b, s);
    550557    npoints++;
     558}
     559
     560static uint32_t pack_coords(int x1, int y1, int x2, int y2)
     561{
     562    return ((y2 * RANGE_X + x2) * RANGE_Y + y1) * RANGE_X + x1;
     563}
     564
     565static void unpack_coords(uint32_t pack, int *x1, int *y1, int *x2, int *y2)
     566{
     567    *x1 = pack % RANGE_X; pack /= RANGE_X;
     568    *y1 = pack % RANGE_Y; pack /= RANGE_Y;
     569    *x2 = pack % RANGE_X; pack /= RANGE_X;
     570    *y2 = pack % RANGE_Y;
    551571}
    552572
     
    12741294        {
    12751295#if POINTS_PER_CELL == 2
     1296            int x1, y1, x2, y2;
     1297            x1 = (points[i] / RANGE_Y) % RANGE_X;
     1298            y1 = points[i] % RANGE_Y;
     1299            x2 = (points[i + 1] / RANGE_Y) % RANGE_X;
     1300            y2 = points[i + 1] % RANGE_Y;
     1301            uint32_t pack = pack_coords(x1, y1, x2, y2);
     1302
    12761303            b.push(points[i] / RANGE_XY, RANGE_SBGR);
    1277             b.push(points[i] % RANGE_XY, RANGE_XY);
    12781304            b.push(points[i + 1] / RANGE_XY, RANGE_SBGR);
    1279             b.push(points[i + 1] % RANGE_XY, RANGE_XY);
     1305            b.push(pack, RANGE_XYXY);
    12801306#else
    12811307            b.push(points[i], RANGE_SBGRXY);
     
    12961322        {
    12971323#if POINTS_PER_CELL == 2
    1298             uint32_t c1 = b.pop(RANGE_XY);
     1324            uint32_t pack = b.pop(RANGE_XYXY);
     1325            uint32_t p2 = b.pop(RANGE_SBGR);
    12991326            uint32_t p1 = b.pop(RANGE_SBGR);
    1300             uint32_t c2 = b.pop(RANGE_XY);
    1301             uint32_t p2 = b.pop(RANGE_SBGR);
    1302             points[i * 2 + 1] = p1 * RANGE_XY + c1;
    1303             points[i * 2] = p2 * RANGE_XY + c2;
     1327            int x1, y1, x2, y2;
     1328            unpack_coords(pack, &x1, &y1, &x2, &y2);
     1329            points[i * 2] = p1 * RANGE_XY + x1 * RANGE_Y + y1;
     1330            points[i * 2 + 1] = p2 * RANGE_XY + x2 * RANGE_Y + y2;
    13041331#else
    13051332            points[i] = b.pop(RANGE_SBGRXY);
Note: See TracChangeset for help on using the changeset viewer.