diff --git a/demos/second/part18_3d/auto/NOTES b/demos/second/part18_3d/auto/NOTES index 383c7663..f20a5b27 100644 --- a/demos/second/part18_3d/auto/NOTES +++ b/demos/second/part18_3d/auto/NOTES @@ -21,6 +21,7 @@ todo, compressed: 498 bytes: try11: sort HLIN by Y1 431 bytes: try12: with don't cares 336 bytes: try13: sort colors by popularity + 299 bytes: try14: shrink the window for finding colors to only include colors TODO: Only use don't care result if not wider than max X or longer than @@ -28,7 +29,9 @@ TODO: sort BOX and do optimizations like HLIN - Try all color combos? Not possible? + Try all color combos? + K-permutations. For K=16 it's literally billions+? + Maybe try just top 4? Only 24 combos then? MOVE PLOTS one line before HLIN? diff --git a/demos/second/part18_3d/auto/box_convert.c b/demos/second/part18_3d/auto/box_convert.c index bc09199e..0ef6f98c 100644 --- a/demos/second/part18_3d/auto/box_convert.c +++ b/demos/second/part18_3d/auto/box_convert.c @@ -166,6 +166,36 @@ int create_using_hlins_by_color(void) { return current_primitive; } +int find_max_color_extent(int current_color,int *color_minx,int *color_miny, + int *color_maxx,int *color_maxy) { + + + int xx,yy; + + *color_minx=39; + *color_miny=47; + *color_maxx=0; + *color_maxy=0; + + /* Find maximum extent of color */ + for(yy=0;yy<48;yy++) { + for(xx=0;xx<40;xx++) { + if (current_color==framebuffer[xx][yy]) { + if (xx<*color_minx) *color_minx=xx; + if (xx>*color_maxx) *color_maxx=xx; + if (yy<*color_miny) *color_miny=yy; + if (yy>*color_maxy) *color_maxy=yy; + } + } + } + if (debug) fprintf(stderr,"Color %d: range %d,%d to %d,%d\n", + current_color,*color_minx,*color_miny, + *color_maxx,*color_maxy); + + + return 0; + +} int create_using_boxes(void) { @@ -173,24 +203,33 @@ int create_using_boxes(void) { int row,col,box; int current_color; int color; + int color_minx,color_maxx,color_miny,color_maxy; for(color=0;color<16;color++) { current_color=color_lookup[color].color; if (current_color==background_color) continue; + + find_max_color_extent(current_color, + &color_minx,&color_miny, + &color_maxx,&color_maxy); + for(box=0;box=color_minx)&&((col+box_sizes[box].x-1)<=color_maxx)&& + ((row)>=color_miny)&&((row+box_sizes[box].y-1)<=color_maxy)) { + color_found2=1; + } + + + if ((box_found)&&(color_found)&&(color_found2)) { if (debug) fprintf(stderr,"Found box c=%d %d,%d to %d,%d\n", current_color,col,row,col+box_sizes[box].x-1, row+box_sizes[box].y-1); @@ -230,6 +275,9 @@ int create_using_boxes(void) { } } } + find_max_color_extent(current_color, + &color_minx,&color_miny, + &color_maxx,&color_maxy); }