int TessDllAPI::BeginPage(uinT32 xsize,uinT32 ysize,unsigned char *buf,uinT8 bpp) { inT16 c; EndPage(); if (page_image.create (xsize+800, ysize+800, 1)==-1) return 0L; //make the image bigger to enclose in whitespace //copy the passed buffer into the center of the image IMAGE tmp; tmp.create(xsize, ysize, bpp); for (c=0;c<ysize;c++) CopyMemory(tmp.get_buffer ()+(c)*((xsize*bpp + 7)/8), buf+((ysize-1)-c)*((xsize*bpp + 7)/8),((xsize*bpp + 7)/8)); copy_sub_image(&tmp, 0, 0, 0, 0, &page_image, 400, 400, false); return ProcessPagePass1(); }
void find_components( BLOCK_LIST *blocks, TO_BLOCK_LIST *land_blocks, TO_BLOCK_LIST *port_blocks, TBOX *page_box) { BLOCK *block; //current block PDBLK_CLIST pd_blocks; //copy of list BLOCK_IT block_it = blocks; //iterator PDBLK_C_IT pd_it = &pd_blocks; //iterator IMAGE thresh_image; //thresholded int width = page_image.get_xsize(); int height = page_image.get_ysize(); if (width > MAX_INT16 || height > MAX_INT16) { tprintf("Input image too large! (%d, %d)\n", width, height); return; // Can't handle it. } ICOORD page_tr(width, height); block_it.set_to_list (blocks); if (global_monitor != NULL) global_monitor->ocr_alive = TRUE; set_global_loc_code(LOC_EDGE_PROG); if (!page_image.white_high ()) invert_image(&page_image); #ifndef EMBEDDED previous_cpu = clock (); #endif for (block_it.mark_cycle_pt(); !block_it.cycled_list(); block_it.forward()) { block = block_it.data(); if (block->poly_block() == NULL || block->poly_block()->IsText()) { #ifndef GRAPHICS_DISABLED extract_edges(NULL, &page_image, &page_image, page_tr, block); #else extract_edges(&page_image, &page_image, page_tr, block); #endif *page_box += block->bounding_box (); } } if (global_monitor != NULL) { global_monitor->ocr_alive = TRUE; global_monitor->progress = 10; } assign_blobs_to_blocks2(blocks, land_blocks, port_blocks); if (global_monitor != NULL) global_monitor->ocr_alive = TRUE; filter_blobs (page_box->topright (), land_blocks, textord_test_landscape); #ifndef EMBEDDED previous_cpu = clock (); #endif filter_blobs (page_box->topright (), port_blocks, !textord_test_landscape); if (global_monitor != NULL) global_monitor->ocr_alive = TRUE; }
void scale_image_cop_out( //scale an image IMAGE &image, //source image IMAGE &target_image, //target image float factor, //scale factor int *hires, int *lores, int *oldhires, int *oldlores) { inT32 xsize, ysize, new_xsize, new_ysize; xsize = image.get_xsize (); ysize = image.get_ysize (); new_xsize = target_image.get_xsize (); new_ysize = target_image.get_ysize (); if (factor <= 0.5) reduce_sub_image (&image, 0, 0, xsize, ysize, &target_image, 0, 0, (inT32) (1.0 / factor), FALSE); else if (factor >= 2) enlarge_sub_image (&image, 0, 0, &target_image, 0, 0, new_xsize, new_ysize, (inT32) factor, FALSE); else copy_sub_image (&image, 0, 0, xsize, ysize, &target_image, 0, 0, FALSE); free(hires); free(lores); free(oldhires); free(oldlores); }
/* Call a stop function if a sequence is running in this VipsRegion. */ void vips__region_stop( VipsRegion *region ) { IMAGE *image = region->im; if( region->seq && image->stop_fn ) { int result; VIPS_GATE_START( "vips__region_stop: wait" ); g_mutex_lock( image->sslock ); VIPS_GATE_STOP( "vips__region_stop: wait" ); result = image->stop_fn( region->seq, image->client1, image->client2 ); g_mutex_unlock( image->sslock ); /* stop function can return an error, but we have nothing we * can really do with it, sadly. */ if( result ) vips_warn( "VipsRegion", "stop callback failed for image %s", image->filename ); region->seq = NULL; } }
void M_clear(POINT pt, IMAGE *bk)//pt上一个动作图片的输出坐标,bk背景图片 { IMAGE clear; SetWorkingImage(bk);//设定当前的绘图设备为背景图片 getimage(&clear, pt.x, pt.y, background.getwidth(), background.getheight());//获取图像 SetWorkingImage();//设定回默认绘图窗口 putimage(pt.x, pt.y, &clear);//输出 }
// Cut out the requested rectangle of the binary image to the // tesseract global image ready for recognition. void TessBaseAPI::CopyBinaryRect(const unsigned char* imagedata, int bytes_per_line, int left, int top, int width, int height) { // Copy binary image, cutting out the required rectangle. IMAGE image; image.capture(const_cast<unsigned char*>(imagedata), bytes_per_line*8, top + height, 1); page_image.create(width, height, 1); copy_sub_image(&image, left, 0, width, height, &page_image, 0, 0, false); }
/************* * DESCRIPTION: find image with name 'name' * INPUT: imagename name of image * OUTPUT: pointer to image, NULL if non found *************/ IMAGE* FindImage(RSICONTEXT *rc, char *imagename) { IMAGE *cur; cur = rc->image_root; while(cur && cur->name) { if(!strcmp(imagename, cur->name)) return cur; cur = (IMAGE*)cur->GetNext(); } return NULL; }
WINDOW display_clip_image(WERD *word, //word to be processed IMAGE &bin_image, //whole image PIXROW_LIST *pixrow_list, //pixrows built BOX &pix_box //box of subimage ) { WINDOW clip_window; //window for debug BOX word_box = word->bounding_box (); int border = word_box.height () / 2; BOX display_box = word_box; display_box.move_bottom_edge (-border); display_box.move_top_edge (border); display_box.move_left_edge (-border); display_box.move_right_edge (border); display_box -= BOX (ICOORD (0, 0 - BUG_OFFSET), ICOORD (bin_image.get_xsize (), bin_image.get_ysize () - BUG_OFFSET)); pgeditor_msg ("Creating Clip window..."); clip_window = create_window ("Clipped Blobs", SCROLLINGWIN, editor_word_xpos, editor_word_ypos, 3 * (word_box.width () + 2 * border), 3 * (word_box.height () + 2 * border), //window width,height // xmin, xmax display_box.left (), display_box.right (), display_box.bottom () - BUG_OFFSET, display_box.top () - BUG_OFFSET, // ymin, ymax TRUE, FALSE, FALSE, TRUE); // down event & key only pgeditor_msg ("Creating Clip window...Done"); clear_view_surface(clip_window); show_sub_image (&bin_image, display_box.left (), display_box.bottom (), display_box.width (), display_box.height (), clip_window, display_box.left (), display_box.bottom () - BUG_OFFSET); word->plot (clip_window, RED); word_box.plot (clip_window, INT_HOLLOW, TRUE, BLUE, BLUE); pix_box.plot (clip_window, INT_HOLLOW, TRUE, BLUE, BLUE); plot_pixrows(pixrow_list, clip_window); overlap_picture_ops(TRUE); return clip_window; }
//Set up variables bool DemoInit() { if(!window.Init("Project Template", 640, 480, 32, 24, 8, WINDOWED_SCREEN)) return 0; //quit if not created SetUpARB_multitexture(); SetUpEXT_texture3D(); SetUpEXT_texture_edge_clamp(); SetUpNV_register_combiners(); SetUpNV_texture_shader(); SetUpNV_vertex_program(); if( !EXT_texture_edge_clamp_supported || !ARB_multitexture_supported || !NV_vertex_program_supported || !NV_register_combiners_supported) return false; //Check we have at least 3 texture units GLint maxTextureUnitsARB; glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &maxTextureUnitsARB); if(maxTextureUnitsARB<3) { errorLog.OutputError("I require at least 3 texture units"); return false; } //Set light colors lightColors[0].Set(1.0f, 1.0f, 1.0f, 1.0f); lightColors[1].Set((float)47/255, (float)206/255, (float)240/255, 1.0f); lightColors[2].Set((float)254/255, (float)48/255, (float)18/255, 1.0f); lightColors[3].Set((float)83/255, (float)243/255, (float)29/255, 1.0f); //Load textures //Decal image decalImage.Load("decal.tga"); glGenTextures(1, &decalTexture); glBindTexture(GL_TEXTURE_2D, decalTexture); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, decalImage.width, decalImage.height, 0, decalImage.format, GL_UNSIGNED_BYTE, decalImage.data); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); //Create light textures if(!InitLightTextures( atten1DTexture, atten2DTexture, atten3DTexture, gaussian1DTexture, gaussian2DTexture)) return false; camera.Init(VECTOR3D(0.0f, 0.0f, 3.5f)); //reset timer for start timer.Reset(); return true; }
EXPORT(void) BlitImage(IMAGE image, int x, int y, CImage32::BlendMode blendmode) { // don't draw it if it's off the screen if (x + image->width < ClippingRectangle.left || y + image->height < ClippingRectangle.top || x > ClippingRectangle.right || y > ClippingRectangle.bottom) { return; } switch (blendmode) { case CImage32::BLEND: image->blit_routine(image, x, y); break; case CImage32::ADD: AddBlit(image, x, y); break; case CImage32::SUBTRACT: SubtractBlit(image, x, y); break; case CImage32::MULTIPLY: MultiplyBlit(image, x, y); break; } }
void extract_edges(Pix* pix, // thresholded image BLOCK *block) { // block to scan C_OUTLINE_LIST outlines; // outlines in block C_OUTLINE_IT out_it = &outlines; // TODO(rays) move the pix all the way down to the bottom. IMAGE image; image.FromPix(pix); block_edges(&image, block, &out_it); ICOORD bleft; // block box ICOORD tright; block->bounding_box(bleft, tright); // make blobs outlines_to_blobs(block, bleft, tright, &outlines); }
/* Generate into a region. */ static int fill_region( REGION *reg ) { IMAGE *im = reg->im; /* Start new sequence, if necessary. */ if( im__call_start( reg ) ) return( -1 ); /* Ask for evaluation. */ if( im->generate( reg, reg->seq, im->client1, im->client2 ) ) return( -1 ); return( 0 ); }
/* Call a stop function if a sequence is running in this REGION. No error * return is possible, really. */ void im__call_stop( REGION *reg ) { IMAGE *im = reg->im; int res; /* Stop any running sequence. */ if( reg->seq && im->stop ) { g_mutex_lock( im->sslock ); res = im->stop( reg->seq, im->client1, im->client2 ); g_mutex_unlock( im->sslock ); if( res ) error_exit( "panic: user stop callback failed " "for image %s", im->filename ); reg->seq = NULL; } }
int TessDllAPI::BeginPageUpright(uinT32 xsize,uinT32 ysize,unsigned char *buf, uinT8 bpp) { EndPage(); //It looks like Adaptive thresholding is disabled so this must be a 1 bpp image if (page_image.create (xsize+800, ysize+800, 1)==-1) return 0L; //make the image bigger to enclose in whitespace //copy the passed buffer into the center of the image IMAGE tmp; tmp.capture(buf, xsize, ysize, bpp); copy_sub_image(&tmp, 0, 0, 0, 0, &page_image, 400, 400, true); return ProcessPagePass1(); }
CHAR_SAMPLE *clip_sample( //lines of the image PIXROW *pixrow, IMAGELINE *imlines, TBOX pix_box, //box of imlines extent BOOL8 white_on_black, char c) { TBOX b_box = pixrow->bounding_box (); float baseline_pos = 0; inT32 resolution = page_image.get_res (); if (!b_box.null_box ()) { ASSERT_HOST (b_box.width () < page_image.get_xsize () && b_box.height () < page_image.get_ysize ()); if (b_box.width () > resolution || b_box.height () > resolution) { tprintf ("clip sample: sample too big (%d x %d)\n", b_box.width (), b_box.height ()); return NULL; } IMAGE *image = new (IMAGE); if (image->create (b_box.width (), b_box.height (), 1) == -1) { tprintf ("clip sample: create image failed (%d x %d)\n", b_box.width (), b_box.height ()); delete image; return NULL; } if (!white_on_black) invert_image(image); // Set background to white pixrow->char_clip_image (imlines, pix_box, NULL, *image, baseline_pos); if (white_on_black) invert_image(image); //invert white on black for scaling &NN return new CHAR_SAMPLE (image, c); } else return NULL; }
/* Call a start function if no sequence is running on this REGION. */ int im__call_start( REGION *reg ) { IMAGE *im = reg->im; /* Have we a sequence running on this region? Start one if not. */ if( !reg->seq && im->start ) { g_mutex_lock( im->sslock ); reg->seq = im->start( im, im->client1, im->client2 ); g_mutex_unlock( im->sslock ); if( !reg->seq ) { im_error( "im__call_start", _( "start function failed for image %s" ), im->filename ); return( -1 ); } } return( 0 ); }
IMAGE *CHAR_PROTO::make_image() { IMAGE *image; IMAGELINE imline_p; INT32 x; INT32 y; ASSERT_HOST (nsamples != 0); image = new (IMAGE); image->create (xsize, ysize, 8); for (y = 0; y < ysize; y++) { image->fast_get_line (0, y, xsize, &imline_p); for (x = 0; x < xsize; x++) { imline_p.pixels[x] = 128 + (UINT8) ((proto[x][y] * 128.0) / (0.00001 + nsamples)); } image->fast_put_line (0, y, xsize, &imline_p); } return image; }
// Copy the raw image rectangle, taking all data from the class, to the Pix. void ImageThresholder::RawRectToPix(Pix** pix) const { if (image_bytespp_ < 4) { // Go via a tesseract image structure (doesn't copy the data) // and use ToPix. IMAGE image; int bits_per_pixel = image_bytespp_ * 8; if (image_bytespp_ == 0) bits_per_pixel = 1; image.capture(const_cast<uinT8*>(image_data_), image_width_, rect_top_ + rect_height_, bits_per_pixel); if (IsFullImage()) { *pix = image.ToPix(); } else { IMAGE rect; rect.create(rect_width_, rect_height_, bits_per_pixel); // The capture chopped the image off at top+height, so copy // the rectangle with y = 0 to get a rectangle of height // starting at the bottom, since copy_sub_image uses bottom-up coords. copy_sub_image(&image, rect_left_, 0, rect_width_, rect_height_, &rect, 0, 0, true); *pix = rect.ToPix(); } } else { *pix = pixCreate(rect_width_, rect_height_, 32); uinT32* data = pixGetData(*pix); int wpl = pixGetWpl(*pix); const uinT8* imagedata = image_data_ + rect_top_ * image_bytespl_ + rect_left_ * image_bytespp_; for (int y = 0; y < rect_height_; ++y) { const uinT8* linedata = imagedata; uinT32* line = data + y * wpl; for (int x = 0; x < rect_width_; ++x) { line[x] = (linedata[0] << 24) | (linedata[1] << 16) | (linedata[2] << 8) | linedata[3]; linedata += 4; } imagedata += image_bytespl_; } } }
HRESULT Update( IMAGE &Image, wchar_t *str, LOGFONTW &LogFont, COLORREF color, DWORD &Width, DWORD &Height ){ return Image.Update ( str, LogFont, color, Width, Height ) ; }
HRESULT Update( IMAGE &Image, IDirect3DSurface9 *pSur ){ CDeviceManager dev(m_D3D) ; return Image.Update(dev.GetDevice(), m_pDXVAHD, pSur) ; }
HRESULT Update( IMAGE &Image, YUV_FRAME_INFO *pInfo ){ return Image.Update(Image, pInfo) ; }
HRESULT Update( IMAGE &Image, BYTE *pFrame, long Stride ){ return Image.Update(pFrame, Stride) ; }
void PIXROW::char_clip_image( //box of imlines extnt IMAGELINE *imlines, BOX &im_box, ROW *row, //row containing word IMAGE &clip_image, //unscaled sq subimage float &baseline_pos //baseline ht in image ) { INT16 clip_image_xsize; //sub image x size INT16 clip_image_ysize; //sub image y size INT16 x_shift; //from pixrow to subim INT16 y_shift; //from pixrow to subim BOX char_pix_box; //bbox of char pixels INT16 y_dest; INT16 x_min; INT16 x_max; INT16 x_min_dest; INT16 x_max_dest; INT16 x_width; INT16 y; clip_image_xsize = clip_image.get_xsize (); clip_image_ysize = clip_image.get_ysize (); char_pix_box = bounding_box (); /* The y shift is calculated by first finding the coord of the bottom of the image relative to the image lines. Then reducing this so by the amount relative to the clip image size, necessary to vertically position the character. */ y_shift = char_pix_box.bottom () - row_offset - (INT16) floor ((clip_image_ysize - char_pix_box.height () + 0.5) / 2); /* The x_shift is the shift to be applied to the page coord in the pixrow to generate a centred char in the clip image. Thus the left hand edge of the char is shifted to the margin width of the centred character. */ x_shift = char_pix_box.left () - (INT16) floor ((clip_image_xsize - char_pix_box.width () + 0.5) / 2); for (y = 0; y < row_count; y++) { /* Check that there is something in this row of the source that will fit in the sub image. If there is, reduce x range if necessary, then copy it */ y_dest = y - y_shift; if ((min[y] <= max[y]) && (y_dest >= 0) && (y_dest < clip_image_ysize)) { x_min = min[y]; x_min_dest = x_min - x_shift; if (x_min_dest < 0) { x_min = x_min - x_min_dest; x_min_dest = 0; } x_max = max[y]; x_max_dest = x_max - x_shift; if (x_max_dest > clip_image_xsize - 1) { x_max = x_max - (x_max_dest - (clip_image_xsize - 1)); x_max_dest = clip_image_xsize - 1; } x_width = x_max - x_min + 1; if (x_width > 0) { x_min -= im_box.left (); //offset pixel ptr imlines[y].pixels += x_min; clip_image.put_line (x_min_dest, y_dest, x_width, imlines + y, 0); imlines[y].init (); //reset pixel ptr } } } /* Baseline position relative to clip image: First find the baseline relative to the page origin at the x coord of the centre of the character. Then make this relative to the character bottom. Finally shift by the margin between the bottom of the character and the bottom of the clip image. */ if (row == NULL) baseline_pos = 0; //Not needed else baseline_pos = row->base_line ((char_pix_box.left () + char_pix_box.right ()) / 2.0) - char_pix_box.bottom () + ((clip_image_ysize - char_pix_box.height ()) / 2); }
void display_images(IMAGE &clip_image, IMAGE &scaled_image) { WINDOW clip_im_window; //window for debug WINDOW scale_im_window; //window for debug INT16 i; GRAPHICS_EVENT event; // c; // xmin xmax ymin ymax clip_im_window = create_window ("Clipped Blob", SCROLLINGWIN, editor_word_xpos - 20, editor_word_ypos - 100, 5 * clip_image.get_xsize (), 5 * clip_image.get_ysize (), 0, clip_image.get_xsize (), 0, clip_image.get_ysize (), TRUE, FALSE, FALSE, TRUE); // down event & key only clear_view_surface(clip_im_window); show_sub_image (&clip_image, 0, 0, clip_image.get_xsize (), clip_image.get_ysize (), clip_im_window, 0, 0); line_color_index(clip_im_window, RED); for (i = 1; i < clip_image.get_xsize (); i++) { move2d (clip_im_window, i, 0); draw2d (clip_im_window, i, clip_image.get_xsize ()); } for (i = 1; i < clip_image.get_ysize (); i++) { move2d (clip_im_window, 0, i); draw2d (clip_im_window, clip_image.get_xsize (), i); } // xmin xmax ymin ymax scale_im_window = create_window ("Scaled Blob", SCROLLINGWIN, editor_word_xpos + 300, editor_word_ypos - 100, 5 * scaled_image.get_xsize (), 5 * scaled_image.get_ysize (), 0, scaled_image.get_xsize (), 0, scaled_image.get_ysize (), TRUE, FALSE, FALSE, TRUE); // down event & key only clear_view_surface(scale_im_window); show_sub_image (&scaled_image, 0, 0, scaled_image.get_xsize (), scaled_image.get_ysize (), scale_im_window, 0, 0); line_color_index(scale_im_window, RED); for (i = 1; i < scaled_image.get_xsize (); i++) { move2d (scale_im_window, i, 0); draw2d (scale_im_window, i, scaled_image.get_xsize ()); } for (i = 1; i < scaled_image.get_ysize (); i++) { move2d (scale_im_window, 0, i); draw2d (scale_im_window, scaled_image.get_xsize (), i); } overlap_picture_ops(TRUE); await_event(scale_im_window, TRUE, ANY_EVENT, &event); destroy_window(clip_im_window); destroy_window(scale_im_window); }
//Set up variables bool DemoInit() { //Seed random number generator srand( (unsigned)time( NULL ) ); //Initialise the array of vertices numVertices=gridDensity*gridDensity; vertices=new SIMPLE_VERTEX[numVertices]; if(!vertices) { LOG::Instance()->OutputError("Unable to allocate space for %d vertices", numVertices); return false; } for(int i=0; i<gridDensity; ++i) { for(int j=0; j<gridDensity; ++j) { vertices[i*gridDensity+j].position.Set( (float(i)/(gridDensity-1))*2-1, 0.0f, (float(j)/(gridDensity-1))*2-1); vertices[i*gridDensity+j].normal.Set( 0.0f, 1.0f, 0.0f); vertices[i*gridDensity+j].texCoords.Set( (float(i)/(gridDensity-1)), -(float(j)/(gridDensity-1))); } } //Initialise the indices numIndices=2*(gridDensity)*(gridDensity-1); indices=new GLuint[numIndices]; if(!indices) { LOG::Instance()->OutputError("Unable to allocate space for %d indices", numIndices); return false; } for(int i=0; i<gridDensity-1; ++i) { for(int j=0; j<gridDensity; ++j) { indices[(i*gridDensity+j)*2 ]=(i+1)*gridDensity+j; indices[(i*gridDensity+j)*2+1]=i*gridDensity+j; } } //Load texture IMAGE floorImage; floorImage.Load("OpenGL.tga"); if(floorImage.paletted) floorImage.ExpandPalette(); glGenTextures(1, &floorTexture); glBindTexture(GL_TEXTURE_2D, floorTexture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); gluBuild2DMipmaps( GL_TEXTURE_2D, GL_RGBA8, floorImage.width, floorImage.height, floorImage.format, GL_UNSIGNED_BYTE, floorImage.data); //Initialise the lights for(int i=0; i<numLights; ++i) { lights[i].position.Set( (float(rand())/RAND_MAX)*2-1, 0.02f, (float(rand())/RAND_MAX)*2-1); lights[i].velocity.Set( (float(rand())/RAND_MAX)*2-1, 0.0f, (float(rand())/RAND_MAX)*2-1); lights[i].color.Set( (float(rand())/RAND_MAX)*0.75f, (float(rand())/RAND_MAX)*0.75f, (float(rand())/RAND_MAX)*0.75f, 1.0f); } //Load vertex programs if(GLEE_NV_vertex_program) { glGenProgramsNV(1, &vp1); glBindProgramNV(GL_VERTEX_PROGRAM_NV, vp1); LoadARB_program(GL_VERTEX_PROGRAM_NV, "vp1.txt"); } if(GLEE_NV_vertex_program2) { glGenProgramsNV(1, &vp2); glBindProgramNV(GL_VERTEX_PROGRAM_NV, vp2); LoadARB_program(GL_VERTEX_PROGRAM_NV, "vp2.txt"); } if(GLEE_NV_vertex_program || GLEE_NV_vertex_program2) { //Track modelview-projection matrix glTrackMatrixNV(GL_VERTEX_PROGRAM_NV, 0, GL_MODELVIEW_PROJECTION_NV, GL_IDENTITY_NV); } //reset timer timer.Reset(); return true; }
//Set up variables bool DemoInit() { if(!window.Init("Project Template", 640, 480, 32, 24, 8, WINDOWED_SCREEN)) return 0; //quit if not created SetUpARB_multitexture(); SetUpARB_texture_cube_map(); SetUpEXT_texture_edge_clamp(); SetUpNV_register_combiners(); SetUpNV_register_combiners2(); SetUpNV_vertex_program(); //Check for necessary extensions if( !ARB_multitexture_supported || !ARB_texture_cube_map_supported || !EXT_texture_edge_clamp_supported || !NV_register_combiners_supported || !NV_vertex_program_supported) return false; //Check for single-pass chromatic aberration states GLint maxTextureUnits; glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &maxTextureUnits); if( NV_register_combiners2_supported && maxTextureUnits>=4) { errorLog.OutputSuccess("Single Pass Chromatic Aberration Supported!"); pathOneSupported=true; renderPath=CHROMATIC_SINGLE; } camera.Init(VECTOR3D(0.0f, 0.0f, 4.0f), 2.5f, 10.0f); if( !cubeMapPosX.Load("cube_face_posx.tga") || !cubeMapNegX.Load("cube_face_negx.tga") || !cubeMapPosY.Load("cube_face_posy.tga") || !cubeMapNegY.Load("cube_face_negy.tga") || !cubeMapPosZ.Load("cube_face_posz.tga") || !cubeMapNegZ.Load("cube_face_negz.tga")) return false; //Build a texture from the data glGenTextures(1, &cubeMapTexture); //Generate Texture ID glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, cubeMapTexture); //Bind texture glTexImage2D( GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB, 0, GL_RGBA8, cubeMapPosX.width, cubeMapPosX.height, 0, cubeMapPosX.format, GL_UNSIGNED_BYTE, cubeMapPosX.data); glTexImage2D( GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB, 0, GL_RGBA8, cubeMapNegX.width, cubeMapNegX.height, 0, cubeMapNegX.format, GL_UNSIGNED_BYTE, cubeMapNegX.data); glTexImage2D( GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB, 0, GL_RGBA8, cubeMapPosY.width, cubeMapPosY.height, 0, cubeMapPosY.format, GL_UNSIGNED_BYTE, cubeMapPosY.data); glTexImage2D( GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB, 0, GL_RGBA8, cubeMapNegY.width, cubeMapNegY.height, 0, cubeMapNegY.format, GL_UNSIGNED_BYTE, cubeMapNegY.data); glTexImage2D( GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB, 0, GL_RGBA8, cubeMapPosZ.width, cubeMapPosZ.height, 0, cubeMapPosZ.format, GL_UNSIGNED_BYTE, cubeMapPosZ.data); glTexImage2D( GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB, 0, GL_RGBA8, cubeMapNegZ.width, cubeMapNegZ.height, 0, cubeMapNegZ.format, GL_UNSIGNED_BYTE, cubeMapNegZ.data); glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); //reset timer for start timer.Reset(); return true; }
void HISTCalculate(HISTOGRAM* histPTR) { uint32 hist_max[3] = { 0, 0, 0 }, i = 0, j = 0, k = 0; uint64 hist_sum = 0, hist_var = 0; IMAGE* imgPTR = histPTR->imgPTR; IMAGE* histimgPTR = histPTR->histImgPTR; float hist_aver = 0.0, hist_stan_dev = 0.0, scale[3] = { 0.0, 0.0, 0.0 }; histPTR->histogramClear(); for (i = 0; i < 3; i++) { histPTR->histogram[i] = (uint32*)calloc(256, sizeof(uint32)); if (!histPTR->histogram[i]) { errorCallB("Couldn't allocate memory"); HISTFree(histPTR); return; } } for (i = 0; i < imgPTR->height; i++) { for (j = 0; j < imgPTR->width ; j++) { for (k = 0; k < 3; k++) { histPTR->histogram[k][imgPTR->imgBUFS[0][i*imgPTR->stride + j*3 + k]] += 1; } } } for (i = 0; i < 3; i++) { hist_sum = 0; hist_var = 0; for (j = 0; j < 256; j++) { if (hist_max[i] < histPTR->histogram[i][j]) { hist_max[i] = histPTR->histogram[i][j]; } hist_sum += histPTR->histogram[i][j] * j; hist_var += histPTR->histogram[i][j] * j*j; } hist_aver = ((float)hist_sum) / (imgPTR->dimensions); hist_stan_dev = (float)sqrt(((float)hist_var / (imgPTR->dimensions)) - pow((double)hist_aver, 2)); if (imgPTR->encoding[0] == PHOTOMETRIC_RGB) { histPTR->histogramAdd(hist_aver, hist_stan_dev, hist_max[i], RGB_CHANNELS[i]); } else if (imgPTR->encoding[0] == PHOTOMETRIC_YCBCR) { histPTR->histogramAdd(hist_aver, hist_stan_dev, hist_max[i], YCBCR_CHANNELS[i]); } scale[i] = (float)(hist_max[i])*((float)1. / 256); } histimgPTR->lockImage(); for (i = 0; i < 256; i++) { for (j = 0; j < 256; j++) { if ((hist_max[2] - histPTR->histogram[2][j]) / scale[2] + 0.5f <= i) { histimgPTR->imgBUFS[3][i*histimgPTR->stride + j * 3 + 0] = 53; histimgPTR->imgBUFS[3][i*histimgPTR->stride + j * 3 + 1] = 53; histimgPTR->imgBUFS[3][i*histimgPTR->stride + j * 3 + 2] = 228; } else if ((hist_max[1] - histPTR->histogram[1][j]) / scale[1] + 0.5f <= i) { histimgPTR->imgBUFS[3][i*histimgPTR->stride + j * 3 + 0] = 53; histimgPTR->imgBUFS[3][i*histimgPTR->stride + j * 3 + 1] = 228; histimgPTR->imgBUFS[3][i*histimgPTR->stride + j * 3 + 2] = 53; } else if ((hist_max[0] - histPTR->histogram[0][j]) / scale[0] + 0.5f <= i) { histimgPTR->imgBUFS[3][i*histimgPTR->stride + j * 3 + 0] = 228; histimgPTR->imgBUFS[3][i*histimgPTR->stride + j * 3 + 1] = 53; histimgPTR->imgBUFS[3][i*histimgPTR->stride + j * 3 + 2] = 53; } else { histimgPTR->imgBUFS[3][i*histimgPTR->stride + j * 3 + 0] = 208; histimgPTR->imgBUFS[3][i*histimgPTR->stride + j * 3 + 1] = 209; histimgPTR->imgBUFS[3][i*histimgPTR->stride + j * 3 + 2] = 215; } } } histimgPTR->unlockImage(256,256); }
void char_clip_word( // WERD *word, //word to be processed IMAGE &bin_image, //whole image PIXROW_LIST *&pixrow_list, //pixrows built IMAGELINE *&imlines, //lines cut from image BOX &pix_box //box defining imlines ) { BOX word_box = word->bounding_box (); PBLOB_LIST *blob_list; PBLOB_IT blob_it; PIXROW_IT pixrow_it; INT16 pix_offset; //Y pos of pixrow[0] INT16 row_height; //No of pix rows INT16 imlines_x_offset; PIXROW *prev; PIXROW *next; PIXROW *current; BOOL8 changed; //still improving BOOL8 just_changed; //still improving INT16 iteration_count = 0; INT16 foreground_colour; if (word->flag (W_INVERSE)) foreground_colour = 1; else foreground_colour = 0; /* Define region for max pixrow expansion */ pix_box = word_box; pix_box.move_bottom_edge (-pix_word_margin); pix_box.move_top_edge (pix_word_margin); pix_box.move_left_edge (-pix_word_margin); pix_box.move_right_edge (pix_word_margin); pix_box -= BOX (ICOORD (0, 0 + BUG_OFFSET), ICOORD (bin_image.get_xsize (), bin_image.get_ysize () - BUG_OFFSET)); /* Generate pixrows list */ pix_offset = pix_box.bottom (); row_height = pix_box.height (); blob_list = word->blob_list (); blob_it.set_to_list (blob_list); pixrow_list = new PIXROW_LIST; pixrow_it.set_to_list (pixrow_list); for (blob_it.mark_cycle_pt (); !blob_it.cycled_list (); blob_it.forward ()) { PIXROW *row = new PIXROW (pix_offset, row_height, blob_it.data ()); ASSERT_HOST (!row-> bad_box (bin_image.get_xsize (), bin_image.get_ysize ())); pixrow_it.add_after_then_move (row); } imlines = generate_imlines (bin_image, pix_box); /* Contract pixrows - shrink min and max back to black pixels */ imlines_x_offset = pix_box.left (); pixrow_it.move_to_first (); for (pixrow_it.mark_cycle_pt (); !pixrow_it.cycled_list (); pixrow_it.forward ()) { ASSERT_HOST (!pixrow_it.data ()-> bad_box (bin_image.get_xsize (), bin_image.get_ysize ())); pixrow_it.data ()->contract (imlines, imlines_x_offset, foreground_colour); ASSERT_HOST (!pixrow_it.data ()-> bad_box (bin_image.get_xsize (), bin_image.get_ysize ())); } /* Expand pixrows iteratively 1 pixel at a time */ do { changed = FALSE; pixrow_it.move_to_first (); prev = NULL; current = NULL; next = pixrow_it.data (); for (pixrow_it.mark_cycle_pt (); !pixrow_it.cycled_list (); pixrow_it.forward ()) { prev = current; current = next; if (pixrow_it.at_last ()) next = NULL; else next = pixrow_it.data_relative (1); just_changed = current->extend (imlines, pix_box, prev, next, foreground_colour); ASSERT_HOST (!current-> bad_box (bin_image.get_xsize (), bin_image.get_ysize ())); changed = changed || just_changed; } iteration_count++; } while (changed); }
//Set up variables bool DemoInit() { if(!window.Init("Render To Texture", 640, 480, 32, 24, 8, WINDOWED_SCREEN)) return 0; //quit if not created camera.Init(VECTOR3D(0.0f, 0.0f, -2.5f), 2.0f, 100.0f); //Set up extensions if( !SetUpWGL_ARB_extensions_string()) return false; SetUpEXT_texture_filter_anisotropic(); SetUpSGIS_generate_mipmap(); //Get the WGL extensions string const char * wglExtensions; wglExtensions=wglGetExtensionsStringARB(window.hDC); //Set up wgl extensions if( !SetUpWGL_ARB_pbuffer(wglExtensions) || !SetUpWGL_ARB_pixel_format(wglExtensions) || !SetUpWGL_ARB_render_texture(wglExtensions)) return false; //Init the pbuffer int pbufferExtraIAttribs[]={WGL_BIND_TO_TEXTURE_RGBA_ARB, true, 0}; int pbufferFlags[]={WGL_TEXTURE_FORMAT_ARB, WGL_TEXTURE_RGBA_ARB, WGL_TEXTURE_TARGET_ARB, WGL_TEXTURE_2D_ARB, //request mipmap space if mipmaps are to be used SGIS_generate_mipmap_supported ? WGL_MIPMAP_TEXTURE_ARB : 0, SGIS_generate_mipmap_supported ? true : 0, 0}; if(!pbuffer.Init(pbufferSize, pbufferSize, 32, 24, 8, 1, pbufferExtraIAttribs, pbufferFlags)) return false; //Create the texture object to relate to the pbuffer glGenTextures(1, &pbufferTexture); glBindTexture(GL_TEXTURE_2D, pbufferTexture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); //Use generated mipmaps if supported if(SGIS_generate_mipmap_supported) { glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, true); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glHint(GL_GENERATE_MIPMAP_HINT_SGIS, GL_NICEST); useMipmapFilter=true; } //Use maximum anisotropy if supported if(EXT_texture_filter_anisotropic_supported) { glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnisotropy); currentAnisotropy=maxAnisotropy; glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, currentAnisotropy); } //Load the decal texture //Note: This MUST be done when the pbuffer is the current context pbuffer.MakeCurrent(); IMAGE decalImage; decalImage.Load("decal.bmp"); glGenTextures(1, &decalTexture); glBindTexture(GL_TEXTURE_2D, decalTexture); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, decalImage.width, decalImage.height, 0, decalImage.format, GL_UNSIGNED_BYTE, decalImage.data); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); //reset timer for start timer.Reset(); return true; }
///////////////////BSP::LoadTextures//////// //////////////////////////////////////////// bool BSP::LoadTextures(FILE * file) { //Calculate number of textures numTextures=header.directoryEntries[bspTextures].length/sizeof(BSP_LOAD_TEXTURE); //Create space for this many BSP_LOAD_TEXTUREs BSP_LOAD_TEXTURE * loadTextures=new BSP_LOAD_TEXTURE[numTextures]; if(!loadTextures) { errorLog.OutputError("Unable to allocate space for %d BSP_LOAD_TEXTUREs", numTextures); return false; } //Load textures fseek(file, header.directoryEntries[bspTextures].offset, SEEK_SET); fread(loadTextures, 1, header.directoryEntries[bspTextures].length, file); //Create storage space for that many texture identifiers decalTextures=new GLuint[numTextures]; if(!decalTextures) { errorLog.OutputError("Unable to create storage space for %d texture IDs", numTextures); return false; } //Create storage space for that many booleans to tell if texture has loaded isTextureLoaded=new bool[numTextures]; if(!isTextureLoaded) { errorLog.OutputError("Unable to create storage space for %d booleans", numTextures); return false; } //Generate the texture identifiers glGenTextures(numTextures, decalTextures); //Loop through and create textures IMAGE textureImage; //Image used to load textures for(int i=0; i<numTextures; ++i) { glBindTexture(GL_TEXTURE_2D, decalTextures[i]); //add file extension to the name char tgaExtendedName[68]; char jpgExtendedName[68]; strcpy(tgaExtendedName, loadTextures[i].name); strcat(tgaExtendedName, ".tga"); strcpy(jpgExtendedName, loadTextures[i].name); strcat(jpgExtendedName, ".jpg"); //Load texture image bool isJpgTexture=false; //have we loaded a jpg? if(!textureImage.Load(tgaExtendedName)) //try to load .tga, if not { if(LoadJPG(&textureImage, jpgExtendedName)) //try to load jpg { isJpgTexture=true; isTextureLoaded[i]=true; } else isTextureLoaded[i]=false; } else isTextureLoaded[i]=true; //if a jpg texture, need to set UNPACK_ALIGNMENT to 1 if(isJpgTexture) glPixelStorei(GL_UNPACK_ALIGNMENT, 1); //Create texture gluBuild2DMipmaps( GL_TEXTURE_2D, GL_RGBA8, textureImage.width, textureImage.height, textureImage.format, GL_UNSIGNED_BYTE, textureImage.data); glPixelStorei(GL_UNPACK_ALIGNMENT, 4); //Set Parameters glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); } if(loadTextures) delete [] loadTextures; loadTextures=NULL; return true; }