void TCOD_image_blit_2x(TCOD_image_t image, TCOD_console_t con, int dx, int dy, int sx, int sy, int w, int h) { TCOD_color_t grid[4]; TCOD_color_t cols[2]; int nbCols; int width,height,ascii,cx,cy; TCOD_console_data_t *dat = con ? (TCOD_console_data_t *)(con) : TCOD_ctx.root; image_data_t *img=(image_data_t *)image; int maxx,maxy; TCOD_IFNOT(image != NULL && dat != NULL) return; TCOD_image_get_size(image,&width,&height); if ( w == -1 ) w=width; if ( h == -1 ) h=height; /* check that the sx,sy/w,h rectangle is inside the image */ TCOD_ASSERT(sx >= 0 && sy >= 0 && sx+w <= width && sy+h <= height); TCOD_IFNOT(w > 0 && h > 0) return; sx=MAX(0,sx); sy=MAX(0,sy); w = MIN(w,width-sx); h = MIN(h,height-sy); maxx=dx+w/2 <= dat->w ? w : (dat->w-dx)*2; maxy=dy+h/2 <= dat->h ? h : (dat->h-dy)*2; /* check that the image is not blitted outside the console */ TCOD_IFNOT(dx+maxx/2 >= 0 && dy+maxy/2 >= 0 && dx < dat->w && dy < dat->h) return; maxx+=sx; maxy+=sy; for (cx=sx; cx < maxx; cx += 2) { for (cy=sy; cy < maxy; cy += 2) { /* get the 2x2 super pixel colors from the image */ int conx=dx+(cx-sx)/2; int cony=dy+(cy-sy)/2; TCOD_color_t consoleBack=TCOD_console_get_char_background(con,conx,cony); grid[0]=TCOD_image_get_pixel(image,cx,cy); if ( img->has_key_color && grid[0].r == img->key_color.r && grid[0].g == img->key_color.g && grid[0].b == img->key_color.b) grid[0]=consoleBack; if ( cx < maxx-1 ) { grid[1]=TCOD_image_get_pixel(image,cx+1,cy); if ( img->has_key_color && grid[1].r == img->key_color.r && grid[1].g == img->key_color.g && grid[1].b == img->key_color.b) grid[1]=consoleBack; } else grid[1]=consoleBack; if ( cy < maxy-1 ) { grid[2]=TCOD_image_get_pixel(image,cx,cy+1); if ( img->has_key_color && grid[2].r == img->key_color.r && grid[2].g == img->key_color.g && grid[2].b == img->key_color.b) grid[2]=consoleBack; } else grid[2]=consoleBack; if ( cx < maxx-1 && cy < maxy-1 ) { grid[3]=TCOD_image_get_pixel(image,cx+1,cy+1); if ( img->has_key_color && grid[3].r == img->key_color.r && grid[3].g == img->key_color.g && grid[3].b == img->key_color.b) grid[3]=consoleBack; } else grid[3]=consoleBack; /* analyse color, posterize, get pattern */ getPattern(grid,cols,&nbCols,&ascii); if ( nbCols == 1 ) { /* single color */ TCOD_console_set_char_background(con,conx,cony,cols[0],TCOD_BKGND_SET); TCOD_console_set_char(con,conx,cony,' '); } else { if ( ascii >= 0 ) { TCOD_console_set_default_background(con,cols[0]); TCOD_console_set_default_foreground(con,cols[1]); TCOD_console_put_char(con,conx,cony,ascii,TCOD_BKGND_SET); } else { /* negative ascii code means we need to invert back/fore colors */ TCOD_console_set_default_background(con,cols[1]); TCOD_console_set_default_foreground(con,cols[0]); TCOD_console_put_char(con,conx,cony,-ascii,TCOD_BKGND_SET); } } } } }
colornum_t TCOD_console_get_char_background_wrapper(TCOD_console_t con, int x, int y) { return color_to_int(TCOD_console_get_char_background (con, x, y)); }
TCODColor TCODConsole::getCharBackground(int x, int y) const { return TCOD_console_get_char_background(data,x,y); }