Changeset 3533
 Timestamp:
 May 28, 2009 3:54:35 AM (5 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

libpipi/trunk/examples/img2twit.cpp
r3532 r3533 110 110 static unsigned int TOTAL_CELLS; 111 111 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) 117 118 118 119 struct K : CGAL::Exact_predicates_inexact_constructions_kernel {}; … … 140 141 DATA_BITS = TOTAL_BITS  HEADER_BITS; 141 142 #if POINTS_PER_CELL == 1 142 CELL_BITS = logf(RANGE_S YXRGB) / logf(2);143 CELL_BITS = logf(RANGE_SBGRXY) / logf(2); 143 144 #else 144 145 // TODO: implement the following shit … … 146 147 //float other_bits = logf(RANGE_R * RANGE_G * RANGE_B * RANGE_S); 147 148 //CELL_BITS = (coord_bits + 2 * other_bits) / logf(2); 148 CELL_BITS = 2 * logf(RANGE_S YXRGB) / logf(2);149 CELL_BITS = 2 * logf(RANGE_SBGRXY) / logf(2); 149 150 #endif 150 151 TOTAL_CELLS = (int)(DATA_BITS / CELL_BITS); … … 510 511 int ib = range2int(b, RANGE_B); 511 512 512 points[index] = i s + 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))))); 514 515 } 515 516 … … 521 522 522 523 index2cell(index, &dx, &dy); 523 524 *s = int2fullrange(pt % RANGE_S, RANGE_S); pt /= RANGE_S;525 524 526 525 float fy = int2midrange(pt % RANGE_Y, RANGE_Y); pt /= RANGE_Y; … … 542 541 *r = int2midrange(pt % RANGE_B, RANGE_B); pt /= RANGE_B; 543 542 } 543 544 *s = int2fullrange(pt % RANGE_S, RANGE_S); pt /= RANGE_S; 544 545 } 545 546 … … 553 554 static void add_random_point() 554 555 { 555 points[npoints] = det_rand(RANGE_S YXRGB);556 points[npoints] = det_rand(RANGE_SBGRXY); 556 557 npoints++; 557 558 } … … 587 588 /* Statistics show that this helps often, but does not reduce 588 589 * 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; 590 594 case 2: /* Move up; if impossible, down */ 591 rem = val % RANGE_S; 592 ext = (val / RANGE_S) % RANGE_Y; 595 ext = val % RANGE_Y; 593 596 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; 595 598 case 3: /* Move down; if impossible, up */ 596 rem = val % RANGE_S; 597 ext = (val / RANGE_S) % RANGE_Y; 599 ext = val % RANGE_Y; 598 600 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; 600 602 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; 603 605 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; 605 607 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; 608 610 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; 610 612 case 6: /* Corner 1 */ 611 613 return apply_op(2, apply_op(4, val)); … … 625 627 return apply_op(5, apply_op(5, val)); 626 628 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; 629 631 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; 631 633 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; 634 636 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; 636 638 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; 639 641 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; 641 643 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; 644 646 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; 646 648 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; 649 651 ext = ext > 0 ? ext  1 : ext + 1; 650 return ext * RANGE_SYXRG+ rem;652 return (val / RANGE_BGRXY * RANGE_B + ext) * RANGE_GRXY + rem; 651 653 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; 654 656 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; 656 658 #if 0 657 659 case 15: /* Brightness */ … … 1269 1271 1270 1272 /* 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 } 1273 1284 b.push(height  1, RANGE_H); 1274 1285 b.push(width  1, RANGE_W); … … 1285 1296 { 1286 1297 #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; 1289 1304 #else 1290 points[i] = b.pop(RANGE_S YXRGB);1305 points[i] = b.pop(RANGE_SBGRXY); 1291 1306 #endif 1292 1307 }
Note: See TracChangeset
for help on using the changeset viewer.