X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=pdf%2Fxpdf%2FThumb.cc;h=0fdbf541a55ce6580c5c359f8d7440d5898c3f90;hb=1f7e03f2861f4b8d2bb75bd220754b7a89b7847e;hp=6c0c3b6d4e4e5e3e0adecdf029fdab25f26d4c78;hpb=6f1bebdea1c8a0302544588f81506bfe72750124;p=evince.git diff --git a/pdf/xpdf/Thumb.cc b/pdf/xpdf/Thumb.cc index 6c0c3b6d..0fdbf541 100644 --- a/pdf/xpdf/Thumb.cc +++ b/pdf/xpdf/Thumb.cc @@ -36,188 +36,18 @@ #include "GfxState.h" #include "Thumb.h" -static GHashTable *cmhash = NULL; - -/* - * ThumbColorMap - */ -ThumbColorMap::ThumbColorMap(int bitsA, - Object *obj, - GfxColorSpace *csA) : - bits(bitsA), - str(NULL), - length(0), - cs(csA) -{ - Object obj1, obj2; - GfxIndexedColorSpace *iCS; - GfxSeparationColorSpace *sepCS; - int maxPixel, indexHigh; - Dict *streamDict; - int n; - int baseNComps; - /* LZW params */ - int colors = 0, early = 0; - /* CCITTFax params */ - int encoding = 0, rows = 0; - GBool eol = gFalse, byteAlign = gFalse, eob = gFalse, black = gFalse; - /* Common params */ - int pred = 0, cols = 0; - - ok = gFalse; - maxPixel = (1 << bits) - 1; - - do { - if (!obj->isStream ()) { - printf ("Error: Invalid object of type %s\n", - obj->getTypeName ()); - break; - } - str = obj->getStream(); - - streamDict = obj->streamGetDict (); - - streamDict->lookupNF ("Filter", &obj1); - if (!obj1.isArray ()) { - printf ("Error: Invalid filter object of type %s\n", - obj1.getTypeName ()); - break; - } - - str = str->addFilters(obj); - - streamDict->lookup ("Length", &obj1); - if (obj1.isNull ()) - { - printf ("Error: No Length object\n"); - break; - } - if (!obj1.isInt ()) { - printf ("Error: Invalid Width object %s\n", - obj1.getTypeName ()); - obj1.free (); - break; - } - length = obj1.getInt (); - obj1.free (); - - nComps = cs->getNComps(); - - if (cs->getMode () == csIndexed) { - iCS = (GfxIndexedColorSpace *)cs; - baseNComps = iCS->getBase ()->getNComps (); - str->reset(); - if (iCS->getBase ()->getMode () == csDeviceGray) { - gray = (double *)gmalloc(sizeof(double) * (iCS->getIndexHigh () + 1)); - for (n = 0; n <= iCS->getIndexHigh (); n++) { - double comp = (double)str->getChar(); - //printf ("Gray pixel [%03d] = %02x\n", n, (int)comp); - gray[n] = comp / (double)iCS->getIndexHigh (); - } - } - else if (iCS->getBase ()->getMode () == csDeviceRGB) { - rgb = (GfxRGB *)gmalloc(sizeof(GfxRGB) * (iCS->getIndexHigh () + 1)); - for (n = 0; n <= iCS->getIndexHigh (); n++) { - double comp_r = (double)str->getChar(); - double comp_g = (double)str->getChar(); - double comp_b = (double)str->getChar(); -// printf ("RGB pixel [0x%02x] = (%02x,%02x,%02x)\n", -// n, (int)comp_r, (int)comp_g, (int)comp_b); - rgb[n].r = comp_r / (double)iCS->getIndexHigh (); - rgb[n].g = comp_g / (double)iCS->getIndexHigh (); - rgb[n].b = comp_b / (double)iCS->getIndexHigh (); - } - } - else if (iCS->getBase ()->getMode () == csDeviceCMYK) { - cmyk = (GfxCMYK *)gmalloc(sizeof(GfxCMYK) * (iCS->getIndexHigh () + 1)); - for (n = 0; n <= iCS->getIndexHigh (); n++) { - double comp_c = (double)str->getChar(); - double comp_m = (double)str->getChar(); - double comp_y = (double)str->getChar(); - double comp_k = (double)str->getChar(); - //printf ("CMYK pixel [%03d] = (%02x,%02x,%02x,%02x)\n", - // n, (int)comp_c, (int)comp_m, (int)comp_y, (int)comp_k); - cmyk[n].c = comp_c / (double)iCS->getIndexHigh (); - cmyk[n].m = comp_m / (double)iCS->getIndexHigh (); - cmyk[n].y = comp_y / (double)iCS->getIndexHigh (); - cmyk[n].k = comp_k / (double)iCS->getIndexHigh (); - } - } - } - else if (cs->getMode () == csSeparation) { - sepCS = (GfxSeparationColorSpace *)cs; - /* FIXME: still to do */ - } - - ok = gTrue; - } - while (0); -} - -ThumbColorMap * -ThumbColorMap::lookupColorMap(XRef *xref, int bits, Object *obj, GfxColorSpace *cs) -{ - Object obj1; - ThumbColorMap *cm; - gchar *key; - - if (!cmhash) - cmhash = g_hash_table_new(NULL, g_int_equal); - - key = g_strdup_printf ("%d %d R", obj->getRefNum (), obj->getRefGen ()); - - if (!(cm = (ThumbColorMap *)g_hash_table_lookup (cmhash, &key))) { - cm = new ThumbColorMap(bits, obj->fetch(xref, &obj1), cs); - obj1.free(); - g_hash_table_insert(cmhash, &key, cm); - } - - g_free (key); - - return cm; -} - -void -ThumbColorMap::getGray(Guchar *x, double *outgray) -{ - *outgray = gray[*x]; -} - -void -ThumbColorMap::getRGB(Guchar *x, GfxRGB *outrgb) -{ - outrgb->r = rgb[*x].r; - outrgb->g = rgb[*x].g; - outrgb->b = rgb[*x].b; -} - -void -ThumbColorMap::getCMYK(Guchar *x, GfxCMYK *outcmyk) -{ - outcmyk->c = cmyk[*x].c; - outcmyk->m = cmyk[*x].m; - outcmyk->y = cmyk[*x].y; - outcmyk->k = cmyk[*x].k; -} - -ThumbColorMap::~ThumbColorMap() -{ - delete str; - gfree((void *)gray); -} - /* * Thumb */ Thumb::Thumb(XRef *xrefA, Object *obj) : xref(xrefA), - str(NULL) + str(NULL), + ok_flag(0) { Object obj1, obj2; Dict *dict; - unsigned int dsize; - int row, col, comp; + GfxColorSpace *colorSpace; do { /* Get stream dict */ @@ -232,7 +62,7 @@ Thumb::Thumb(XRef *xrefA, Object *obj) : dict->lookup ("W", &obj1); } if (!obj1.isInt ()) { - printf ("Error: Invalid Width object %s\n", + fprintf (stderr, "Error: Invalid Width object %s\n", obj1.getTypeName ()); obj1.free (); break; @@ -248,7 +78,7 @@ Thumb::Thumb(XRef *xrefA, Object *obj) : dict->lookup ("H", &obj1); } if (!obj1.isInt ()) { - printf ("Error: Invalid Height object %s\n", + fprintf (stderr, "Error: Invalid Height object %s\n", obj1.getTypeName ()); obj1.free (); break; @@ -264,7 +94,7 @@ Thumb::Thumb(XRef *xrefA, Object *obj) : dict->lookup ("BPC", &obj1); } if (!obj1.isInt ()) { - printf ("Error: Invalid BitsPerComponent object %s\n", + fprintf (stderr, "Error: Invalid BitsPerComponent object %s\n", obj1.getTypeName ()); obj1.free (); break; @@ -279,21 +109,29 @@ Thumb::Thumb(XRef *xrefA, Object *obj) : obj1.free (); dict->lookup ("CS", &obj1); } - if (!(gfxCS = GfxColorSpace::parse (&obj1))) - { - printf ("Error: Cannot parse color space\n"); - obj1.free (); + colorSpace = GfxColorSpace::parse(&obj1); + obj1.free(); + if (!colorSpace) { + fprintf (stderr, "Error: Cannot parse color space\n"); break; } - if (gfxCS->getMode () == csIndexed) - thumbCM = ThumbColorMap::lookupColorMap (xref, bits, obj1.arrayGetNF(3, &obj2), gfxCS); - else if (gfxCS->getMode () == csSeparation) - printf ("Not yet implemented\n"); - - + + dict->lookup("Decode", &obj1); + if (obj1.isNull()) { + obj1.free(); + dict->lookup("D", &obj1); + } + colorMap = new GfxImageColorMap(bits, &obj1, colorSpace); + obj1.free(); + if (!colorMap->isOk()) { + fprintf (stderr, "Error: invalid colormap\n"); + delete colorMap; + colorMap = NULL; + } + dict->lookup ("Length", &obj1); if (!obj1.isInt ()) { - printf ("Error: Invalid Length Object %s\n", + fprintf (stderr, "Error: Invalid Length Object %s\n", obj1.getTypeName ()); obj1.free (); break; @@ -302,6 +140,8 @@ Thumb::Thumb(XRef *xrefA, Object *obj) : obj1.free (); str->addFilters(obj); + + ok_flag = 1; } while (0); } @@ -312,15 +152,21 @@ Thumb::getPixbufData() ImageStream *imgstr; unsigned char *pixbufdata; unsigned int pixbufdatasize; - int row, col, i; + int row, col; unsigned char *p; /* RGB Pixbuf data */ pixbufdatasize = width * height * 3; - pixbufdata =(unsigned char *)g_malloc(pixbufdatasize); + if (colorMap) { + pixbufdata =(unsigned char *)g_malloc(pixbufdatasize); + } else { + pixbufdata =(unsigned char *)g_malloc0(pixbufdatasize); + return pixbufdata; + } + p = pixbufdata; - imgstr = new ImageStream(str, width, thumbCM->getNumPixelComps(), thumbCM->getBits()); + imgstr = new ImageStream(str, width, colorMap->getNumPixelComps(), colorMap->getBits()); imgstr->reset(); for (row = 0; row < height; ++row) { for (col = 0; col < width; ++col) { @@ -328,7 +174,7 @@ Thumb::getPixbufData() GfxRGB rgb; imgstr->getPixel(pix); - thumbCM->getRGB(pix, &rgb); + colorMap->getRGB(pix, &rgb); *p++ = (guchar)(rgb.r * 255.99999); *p++ = (guchar)(rgb.g * 255.99999); @@ -341,7 +187,7 @@ Thumb::getPixbufData() } Thumb::~Thumb() { - delete thumbCM; + delete colorMap; delete str; }