Giter VIP home page Giter VIP logo

Comments (6)

DanBloomberg avatar DanBloomberg commented on August 16, 2024

BMP writing in leptonica has been tested on many different kinds of images.
For example, the following when run with valgrind has no memory issues, where the
images being tested are all in the prog directory:

const char *infile[15] = {"test1.bmp", "speckle2.png", "weasel2.4g.png",
                          "speckle4.png", "dreyfus8.png", "weasel8.240c.png",
                          "test8.jpg", "test16.tif", "marge.jpg",
                          "test32-alpha.png", "test-1bit-alpha.png",
                          "test-cmap-alpha.png", "test-fulltrans-alpha.png",
                          "test-gray-alpha.png", "gray-alpha.tif"};

    pixa1 = pixaCreate(16);
    for (i = 0; i < 15; i++) {
        pix1 = pixRead(infile[i]);
        cmap = pixGetColormap(pix1);
        snprintf(outfile, sizeof(outfile), "/tmp/outfile.%d", i);
        pixWrite(outfile, pix1, IFF_BMP);
        pix2 = pixRead(outfile);
        if (!cmap)
            pix3 = pixRemoveColormap(pix2, REMOVE_CMAP_BASED_ON_SRC);
        else
            pix3 = pixClone(pix2);
        pixaAddPix(pixa1, pix3, L_INSERT);
        pixEqual(pix1, pix3, &equal);
        if (!equal)
            lept_stderr("failure for i = %d\n", i);
        pixDestroy(&pix1);
        pixDestroy(&pix2);
    }
    pix1 = pixaDisplayTiledInColumns(pixa1, 1, 1.0, 30, 2);
    pixWrite("/tmp/results.png", pix1, IFF_PNG);
    pixaDestroy(&pixa1);
    pixDestroy(&pix1);

Questions:

  • How do you know the failure is due to not checking for a colormap'?
  • What is the input image that is failing in tesseract?

It would help to write the pix out in png format.

from leptonica.

casensiom avatar casensiom commented on August 16, 2024

I'm using a raw image from memory.
I use this method from Tesseract to initialize the image:

void TessBaseAPI::SetImage(const unsigned char *imagedata, int width, int height,
                           int bytes_per_pixel, int bytes_per_line) {
  if (InternalSetImage()) {
    thresholder_->SetImage(imagedata, width, height, bytes_per_pixel, bytes_per_line);
    SetInputImage(thresholder_->GetPixRect());
  }
}

I found the crash location while debugging. I'm using tesseract 1.83.1

As you can see in the screenshot I have to add an small patch to use the library. (just a check for the presence of colormap)
leptonica-patch

I will try to write the pix in png format and let you know about it.

from leptonica.

DanBloomberg avatar DanBloomberg commented on August 16, 2024

Thank you. You have prevented the crash by adding the check for the colormap, right?

That code in bmpio.c says that bmp files with d <=8 have colormaps.
This pix has d = 32 bpp, with 3 spp. So it does not have a colormap.
Without the check that you added, it crashes in l. 548 when referencing into NULL.

I don't need the png file and will fix the code.

from leptonica.

casensiom avatar casensiom commented on August 16, 2024

Right, that’s exactly the situation.
Thanks

from leptonica.

DanBloomberg avatar DanBloomberg commented on August 16, 2024

Resolved in commit 76c635c

from leptonica.

DanBloomberg avatar DanBloomberg commented on August 16, 2024

Thanks again, Carlos !

from leptonica.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.