[osg-users] Need help with OSG Image.

308 views
Skip to first unread message

Akhtar Shamim

unread,
Jun 30, 2010, 6:51:20 AM6/30/10
to osg-...@lists.openscenegraph.org
Hi,

I am facing a problem with OSG Image and would like to seek some advice from the community.

I have a model exported in IVE format. This model is just a quad with a texture mapped onto it. I want to retrieve the original image from osg::Image object and convert it to JPG/PNG or any other format. Seems simple, but I am not sure what is causing the problem.

The image when loaded using osgviewer looks perfectly fine. But when I debug and look at the contents of the osg::Image object I find that both the InternalTextureFormat and the PixelFormat are invalid.

        _internalTextureFormat    33776    int
        _pixelFormat    33776    unsigned int

The pixel size is 4 bits per pixel. I tried using osg::writeImageFile with extension as JPG, TGA and PNG. Nothing works. With extension as RGB the image is saved but is incorrect. I think it is because of the fact that the image is 4 bits per pixel.

So, what I did is to use ImageMagick to convert the image data buffer to a common format (JPG, PNG or TGA). However I am unable to do the conversion from the 4 bit per pixel to a 24 bit per pixel. Any help here would be greatly appreciated.


My mechanism for conversion from a 4 BPP to a 24 BPP is as follows:


>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
        unsigned int total_size_in_bytes = image->getTotalSizeInBytes();
        unsigned int row_size_in_bytes = image->getRowSizeInBytes();
        unsigned int image_size_in_bytes = image->getImageSizeInBytes();
        unsigned char* ptr = image->data();

        unsigned int size = w*h;
        unsigned char* writePtr = new unsigned char[size];
        memset(writePtr, 0, size);

        // i convert to byte array (not sure if this is the correct way to do)
        for(unsigned int i = 0; i < size; i+=2)
        {
            writePtr[i]   = (ptr[i/2] >> 4);
            writePtr[i+1] = (ptr[i/2] & 0x0F);
        }

        // now i have the byte array and i set to imagemagick
       
        for (unsigned int y = 0; y < h; y++)
        {
            for (unsigned int x = 0; x < w; x++)
            {
                unsigned char c = writePtr[x+y*w];
                Magick::PixelPacket* curMagickPix = 0;
                curMagickPix = magickPixels + (y*w + x);

                curMagickPix->red = c;
                curMagickPix->green = c;
                curMagickPix->blue = c;  
            }
        }
        delete [] writePtr;
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

I tried to attach the IVE file but the email bounced. So I am putting it up for download. The URL is: http://68.168.137.66/osguser/Ceiling_1LightingMap.ive


Regards,
Shamim

Ulrich Hertlein

unread,
Jul 2, 2010, 8:42:23 PM7/2/10
to OpenSceneGraph Users
Hi Shamim,

On 30/06/10 20:51 , Akhtar Shamim wrote:
> I have a model exported in IVE format. This model is just a quad with a texture mapped
> onto it. I want to retrieve the original image from osg::Image object and convert it to
> JPG/PNG or any other format. Seems simple, but I am not sure what is causing the problem.
>
> The image when loaded using osgviewer looks perfectly fine. But when I debug and look at
> the contents of the osg::Image object I find that both the InternalTextureFormat and the
> PixelFormat are invalid.
>
> _internalTextureFormat 33776 int
> _pixelFormat 33776 unsigned int

They are not invalid, decimal 33776 is hex 0x83f0 is GL_COMPRESSED_RGB_S3TC_DXT1_EXT.
In the process of converting to .ive they have been compressed to speed up texture upload.

As far as I know no image exporter supports writing these compressed images.

You could render the texture to a framebuffer and read that back... :-/

/ulrich
_______________________________________________
osg-users mailing list
osg-...@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Farshid Lashkari

unread,
Jul 2, 2010, 10:13:16 PM7/2/10
to OpenSceneGraph Users
On Fri, Jul 2, 2010 at 5:42 PM, Ulrich Hertlein <u.her...@sandbox.de> wrote:

They are not invalid, decimal 33776 is hex 0x83f0 is GL_COMPRESSED_RGB_S3TC_DXT1_EXT.
In the process of converting to .ive they have been compressed to speed up texture upload.

As far as I know no image exporter supports writing these compressed images.

The dds plugin should be able to read/write compressed images

Cheers,
Farshid 

Ulrich Hertlein

unread,
Jul 3, 2010, 2:12:43 AM7/3/10
to OpenSceneGraph Users

Good point, but it will only save it in its compressed form, so one still needs to find a
tool to uncompress the file.

Cheers,

Farshid Lashkari

unread,
Jul 3, 2010, 11:25:17 AM7/3/10
to OpenSceneGraph Users
On Fri, Jul 2, 2010 at 11:12 PM, Ulrich Hertlein <u.her...@sandbox.de> wrote:
Good point, but it will only save it in its compressed form, so one still needs to find a
tool to uncompress the file.

If your are on Windows, the excellent (and free) Paint.NET image editor can open/save compressed dds files.

Cheers,
Farshid 

Jean-Sébastien Guay

unread,
Jul 3, 2010, 6:23:21 PM7/3/10
to OpenSceneGraph Users
Hi Farshid,

> If your are on Windows, the excellent (and free) Paint.NET image editor
> can open/save compressed dds files.

I personally like XnView (also free ($) but not free (libre) unfortunately).

Ulrich, it's really not hard these days to find something to open dds
files with. The DirectX SDK includes a viewer of course, GIMP opens and
saves them, osgviewer --image loads them, etc. Unfortunately OSG won't
convert internal image formats between load and save, so you can't just
load a dds and save a jpg/png/tga/bmp for example, but many tools can do
it (GIMP, command line ImageMagick, etc.)

Hope this helps,

J-S
--
______________________________________________________
Jean-Sebastien Guay jean-seba...@cm-labs.com
http://www.cm-labs.com/
http://whitestar02.webhop.org/

Reply all
Reply to author
Forward
0 new messages