void tTVPDrawer_GDIDoubleBuffering::CreateBitmap() { // スクリーン互換の DDB を作成する。 // これはたいていの場合、ビデオメモリ上に作成される。 DestroyBitmap(); if(TargetWindow && SrcWidth > 0 && SrcHeight > 0) { try { HDC screendc = GetDC(TargetWindow); if(!screendc) TVPThrowExceptionMessage( TVPFailedToCreateScreenDC ); OffScreenBitmap = CreateCompatibleBitmap(screendc, SrcWidth, SrcHeight); if(!OffScreenBitmap) TVPThrowExceptionMessage( TVPFailedToCreateOffscreenBitmap ); OffScreenDC = CreateCompatibleDC(screendc); if(!OffScreenDC) TVPThrowExceptionMessage( TVPFailedToCreateOffscreenDC ); ReleaseDC(TargetWindow, screendc); OldOffScreenBitmap = SelectObject(OffScreenDC, OffScreenBitmap); } catch(...) { DestroyBitmap(); throw; } } }
int Orient( char *filename, int setflags, int orientation ) { PBITMAP tiff; tiff = ReadTiff( filename, 0 ); if ( !tiff ) { fprintf( stderr, "Can't read %s\n", filename ); return 1; } if ( tiff->sampleformat!=BITMAP_UINT8 && tiff->sampleformat!=BITMAP_UINT16 && tiff->sampleformat!=BITMAP_IEEE ) { fprintf( stderr, "TIFF file %s is not a \"r\", \"rgb\", \"rgba\" or IEEE image\n", filename ); goto Error; } if (setflags) { tiff->orientation = orientation; } else { tiff = OrientBitmap( tiff, orientation ); } if (WriteTiff( tiff, filename )) { fprintf( stderr, "Can't write file: \"%s\"\n", filename ); goto Error; } DestroyBitmap( tiff ); return 0; Error: DestroyBitmap( tiff ); return 1; }
//--------------------------------------------------------------------------- void TJS_INTF_METHOD tTVPGDIDrawDevice::SetDestRectangle(const tTVPRect & rect) { // 位置だけの変更の場合かどうかをチェックする if(rect.get_width() == DestRect.get_width() && rect.get_height() == DestRect.get_height()) { // 位置だけの変更だ inherited::SetDestRectangle(rect); } else { // サイズも違う inherited::SetDestRectangle(rect); DestroyBitmap(); EnsureDrawer(); } }
//--------------------------------------------------------------------------- void tTVPGDIDrawDevice::CreateBitmap() { // スクリーン互換の DDB を作成する。 // これはたいていの場合、ビデオメモリ上に作成される。 DestroyBitmap(); tjs_int w, h; GetSrcSize( w, h ); if(TargetWindow && w > 0 && h > 0) { try { HDC screendc = ::GetDC(TargetWindow); if(!screendc) TVPThrowExceptionMessage(TJS_W("Failed to create screen DC")); OffScreenBitmap = ::CreateCompatibleBitmap(screendc, w, h); if(!OffScreenBitmap) TVPThrowExceptionMessage(TJS_W("Failed to create offscreen bitmap")); OffScreenDC = ::CreateCompatibleDC(screendc); if(!OffScreenDC) TVPThrowExceptionMessage(TJS_W("Failed to create offscreen DC")); ::ReleaseDC(TargetWindow, screendc); OldOffScreenBitmap = (HBITMAP)::SelectObject(OffScreenDC, OffScreenBitmap); } catch(...) { DestroyBitmap(); throw; } } }
int main(int argc, char **argv) { PBITMAP tiff; if ( argc < 3 || (argc > 1 && argv[1][0]=='-') ) { /* User tried to specify an option, so just print help text. */ printf( "tiff2pix tiff_filename X_filename\n" \ " tiff_filename TIFF file to read from.\n" \ " X_filename X windows bitmap file.\n" ); return 1; } /* Check that the input file name doesn't match the output file name. */ if (!strcmp(argv[1],argv[2])) { fprintf( stderr, "Filenames can not refer to the same file: \"%s\".\n", argv[1] ); return 1; } tiff = ReadTiff( argv[1], 0 ); if (!tiff) { fprintf( stderr, "Can't read %s\n", argv[1] ); return 1; } tiff = OrientBitmap( tiff, BITMAP_TOPLEFT ); if (tiff->nsamples!=1 && tiff->bitspersample!=1) { fprintf( stderr, "Requires data to be 1 bit per pixel.\n" ); return 1; } if (WriteX( tiff, argv[2] )) { fprintf( stderr, "Can't write %s\n", argv[2] ); return 1; } DestroyBitmap( tiff ); return 0; }
void SymbolPanel::UpdateBitmap() { if ( !mFontInfo ) { DestroyBitmap(); return; } SymbolInfoPtr sym = mFontInfo->GetSymbol( mSymbolNumber ); if (!sym) { wxLogMessage( wxString::Format("SymbolPanel::UpdateBitmap: can't update bitmap for symbol %d", mSymbolNumber) ); return; } ImageInfoPtr img = std::make_shared<ImageInfo>(sym->GetData(), mFontInfo->GetPalette()); this->SetIndexedBitmap(img, false ); }
int main(int argc, char **argv) { PBITMAP tiff; uint32 n; uint8 *p8; uint16 *p16; auto uint32 i,j,x,y; if ( argc < 2 || (argc > 1 && argv[1][0]=='-') ) { /* User tried to specify an option, so just print help text. */ printf( "tiffinvert tiff_filename1 ...\n" \ " tiff_filename1 ... TIFF file(s) to overwrite with an\n" \ " an inverted version of their image.\n" ); return 1; } for ( i=1; i<argc; i++ ) { tiff = ReadTiff( argv[i], 0 ); if ( !tiff ) { fprintf( stderr, "Can't read %s\n", argv[i] ); return 1; } if ( tiff->sampleformat!=BITMAP_UINT8 && tiff->sampleformat!=BITMAP_UINT16 ) { fprintf( stderr, "TIFF file %s is not an \"r\", \"rgb\" or \"rgba\" image\n", argv[i] ); goto Skip; } if ( tiff->sampleformat==BITMAP_UINT8 ) { n = tiff->yres * tiff->rowbytes; p8 = tiff->pbits; for ( j=0; j<n; j++ ) *p8++ = 0xff - *p8; } else /* tiff->sampleformat==BITMAP_UINT16 */ { n = tiff->xres * tiff->nsamples; p16 = (uint16*)tiff->pbits; for ( y=0; y<tiff->yres; y++ ) for ( x=0; x<n; x++ ) *p16++ = 0xffff - *p16; } if (WriteTiff( tiff, argv[i] )) { fprintf( stderr, "Can't write file: \"%s\"\n", argv[i] ); goto Error; } Skip: DestroyBitmap( tiff ); } return 0; Error: DestroyBitmap( tiff ); return 1; }
void WED_DoMakeNewOverlay(IResolver * inResolver, WED_MapZoomerNew * zoomer) { char * path = GetMultiFilePathFromUser("Please pick an image file", "Open", FILE_DIALOG_PICK_IMAGE_OVERLAY); if(path) { Point2 coords[4]; double c[8]; WED_Thing * wrl = WED_GetWorld(inResolver); ISelection * sel = WED_GetSelect(inResolver); wrl->StartOperation("Add Overlay Image"); sel->Clear(); char * free_me = path; while(*path) { ImageInfo inf; int has_geo = 0; int align = dem_want_Area; int res = MakeSupportedType(path, &inf); if(res != 0) { string msg = "Unable to open image file: "; msg += path; DoUserAlert(msg.c_str()); path = path + strlen(path)+1; continue; } switch(GetSupportedType(path)) { #if USE_GEOJPEG2K case WED_JP2K: if(FetchTIFFCornersWithJP2K(path,c,align)) { coords[3].x_ = c[0]; coords[3].y_ = c[1]; coords[0].x_ = c[2]; coords[0].y_ = c[3]; coords[2].x_ = c[4]; coords[2].y_ = c[5]; coords[1].x_ = c[6]; coords[1].y_ = c[7]; has_geo=1; } break; #endif case WED_TIF: if (FetchTIFFCorners(path, c, align)) { // SW, SE, NW, NE from tiff, but SE NE NW SW internally coords[3].x_ = c[0]; coords[3].y_ = c[1]; coords[0].x_ = c[2]; coords[0].y_ = c[3]; coords[2].x_ = c[4]; coords[2].y_ = c[5]; coords[1].x_ = c[6]; coords[1].y_ = c[7]; has_geo=1; } break; } if(!has_geo) { double nn,ss,ee,ww; zoomer->GetPixelBounds(ww,ss,ee,nn); Point2 center((ee+ww)*0.5,(nn+ss)*0.5); double grow_x = 0.5*(ee-ww)/((double) inf.width); double grow_y = 0.5*(nn-ss)/((double) inf.height); double pix_w, pix_h; if (grow_x < grow_y) { pix_w = grow_x * (double) inf.width; pix_h = grow_x * (double) inf.height; } else { pix_w = grow_y * (double) inf.width; pix_h = grow_y * (double) inf.height; } coords[0] = zoomer->PixelToLL(center + Vector2( pix_w,-pix_h)); coords[1] = zoomer->PixelToLL(center + Vector2( pix_w,+pix_h)); coords[2] = zoomer->PixelToLL(center + Vector2(-pix_w,+pix_h)); coords[3] = zoomer->PixelToLL(center + Vector2(-pix_w,-pix_h)); } DestroyBitmap(&inf); WED_OverlayImage * img = WED_OverlayImage::CreateTyped(wrl->GetArchive()); WED_Ring * rng = WED_Ring::CreateTyped(wrl->GetArchive()); WED_TextureNode * p1 = WED_TextureNode::CreateTyped(wrl->GetArchive()); WED_TextureNode * p2 = WED_TextureNode::CreateTyped(wrl->GetArchive()); WED_TextureNode * p3 = WED_TextureNode::CreateTyped(wrl->GetArchive()); WED_TextureNode * p4 = WED_TextureNode::CreateTyped(wrl->GetArchive()); p1->SetParent(rng,0); p2->SetParent(rng,1); p3->SetParent(rng,2); p4->SetParent(rng,3); rng->SetParent(img,0); img->SetParent(wrl,0); sel->Select(img); p1->SetLocation(gis_Geo,coords[3]); p2->SetLocation(gis_Geo,coords[2]); p3->SetLocation(gis_Geo,coords[1]); p4->SetLocation(gis_Geo,coords[0]); string img_path(path); WED_GetLibrarian(inResolver)->ReducePath(img_path); img->SetImage(img_path); p1->SetName("Corner 1"); p1->SetName("Corner 2"); p1->SetName("Corner 3"); p1->SetName("Corner 4"); rng->SetName("Image Boundary"); const char * p = path; const char * n = path; //While p is not the null pointer (not the end of the of the char*) while(*p) { //If the letter is special if (*p == '/' || *p == ':' || *p == '\\') { //Advance n's pointer n = p+1; } //Advance regardless ++p; } //n is now just the file name img->SetName(n); p1->SetLocation(gis_UV,Point2(0,0)); p2->SetLocation(gis_UV,Point2(0,1)); p3->SetLocation(gis_UV,Point2(1,1)); p4->SetLocation(gis_UV,Point2(1,0)); path = path + strlen(path)+1; } if(sel->GetSelectionCount() == 0) wrl->AbortOperation(); else wrl->CommitOperation(); free(free_me); } }
/* * Flip image around diagonal line from upper left to lower right. */ static PBITMAP DiagonalFlipImage( PBITMAP pBmp, int bitsperpixel ) { PBITMAP target = NULL; unsigned int nbytes; auto unsigned int count,i,n,tmp; auto char *p,*pp; /* If a square bitmap, then just move the pixels around. */ if ( pBmp->yres == pBmp->xres ) { /* See if there is more than one row and column. */ if (pBmp->yres<=1) /* Note xres=yres, so just check one of them. */ return pBmp; /* Swap xpos, ypos values. */ tmp = pBmp->xpos; pBmp->xpos = pBmp->ypos; pBmp->ypos = tmp; n = pBmp->xres-1; nbytes = pBmp->rowbytes; switch (bitsperpixel) { case 8: for ( i=0; i<n; i++ ) { p = (char*)(pBmp->pbits) + i + i*nbytes; pp = p + nbytes; p++; for ( count = n-i; count; count-- ) { tmp = p[0]; p[0] = pp[0]; pp[0] = tmp; p++; pp+=nbytes; } } break; case 16: for ( i=0; i<n; i++ ) { p = (char*)(pBmp->pbits) + 2*i + i*nbytes; pp = p + nbytes; p+=2; for ( count = n-i; count; count-- ) { tmp = p[0]; p[0] = pp[0]; pp[0] = tmp; tmp = p[1]; p[1] = pp[1]; pp[1] = tmp; p+=2; pp+=nbytes; } } break; case 24: for ( i=0; i<n; i++ ) { p = (char*)(pBmp->pbits) + 3*i + i*nbytes; pp = p + nbytes; p+=3; for ( count = n-i; count; count-- ) { tmp = p[0]; p[0] = pp[0]; pp[0] = tmp; tmp = p[1]; p[1] = pp[1]; pp[1] = tmp; tmp = p[2]; p[2] = pp[2]; pp[2] = tmp; p+=3; pp+=nbytes; } } break; case 32: for ( i=0; i<n; i++ ) { p = (char*)(pBmp->pbits) + 4*i + i*nbytes; pp = p + nbytes; p+=4; for ( count = n-i; count; count-- ) { tmp = p[0]; p[0] = pp[0]; pp[0] = tmp; tmp = p[1]; p[1] = pp[1]; pp[1] = tmp; tmp = p[2]; p[2] = pp[2]; pp[2] = tmp; tmp = p[3]; p[3] = pp[3]; pp[3] = tmp; p+=4; pp+=nbytes; } } break; case 48: for ( i=0; i<n; i++ ) { p = (char*)(pBmp->pbits) + 6*i + i*nbytes; pp = p + nbytes; p+=6; for ( count = n-i; count; count-- ) { tmp = p[0]; p[0] = pp[0]; pp[0] = tmp; tmp = p[1]; p[1] = pp[1]; pp[1] = tmp; tmp = p[2]; p[2] = pp[2]; pp[2] = tmp; tmp = p[3]; p[3] = pp[3]; pp[3] = tmp; tmp = p[4]; p[4] = pp[4]; pp[4] = tmp; tmp = p[5]; p[5] = pp[5]; pp[5] = tmp; p+=6; pp+=nbytes; } } break; case 64: for ( i=0; i<n; i++ ) { p = (char*)(pBmp->pbits) + 8*i + i*nbytes; pp = p + nbytes; p+=8; for ( count = n-i; count; count-- ) { tmp = p[0]; p[0] = pp[0]; pp[0] = tmp; tmp = p[1]; p[1] = pp[1]; pp[1] = tmp; tmp = p[2]; p[2] = pp[2]; pp[2] = tmp; tmp = p[3]; p[3] = pp[3]; pp[3] = tmp; tmp = p[4]; p[4] = pp[4]; pp[4] = tmp; tmp = p[5]; p[5] = pp[5]; pp[5] = tmp; tmp = p[6]; p[6] = pp[6]; pp[6] = tmp; tmp = p[7]; p[7] = pp[7]; pp[7] = tmp; p+=8; pp+=nbytes; } } break; default: /* Unexpected pixel size, just return bitmap untouched. */ return pBmp; } } else { target = CreateBitmap( pBmp->yres, pBmp->xres, /* Swap x and y. */ pBmp->ypos, pBmp->xpos, /* Swap x and y. */ pBmp->nsamples, pBmp->sampleformat, pBmp->bitspersample ); if (!target) return pBmp; p = (char*)(pBmp->pbits); nbytes = target->rowbytes; switch (bitsperpixel) { case 8: for ( i=0; i < pBmp->yres; i++ ) { pp = (char*)(target->pbits) + i; for ( count = pBmp->xres; count; count-- ) { *pp = *p; p++; pp+=nbytes; } } break; case 16: for ( i=0; i < pBmp->yres; i++ ) { pp = (char*)(target->pbits) + 2*i; for ( count = pBmp->xres; count; count-- ) { pp[0] = p[0]; pp[1] = p[1]; p+=2; pp+=nbytes; } } break; case 24: for ( i=0; i < pBmp->yres; i++ ) { pp = (char*)(target->pbits) + 3*i; for ( count = pBmp->xres; count; count-- ) { pp[0] = p[0]; pp[1] = p[1]; pp[2] = p[2]; p+=3; pp+=nbytes; } } break; case 32: for ( i=0; i < pBmp->yres; i++ ) { pp = (char*)(target->pbits) + 4*i; for ( count = pBmp->xres; count; count-- ) { pp[0] = p[0]; pp[1] = p[1]; pp[2] = p[2]; pp[3] = p[3]; p+=4; pp+=nbytes; } } break; case 48: for ( i=0; i < pBmp->yres; i++ ) { pp = (char*)(target->pbits) + 6*i; for ( count = pBmp->xres; count; count-- ) { pp[0] = p[0]; pp[1] = p[1]; pp[2] = p[2]; pp[3] = p[3]; pp[4] = p[4]; pp[5] = p[5]; p+=6; pp+=nbytes; } } break; case 64: for ( i=0; i < pBmp->yres; i++ ) { pp = (char*)(target->pbits) + 8*i; for ( count = pBmp->xres; count; count-- ) { pp[0] = p[0]; pp[1] = p[1]; pp[2] = p[2]; pp[3] = p[3]; pp[4] = p[4]; pp[5] = p[5]; pp[6] = p[6]; pp[7] = p[7]; p+=8; pp+=nbytes; } } break; default: return pBmp; /* Unexpected number of samples per pixel. */ } } if (target) { DestroyBitmap( pBmp ); return target; } return pBmp; }
int DisplayBitmap( PBITMAP pBmp, char *filename ) { int scrn; XVisualInfo *visi = NULL; XSetWindowAttributes xwndsetattr; XWindowAttributes xwndattr; Colormap clrmap; XSizeHints szhints; XEvent event; GLXContext glctx; Atom wm_delete_window; XWMHints hints; Pixmap icon; char *s; if (!pBmp) { fprintf( stderr, "Can't read %s\n", filename ); return 1; } if ( pBmp->sampleformat!=BITMAP_UINT8 && pBmp->sampleformat!=BITMAP_IEEE ) { fprintf( stderr, "Can't display %s: not 8 bits or IEEE 32 bits per sample.\n", filename ); return 1; } if ( pBmp->nsamples!=1 && pBmp->nsamples!=3 && pBmp->nsamples!=4 ) { fprintf( stderr, "Can't display %s: not an 8, 24, or 32 bit per pixel image.\n", filename ); return 1; } dspy = XOpenDisplay( 0 ); if (!dspy) { fprintf( stderr, "Error connecting to X server\n" ); exit( -1 ); } scrn = DefaultScreen( dspy ); visi = glXChooseVisual( dspy, scrn, attributeListSgl ); if ( !visi ) { visi = glXChooseVisual( dspy, scrn, attributeListDbl ); switchbuffer = 1; } glctx = glXCreateContext( dspy, visi, 0, GL_TRUE ); clrmap = XCreateColormap( dspy, RootWindow(dspy, visi->screen ), visi->visual, AllocNone ); xwndsetattr.colormap = clrmap; xwndsetattr.border_pixel = 0; xwndsetattr.event_mask = StructureNotifyMask; wnd = XCreateWindow( dspy, RootWindow( dspy, visi->screen ), 0, /* x */ 0, /* y */ pBmp->xres, /* width */ pBmp->yres, /* height */ 0, visi->depth, InputOutput, visi->visual, CWBorderPixel | CWColormap | CWEventMask, &xwndsetattr ); XGetWindowAttributes( dspy, wnd, &xwndattr ); /* OpenGL likes the bitmap data to have the bottom row first, not the * top row. Note the left most column is the first column. */ pBmp = OrientBitmap( pBmp, BITMAP_BOTLEFT ); /* Get a hook in on the user quitting the app. This will prevent * that annoying "X connection to 0:0 broken" message. */ wm_delete_window = XInternAtom( dspy, "WM_DELETE_WINDOW", False ); (void) XSetWMProtocols( dspy, wnd, &wm_delete_window, 1 ); s = strrchr( filename, '/' ); if (!s) s = filename; else s++; XStoreName( dspy, wnd, s ); icon = XCreateBitmapFromData( dspy, wnd, (const char *)affine_bits, affine_width, affine_height ); hints.icon_pixmap = icon; hints.flags = IconPixmapHint; XSetWMHints( dspy, wnd, &hints ); szhints.flags = PMinSize | PMaxSize; szhints.min_width = pBmp->xres; szhints.max_width = pBmp->xres; szhints.min_height = pBmp->yres; szhints.max_height = pBmp->yres; XSetNormalHints( dspy, wnd, &szhints ); XMapWindow( dspy, wnd ); /* Connect the context to the window. */ glXMakeCurrent(dspy, wnd, glctx); glShadeModel(GL_FLAT); glPixelStorei( GL_UNPACK_ALIGNMENT, 1 ); glViewport(0,0,pBmp->xres,pBmp->yres); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0,pBmp->xres,0.0,pBmp->yres,-1.0,1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glClearColor(0,0,0,0); glClear(GL_COLOR_BUFFER_BIT); XSelectInput( dspy, wnd, ExposureMask | StructureNotifyMask ); for (;;) { XNextEvent( dspy, &event ); switch (event.type) { case MapNotify: DisplayBits( pBmp, 0, 0, pBmp->xres, pBmp->yres ); break; case Expose: if ( event.xexpose.window == wnd ) DisplayBits( pBmp, event.xexpose.x, event.xexpose.y, event.xexpose.width, event.xexpose.height ); break; case ClientMessage: if (event.xclient.data.l[0] == wm_delete_window && event.xclient.window == wnd ) goto Exit; break; } } Exit: if (wnd) XDestroyWindow( dspy, wnd ); if (visi) XFree(visi); if (pBmp) DestroyBitmap( pBmp ); return 0; }
//! @brief デストラクタ tTVPDrawer_GDIDoubleBuffering::~tTVPDrawer_GDIDoubleBuffering() { DestroyBitmap(); }
//--------------------------------------------------------------------------- tTVPGDIDrawDevice::~tTVPGDIDrawDevice() { DestroyBitmap(); if(TargetDC && TargetWindow) ::ReleaseDC(TargetWindow, TargetDC); if(DrawDibHandle) ::DrawDibClose(DrawDibHandle), DrawDibHandle = NULL; }