using libjpeg.a : "Output file write error"

J

JR

Hi all,

I'm experiencing a problem using the libjpeg.a (version 7.0) when i
execute a small application of mine that converts a bpm file into jpg
format.
when writing the jpg output to file, the libjpeg complains:

"Output file write error --- out of disk space?"

OK.
1.) yes i have enough disk space left.
2.) my platform is CYGWIN_NT-5.1
3.) inside the libjpeg, i traced the error to the function jdatadst.c,
this is the code fragment that causes the trouble:

/* Write any data remaining in the buffer */
if (datacount > 0) {
if (JFWRITE(dest->outfile, dest->buffer, datacount) != datacount)
{
printf("location 2\n"); fflush(stdout);
ERREXIT(cinfo, JERR_FILE_WRITE);
}
}
4.) the code fragment that calls 3.) looks as follows:
for (y=0; y<height; ++y) {
*rp = (str + y*x);
jpeg_write_scanlines( &cinfo, rp, 1 );
}
with x being the size of a row.


Did anybody experience (and pro'ly solve) this problem before?
TIA,

Jorg.
 
B

Ben Bacarisse

JR said:
I'm experiencing a problem using the libjpeg.a (version 7.0) when i
execute a small application of mine that converts a bpm file into jpg
format.
when writing the jpg output to file, the libjpeg complains:

"Output file write error --- out of disk space?"
/* Write any data remaining in the buffer */
if (datacount > 0) {
if (JFWRITE(dest->outfile, dest->buffer, datacount) != datacount)
{
printf("location 2\n"); fflush(stdout);
ERREXIT(cinfo, JERR_FILE_WRITE);
}
}
Did anybody experience (and pro'ly solve) this problem before?

Did you open the output stream in binary mode? It is possible that
whatever code lies behind JFWRITE might be counting bytes output
rather than elements written (as C's fwrite is obliged to do) and it
is therefore getting confused by a \n to \r\n translation.

Not likely, I admit, but it seems worth checking that first off.
 
B

Barry Schwarz

Hi all,

I'm experiencing a problem using the libjpeg.a (version 7.0) when i
execute a small application of mine that converts a bpm file into jpg
format.
when writing the jpg output to file, the libjpeg complains:

"Output file write error --- out of disk space?"

OK.
1.) yes i have enough disk space left.
2.) my platform is CYGWIN_NT-5.1
3.) inside the libjpeg, i traced the error to the function jdatadst.c,
this is the code fragment that causes the trouble:

/* Write any data remaining in the buffer */
if (datacount > 0) {
if (JFWRITE(dest->outfile, dest->buffer, datacount) != datacount)
{
printf("location 2\n"); fflush(stdout);
ERREXIT(cinfo, JERR_FILE_WRITE);
}
}

If JFWRITE calls fwrite and returns its return value, there are other
reasons than lack of disk space which can cause this error message.
That is the significance of the "?" at the end of the error message.

Are you certain the output file was opened successfully? Do you have
permission to write to the file? Could another task have the file
locked? Have you checked your disk for bad sectors?

Considerations raised by a brief google search: Have you successfully
used this version libjpeg before? Are you sure you built it correctly
after downloading it? Did you recently convert from version 6.2?

You might want to perform a more thorough review of google hits.
 
J

JR

Are you certain the output file was opened successfully?

yes, certainly checked it before
Do you have
permission to write to the file?  
yes

Could another task have the file
locked?
no

Have you checked your disk for bad sectors?

:) by now, yes. it is OK
Considerations raised by a brief google search: Have you successfully
used this version libjpeg before?

no, i used 6.2 and upgraded after i experienced the same problem w/
6.2
Are you sure you built it correctly
after downloading it?  

yes! (-> "make test")

thank you for the suggestions anyway.

as suggested by Ben, i will now go into jfwrite and implement some
checks and output there.

Jorg
 
J

jacob navia

JR a écrit :
Hi all,

I'm experiencing a problem using the libjpeg.a (version 7.0) when i
execute a small application of mine that converts a bpm file into jpg
format.
when writing the jpg output to file, the libjpeg complains:

"Output file write error --- out of disk space?"

OK.
1.) yes i have enough disk space left.
2.) my platform is CYGWIN_NT-5.1
3.) inside the libjpeg, i traced the error to the function jdatadst.c,
this is the code fragment that causes the trouble:

/* Write any data remaining in the buffer */
if (datacount > 0) {
if (JFWRITE(dest->outfile, dest->buffer, datacount) != datacount)
{
printf("location 2\n"); fflush(stdout);
ERREXIT(cinfo, JERR_FILE_WRITE);
}
}
4.) the code fragment that calls 3.) looks as follows:
for (y=0; y<height; ++y) {
*rp = (str + y*x);
jpeg_write_scanlines( &cinfo, rp, 1 );
}
with x being the size of a row.


Did anybody experience (and pro'ly solve) this problem before?
TIA,

Jorg.

could be that your file is bigger than 2gigs and that your
fwrite is 32 bits?
 
B

Barry Schwarz

yes, certainly checked it before


:) by now, yes. it is OK


no, i used 6.2 and upgraded after i experienced the same problem w/
6.2

The first couple of google hits are about problems converting from 6.2
to 7.0.
 
J

JR

OK folks,
here's the solution.

Manager's summary: Barry's guess was best ("there are other reasons
than lack of disk space...")

my code was:

for (y=0; y<height; ++y) {
*rp = (str + y*x);
jpeg_write_scanlines( &cinfo, rp, 1 );
} ,
where jpeg_write_scanlines is a function which does not directly
convert data into jpg format and write these. instead, a buffer is
filled with raw image data.
The libjpeg converts this buffer to the target format and writes it to
the destination file only when the compression is executed with
jpeg_finish_compress(&cinfo).
This is how my code continued:

<begin original code>
// -- clean up
fclose(fp);
jpeg_finish_compress(&cinfo);
jpeg_destroy_compress(&cinfo);
<end original code>

This is certainly f**ed up because fp is closed before the compression
is executed and the jpg buffer is written. it must be

<begin corrected code>
// -- clean up
jpeg_finish_compress(&cinfo);
jpeg_destroy_compress(&cinfo);
fclose(fp);
<end corrected code>

So, the 7.0 is fine (so far), the reason is me being braindead.
Annoys me. At least, where there's pain, there must still be life.
Thank you to all of you, and have a merry christmas.

Jorg.
 
B

BGB / cr88192

jacob navia said:
JR a écrit :

could be that your file is bigger than 2gigs and that your
fwrite is 32 bits?

if writing a JPEG does this, then one has BIGGER problems...


oddly, I don't use libjpeg, as I instead just beat together a JPEG
reader/writer based of of T.81 and JFIF... (it does not directly read/write
files, rather encode/decode images in memory buffers...).

I also used it before to beat together a "motion JPEG" output video codec
for my 3D renderer, but alas many people seem unable to play the files due
to not going and downloading CCCP or similar.

well, that, and the files are large, and it was difficult to get real-time
video-capture to work without too severe of a framerate impact.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top