Changeset 3533


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

img2twit: change the position of the S component to help decompose points
for a forthcoming optimisation.

File:
1 edited

Legend:

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

    r3532 r3533  
    110110static unsigned int TOTAL_CELLS;
    111111
    112 #define RANGE_SY (RANGE_S*RANGE_Y)
    113 #define RANGE_SYX (RANGE_S*RANGE_Y*RANGE_X)
    114 #define RANGE_SYXR (RANGE_S*RANGE_Y*RANGE_X*RANGE_R)
    115 #define RANGE_SYXRG (RANGE_S*RANGE_Y*RANGE_X*RANGE_R*RANGE_G)
    116 #define RANGE_SYXRGB (RANGE_S*RANGE_Y*RANGE_X*RANGE_R*RANGE_G*RANGE_B)
     112#define RANGE_XY (RANGE_Y*RANGE_X)
     113#define RANGE_RXY (RANGE_Y*RANGE_X*RANGE_R)
     114#define RANGE_GRXY (RANGE_Y*RANGE_X*RANGE_R*RANGE_G)
     115#define RANGE_BGRXY (RANGE_Y*RANGE_X*RANGE_R*RANGE_G*RANGE_B)
     116#define RANGE_SBGRXY (RANGE_Y*RANGE_X*RANGE_R*RANGE_G*RANGE_B*RANGE_S)
     117#define RANGE_SBGR (RANGE_R*RANGE_G*RANGE_B*RANGE_S)
    117118
    118119struct K : CGAL::Exact_predicates_inexact_constructions_kernel {};
     
    140141    DATA_BITS = TOTAL_BITS - HEADER_BITS;
    141142#if POINTS_PER_CELL == 1
    142     CELL_BITS = logf(RANGE_SYXRGB) / logf(2);
     143    CELL_BITS = logf(RANGE_SBGRXY) / logf(2);
    143144#else
    144145    // TODO: implement the following shit
     
    146147    //float other_bits = logf(RANGE_R * RANGE_G * RANGE_B * RANGE_S);
    147148    //CELL_BITS = (coord_bits + 2 * other_bits) / logf(2);
    148     CELL_BITS = 2 * logf(RANGE_SYXRGB) / logf(2);
     149    CELL_BITS = 2 * logf(RANGE_SBGRXY) / logf(2);
    149150#endif
    150151    TOTAL_CELLS = (int)(DATA_BITS / CELL_BITS);
     
    510511    int ib = range2int(b, RANGE_B);
    511512
    512     points[index] = is + RANGE_S * (iy + RANGE_Y * (ix + RANGE_X *
    513                                (ib + RANGE_B * (ig + (RANGE_R * ir)))));
     513    points[index] = iy + RANGE_Y * (ix + RANGE_X * (ib + RANGE_B *
     514                      (ig + (RANGE_R * ir + (RANGE_S * is)))));
    514515}
    515516
     
    521522
    522523    index2cell(index, &dx, &dy);
    523 
    524     *s = int2fullrange(pt % RANGE_S, RANGE_S); pt /= RANGE_S;
    525524
    526525    float fy = int2midrange(pt % RANGE_Y, RANGE_Y); pt /= RANGE_Y;
     
    542541        *r = int2midrange(pt % RANGE_B, RANGE_B); pt /= RANGE_B;
    543542    }
     543
     544    *s = int2fullrange(pt % RANGE_S, RANGE_S); pt /= RANGE_S;
    544545}
    545546
     
    553554static void add_random_point()
    554555{
    555     points[npoints] = det_rand(RANGE_SYXRGB);
     556    points[npoints] = det_rand(RANGE_SBGRXY);
    556557    npoints++;
    557558}
     
    587588        /* Statistics show that this helps often, but does not reduce
    588589         * the error significantly. */
    589         return val ^ 1;
     590        rem = val % RANGE_BGRXY;
     591        ext = val / RANGE_BGRXY;
     592        ext ^= 1;
     593        return ext * RANGE_BGRXY + rem;
    590594    case 2: /* Move up; if impossible, down */
    591         rem = val % RANGE_S;
    592         ext = (val / RANGE_S) % RANGE_Y;
     595        ext = val % RANGE_Y;
    593596        ext = ext > 0 ? ext - 1 : ext + 1;
    594         return (val / RANGE_SY * RANGE_Y + ext) * RANGE_S + rem;
     597        return val / RANGE_Y * RANGE_Y + ext;
    595598    case 3: /* Move down; if impossible, up */
    596         rem = val % RANGE_S;
    597         ext = (val / RANGE_S) % RANGE_Y;
     599        ext = val % RANGE_Y;
    598600        ext = ext < RANGE_Y - 1 ? ext + 1 : ext - 1;
    599         return (val / RANGE_SY * RANGE_Y + ext) * RANGE_S + rem;
     601        return val / RANGE_Y * RANGE_Y + ext;
    600602    case 4: /* Move left; if impossible, right */
    601         rem = val % RANGE_SY;
    602         ext = (val / RANGE_SY) % RANGE_X;
     603        rem = val % RANGE_Y;
     604        ext = (val / RANGE_Y) % RANGE_X;
    603605        ext = ext > 0 ? ext - 1 : ext + 1;
    604         return (val / RANGE_SYX * RANGE_X + ext) * RANGE_SY + rem;
     606        return (val / RANGE_XY * RANGE_X + ext) * RANGE_Y + rem;
    605607    case 5: /* Move left; if impossible, right */
    606         rem = val % RANGE_SY;
    607         ext = (val / RANGE_SY) % RANGE_X;
     608        rem = val % RANGE_Y;
     609        ext = (val / RANGE_Y) % RANGE_X;
    608610        ext = ext < RANGE_X - 1 ? ext + 1 : ext - 1;
    609         return (val / RANGE_SYX * RANGE_X + ext) * RANGE_SY + rem;
     611        return (val / RANGE_XY * RANGE_X + ext) * RANGE_Y + rem;
    610612    case 6: /* Corner 1 */
    611613        return apply_op(2, apply_op(4, val));
     
    625627        return apply_op(5, apply_op(5, val));
    626628    case 10: /* R-- (or R++) */
    627         rem = val % RANGE_SYX;
    628         ext = (val / RANGE_SYX) % RANGE_R;
     629        rem = val % RANGE_XY;
     630        ext = (val / RANGE_XY) % RANGE_R;
    629631        ext = ext > 0 ? ext - 1 : ext + 1;
    630         return (val / RANGE_SYXR * RANGE_R + ext) * RANGE_SYX + rem;
     632        return (val / RANGE_RXY * RANGE_R + ext) * RANGE_XY + rem;
    631633    case 11: /* R++ (or R--) */
    632         rem = val % RANGE_SYX;
    633         ext = (val / RANGE_SYX) % RANGE_R;
     634        rem = val % RANGE_XY;
     635        ext = (val / RANGE_XY) % RANGE_R;
    634636        ext = ext < RANGE_R - 1 ? ext + 1 : ext - 1;
    635         return (val / RANGE_SYXR * RANGE_R + ext) * RANGE_SYX + rem;
     637        return (val / RANGE_RXY * RANGE_R + ext) * RANGE_XY + rem;
    636638    case 12: /* G-- (or G++) */
    637         rem = val % RANGE_SYXR;
    638         ext = (val / RANGE_SYXR) % RANGE_G;
     639        rem = val % RANGE_RXY;
     640        ext = (val / RANGE_RXY) % RANGE_G;
    639641        ext = ext > 0 ? ext - 1 : ext + 1;
    640         return (val / RANGE_SYXRG * RANGE_G + ext) * RANGE_SYXR + rem;
     642        return (val / RANGE_GRXY * RANGE_G + ext) * RANGE_RXY + rem;
    641643    case 13: /* G++ (or G--) */
    642         rem = val % RANGE_SYXR;
    643         ext = (val / RANGE_SYXR) % RANGE_G;
     644        rem = val % RANGE_RXY;
     645        ext = (val / RANGE_RXY) % RANGE_G;
    644646        ext = ext < RANGE_G - 1 ? ext + 1 : ext - 1;
    645         return (val / RANGE_SYXRG * RANGE_G + ext) * RANGE_SYXR + rem;
     647        return (val / RANGE_GRXY * RANGE_G + ext) * RANGE_RXY + rem;
    646648    case 14: /* B-- (or B++) */
    647         rem = val % RANGE_SYXRG;
    648         ext = (val / RANGE_SYXRG) % RANGE_B;
     649        rem = val % RANGE_GRXY;
     650        ext = (val / RANGE_GRXY) % RANGE_B;
    649651        ext = ext > 0 ? ext - 1 : ext + 1;
    650         return ext * RANGE_SYXRG + rem;
     652        return (val / RANGE_BGRXY * RANGE_B + ext) * RANGE_GRXY + rem;
    651653    case 15: /* B++ (or B--) */
    652         rem = val % RANGE_SYXRG;
    653         ext = (val / RANGE_SYXRG) % RANGE_B;
     654        rem = val % RANGE_GRXY;
     655        ext = (val / RANGE_GRXY) % RANGE_B;
    654656        ext = ext < RANGE_B - 1 ? ext + 1 : ext - 1;
    655         return ext * RANGE_SYXRG + rem;
     657        return (val / RANGE_BGRXY * RANGE_B + ext) * RANGE_GRXY + rem;
    656658#if 0
    657659    case 15: /* Brightness-- */
     
    12691271
    12701272        /* Push our points to the bitstream */
    1271         for(int i = 0; i < npoints; i++)
    1272             b.push(points[i], RANGE_SYXRGB);
     1273        for(int i = 0; i < npoints; i += POINTS_PER_CELL)
     1274        {
     1275#if POINTS_PER_CELL == 2
     1276            b.push(points[i] / RANGE_XY, RANGE_SBGR);
     1277            b.push(points[i] % RANGE_XY, RANGE_XY);
     1278            b.push(points[i + 1] / RANGE_XY, RANGE_SBGR);
     1279            b.push(points[i + 1] % RANGE_XY, RANGE_XY);
     1280#else
     1281            b.push(points[i], RANGE_SBGRXY);
     1282#endif
     1283        }
    12731284        b.push(height - 1, RANGE_H);
    12741285        b.push(width - 1, RANGE_W);
     
    12851296        {
    12861297#if POINTS_PER_CELL == 2
    1287             points[i * 2 + 1] = b.pop(RANGE_SYXRGB);
    1288             points[i * 2] = b.pop(RANGE_SYXRGB);
     1298            uint32_t c1 = b.pop(RANGE_XY);
     1299            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;
    12891304#else
    1290             points[i] = b.pop(RANGE_SYXRGB);
     1305            points[i] = b.pop(RANGE_SBGRXY);
    12911306#endif
    12921307        }
Note: See TracChangeset for help on using the changeset viewer.