[Image-SIG] PIL and ICC: littlecms?

Kevin@Cazabon.com kevin@cazabon.com
Thu, 19 Dec 2002 01:05:56 -0700


Well, I've managed to get things started, but have a couple problems related
to accessing/modifying the image pixel data directly in my DLL... I don't
think I'm using the right syntax... any help?

Once I get this working, adding the rest of the littlecms ICC Color
Management Support should be pretty simple.

Thanks!
Kevin.

See notes in code below:

----------------------------

#include "Python.h"
#include "lcms.h"
#include "Imaging.h"

// I'm not sure why I had to define this here... but it solved the issue
typedef struct {
    PyObject_HEAD
    Imaging image;
} ImagingObject;

static PyObject *
profileToProfile(PyObject *self, PyObject *args)
{
  ImagingObject* im;
  ImagingObject* imOut;

  char *sInputProfile = NULL;
  char *sOutputProfile = NULL;
  char *sRenderingIntent = NULL;

  int imLength = 0;
  int i = 0;


  cmsHPROFILE hInProfile, hOutProfile;
  cmsHTRANSFORM hTransform;

  // parse the PyObject arguments, assign to variables accordingly
  // until I get ImagingNew working, we pass in TWO images... source and
destination of the same size
  if (!PyArg_ParseTuple(args, "OOss|s", &im, &imOut, &sInputProfile,
&sOutputProfile, &sRenderingIntent)) {
    return Py_BuildValue("i", -1);
  }

  hInProfile  = cmsOpenProfileFromFile(sInputProfile, "r");
  hOutProfile = cmsOpenProfileFromFile(sOutputProfile, "r");

  hTransform = cmsCreateTransform(hInProfile,
                                 TYPE_BGR_8,
                                 hOutProfile,
                                 TYPE_BGR_8,
                                 INTENT_PERCEPTUAL, 0);

  //imOut = ImagingNew(im->image->mode, im->image->xsize, im->image->ysize);
  // I'm having an unresolved external error for ImagingNew here... ????
  // why is ImagingNew unresolved... I'm not a C guy...???????

  imLength = im->image->xsize * im->image->ysize;

// THIS IS THE AREA I NEED HELP WITH
// it is intended to go through the image pixel for pixel and apply the
transform
// I'll tweak the buffersize later once its working
// cmsDoTransform uses the transform, inBuffer, outBuffer, and bufferSize.
it reads bufferSize
// pixels from inBuffer, processes them through the transform, and writes
new values
// to outBuffer

  for (i=0; i < imLength; i++)
  {
    cmsDoTransform(hTransform, &im->image[i],
                              &imOut->image[i],
                                // is this syntax correct for accessing the
pixel data for read/write???
                              1);
  }

// END OF MAJOR PROBLEMS FOR NOW...

  cmsDeleteTransform(hTransform);
  cmsCloseProfile(hInProfile);
  cmsCloseProfile(hOutProfile);

  return Py_BuildValue("O", imOut);

}

static PyMethodDef pyCMS_methods[] = {
  {"profileToProfile", profileToProfile, 1, "profileToProfile() doc
string"},
  {NULL, NULL}
};

void initpyCMS(void)
{
  Py_InitModule("pyCMS", pyCMS_methods);
}