Changeset 3535
 Timestamp:
 May 28, 2009, 3:54:50 AM (9 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

libpipi/trunk/examples/img2twit.cpp
r3533 r3535 9 9 * To Public License, Version 2, as published by Sam Hocevar. See 10 10 * 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. 11 16 */ 12 17 … … 111 116 112 117 #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) 113 120 #define RANGE_RXY (RANGE_Y*RANGE_X*RANGE_R) 114 121 #define RANGE_GRXY (RANGE_Y*RANGE_X*RANGE_R*RANGE_G) … … 549 556 set_point(npoints, x, y, r, g, b, s); 550 557 npoints++; 558 } 559 560 static 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 565 static 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; 551 571 } 552 572 … … 1274 1294 { 1275 1295 #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 1276 1303 b.push(points[i] / RANGE_XY, RANGE_SBGR); 1277 b.push(points[i] % RANGE_XY, RANGE_XY);1278 1304 b.push(points[i + 1] / RANGE_XY, RANGE_SBGR); 1279 b.push(p oints[i + 1] % RANGE_XY, RANGE_XY);1305 b.push(pack, RANGE_XYXY); 1280 1306 #else 1281 1307 b.push(points[i], RANGE_SBGRXY); … … 1296 1322 { 1297 1323 #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); 1299 1326 uint32_t p1 = b.pop(RANGE_SBGR); 1300 uint32_t c2 = b.pop(RANGE_XY);1301 u int32_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; 1304 1331 #else 1305 1332 points[i] = b.pop(RANGE_SBGRXY);
Note: See TracChangeset
for help on using the changeset viewer.