/* * pdf_test_invert.c * * Generates pdf from 1 bpp pix, with and without a colormap. * Inspection of the two pdf files generated shows that the first * has a colormap and the second one doesn't. */ #include "allheaders.h" l_int32 main(int argc, char **argv) { l_uint8 *data8; size_t nbytes; PIX *pix1, *pix2; PIXCMAP *cmap, *cmap2; L_COMP_DATA *cid1, *cid2; setLeptDebugOK(1); // This troublesome 1 bpp image may have had a colormap. // Reading using pixRead() will remove it, if it existed. pix1 = pixRead("bitinvert1.png"); pixDisplay(pix1, 100, 0); // Put a colormap in by hand cmap = pixcmapCreate(1); pixcmapAddColor(cmap, 255, 255, 255); // white = 0 pixcmapAddColor(cmap, 0, 0, 0); // black = 1 pixSetColormap(pix1, cmap); pixDisplay(pix1, 100, 300); // Generate a pdf from this pix. The pdf has the colormap. pixGenerateCIData(pix1, L_FLATE_ENCODE, 0, 0, &cid1); fprintf(stderr, "Should have 2 colors: num colors1 = %d\n", cid1->ncolors); cidConvertToPdfData(cid1, "with colormap",&data8, &nbytes); l_binaryWrite("/tmp/bitinvert1.pdf", "w", data8, nbytes); // Write pix1 out as PNG; the colormap is in the PNG file pixWrite("/tmp/bitinvert2.png", pix1, IFF_PNG); // has colormap pix2 = pixRead("/tmp/bitinvert2.png"); // this removes the colormap pixDisplay(pix2, 100, 600); lept_free(data8); // Generate a pdf from bitinvert2.png. // l_generateCIDataForPdf() calls l_generateFlateDataPdf() // which calls pixRead(), removing the cmap l_generateCIDataForPdf("/tmp/bitinvert2.png", NULL, 75, &cid1); fprintf(stderr, "Should have 0 colors: num colors1 = %d\n", cid1->ncolors); cidConvertToPdfData(cid1, "no colormap",&data8, &nbytes); l_binaryWrite("/tmp/bitinvert2.pdf", "w", data8, nbytes); lept_free(data8); pixDestroy(&pix1); pixDestroy(&pix2); return 0; }