Hi Matthias,
can you post the complete file?
cheers,
Stephan
Am 13.09.12 14:59, schrieb Matthias Thöny:
> Hi Stephan,
>
> thanks for your file and the information. I saw that the file contains all
> values from 0...1 and I realized that with the current implementation this is
> not working, because as far as I have seen, after the call
>
>
> Code:
>
> CGContextDrawImage(bitmap_context, rect, image_ref);
> CGContextRelease(bitmap_context);
>
>
>
>
> the byte array contains values like
>
> 128 128 128 255 (for 1 Pixel).
>
> So in fact, may be there are in the end float values, but they are scaled to
> 1... 255 in the current implementation, this is also why you end up having
> RGBA and unsigned byte. (probably there is aliasing in the resulting
> OSG::Image).
>
> I tried implementing this by myself and realized, that the whole function
> should probably get another iteration, because at the moment the
> bits_per_component are restricted to 8 and datatypes on grayscale bigger than
> 8 bits are not handled properly.
>
> So it should be:
>
>
> Code:
>
> size_t bits_per_component = CGImageGetBitsPerComponent(image_ref);
> //size_t bits_per_component = 8;
>
>
>
>
> further at the position where you also fixed something the code should
> contain a switch more, for the bits_per_component. Here is what I did (I did
> not test the code with other pictures formats (gif, png etc..):
>
>
> Code:
>
> case 16:
> {
> <BLOCKQUOTE>image_data = calloc(width * 2, height);
> internal_format = GL_R;
> pixel_format = GL_RED;
> data_type = GL_UNSIGNED_SHORT;
>
> bytes_per_row = width*2;
> color_space = CGColorSpaceCreateDeviceGray();
> bits_per_component = 16;
> #if __BIG_ENDIAN__
> bitmap_info = kCGImageAlphaNone | kCGBitmapByteOrder32Big; /* XRGB Big Endian
> */
> #else
> bitmap_info = kCGImageAlphaNone | kCGBitmapByteOrder32Little; /* XRGB Little
> Endian */
> #endif
> bitmap_context =
> CGBitmapContextCreate(image_data,width,height,bits_per_component,bytes_per_row,color_space,alpha_info);
> break;
> </BLOCKQUOTE>}
> case 32:
> case 64:
> {
> <BLOCKQUOTE>image_data = (float*)calloc(width * 4, height);
> switch(bits_per_component)
> {
> <BLOCKQUOTE>case 8:
> {
> <BLOCKQUOTE>internal_format = GL_RGBA8;
> pixel_format = GL_BGRA_EXT;
> data_type = GL_UNSIGNED_INT_8_8_8_8_REV;
>
> bytes_per_row = width*4;
> color_space = CGColorSpaceCreateDeviceRGB();
> #if __BIG_ENDIAN__
> bitmap_info = kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Big; /*
> XRGB Big Endian */
> #else
> bitmap_info = kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little;
> /* XRGB Little Endian */
> #endif
> break;
> </BLOCKQUOTE>}
> case 32:
> {
> <BLOCKQUOTE>internal_format = GL_R;
> pixel_format = GL_RED;
> data_type = GL_FLOAT;
> bytes_per_row = width*4;
> color_space = CGColorSpaceCreateDeviceGray();
> #if __BIG_ENDIAN__
> bitmap_info = kCGImageAlphaNone | kCGBitmapFloatComponents |
> kCGBitmapByteOrder32Big; /* XRGB Big Endian */
> #else
> bitmap_info = kCGImageAlphaNone | kCGBitmapFloatComponents |
> kCGBitmapByteOrder32Little; /* XRGB Little Endian */
> #endif
> bitmap_context = CGBitmapContextCreate(image_data, width, height,
> bits_per_component, bytes_per_row, color_space, bitmap_info);
> break;
> </BLOCKQUOTE>}
> </BLOCKQUOTE>}
> break;
> </BLOCKQUOTE>}
>
>
>
>
> I hope this helps others. I think for a submission one would have to refactor
> the whole function. There are may be more cases to go especially for 64 bit
> cases.
>
> Thanks for the help!
>
> Matthias
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=50011#50011
>
>
>
>
>
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org