Hi all,

I just wanted to resurrect this thread to see if I really had a bug or if one of you has a solution to this problem.

I'm trying to get the bits of the png image out of the vil_stream_core. With the jpeg format I can omit the imageResource = NULL; line and the vil_stream_core contains the whole bitstream. The png format writes the header only and claims to need to be destroyed (in vil_png.cxx) before the total image is written to the stream. Below is the code snippet that causes the crash:

vil_image_view<vxl_byte> frame = vil_load( "woo.png" );

vil_stream* imgStream = new vil_stream_core();

  vil_image_resource_sptr imageResource = vil_new_image_resource(
    imgStream, frame.ni(), frame.nj(),
    frame.nplanes() *
    vil_pixel_format_num_components( frame.pixel_format() ),
    vil_pixel_format_component_format( frame.pixel_format() ),
    "png" );

imageResource->put_view( frame, 0, 0 );

imageResource = NULL;

imageStream->tell(); // SEGFAULT

Any hints would be greatly appreciated.

Patrick Reynolds
R & D Engineer
Kitware, Inc.
919 969 6990 x303

On Wed, Apr 29, 2009 at 11:29 AM, Patrick Reynolds <patrick.reynolds@kitware.com> wrote:

Thanks for the help. vil_stream_core cannot be used without deriving it (it has a protected destructor). I've created a simple derived class and I end up with the same problem when using it.

I'll try that debugging tip with vil_stream_core.

Patrick Reynolds
R & D Engineer
Kitware, Inc.

On Wed, Apr 29, 2009 at 11:22 AM, Ian Scott <ian.m.scott@student.manchester.ac.uk> wrote:
Not that this will fix your actual problem, but you are trying to write into a buffer, so why go via a vil_stream_fstream which wraps a real file? Just use the in memory derivative of vil_stream - vil_stream_core.

Have you checked if your tmp file contains a valid png?

One possibility is that the png image resource won't finish (or possibly even start) writing the file until the resource is destroyed.

If it isn't that, I can't see anything obviously wrong. But I start debugging by putting a break point at the vil_stream_whatever::write() method and check that meaningful data is going into the stream.


Patrick Reynolds wrote:
Hi all,

I'm trying to write a simple application that takes a vil_image_view and writes it to a buffer in a given encoding, png for example. The method in which I'm trying to do this seems logical, but doesn't yield the correct data into the buffer (code below):

vil_image_view<vxl_byte> frame = vil_load( "test.png" );
vil_png_file_format png;
vil_stream_fstream* pngStream = new vil_stream_fstream( "tmp", "r" ); // I've tried this with 'w' as well
vil_image_resource_sptr pngImageRes = png.make_output_image(
                                                      frame.ni <http://frame.ni>(),

                                                      VIL_PIXEL_FORMAT_BYTE );

pngImageRes->put_view( frame );
char* buf = new char[ pngStream->file_size() ];
pngStream->read( buf, pngStream->file_size() );

I've also tried this using a simple sub-class of vil_stream_core that simply makes its destructor public, but I get the same or similar results. Hopefully, I'm missing something simple.

Also, sorry if this is a question that's been asked before, sourceforge's mailing list search seems to be broken... Anyone know of another way to search it?

Patrick Reynolds
R & D Engineer
Kitware, Inc.