Hi Robert,

I have indeed gone through the debugger and the values are what I would
expect.  I've attached an example so you could see the issue.  If I am
interpreting the osg::copyImage parameters correctly, then the "if
((src_t+height) > (dest_t + destImage->t()))" check seems should rather be
"if ((src_t+height) > (srcImage->t()))" if testing if the height parameter
is valid.  The attached example fails the "if ((src_t+height) > (dest_t +
destImage->t()))" check.  If I remove this check from osg::copyImage, then
the output image is what I would expect.

Thanks,

Donny


On Wed, Apr 22, 2009 at 1:10 PM, Robert Osfield <[email protected]>wrote:

> Hi Donald,
>
> Have you gone through your code with a debugger at all?  Check what
> value of nHalfSrcHeight you are getting.
>
> One fix to your code you could do would be to use /2 rather *0.5 as /2
> can use integer maths, while *0.5 requires pImageSrc->t() to be
> automatically promoted to a float for it work.
>
> Robert.
>
> On Wed, Apr 22, 2009 at 5:57 PM, Donald Cipperly <[email protected]>
> wrote:
> > Hi Robert,
> >
> > I'm trying to copy the top half of an existing image using
> osg::copyImage.
> > I do this as such:
> >
> >     // Read in source image
> >     osg::ref_ptr< osg::Image > pImageSrc = osgDB::readImageFile(
> "test.jpg"
> > );
> >     int nHalfSrcHeight = (int)(pImageSrc->t() * 0.5);
> >
> >     // Allocate destination image
> >     osg::Image *pImageDest = new osg::Image();
> >     pImageDest->allocateImage(pImageSrc->s(), nHalfSrcHeight,
> > pImageSrc->r(), pImageSrc->getPixelFormat(), pImageSrc->getDataType());
> >
> >     // Copy top half of source image to destination
> >     myCopyImage( pImageSrc.get(), 0, (nHalfSrcHeight-1), 0,
> pImageSrc->s(),
> > nHalfSrcHeight, pImageSrc->r(),
> >         pImageDest, 0, 0, 0, false );
> >
> >
> > This appears to be the correct way to perform this operation.  Is this
> > correct?  If so, then line 210 of osg/ImageUtils.cpp appears to be
> incorrect
> > as it notifies that my input height is too large.  And indeed when I
> commend
> > out the block below in ImageUtils.cpp, then it outputs the top half of my
> > image as I expect.
> >
> >     if ((src_t+height) > (dest_t + destImage->t()))
> >     {
> >         osg::notify(osg::NOTICE)<<"copyImage("<<srcImage<<", "<<src_s<<",
> > "<< src_t<<", "<<src_r<<", "<<width<<", "<<height<<",
> "<<depth<<std::endl;
> >         osg::notify(osg::NOTICE)<<"          "<<destImage<<",
> "<<dest_s<<",
> > "<< dest_t<<", "<<dest_r<<", "<<doRescale<<")"<<std::endl;
> >         osg::notify(osg::NOTICE)<<"   input height too
> large."<<std::endl;
> >         return false;
> >     }
> >
> > Thanks for any help you can provide,
> >
> > Donny
> >
> >
> > _______________________________________________
> > 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
>

#include <osgDB/ReadFile>
#include <osgDB/WriteFile>
#include <osg/ImageUtils>



int main( int, char **)
{
        // Read in source image...clockface.JPG from the base 
OpenSceneGraph-Data
        osg::ref_ptr< osg::Image > pImageSrc = osgDB::readImageFile( 
"Images/clockface.JPG" );
        int nHalfSrcHeight = pImageSrc->t() / 2;

        // Allocate destination image
        osg::Image *pImageDest = new osg::Image();
        pImageDest->allocateImage(pImageSrc->s(), nHalfSrcHeight, 
pImageSrc->r(), pImageSrc->getPixelFormat(), pImageSrc->getDataType());

        // Copy top half of source image to destination
        osg::copyImage( pImageSrc.get(), 0, (nHalfSrcHeight-1), 0, 
pImageSrc->s(), nHalfSrcHeight, pImageSrc->r(), 
                pImageDest, 0, 0, 0, false );

        // Write the destination image to file
        osgDB::writeImageFile( *pImageDest, 
std::string("C:/OpenSceneGraph-Data/Images/clockfaceTop.jpg") );

    return 0;
}
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to