<html>
    <head>
      <base href="https://bugs.freedesktop.org/" />
    </head>
    <body>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Page not rendered - text is wrong colour"
   href="https://bugs.freedesktop.org/show_bug.cgi?id=86388#c20">Comment # 20</a>
              on <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Page not rendered - text is wrong colour"
   href="https://bugs.freedesktop.org/show_bug.cgi?id=86388">bug 86388</a>
              from <span class="vcard"><a class="email" href="mailto:Thomas.Freitag@alfa.de" title="Thomas Freitag <Thomas.Freitag@alfa.de>"> <span class="fn">Thomas Freitag</span></a>
</span></b>
        <pre>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)</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>