siriz / leptonica

Automatically exported from code.google.com/p/leptonica
0 stars 0 forks source link

GIF file support is broken #28

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Try to run gifio_reg.

What is the expected output? What do you see instead?
I expect to see various gif files created.
Instead gifio_reg fails to compile under Windows, and when compilation
errors are fixed, leptonica aborts with "file not open" error.

What version of the product are you using? On what operating system?
leptonlib-1.64
Microsoft Visual Studio 2008 SP1 with latest updates also applied.
Windows XP Pro SP3.

Please provide any additional information below.

First of all, gifio.c isn't part of the current leptonlib.vcproj file, only
gifiostub.c is (I'll fix this).

Next, gifio.c has to be changed to:

#ifndef COMPILER_MSVC
#include <unistd.h>
#else
#include <io.h>
#endif

and near line 76:

#ifndef COMPILER_MSVC
    lseek(fd, 0, SEEK_SET);
#else
    _lseek(fd, 0, SEEK_SET);
#endif

----

Since EGifCloseFile() in egif_lib.c (called by
pixWriteStream/pixWriteStreamGif) at line 760 does:

    if (File && fclose(File) != 0) {
        _GifError = E_GIF_ERR_CLOSE_FAILED;
        return GIF_ERROR;
    }

writefile.c line 241, needs to be changed to:

    if (format != IFF_GIF)
        fclose(fp);

---

Similar issue with DGifCloseFile() in dgif_lib.c at line 610 (called
from pixReadStreamGif):

    if (File && (fclose(File) != 0)) {
        _GifError = D_GIF_ERR_CLOSE_FAILED;
        return GIF_ERROR;
    }

so pixRead() in readfile.c, needs to be changed to:

PIX *
pixRead(const char  *filename)
{
FILE  *fp;
PIX   *pix;
l_int32  format;

    PROCNAME("pixRead");

    if (!filename)
        return (PIX *)ERROR_PTR("filename not defined", procName, NULL);

    if ((fp = fopenReadStream(filename)) == NULL)
        return (PIX *)ERROR_PTR("image file not found", procName, NULL);
    pix = pixReadStream(fp, 0);
    format = getImpliedFileFormat(filename);
    if (format != IFF_GIF)
        fclose(fp);

    if (!pix)
        return (PIX *)ERROR_PTR("image not returned", procName, NULL);
    return pix;
}

Original issue reported on code.google.com by tomp2...@gmail.com on 8 Jan 2010 at 4:05

GoogleCodeExporter commented 9 years ago
Hi,
thanks for your corrections.Leptonica164 can read gif images but when close the
program it gives error. i guess it's due to gifiostub.c. it must be fixed.
Thanks

Original comment by fatih...@gmail.com on 8 Jan 2010 at 1:08

GoogleCodeExporter commented 9 years ago
Thanks Tom.  All changes will be incorporated in 1.65.

In pixRead(), use pixGetInputFormat() because the extension may be incorrect
or missing, and we have just read the pix from file so we know the actual 
format.

The nerve of the giflib, to close an open stream that was passed in to its 
functions!!

Original comment by dan.bloo...@gmail.com on 8 Jan 2010 at 6:05

GoogleCodeExporter commented 9 years ago
Fixed in 1.65

Original comment by dan.bloo...@gmail.com on 8 Apr 2010 at 6:01