|
Boost Users : |
Subject: [Boost-users] [gil] Using gil with windows bitmaps
From: Dan Bloomquist (danb_at_[hidden])
Date: 2011-11-10 13:26:30
Hi,
Yesterday I went on a bend to understand memory images, so far I've just
taken them for granted. I have a situation where I need to resample
photos at print time. If a client uses their 37 gigapixel camera and I
print that to pdf it bloats the size of the pdf so as they can't email
them. My old hack was with GDI+, code I barely understood. So I've
gotten to the code below and for all I know it is not a good start, but
it works. With gil I could do more like crop and rotate without
modifying the source image.
Right now I'm at a loss as to how to attach a bitmap to a gil view.
(Over ride the allocator?) In my test I've got two extra memcpy calls I
should not have to do. I'd like to use gil directly on the windows
bitmap memory.
BTW, that one hour flash at Adobe was great. Now I want to 'Gilify' my code.
Note HEImage::g_image is a rgb8_image_t;
HBITMAP test_gil( HBITMAP hBitmap )
{
DIBSECTION d;
//testing, assume rgb8_image_t in object
int nBytes = ::GetObject( hBitmap, sizeof( DIBSECTION ), &d );
HEImage image( d.dsBm.bmWidth, d.dsBm.bmHeight );//, d.dsBm.bmBits,
0 ); should just be able to attach bits
memcpy( &image.g_image._view[ 0 ], d.dsBm.bmBits,
d.dsBmih.biSizeImage );
//gil::jpeg_read_image(
"C:\\cpp\\HE_9\\jpeg-8c\\GIL_test\\In\\IMG_0006.JPG", image.g_image );
HEImage image2( d.dsBm.bmWidth, d.dsBm.bmHeight );
//testing, just flip image...
gil::copy_pixels( gil::rotated180_view( image.g_image._view ),
image2.g_image._view );
BITMAPINFO bi24BitInfo; //testing, populate to match rgb8_image_t
memset( &bi24BitInfo, 0, sizeof( BITMAPINFO ) );
bi24BitInfo.bmiHeader.biSize = sizeof(bi24BitInfo.bmiHeader);
bi24BitInfo.bmiHeader.biBitCount = 24; // rgb 8 bytes for each
component(3)
bi24BitInfo.bmiHeader.biCompression = BI_RGB;// rgb = 3 components
bi24BitInfo.bmiHeader.biPlanes = 1;
bi24BitInfo.bmiHeader.biWidth = d.dsBm.bmWidth;
bi24BitInfo.bmiHeader.biHeight = d.dsBm.bmHeight;
HBITMAP oBitmap = ::CreateDIBSection( NULL, &bi24BitInfo,
DIB_RGB_COLORS, 0, 0, 0 );
nBytes = ::GetObject( oBitmap, sizeof( DIBSECTION ), &d );
memcpy( d.dsBm.bmBits, &image2.g_image._view[ 0 ],
d.dsBmih.biSizeImage );
return oBitmap;
}
In test used like:
bResamplePhoto= true; //TODO testing....
if( bResamplePhoto )
{
for( size_t i= 0; i < photoWnd.size( ); ++i )
{
HBITMAP hB= test_gil( photoWnd.at( i ) );
photoWnd.at( i ).Destroy( );
photoWnd.at( i ).Attach( hB );
}
}
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net