void truecolor_create_tables(void) { pixel_t *table; pixel_t pixel; u32 i; /* Truecolor */ CREATE_COMPONENT_TABLE(red, red); CREATE_COMPONENT_TABLE(green, green); CREATE_COMPONENT_TABLE(blue, blue); CREATE_COMPONENT_TABLE(alpha, transp); /* Grayscale */ gray_bits = min(min(red_bits, green_bits), blue_bits); gray_len = 1<<gray_bits; table = malloc(gray_len*sizeof(pixel_t)); for (i = 0; i < gray_len; i++) { pixel = rgb_pixel(CONVERT_RANGE(i, gray_len-1, red_len-1), CONVERT_RANGE(i, gray_len-1, green_len-1), CONVERT_RANGE(i, gray_len-1, blue_len-1)); table[i] = pixel; } gray_pixel = table; /* Monochrome */ black_pixel = rgb_pixel(0, 0, 0); white_pixel = rgb_pixel(red_len-1, green_len-1, blue_len-1); /* Pseudocolor emulation */ idx_bits = min(red_bits+green_bits+blue_bits, 9); idx_len = 1<<idx_bits; idx_pixel = truecolor_idx_pixel = malloc(idx_len*sizeof(pixel_t)); clut = malloc(idx_len*sizeof(rgba_t)); clut_init_nice(); }
void scrollStyle::draw_scroll_bar_background( const canvas& c, const rectangle& rect, const bool enabled, const long lastx, const long lasty, const bool is_depressed ) const { if ( is_depressed ) draw_checkered( c, rect, rgb_pixel( 0, 0, 0 ), rgb_pixel( 43, 47, 55 ) ); else fill_rect( c, rect, rgb_pixel( 240, 240, 240 ) ); }
void Terrain:: smoothPNG() { image<rgb_pixel> smooth(width, height); float* rgb = new float[3]; float* mid_middle = new float[3]; float* mid_top = new float[3]; float* mid_bottom = new float[3]; float* left_middle = new float[3]; float* left_top = new float[3]; float* left_bottom = new float[3]; float* right_middle = new float[3]; float* right_top = new float[3]; float* right_bottom = new float[3]; for(int z = 1; z < height - 1; z++) { for (int x = 1; x < width - 1; x++) { mid_top = getRGB(x, z-1);//2 mid_middle = getRGB(x, z);//4 mid_bottom = getRGB(x, z+1);//2 left_top = getRGB(x-1, z-1);//1 left_middle = getRGB(x-1, z);//2 left_bottom = getRGB(x-1, z+1);//1 right_top = getRGB(x+1, z-1);//1 right_middle = getRGB(x+1, z);//2 right_bottom = getRGB(x+1, z+1);//1 rgb[0] = (4.0f * mid_middle[0] + 2.0f * mid_top[0] + 2.0f * mid_bottom[0] + 2.0f * left_middle[0] + 2.0f * right_middle[0] + 1.0f * left_top[0] + 1.0f * right_top[0] + 1.0f * left_bottom[0] + 1.0f * right_bottom[0]) / 16.0f; rgb[1] = (4.0f * mid_middle[1] + 2.0f * mid_top[1] + 2.0f * mid_bottom[1] + 2.0f * left_middle[1] + 2.0f * right_middle[1] + 1.0f * left_top[1] + 1.0f * right_top[1] + 1.0f * left_bottom[1] + 1.0f * right_bottom[1]) / 16.0f; rgb[2] = (4.0f * mid_middle[2] + 2.0f * mid_top[2] + 2.0f * mid_bottom[2] + 2.0f * left_middle[2] + 2.0f * right_middle[2] + 1.0f * left_top[2] + 1.0f * right_top[2] + 1.0f * left_bottom[2] + 1.0f * right_bottom[2]) / 16.0f; float r = (float)heightMap.get_pixel(x, z).red; float g = (float)heightMap.get_pixel(x, z).green; float b = (float)heightMap.get_pixel(x, z).blue; //cout << "(" << (float)heightMap.get_pixel(x, z).red << "," << (float)heightMap.get_pixel(x, z).green << "," << (float)heightMap.get_pixel(x, z).blue << ")"; smooth[x][z] = rgb_pixel(rgb[0], rgb[0], rgb[0]); } } //smooth.write("heightmaps/GoodHeightmap1Smoothing.png"); //image<rgb_pixel > image("heightmaps/GoodHeightmap1Smoothing.png"); heightMap = smooth; }
void CodeGenerator::generateRendering(const std::string& filename) const { //Calculate image size int pngWidth=0; int pngHehight=glyphs.at(0).getHeight(); for(int i=0;i<glyphs.size();i++) pngWidth+=glyphs.at(i).getWidth()+1; if(pngWidth==0 || pngHehight==0) throw(runtime_error("Error: height or width of image is zero")); if(log) *logStream<<"PNG: height="<<pngHehight<<" width="<< pngWidth<<endl; if(log) logStream->flush(); image<rgb_pixel> img(pngWidth,pngHehight); const rgb_pixel background(255,255,255); const rgb_pixel foreground(0,0,0); const rgb_pixel separator(255,255,0); int xstart=0;//start of a character for(int i=0;i<glyphs.size();i++) { Glyph current=glyphs.at(i); bool aa=current.isAntialiased(); for(int j=0;j<pngHehight;j++) { for(int k=0;k<current.getWidth();k++) { if(aa==false) { if(current.getPixelAt(k,j)) img.set_pixel(xstart+k,j,foreground); else img.set_pixel(xstart+k,j,background); } else { static const unsigned char values[]={0xff, 0xaa, 0x55, 0x0}; unsigned char color=values[current.getPixelAt(k,j)]; img.set_pixel(xstart+k,j,rgb_pixel(color,color,color)); } } } for(int j=0;j<pngHehight;j++) { img.set_pixel(xstart+current.getWidth(),j,separator); } xstart+=current.getWidth()+1; } img.write(filename); }
// ===================================================== void Palette::init(int size) // ===================================================== { all_colors.clear(); palette_size = size; this_palette.resize(palette_size); int i; for (i=0; i<palette_size; ++i) { all_colors.insert(i); // start from 1 to avoid black as a palette color int j=i+1; unsigned char r=0; unsigned char g=0; unsigned char b=0; int bit=sizeof(unsigned char)*CHAR_BIT-1; for (; j>0; bit--) { // lowest bit should be unused assert(bit>0); unsigned char add=1<<bit; if (j%2) r+=add; j/=2; if (j%2) g+=add; j/=2; if (j%2) b+=add; j/=2; } if (r==0) r=1; rgb_pixel col_i=rgb_pixel(r,g,b); this_palette[i]=col_i; //std::cout<<"palette["<<i<<"]=("<<(int)col_i.r<<","<<(int)col_i.g<<","<<(int)col_i.b<<")\n"; reverse_palette[col_i]=i; //std::cerr<<"> "<<reverse_palette[col_i]<<"\n"; } }
//////////////////////////////////////////////////////////// /// Toogle button style //////////////////////////////////////////////////////////// void TBtStyle::draw_toggle_button( const canvas& c, const rectangle& rect, const bool enabled, const font& mfont, const long lastx, const long lasty, const ustring& name, const bool is_depressed, const bool is_checked ) const { rectangle area = rect.intersect( c ); if ( area.is_empty() ) return; unsigned char red, green, blue; if ( enabled ) { red = 0; green = 0; blue = 0; } else { red = 128; green = 128; blue = 128; } // compute the name length if it hasn't already been computed if ( name_width == 0 ) { unsigned long height; mfont.compute_size( name, name_width, height ); } // figure out where the name string should appear rectangle name_rect; const unsigned long width = name_width; const unsigned long height = mfont.height(); name_rect.set_left(( rect.right() + rect.left() - width ) / 2 ); name_rect.set_top(( rect.bottom() + rect.top() - height ) / 2 + 1 ); name_rect.set_right( name_rect.left() + width - 1 ); name_rect.set_bottom( name_rect.top() + height ); long d = 0; if ( is_checked ) d = 1; if ( is_depressed ) d = 2; name_rect.set_left( name_rect.left() + d ); name_rect.set_right( name_rect.right() + d ); name_rect.set_top( name_rect.top() + d ); name_rect.set_bottom( name_rect.bottom() + d ); // now draw the edge of the button if ( is_checked || is_depressed ) { fill_rect_with_vertical_gradient( c, rect, rgb_pixel( 233, 241, 246 ), rgb_pixel( 197, 220, 232 ) ); mfont.draw_string( c, name_rect, name, rgb_pixel( red, green, blue ) ); draw_button_down( c, rect ); } else { fill_rect_with_vertical_gradient( c, rect, rgb_pixel( 241, 241, 241 ), rgb_pixel( 210, 210, 210 ) ); mfont.draw_string( c, name_rect, name, rgb_pixel( red, green, blue ) ); draw_button_up( c, rect ); } }
void scrollStyle::draw_scroll_bar_slider( const canvas& c, const rectangle& rect, const bool enabled, const long lastx, const long lasty, const bool is_being_dragged ) const { fill_rect_with_vertical_gradient( c, rect, rgb_pixel( 210, 210, 210 ), rgb_pixel( 241, 241, 241 ) ); draw_button_up( c, rect ); }
//////////////////////////////////////////////////////////// /// ButtonArrow style //////////////////////////////////////////////////////////// void arrowBtStyle::draw_button( const canvas& c, const rectangle& rect, const bool enabled, const font& mfont, const long lastx, const long lasty, const ustring& name, const bool is_depressed ) const { rectangle area = rect.intersect( c ); if ( area.is_empty() ) return; const long height = rect.height(); const long width = rect.width(); const long smallest = ( width < height ) ? width : height; const long rows = ( smallest + 3 ) / 4; const long start = rows + rows / 2 - 1; long dep; long tip_x = 0; long tip_y = 0; long wy = 0; long hy = 0; long wx = 0; long hx = 0; if ( is_depressed ) { dep = 0; fill_rect_with_vertical_gradient( c, rect, rgb_pixel( 164, 213, 239 ), rgb_pixel( 232, 246, 253 ) ); // draw the button's border draw_button_down( c, rect ); } else { dep = -1; fill_rect_with_vertical_gradient( c, rect, rgb_pixel( 199, 199, 203 ), rgb_pixel( 242, 242, 242 ) ); // draw the button's border draw_button_up( c, rect ); } switch ( dir ) { case UP: tip_x = width / 2 + rect.left() + dep; tip_y = ( height - start ) / 2 + rect.top() + dep + 1; wy = 0; hy = 1; wx = 1; hx = 0; break; case DOWN: tip_x = width / 2 + rect.left() + dep; tip_y = rect.bottom() - ( height - start ) / 2 + dep; wy = 0; hy = -1; wx = 1; hx = 0; break; case LEFT: tip_x = rect.left() + ( width - start ) / 2 + dep + 1; tip_y = height / 2 + rect.top() + dep; wy = 1; hy = 0; wx = 0; hx = 1; break; case RIGHT: tip_x = rect.right() - ( width - start ) / 2 + dep; tip_y = height / 2 + rect.top() + dep; wy = 1; hy = 0; wx = 0; hx = -1; break; } rgb_pixel color; if ( enabled ) { color.red = 60; color.green = 60; color.blue = 60; } else { color.red = 128; color.green = 128; color.blue = 128; } for ( long i = 0; i < rows; ++i ) { draw_line( c, point( tip_x + wx*i + hx*i, tip_y + wy*i + hy*i ), point( tip_x + wx*i* -1 + hx*i, tip_y + wy*i* -1 + hy*i ), color ); } }
int main(int argc, char **argv) { u16 (*bayer)[WAMI_DEBAYER_IMG_NUM_COLS] = NULL; rgb_pixel (*debayer)[WAMI_DEBAYER_IMG_NUM_COLS-2*PAD] = NULL; char *input_directory = NULL; #ifdef ENABLE_CORRECTNESS_CHECKING rgb_pixel (*gold_debayer)[WAMI_DEBAYER_IMG_NUM_COLS-2*PAD] = NULL; #endif const size_t num_bayer_pixels = WAMI_DEBAYER_IMG_NUM_ROWS * WAMI_DEBAYER_IMG_NUM_COLS; const size_t num_debayer_pixels = (WAMI_DEBAYER_IMG_NUM_ROWS-2*PAD) * (WAMI_DEBAYER_IMG_NUM_COLS-2*PAD); if (argc != 2) { fprintf(stderr, "%s <directory-containing-input-files>\n", argv[0]); exit(EXIT_FAILURE); } input_directory = argv[1]; bayer = XMALLOC(sizeof(u16) * num_bayer_pixels); debayer = XMALLOC(sizeof(rgb_pixel) * num_debayer_pixels); #ifdef ENABLE_CORRECTNESS_CHECKING gold_debayer = XMALLOC(sizeof(rgb_pixel) * num_debayer_pixels); #endif read_image_file( (char *) bayer, input_filename, input_directory, sizeof(u16) * num_bayer_pixels); memset(debayer, 0, sizeof(u16) * num_debayer_pixels); printf("WAMI kernel 1 parameters:\n\n"); printf("Input image width = %u pixels\n", WAMI_DEBAYER_IMG_NUM_COLS); printf("Input image height = %u pixels\n", WAMI_DEBAYER_IMG_NUM_ROWS); printf("Output image width = %u pixels\n", WAMI_DEBAYER_IMG_NUM_COLS-2*PAD); printf("Output image height = %u pixels\n", WAMI_DEBAYER_IMG_NUM_ROWS-2*PAD); printf("\nStarting WAMI kernel 1 (debayer).\n"); tic(); accept_roi_begin(); wami_debayer( debayer, bayer); accept_roi_end(); PRINT_STAT_DOUBLE("CPU time using func toc - ", toc()); #ifdef ENABLE_CORRECTNESS_CHECKING read_image_file( (char *) gold_debayer, golden_output_filename, input_directory, sizeof(rgb_pixel) * num_debayer_pixels); /* * An exact match is expected for the debayer kernel, so we check * each pixel individually and report either the first failure or * a success message. */ { /* // original error metric int r, c, success = 1; for (r = 0; success && r < WAMI_DEBAYER_IMG_NUM_ROWS - 2*PAD; ++r) { for (c = 0; c < WAMI_DEBAYER_IMG_NUM_ROWS - 2*PAD; ++c) { if (ENDORSE(debayer[r][c].r != gold_debayer[r][c].r)) { printf("Validation error: red pixel mismatch at row=%d, col=%d : " "test value = %u, golden value = %u\n\n", r, c, debayer[r][c].r, gold_debayer[r][c].r); success = 0; break; } if (ENDORSE(debayer[r][c].g != gold_debayer[r][c].g)) { printf("Validation error: green pixel mismatch at row=%d, col=%d : " "test value = %u, golden value = %u\n\n", r, c, debayer[r][c].g, gold_debayer[r][c].g); success = 0; break; } if (ENDORSE(debayer[r][c].b != gold_debayer[r][c].b)) { printf("Validation error: blue pixel mismatch at row=%d, col=%d : " "test value = %u, golden value = %u\n\n", r, c, debayer[r][c].b, gold_debayer[r][c].b); success = 0; break; } } } if (success) { printf("\nValidation checks passed -- the test output matches the golden output.\n\n"); } */ // new error metric int r, c; double err; for (r = 0; r < WAMI_DEBAYER_IMG_NUM_ROWS - 2*PAD; ++r) { for (c = 0; c < WAMI_DEBAYER_IMG_NUM_ROWS - 2*PAD; ++c) { double pixel_error = 0.0; pixel_error += ENDORSE(((double) abs(debayer[r][c].r - gold_debayer[r][c].r)) / ((double) 65535)); pixel_error += ENDORSE(((double) abs(debayer[r][c].g - gold_debayer[r][c].g)) / ((double) 65535)); pixel_error += ENDORSE(((double) abs(debayer[r][c].b - gold_debayer[r][c].b)) / ((double) 65535)); err += (pixel_error / ((double) 3)) / ((double) ((WAMI_DEBAYER_IMG_NUM_ROWS - 2*PAD) * (WAMI_DEBAYER_IMG_NUM_ROWS - 2*PAD))); } } FILE *fp = fopen("err.txt", "wb"); assert(fp != NULL); fprintf(fp, "%.2f\n", err); fclose(fp); } #endif #ifdef WRITE_OUTPUT_TO_DISK printf("Writing output to %s/%s.\n", output_directory, output_filename); { const u16 output_channels = 3; write_image_file( (char *) debayer, output_filename, output_directory, WAMI_DEBAYER_IMG_NUM_COLS - 2*PAD, WAMI_DEBAYER_IMG_NUM_ROWS - 2*PAD, output_channels); } #endif FREE_AND_NULL(bayer); FREE_AND_NULL(debayer); #ifdef ENABLE_CORRECTNESS_CHECKING FREE_AND_NULL(gold_debayer); #endif return 0; }
void arrow_button:: draw ( const canvas& c ) const { rectangle area = rect.intersect(c); if (area.is_empty()) return; fill_rect(c,rect,rgb_pixel(212,208,200)); const long height = rect.height(); const long width = rect.width(); const long smallest = (width < height) ? width : height; const long rows = (smallest+3)/4; const long start = rows + rows/2-1; long dep; long tip_x = 0; long tip_y = 0; long wy = 0; long hy = 0; long wx = 0; long hx = 0; if (button_action::is_depressed()) { dep = 0; // draw the button's border draw_button_down(c,rect); } else { dep = -1; // draw the button's border draw_button_up(c,rect); } switch (dir) { case UP: tip_x = width/2 + rect.left() + dep; tip_y = (height - start)/2 + rect.top() + dep + 1; wy = 0; hy = 1; wx = 1; hx = 0; break; case DOWN: tip_x = width/2 + rect.left() + dep; tip_y = rect.bottom() - (height - start)/2 + dep; wy = 0; hy = -1; wx = 1; hx = 0; break; case LEFT: tip_x = rect.left() + (width - start)/2 + dep + 1; tip_y = height/2 + rect.top() + dep; wy = 1; hy = 0; wx = 0; hx = 1; break; case RIGHT: tip_x = rect.right() - (width - start)/2 + dep; tip_y = height/2 + rect.top() + dep; wy = 1; hy = 0; wx = 0; hx = -1; break; } rgb_pixel color; if (enabled) { color.red = 0; color.green = 0; color.blue = 0; } else { color.red = 128; color.green = 128; color.blue = 128; } for (long i = 0; i < rows; ++i) { draw_line(c,point(tip_x + wx*i + hx*i, tip_y + wy*i + hy*i), point(tip_x + wx*i*-1 + hx*i, tip_y + wy*i*-1 + hy*i), color); } }
//***************************************************************************** // METHOD: ossimHsvGridRemapEngine::remapTile // //***************************************************************************** void ossimHsvGridRemapEngine::remapTile(const ossimDpt& origin, ossimGridRemapSource* remapper, ossimRefPtr<ossimImageData>& tile) { static const char MODULE[] = "ossimHsvGridRemapEngine::remapTile"; if (traceExec()) CLOG << "entering..." << endl; //*** // Fetch tile size and NULL pixel value: //*** int width = tile->getWidth(); int height = tile->getHeight(); int offset = 0; void* red_buf = tile->getBuf(0); void* grn_buf = tile->getBuf(1); void* blu_buf = tile->getBuf(2); ossimDblGrid& gridH = *(remapper->getGrid(0)); ossimDblGrid& gridS = *(remapper->getGrid(1)); ossimDblGrid& gridV = *(remapper->getGrid(2)); //--- // Remap according to pixel type: //--- switch(tile->getScalarType()) { case OSSIM_UINT8: { for (double line=origin.line; line<origin.line+height; line+=1.0) { for (double samp=origin.samp; samp<origin.samp+width; samp+=1.0) { //--- // Fetch pixel from the input tile band buffers and convert // to HSV: //--- ossimRgbVector rgb_pixel (((ossim_uint8*)red_buf)[offset], ((ossim_uint8*)grn_buf)[offset], ((ossim_uint8*)blu_buf)[offset]); ossimHsvVector hsv_pixel (rgb_pixel); //--- // Remap pixel HSV with spatially variant bias value: //--- hsv_pixel.setH(hsv_pixel.getH() + gridH(samp,line)); hsv_pixel.setS(hsv_pixel.getS() + gridS(samp,line)); hsv_pixel.setV(hsv_pixel.getV() + gridV(samp,line)); //--- // Convert back to RGB and write to the tile: //--- rgb_pixel = hsv_pixel; // auto-clamped ((ossim_uint8*)red_buf)[offset] = rgb_pixel.getR(); ((ossim_uint8*)grn_buf)[offset] = rgb_pixel.getG(); ((ossim_uint8*)blu_buf)[offset] = rgb_pixel.getB(); offset++; } } break; } case OSSIM_USHORT11: break; case OSSIM_UINT16: break; case OSSIM_SINT16: break; case OSSIM_FLOAT64: break; case OSSIM_NORMALIZED_DOUBLE: break; case OSSIM_FLOAT32: break; case OSSIM_NORMALIZED_FLOAT: break; case OSSIM_SCALAR_UNKNOWN: default: break; } // end switch statement if (traceExec()) CLOG << "returning..." << endl; return; };