Hello Johannes,

On 09/01/2011 09:52 AM, Johannes Brunen wrote:
> imho I found an error in the jpeg image writer method. I have observed
> that on writing images of this type the resolution I have set in my
> Image object is not visible in the written file. After inspection I
> think that a couple of code lines in OSGJPGImageFileType.cpp at line 532
> should be moved after the jpeg_set_defaults(&cinfo); call.
>
> I.e. it should be something like...
>
> /*
>
>      cinfo.density_unit = 1;  // dpi
>
>      cinfo.X_density = UInt16(pImage->getResX()<  0.0f ?
>
>                               pImage->getResX() - 0.5f :
>
>                               pImage->getResX() + 0.5f);
>
>      cinfo.Y_density = UInt16(pImage->getResY()<  0.0f ?
>
>                               pImage->getResY() - 0.5f :
>
>                               pImage->getResY() + 0.5f);
>
> */
>
>      jpeg_create_compress(&cinfo);
>
>
>
>      DestinationManager *destinationManager =
>
>          new ((*cinfo.mem->alloc_small)(j_common_ptr(&cinfo),
>
>                                         JPOOL_IMAGE,
>
>                                         sizeof(DestinationManager)))
>
>          DestinationManager(&cinfo, os);
>
>
>
>      cinfo.dest =
> reinterpret_cast<jpeg_destination_mgr*>(destinationManager);
>
>
>
>      jpeg_set_defaults(&cinfo);
>
>
>
>      cinfo.density_unit = 1;  // dpi
>
>      cinfo.X_density = UInt16(pImage->getResX()<  0.0f ?
>
>                               pImage->getResX() - 0.5f :
>
>                               pImage->getResX() + 0.5f);
>
>      cinfo.Y_density = UInt16(pImage->getResY()<  0.0f ?
>
>                               pImage->getResY() - 0.5f :
>
>                               pImage->getResY() + 0.5f);
>
>
>
>      cinfo.image_width = pImage->getWidth();
>
>      cinfo.image_height = pImage->getHeight();
>
>      cinfo.input_components = pImage->getBpp();
>
>      cinfo.in_color_space = (pImage->getBpp() == 1) ? JCS_GRAYSCALE :
> JCS_RGB;
>
> Could someone please check and change the code base.

hmm, perhaps I'm misreading your message, but to me it sounds as if you 
are not certain if the proposed change fixes your problem. Have you 
tried it, does it make a difference?

FWIW, /usr/share/doc/libjpeg-devel-6b/libjpeg.doc contains this:

<quote>
You must set in_color_space correctly before calling jpeg_set_defaults(),
because the defaults depend on the source image colorspace.  However the
other three source image parameters need not be valid until you call
jpeg_start_compress().  There's no harm in calling jpeg_set_defaults() more
than once, if that happens to be convenient.

Typical code for a 24-bit RGB source image is

cinfo.image_width = Width;      /* image width and height, in pixels */
cinfo.image_height = Height;
cinfo.input_components = 3;     /* # of color components per pixel */
cinfo.in_color_space = JCS_RGB; /* colorspace of input image */

jpeg_set_defaults(&cinfo);
/* Make optional parameter settings here */
</quote>

hmm, reading a bit more in libjpeg.doc it seems that X_density, 
Y_density are considered compression parameters that are set to default 
values by jpeg_set_defaults(), so those two assignments should move 
after the call, the rest should (must, in case of cinfo.in_color_space) 
remain before the call.
You seem to be set up to actually test this, would you be able to just 
move the X_density, Y_density assignment down and see if that fixes your 
problem?

        Cheers,
                Carsten

------------------------------------------------------------------------------
Special Offer -- Download ArcSight Logger for FREE!
Finally, a world-class log management solution at an even better 
price-free! And you'll get a free "Love Thy Logs" t-shirt when you
download Logger. Secure your free ArcSight Logger TODAY!
http://p.sf.net/sfu/arcsisghtdev2dev
_______________________________________________
Opensg-users mailing list
Opensg-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to