[Poppler-bugs] [Bug 86388] Page not rendered - text is wrong colour

bugzilla-daemon at freedesktop.org bugzilla-daemon at freedesktop.org
Fri Nov 21 04:39:44 PST 2014


https://bugs.freedesktop.org/show_bug.cgi?id=86388

--- Comment #20 from Thomas Freitag <Thomas.Freitag at alfa.de> ---
The problem is that poppler expects that all gfx color values are doubles in
the range from 0 to 1. That's almost true, but NOT for LAB colorspaces.
So all the helper functions like dblToCol, colToByte, byteToDbl will not work
for gfx color values in LAB colorspaces. The best way here would probably be to
use the double values itself for the lcms transformation how the following
small test program shows:

#include "lcms2.h"
typedef unsigned int GfxColorComp;

#define gfxColorComp1 0x10000

static inline GfxColorComp dblToCol(double x) {
  return (GfxColorComp)(x * gfxColorComp1);
}

static inline unsigned char colToByte(GfxColorComp x) {
  // 255 * x + 0.5  =  256 * x - x + 0x8000
  return (unsigned char)(((x << 8) - x + 0x8000) >> 16);
}

static inline double byteToDbl(unsigned char x) {
  return (double)x / (double)255.0;
}

int main(void)
{
  cmsHPROFILE hInProfile, hOutProfile;
  cmsHTRANSFORM hTransform, hTransform1;
  unsigned char in[3];
  unsigned char out[3];
  double col[3];
  int i;

  hInProfile = cmsOpenProfileFromFile("gray.icc", "r");
  hOutProfile = cmsCreate_sRGBProfile();
  hTransform = cmsCreateTransform(hInProfile, COLORSPACE_SH(PT_Lab)
|CHANNELS_SH(3) | BYTES_SH(1), 
    hOutProfile, COLORSPACE_SH(PT_RGB) |CHANNELS_SH(3) | BYTES_SH(1),
    INTENT_PERCEPTUAL, 0);
  hTransform1 = cmsCreateTransform(hInProfile, COLORSPACE_SH(PT_Lab)
|CHANNELS_SH(3) | BYTES_SH(0),
    hOutProfile, COLORSPACE_SH(PT_RGB) |CHANNELS_SH(3) | BYTES_SH(1),
    INTENT_PERCEPTUAL, 0);
  cmsCloseProfile(hInProfile);
  cmsCloseProfile(hOutProfile);

  col[0] = 58.8235; col[1] = 3; col[2] = 6;
  for (i = 0;i < 3;i++) {
    in[i] = colToByte(dblToCol(col[i]));
  }
  fprintf(stderr, "Poppler: %x %x %x ->", in[0], in[1], in[2]); 
  cmsDoTransform(hTransform, in, out, 1);
  fprintf(stderr, "%x %x %x\n", out[0], out[1], out[2]); 
  fprintf(stderr, "Use double: %f %f %f ->", col[0], col[1], col[2]); 
  cmsDoTransform(hTransform1, col, out, 1);
  fprintf(stderr, "%x %x %x\n", out[0], out[1], out[2]); 

  fprintf(stderr, "Convert byte back to double: %f %f %f\n", byteToDbl(in[0]),
byteToDbl(in[1]), byteToDbl(in[2]));
}

Output of this program:

Poppler: 98 fd fa ->ff 0 0
Use double: 58.823500 3.000000 6.000000 ->96 8b 83
Convert byte back to double: 0.596078 0.992157 0.980392

(gray.icc is the ICC profile I extract from the PDF)

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/poppler-bugs/attachments/20141121/4856e302/attachment.html>


More information about the Poppler-bugs mailing list