Re: [osg-users] [osgPlugins] Difficulties to load images from memory

2011-06-14 Thread Daniel Cámpora
Hello community,

Apparently, the problem is related to the formation of the strings I'm trying 
to pass to the istringstream. Since they contain the \0 character, they finish 
earlier than expected.

Has anybody found any workaround for this?

Thank you!

Cheers,
Daniel

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=40466#40466





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


Re: [osg-users] [osgPlugins] Difficulties to load images from memory

2011-06-14 Thread Chuck Seberino
Daniel,

Use the ios::binary open mode for istringstream.

HTH
Chuck

On Jun 14, 2011, at 7:35 AM, Daniel Cámpora wrote:

 Hello community,
 
 Apparently, the problem is related to the formation of the strings I'm trying 
 to pass to the istringstream. Since they contain the \0 character, they 
 finish earlier than expected.
 
 Has anybody found any workaround for this?
 
 Thank you!
 
 Cheers,
 Daniel
 
 --
 Read this topic online here:
 http://forum.openscenegraph.org/viewtopic.php?p=40466#40466
 
 
 
 
 
 ___
 osg-users mailing list
 osg-users@lists.openscenegraph.org
 http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

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


Re: [osg-users] [osgPlugins] Difficulties to load images from memory

2011-06-14 Thread J.P. Delport

Hi,

std::string has a constructor that you can pass a char* and size to.

string ( const char * s, size_t n );

This ignores \0's.

You can then  it into a stringstream or possibly even directly put it 
into stringstream.str()


HTH
jp

On 14/06/11 16:35, Daniel Cámpora wrote:

Hello community,

Apparently, the problem is related to the formation of the strings I'm trying 
to pass to the istringstream. Since they contain the \0 character, they finish 
earlier than expected.

Has anybody found any workaround for this?

Thank you!

Cheers,
Daniel

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=40466#40466





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


--
This message is subject to the CSIR's copyright terms and conditions, e-mail legal notice, and implemented Open Document Format (ODF) standard. 
The full disclaimer details can be found at http://www.csir.co.za/disclaimer.html.


This message has been scanned for viruses and dangerous content by MailScanner, 
and is believed to be clean.


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


Re: [osg-users] [osgPlugins] Difficulties to load images from memory

2011-06-14 Thread Daniel Cámpora
Thanks J.P., that was the working solution :)

I found a comprehensive explanation on SO, if anybody is interested.
http://stackoverflow.com/questions/2786816/how-to-create-c-istringstream-from-a-char-array-with-null0-characters

Thanks! :)

Daniel

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=40473#40473





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


Re: [osg-users] [osgPlugins] Difficulties to load images from memory

2011-06-10 Thread Ulrich Hertlein
Hi Daniel,

On 10/06/11 15:56 , Daniel Cámpora wrote:
 I'd like to use the image loaders OSG implements. I've succesfully fetched 
 images from
 web links and my own HD. However, now I'm trying to do the same with an image 
 stored in
 a string, in main memory.
 
 My OSG version is 2.9.9. The extension for the file is png, and considering s 
 is the
 string containing the image, I've tried the following portion of code:
 
 Code: osg::ref_ptrosg::Image image;
 osgDB::ReaderWriter* rw = 
 osgDB::Registry::instance()-getReaderWriterForExtension(png);
 if (rw) { 
 osgDB::ReaderWriter::ReadResult rr = rw-readImage(s);
 if ( rr.success() )
 image = rr.takeImage();
 }

None of the plugins support reading from a string (a string is always 
interpreted as a
file name), but some support reading from a stream, which can be a stringstream.

Try (from memory):
std::stringstream ss(s);
rw-readImage(ss);

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


Re: [osg-users] [osgPlugins] Difficulties to load images from memory

2011-06-10 Thread Daniel Cámpora
Hi Ulrich,

Thanks for the answer. Shortly before your answer I found out I could try the 
istringstream, but I still can't get it to work. The direct conversion is not 
working out of the box for me, it might be related to the string not being 
correctly generated (png crashes, jpeg gives a Corrupt JPEG data pop up).

I'll keep trying.

Thank you!

Cheers,
Daniel

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=40358#40358





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