Changeset 3528
 Timestamp:
 May 27, 2009, 7:04:23 AM (6 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

libpipi/trunk/examples/img2twit.cpp
r3527 r3528 466 466 467 467 static inline void get_point(int index, float *x, float *y, float *r, 468 float *g, float *b, float *s )468 float *g, float *b, float *s, bool final = false) 469 469 { 470 470 uint32_t pt = points[index]; … … 481 481 *y = (fy + dy) * RANGE_Y /*+ 0.5 * (index & 1)*/; 482 482 483 *b = int2midrange(pt % RANGE_R, RANGE_R); pt /= RANGE_R; 484 *g = int2midrange(pt % RANGE_G, RANGE_G); pt /= RANGE_G; 485 *r = int2midrange(pt % RANGE_B, RANGE_B); pt /= RANGE_B; 483 if(final) 484 { 485 *b = int2fullrange(pt % RANGE_R, RANGE_R); pt /= RANGE_R; 486 *g = int2fullrange(pt % RANGE_G, RANGE_G); pt /= RANGE_G; 487 *r = int2fullrange(pt % RANGE_B, RANGE_B); pt /= RANGE_B; 488 } 489 else 490 { 491 *b = int2midrange(pt % RANGE_R, RANGE_R); pt /= RANGE_R; 492 *g = int2midrange(pt % RANGE_G, RANGE_G); pt /= RANGE_G; 493 *r = int2midrange(pt % RANGE_B, RANGE_B); pt /= RANGE_B; 494 } 486 495 } 487 496 … … 626 635 } 627 636 628 static void render(pipi_image_t *dst, int rx, int ry, int rw, int rh) 637 static void render(pipi_image_t *dst, 638 int rx, int ry, int rw, int rh, bool final) 629 639 { 630 640 int lookup[dw * RANGE_X * 2 * dh * RANGE_Y * 2]; … … 645 655 646 656 /* Add fake points to close the triangulation */ 647 dt.insert(K::Point_2( p>w, p>h));648 dt.insert(K::Point_2(2 * p>w, p>h));649 dt.insert(K::Point_2( p>w, 2 * p>h));650 dt.insert(K::Point_2(2 * p>w, 2 * p>h));657 dt.insert(K::Point_2(dw * RANGE_X, dh * RANGE_Y)); 658 dt.insert(K::Point_2(2 * dw * RANGE_X, dh * RANGE_Y)); 659 dt.insert(K::Point_2(dw * RANGE_X, 2 * dh * RANGE_Y)); 660 dt.insert(K::Point_2(2 * dw * RANGE_X, 2 * dh * RANGE_Y)); 651 661 652 662 for(y = ry; y < ry + rh; y++) … … 654 664 for(x = rx; x < rx + rw; x++) 655 665 { 656 K::Point_2 m(x, y); 666 K::Point_2 m((float)x * dw * RANGE_X / p>w, 667 (float)y * dh * RANGE_Y / p>h); 657 668 Point_coordinate_vector coords; 658 669 CGAL::Triple< … … 672 683 fy = (*it).first.y(); 673 684 674 if(fx < 0  fy < 0  fx > p>w  1  fy > p>h  1) 685 if(fx < 0  fy < 0 686  fx > dw * RANGE_X  1  fy > dh * RANGE_Y  1) 675 687 continue; 676 688 … … 678 690 + dw * RANGE_X * 2 * (int)(fy * 2)]; 679 691 680 get_point(index, &fx, &fy, &fr, &fg, &fb, &fs );692 get_point(index, &fx, &fy, &fr, &fg, &fb, &fs, final); 681 693 682 694 //float k = pow((*it).second * (1.0 + fs), 1.2); … … 1055 1067 /* Render what we just computed */ 1056 1068 tmp = pipi_new(dw * RANGE_X, dh * RANGE_Y); 1057 render(tmp, 0, 0, dw * RANGE_X, dh * RANGE_Y );1069 render(tmp, 0, 0, dw * RANGE_X, dh * RANGE_Y, false); 1058 1070 error = pipi_measure_rmsd(src, tmp); 1059 1071 … … 1114 1126 1115 1127 render(scrap, zonex * RANGE_X, zoney * RANGE_Y, 1116 zonew * RANGE_X, zoneh * RANGE_Y );1128 zonew * RANGE_X, zoneh * RANGE_Y, false); 1117 1129 1118 1130 double newerr = pipi_measure_rmsd(src, scrap); … … 1131 1143 points[pt] = candidates[bestop]; 1132 1144 /* Redraw image if the last check wasn't the best one */ 1133 if(bestop != 2)1145 if(bestop != 0) 1134 1146 render(scrap, zonex * RANGE_X, zoney * RANGE_Y, 1135 zonew * RANGE_X, zoneh * RANGE_Y );1147 zonew * RANGE_X, zoneh * RANGE_Y, false); 1136 1148 1137 1149 pipi_free(tmp); … … 1219 1231 1220 1232 /* Render these points to a new image */ 1221 tmp = pipi_new(dw * RANGE_X, dh * RANGE_Y); 1222 render(tmp, 0, 0, dw * RANGE_X, dh * RANGE_Y); 1223 1224 /* TODO: render directly to the final image; scaling sucks */ 1225 dst = pipi_resize(tmp, width, height); 1226 pipi_free(tmp); 1233 dst = pipi_new(width, height); 1234 render(dst, 0, 0, width, height, true); 1227 1235 1228 1236 /* Save image and bail out */
Note: See TracChangeset
for help on using the changeset viewer.