int main( const int argc, const char **argv) { int function = atoi( argv[1]), i; char buff[200]; FILE *ifile = fopen( "loneos.phot", "rb"); double limits[12] = { -.4, 3.9, -.4, 2., /* V-I to B-V */ -.5, 4.2, -.4, 2.1, /* V-I to V-R */ -.3, 2., -.4, 2.2 }; /* V-R to B-V */ double *lim = limits + function * 4; int xcolumns[3] = { 75, 75, 69 }; int ycolumns[3] = { 63, 69, 63 }; _setvideomode( _VRES16COLOR); _setcolor( 2); for( i = 0; i < 640; i++) { double ocolor, icolor = lim[0] + (lim[1] - lim[0]) * (double)i / 640.; if( function == 0) ocolor = v_minus_i_to_b_minus_v( icolor); else if( function == 1) ocolor = v_minus_i_to_v_minus_r( icolor); else ocolor = v_minus_r_to_b_minus_v( icolor); _setpixel( (short)i, (short)( 480. * (ocolor-lim[3]) / (lim[2]-lim[3]))); } _setcolor( 3); while( fgets( buff, sizeof( buff), ifile)) { if( buff[xcolumns[function]] == '.' && buff[ycolumns[function]] == '.') { double icolor = atof( buff + xcolumns[function] - 2); double ocolor = atof( buff + ycolumns[function] - 2); int xpixel = (int)( 640. * (icolor-lim[0]) / (lim[1]-lim[0])); int ypixel = (int)( 480. * (ocolor-lim[3]) / (lim[2]-lim[3])); short ix, iy; short deltas[9 * 2] = { 0,0, 1,0, 0,1, -1,0, 0,-1, 1,1, 1,-1, -1,-1, -1,1 }; for( i = 0; i < 18; i += 2) { ix = (short)( xpixel + deltas[i]); iy = (short)( ypixel + deltas[i + 1]); if( !_getpixel( ix, iy)) i = 99; } if( i != 18) _setpixel( ix, iy); } buff[xcolumns[function]] = buff[ycolumns[function]] = ' '; } fclose( ifile); getch( ); _setvideomode( _DEFAULTMODE); return( 0); }
static void _find_cage_borders(IplImage *threshold_image, IplImage **annotated, puzzle_size size, border_direction direction, border_direction opposite, short cage_borders[PUZZLE_SIZE_MAX][PUZZLE_SIZE_MAX][4]) { assert(threshold_image->height == threshold_image->width); int px_size = threshold_image->height; // first figure out, for this puzzle, the difference between a cage border and // a regular edge. We'll do this via the mean intensity of the rough location // where we expect the edges to be. int fuzz_along = px_size / (size * 3.9); int fuzz_across = px_size / (size * 4.0); int means[size][size]; int mean_max = -1; int mean_min = -1; for (int box_along = 0; box_along < size; ++box_along) { int along_center = (2 * box_along + 1) * (px_size / size / 2); for (int box_across = 0; box_across < (size - 1); ++box_across) { int across_center = (box_across + 1) * (px_size / size); long total = 0; for (int across = across_center - fuzz_across; across <= across_center + fuzz_across; ++across) { for (int along = along_center - fuzz_along; along <= along_center + fuzz_along; ++along) { CvScalar s = _getpixel(threshold_image, annotated, direction, across, along); total += s.val[0]; } } int mean = total / ((2 * fuzz_along + 1) * (2 * fuzz_across + 1)); means[box_across][box_along] = mean; if ((mean_max == -1) || (mean > mean_max)) { mean_max = mean; } if ((mean_min == -1) || (mean < mean_min)) { mean_min = mean; } } } for (int box_along = 0; box_along < size; ++box_along) { int box_across; for (box_across = 0; box_across < (size - 1); ++box_across) { int delta_min = abs(means[box_across][box_along] - mean_min); int delta_max = abs(means[box_across][box_along] - mean_max); *(_getborder(cage_borders, direction, box_across, box_along)) = (delta_max < delta_min); } *(_getborder(cage_borders, direction, box_across, box_along)) = 1; } for (int box_along = 0; box_along < size; ++box_along) { int box_across = 0; *(_getborder(cage_borders, opposite, box_across, box_along)) = 1; for (box_across = 1; box_across < size; ++box_across) { *(_getborder(cage_borders, opposite, box_across, box_along)) = *(_getborder(cage_borders, direction, box_across - 1, box_along)); } } return; }
main(int argc,char *argv[]) { int a; FILE *f1; if(argc==1) { printf("usage: FONT <srclbm> <desttmpfont>"); return(0); } _setvideomode(_VRES16COLOR); for(a=0;a<256;a++) { f_off[a]=0; f_wid[a]=0; f_hig[a]=0; } avercnt=0; averwid=0; out=fopen(argv[2],"wb"); putw(0x1a1a,out); putw(tablep,out); fwrite(tablex,1,256,out); fwrite(tabley,1,256,out); f1=fopen(argv[1],"rb"); readlbm(f1); { char buf[64]; int x0,y0,x,y,a; for(y0=2;y0<7*8-2;y0+=8) for(x0=0;x0<56*8;x0+=8) { for(a=x=0;x<8;x++) for(y=0;y<8;y++) { if((buf[x+y*8]=_getpixel(x0+x,y0+y))==0) a=1; } if(a) { tablex[tablep]=x0/8; tabley[tablep++]=(y0-2)/8; for(y=0;y<8;y++) { for(a=x=0;x<8;x++) { if(!buf[x+y*8]) a+=128>>x; } putc(a,out); } _setcolor(15); } else _setcolor(8); _setpixel(x0,y0); } }
// Round down the supplied co-ordinates to the area granularity, // and move a bit if this causes them to become non-walkable void round_down_coords(int &tmpx, int &tmpy) { int startgran = walk_area_granularity[_getpixel(wallscreen, tmpx, tmpy)]; tmpy = tmpy - tmpy % startgran; if (tmpy < 0) tmpy = 0; tmpx = tmpx - tmpx % startgran; if (tmpx < 0) tmpx = 0; if (_getpixel(wallscreen, tmpx, tmpy) == 0) { tmpx += startgran; if ((_getpixel(wallscreen, tmpx, tmpy) == 0) && (tmpy < wallscreen->h - startgran)) { tmpy += startgran; if (_getpixel(wallscreen, tmpx, tmpy) == 0) tmpx -= startgran; } } }
void ALSoftwareGraphicsDriver::draw_sprite_with_transparency(BITMAP* piccy, int xxx, int yyy, int transparency) { int screen_depth = bitmap_color_depth(virtualScreen); int sprite_depth = bitmap_color_depth(piccy); if (sprite_depth < screen_depth) { if ((sprite_depth == 8) && (screen_depth >= 24)) { // 256-col sprite -> truecolor background // this is automatically supported by allegro, no twiddling needed draw_sprite(virtualScreen, piccy, xxx, yyy); return; } // 256-col spirte -> hi-color background, or // 16-bit sprite -> 32-bit background BITMAP* hctemp=create_bitmap_ex(screen_depth, piccy->w, piccy->h); blit(piccy,hctemp,0,0,0,0,hctemp->w,hctemp->h); int bb,cc,mask_col = bitmap_mask_color(virtualScreen); if (sprite_depth == 8) { // only do this for 256-col, cos the blit call converts // transparency for 16->32 bit for (bb=0; bb<hctemp->w; bb++) { for (cc=0; cc<hctemp->h; cc++) if (_getpixel(piccy,bb,cc)==0) putpixel(hctemp,bb,cc,mask_col); } } draw_sprite(virtualScreen, hctemp, xxx, yyy); destroy_bitmap(hctemp); } else { if ((transparency != 0) && (screen_depth > 8) && (sprite_depth > 8) && (bitmap_color_depth(virtualScreen) > 8)) { set_trans_blender(0,0,0, transparency); draw_trans_sprite(virtualScreen, piccy, xxx, yyy); } else draw_sprite(virtualScreen, piccy, xxx, yyy); } }
int Bitmap::GetPixel(int x, int y) const { if (x < 0 || x >= _alBitmap->w || y < 0 || y >= _alBitmap->h) { return -1; // Allegros getpixel() implementation returns -1 in this case } switch (bitmap_color_depth(_alBitmap)) { case 8: return _getpixel(_alBitmap, x, y); case 15: return _getpixel15(_alBitmap, x, y); case 16: return _getpixel16(_alBitmap, x, y); case 24: return _getpixel24(_alBitmap, x, y); case 32: return _getpixel32(_alBitmap, x, y); } assert(0); // this should not normally happen return getpixel(_alBitmap, x, y); }