static PyObject * pycms_TransformBitmap (PyObject *self, PyObject *args) { ImagingObject* inImage; ImagingObject* outImage; Imaging inImg, outImg; void *transform; cmsHTRANSFORM hTransform; int width, height, i; if (!PyArg_ParseTuple(args, "OOOii", &transform, &inImage, &outImage, &width, &height)) { return NULL; } cmsErrorAction(LCMS_ERROR_IGNORE); inImg=inImage->image; outImg=outImage->image; hTransform = (cmsHTRANSFORM) PyCObject_AsVoidPtr(transform); for (i = 0; i < height; i++) { cmsDoTransform(hTransform, inImg->image[i], outImg->image[i], width); } Py_INCREF(Py_None); return Py_None; }
static PyObject * pycms_TransformPixel (PyObject *self, PyObject *args) { unsigned char *inbuf; int channel1,channel2,channel3,channel4; void *transform; cmsHTRANSFORM hTransform; PyObject *result; if (!PyArg_ParseTuple(args, "Oiiii", &transform, &channel1, &channel2, &channel3, &channel4)) { return NULL; } cmsErrorAction(LCMS_ERROR_IGNORE); inbuf=malloc(4); inbuf[0]=(unsigned char)channel1; inbuf[1]=(unsigned char)channel2; inbuf[2]=(unsigned char)channel3; inbuf[3]=(unsigned char)channel4; hTransform = (cmsHTRANSFORM) PyCObject_AsVoidPtr(transform); cmsDoTransform(hTransform, inbuf, inbuf, 1); result = Py_BuildValue("[iiii]", inbuf[0], inbuf[1], inbuf[2], inbuf[3]); free(inbuf); return result; }
static void cdisplay_proof_class_init (CdisplayProofClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); GimpColorDisplayClass *display_class = GIMP_COLOR_DISPLAY_CLASS (klass); object_class->finalize = cdisplay_proof_finalize; object_class->get_property = cdisplay_proof_get_property; object_class->set_property = cdisplay_proof_set_property; GIMP_CONFIG_INSTALL_PROP_ENUM (object_class, PROP_INTENT, "intent", NULL, GIMP_TYPE_COLOR_RENDERING_INTENT, GIMP_COLOR_RENDERING_INTENT_PERCEPTUAL, 0); GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_BPC, "black-point-compensation", NULL, FALSE, 0); GIMP_CONFIG_INSTALL_PROP_PATH (object_class, PROP_PROFILE, "profile", NULL, GIMP_CONFIG_PATH_FILE, NULL, 0); display_class->name = _("Color Proof"); display_class->help_id = "gimp-colordisplay-proof"; display_class->stock_id = GIMP_STOCK_DISPLAY_FILTER_PROOF; display_class->convert = cdisplay_proof_convert; display_class->configure = cdisplay_proof_configure; display_class->changed = cdisplay_proof_changed; cmsErrorAction (LCMS_ERROR_IGNORE); }
static PyObject* cms_profile_fromstring(PyObject* self, PyObject* args) { cmsHPROFILE hProfile; char* pProfile; int nProfile; #if PY_VERSION_HEX >= 0x03000000 if (!PyArg_ParseTuple(args, "y#:profile_frombytes", &pProfile, &nProfile)) return NULL; #else if (!PyArg_ParseTuple(args, "s#:profile_fromstring", &pProfile, &nProfile)) return NULL; #endif cmsErrorAction(LCMS_ERROR_IGNORE); hProfile = cmsOpenProfileFromMem(pProfile, nProfile); if (!hProfile) { PyErr_SetString(PyExc_IOError, "cannot open profile from string"); return NULL; } return cms_profile_new(hProfile); }
static PyObject * pycms_BuildTransform (PyObject *self, PyObject *args) { char *inMode; char *outMode; int renderingIntent; int inFlags; DWORD flags; void *inputProfile; void *outputProfile; cmsHPROFILE hInputProfile, hOutputProfile; cmsHTRANSFORM hTransform; if (!PyArg_ParseTuple(args, "OsOsii", &inputProfile, &inMode, &outputProfile, &outMode, &renderingIntent, &inFlags)) { return NULL; } cmsErrorAction(LCMS_ERROR_IGNORE); hInputProfile = (cmsHPROFILE) PyCObject_AsVoidPtr(inputProfile); hOutputProfile = (cmsHPROFILE) PyCObject_AsVoidPtr(outputProfile); flags = (DWORD) inFlags; hTransform = cmsCreateTransform(hInputProfile, getLCMStype(inMode), hOutputProfile, getLCMStype(outMode), renderingIntent, flags); if(hTransform==NULL) { Py_INCREF(Py_None); return Py_None; } return Py_BuildValue("O", PyCObject_FromVoidPtr((void *)hTransform, (void *)cmsDeleteTransform)); }
static cmsHTRANSFORM _buildProofTransform(cmsHPROFILE hInputProfile, cmsHPROFILE hOutputProfile, cmsHPROFILE hProofProfile, char *sInMode, char *sOutMode, int iRenderingIntent, int iProofIntent, DWORD cmsFLAGS) { cmsHTRANSFORM hTransform; cmsErrorAction(LCMS_ERROR_IGNORE); Py_BEGIN_ALLOW_THREADS /* create the transform */ hTransform = cmsCreateProofingTransform(hInputProfile, findLCMStype(sInMode), hOutputProfile, findLCMStype(sOutMode), hProofProfile, iRenderingIntent, iProofIntent, cmsFLAGS); Py_END_ALLOW_THREADS if (!hTransform) PyErr_SetString(PyExc_ValueError, "cannot build proof transform"); return hTransform; /* if NULL, an exception is set */ }
static PyObject * buildProofTransform(PyObject *self, PyObject *args) { CmsProfileObject *pInputProfile; CmsProfileObject *pOutputProfile; CmsProfileObject *pProofProfile; char *sInMode; char *sOutMode; int iRenderingIntent = 0; int iProofIntent = 0; int cmsFLAGS = 0; cmsHTRANSFORM transform = NULL; if (!PyArg_ParseTuple(args, "O!O!O!ss|iii:buildProofTransform", &CmsProfile_Type, &pInputProfile, &CmsProfile_Type, &pOutputProfile, &CmsProfile_Type, &pProofProfile, &sInMode, &sOutMode, &iRenderingIntent, &iProofIntent, &cmsFLAGS)) return NULL; cmsErrorAction(LCMS_ERROR_IGNORE); transform = _buildProofTransform(pInputProfile->profile, pOutputProfile->profile, pProofProfile->profile, sInMode, sOutMode, iRenderingIntent, iProofIntent, cmsFLAGS); if (!transform) return NULL; return cms_transform_new(transform, sInMode, sOutMode); }
static PyObject * pycms_TransformPixel2 (PyObject *self, PyObject *args) { double channel1,channel2,channel3,channel4; unsigned char *inbuf; void *transform; cmsHTRANSFORM hTransform; PyObject *result; if (!PyArg_ParseTuple(args, "Odddd", &transform, &channel1, &channel2, &channel3, &channel4)) { return NULL; } cmsErrorAction(LCMS_ERROR_IGNORE); inbuf=malloc(4); inbuf[0]=(unsigned char)(channel1*255); inbuf[1]=(unsigned char)(channel2*255); inbuf[2]=(unsigned char)(channel3*255); inbuf[3]=(unsigned char)(channel4*255); hTransform = (cmsHTRANSFORM) PyCObject_AsVoidPtr(transform); cmsDoTransform(hTransform, inbuf, inbuf, 1); result = Py_BuildValue("(dddd)", (double)inbuf[0]/255, (double)inbuf[1]/255, (double)inbuf[2]/255, (double)inbuf[3]/255); free(inbuf); return result; }
void CLASS apply_profile (const char *input, const char *output) { char *prof; cmsHPROFILE hInProfile=0, hOutProfile=0; cmsHTRANSFORM hTransform; FILE *fp; unsigned size; #ifndef USE_LCMS2 cmsErrorAction (LCMS_ERROR_SHOW); #endif if (strcmp (input, "embed")) hInProfile = cmsOpenProfileFromFile (input, "r"); else if (profile_length) { #ifndef LIBRAW_LIBRARY_BUILD prof = (char *) malloc (profile_length); merror (prof, "apply_profile()"); fseek (ifp, profile_offset, SEEK_SET); fread (prof, 1, profile_length, ifp); hInProfile = cmsOpenProfileFromMem (prof, profile_length); free (prof); #else hInProfile = cmsOpenProfileFromMem (imgdata.color.profile, profile_length); #endif } else { #ifdef LIBRAW_LIBRARY_BUILD imgdata.process_warnings |= LIBRAW_WARN_NO_EMBEDDED_PROFILE; #endif #ifdef DCRAW_VERBOSE fprintf (stderr,_("%s has no embedded profile.\n"), ifname); #endif } if (!hInProfile) { #ifdef LIBRAW_LIBRARY_BUILD imgdata.process_warnings |= LIBRAW_WARN_NO_INPUT_PROFILE; #endif return; } if (!output) hOutProfile = cmsCreate_sRGBProfile(); else if ((fp = fopen (output, "rb"))) { fread (&size, 4, 1, fp); fseek (fp, 0, SEEK_SET); oprof = (unsigned *) malloc (size = ntohl(size)); merror (oprof, "apply_profile()"); fread (oprof, 1, size, fp); fclose (fp); if (!(hOutProfile = cmsOpenProfileFromMem (oprof, size))) { free (oprof); oprof = 0; } #ifdef DCRAW_VERBOSE } else fprintf (stderr,_("Cannot open file %s!\n"), output); #else }
static void color_man_lib_init(void) { static gboolean init_done = FALSE; if (init_done) return; init_done = TRUE; #ifndef HAVE_LCMS2 cmsErrorAction(LCMS_ERROR_IGNORE); #endif }
static PyObject * pycms_GetProfileInfo (PyObject *self, PyObject *args) { void *profile; cmsHPROFILE hProfile; if (!PyArg_ParseTuple(args, "O", &profile)) { return NULL; } cmsErrorAction(LCMS_ERROR_IGNORE); hProfile = (cmsHPROFILE) PyCObject_AsVoidPtr(profile); return Py_BuildValue("s", cmsTakeProductName(hProfile)); }
static PyObject * pycms_CreateRGBProfile(PyObject *self, PyObject *args) { cmsHPROFILE hProfile; cmsErrorAction(LCMS_ERROR_IGNORE); hProfile = cmsCreate_sRGBProfile(); if(hProfile==NULL) { Py_INCREF(Py_None); return Py_None; } return Py_BuildValue("O", PyCObject_FromVoidPtr((void *)hProfile, (void *)cmsCloseProfile)); }
static PyObject* cms_profile_fromstring(PyObject* self, PyObject* args) { cmsHPROFILE hProfile; char* pProfile; int nProfile; if (!PyArg_ParseTuple(args, "s#:profile_fromstring", &pProfile, &nProfile)) return NULL; cmsErrorAction(LCMS_ERROR_IGNORE); hProfile = cmsOpenProfileFromMem(pProfile, nProfile); if (!hProfile) PyErr_SetString(PyExc_IOError, "cannot open profile from string"); return cms_profile_new(hProfile); }
static PyObject* cms_profile_open(PyObject* self, PyObject* args) { cmsHPROFILE hProfile; char* sProfile; if (!PyArg_ParseTuple(args, "s:profile_open", &sProfile)) return NULL; cmsErrorAction(LCMS_ERROR_IGNORE); hProfile = cmsOpenProfileFromFile(sProfile, "r"); if (!hProfile) { PyErr_SetString(PyExc_IOError, "cannot open profile file"); return NULL; } return cms_profile_new(hProfile); }
static PyObject * pycms_CreateGrayProfile(PyObject *self, PyObject *args) { cmsHPROFILE hProfile; LPGAMMATABLE gamma; cmsErrorAction(LCMS_ERROR_IGNORE); gamma = cmsBuildGamma(256, 2.2); hProfile = cmsCreateGrayProfile(cmsD50_xyY(), gamma); cmsFreeGamma(gamma); if(hProfile==NULL) { Py_INCREF(Py_None); return Py_None; } return Py_BuildValue("O", PyCObject_FromVoidPtr((void *)hProfile, (void *)cmsCloseProfile)); }
static PyObject * createProfile(PyObject *self, PyObject *args) { char *sColorSpace; cmsHPROFILE hProfile; int iColorTemp = 0; LPcmsCIExyY whitePoint = NULL; LCMSBOOL result; if (!PyArg_ParseTuple(args, "s|i:createProfile", &sColorSpace, &iColorTemp)) return NULL; cmsErrorAction(LCMS_ERROR_IGNORE); if (strcmp(sColorSpace, "LAB") == 0) { if (iColorTemp > 0) { result = cmsWhitePointFromTemp(iColorTemp, whitePoint); if (!result) { PyErr_SetString(PyExc_ValueError,"ERROR: Could not calculate "\ "white point from color temperature provided, must be "\ "integer in degrees Kelvin"); return NULL; } hProfile = cmsCreateLabProfile(whitePoint); } else hProfile = cmsCreateLabProfile(NULL); } else if (strcmp(sColorSpace, "XYZ") == 0) hProfile = cmsCreateXYZProfile(); else if (strcmp(sColorSpace, "sRGB") == 0) hProfile = cmsCreate_sRGBProfile(); else hProfile = NULL; if (!hProfile) { PyErr_SetString(PyExc_ValueError, "failed to create requested color space"); return NULL; } return cms_profile_new(hProfile); }
static PyObject * pycms_OpenProfile(PyObject *self, PyObject *args) { char *profile = NULL; cmsHPROFILE hProfile; if (!PyArg_ParseTuple(args, "s", &profile)) return NULL; cmsErrorAction(LCMS_ERROR_IGNORE); hProfile = cmsOpenProfileFromFile(profile, "r"); if(hProfile==NULL) { Py_INCREF(Py_None); return Py_None; } return Py_BuildValue("O", PyCObject_FromVoidPtr((void *)hProfile, (void *)cmsCloseProfile)); }
static PyObject * cms_transform_apply(CmsTransformObject *self, PyObject *args) { long idIn; long idOut; Imaging im; Imaging imOut; int result; if (!PyArg_ParseTuple(args, "ll:apply", &idIn, &idOut)) return NULL; im = (Imaging)idIn; imOut = (Imaging)idOut; cmsErrorAction(LCMS_ERROR_IGNORE); result = pyCMSdoTransform(im, imOut, self->transform); return Py_BuildValue("i", result); }
static PyObject * pycms_TransformPixels (PyObject *self, PyObject *args) { int width; unsigned char *pixbuf; unsigned char *result; void *pixels; void *transform; cmsHTRANSFORM hTransform; if (!PyArg_ParseTuple(args, "OOi", &transform, &pixels, &width)) { return NULL; } cmsErrorAction(LCMS_ERROR_IGNORE); hTransform = (cmsHTRANSFORM) PyCObject_AsVoidPtr(transform); pixbuf = (unsigned char *) PyCObject_AsVoidPtr(pixels); result=malloc(width*4); cmsDoTransform(hTransform, pixbuf, result, width); return Py_BuildValue("O", PyCObject_FromVoidPtr((void *)result, (void *)free)); }
void CLASS apply_profile (const char *input, const char *output) { char *prof; cmsHPROFILE hInProfile=0, hOutProfile=0; cmsHTRANSFORM hTransform; FILE *fp; unsigned size; #ifndef USE_LCMS2 cmsErrorAction (LCMS_ERROR_SHOW); #endif if (strcmp (input, "embed")) hInProfile = cmsOpenProfileFromFile (input, "r"); else if (profile_length) { #ifndef LIBRAW_LIBRARY_BUILD prof = (char *) malloc (profile_length); merror (prof, "apply_profile()"); fseek (ifp, profile_offset, SEEK_SET); fread (prof, 1, profile_length, ifp); hInProfile = cmsOpenProfileFromMem (prof, profile_length); free (prof); #else hInProfile = cmsOpenProfileFromMem (imgdata.color.profile, profile_length); #endif } else { #ifdef LIBRAW_LIBRARY_BUILD imgdata.process_warnings |= LIBRAW_WARN_NO_EMBEDDED_PROFILE; #endif #ifdef DCRAW_VERBOSE fprintf (stderr,_("%s has no embedded profile.\n"), ifname); #endif } if (!hInProfile) { #ifdef LIBRAW_LIBRARY_BUILD imgdata.process_warnings |= LIBRAW_WARN_NO_INPUT_PROFILE; #endif return; } if (!output) hOutProfile = cmsCreate_sRGBProfile(); else if ((fp = fopen (output, "rb"))) { fread (&size, 4, 1, fp); fseek (fp, 0, SEEK_SET); oprof = (unsigned *) malloc (size = ntohl(size)); merror (oprof, "apply_profile()"); fread (oprof, 1, size, fp); fclose (fp); if (!(hOutProfile = cmsOpenProfileFromMem (oprof, size))) { free (oprof); oprof = 0; } } #ifdef DCRAW_VERBOSE else fprintf (stderr,_("Cannot open file %s!\n"), output); #endif if (!hOutProfile) { #ifdef LIBRAW_LIBRARY_BUILD imgdata.process_warnings |= LIBRAW_WARN_BAD_OUTPUT_PROFILE; #endif goto quit; } #ifdef DCRAW_VERBOSE if (verbose) fprintf (stderr,_("Applying color profile...\n")); #endif #ifdef LIBRAW_LIBRARY_BUILD RUN_CALLBACK(LIBRAW_PROGRESS_APPLY_PROFILE,0,2); #endif hTransform = cmsCreateTransform (hInProfile, TYPE_RGBA_16, hOutProfile, TYPE_RGBA_16, INTENT_PERCEPTUAL, 0); cmsDoTransform (hTransform, image, image, width*height); raw_color = 1; /* Don't use rgb_cam with a profile */ cmsDeleteTransform (hTransform); cmsCloseProfile (hOutProfile); quit: cmsCloseProfile (hInProfile); #ifdef LIBRAW_LIBRARY_BUILD RUN_CALLBACK(LIBRAW_PROGRESS_APPLY_PROFILE,1,2); #endif }
static LPLUT ComputeGamutWithInput(cmsHPROFILE hInput, cmsHPROFILE hProfile, int Intent) { cmsHPROFILE hLab; LPLUT Gamut; DWORD dwFormat; GAMUTCHAIN Chain; int nErrState, nChannels, nGridpoints; LPGAMMATABLE Trans[3]; icColorSpaceSignature ColorSpace; ZeroMemory(&Chain, sizeof(GAMUTCHAIN)); hLab = cmsCreateLabProfile(NULL); // Safeguard against early abortion nErrState = cmsErrorAction(LCMS_ERROR_IGNORE); // The figure of merit. On matrix-shaper profiles, should be almost zero as // the conversion is pretty exact. On LUT based profiles, different resolutions // of input and output CLUT may result in differences. if (!cmsIsIntentSupported(hProfile, Intent, LCMS_USED_AS_INPUT) && !cmsIsIntentSupported(hProfile, Intent, LCMS_USED_AS_OUTPUT)) Chain.Thereshold = 1.0; else Chain.Thereshold = ERR_THERESHOLD; ColorSpace = cmsGetColorSpace(hProfile); // If input profile specified, create a transform from such profile to Lab if (hInput != NULL) { nChannels = _cmsChannelsOf(ColorSpace); nGridpoints = _cmsReasonableGridpointsByColorspace(ColorSpace, cmsFLAGS_HIGHRESPRECALC); dwFormat = (CHANNELS_SH(nChannels)|BYTES_SH(2)); Chain.hInput = cmsCreateTransform(hInput, dwFormat, hLab, TYPE_Lab_16, Intent, cmsFLAGS_NOTPRECALC); } else { // Input transform=NULL (Lab) Used to compute the gamut tag // This table will take 53 points to give some accurancy, // 53 * 53 * 53 * 2 = 291K nChannels = 3; // For Lab nGridpoints = 53; Chain.hInput = NULL; dwFormat = (CHANNELS_SH(_cmsChannelsOf(ColorSpace))|BYTES_SH(2)); } // Does create the forward step Chain.hForward = cmsCreateTransform(hLab, TYPE_Lab_16, hProfile, dwFormat, INTENT_RELATIVE_COLORIMETRIC, cmsFLAGS_NOTPRECALC); // Does create the backwards step Chain.hReverse = cmsCreateTransform(hProfile, dwFormat, hLab, TYPE_Lab_16, INTENT_RELATIVE_COLORIMETRIC, cmsFLAGS_NOTPRECALC); // Restores error handler previous state cmsErrorAction(nErrState); // All ok? if (Chain.hForward && Chain.hReverse) { // Go on, try to compute gamut LUT from PCS. // This consist on a single channel containing // dE when doing a transform back and forth on // the colorimetric intent. Gamut = cmsAllocLUT(); Gamut = cmsAlloc3DGrid(Gamut, nGridpoints, nChannels, 1); // If no input, then this is a gamut tag operated by Lab, // so include pertinent prelinearization if (hInput == NULL) { CreateLabPrelinearization(Trans); cmsAllocLinearTable(Gamut, Trans, 1); cmsFreeGammaTriple(Trans); } cmsSample3DGrid(Gamut, GamutSampler, (LPVOID) &Chain, Gamut ->wFlags); } else Gamut = NULL; // Didn't work... // Free all needed stuff. if (Chain.hInput) cmsDeleteTransform(Chain.hInput); if (Chain.hForward) cmsDeleteTransform(Chain.hForward); if (Chain.hReverse) cmsDeleteTransform(Chain.hReverse); cmsCloseProfile(hLab); // And return computed hull return Gamut; }
LPLUT _cmsComputeSoftProofLUT(cmsHPROFILE hProfile, int nIntent) { cmsHPROFILE hLab; LPLUT SoftProof; DWORD dwFormat; GAMUTCHAIN Chain; int nErrState; LPGAMMATABLE Trans[3]; // LUTs are never abs. colorimetric, is the transform who // is responsible of generating white point displacement if (nIntent == INTENT_ABSOLUTE_COLORIMETRIC) nIntent = INTENT_RELATIVE_COLORIMETRIC; ZeroMemory(&Chain, sizeof(GAMUTCHAIN)); hLab = cmsCreateLabProfile(NULL); // ONLY 4 channels dwFormat = (CHANNELS_SH(4)|BYTES_SH(2)); // Safeguard against early abortion nErrState = cmsErrorAction(LCMS_ERROR_IGNORE); // Does create the first step Chain.hForward = cmsCreateTransform(hLab, TYPE_Lab_16, hProfile, dwFormat, nIntent, cmsFLAGS_NOTPRECALC); // Does create the last step Chain.hReverse = cmsCreateTransform(hProfile, dwFormat, hLab, TYPE_Lab_16, INTENT_RELATIVE_COLORIMETRIC, cmsFLAGS_NOTPRECALC); // Restores error handler previous state cmsErrorAction(nErrState); // All ok? if (Chain.hForward && Chain.hReverse) { // This is Lab -> Lab, so 33 point should hold anything SoftProof = cmsAllocLUT(); SoftProof = cmsAlloc3DGrid(SoftProof, 33, 3, 3); CreateLabPrelinearization(Trans); cmsAllocLinearTable(SoftProof, Trans, 1); cmsFreeGammaTriple(Trans); cmsSample3DGrid(SoftProof, SoftProofSampler, (LPVOID) &Chain, SoftProof->wFlags); } else SoftProof = NULL; // Didn't work... // Free all needed stuff. if (Chain.hForward) cmsDeleteTransform(Chain.hForward); if (Chain.hReverse) cmsDeleteTransform(Chain.hReverse); cmsCloseProfile(hLab); return SoftProof; }
void mnglcms_initlibrary () { cmsErrorAction (LCMS_ERROR_IGNORE); /* LCMS should ignore errors! */ }
static void run ( const gchar *name, gint nparams, const GimpParam *param, gint *nreturn_vals, GimpParam **return_vals) { static GimpParam values[3]; GimpRunMode run_mode; GimpPDBStatusType status = GIMP_PDB_SUCCESS; SeparateContext mysc; //enum separate_function func = SEP_NONE; run_mode = param[0].data.d_int32; /* setup for localization */ INIT_I18N (); cmsErrorAction( LCMS_ERROR_IGNORE ); mysc.filename = NULL; if( nparams != ( run_mode == GIMP_RUN_NONINTERACTIVE ? 2 : 1 ) ) status = GIMP_PDB_CALLING_ERROR; else if( run_mode == GIMP_RUN_NONINTERACTIVE ) { if( param[1].type != GIMP_PDB_STRING || strlen( param[1].data.d_string ) == 0 ) status = GIMP_PDB_CALLING_ERROR; else mysc.filename = g_strdup( param[1].data.d_string ); } else { gint size = gimp_get_data_size( "plug-in-separate-import/lastpath" ); if( size ) { mysc.filename = g_malloc( size ); gimp_get_data( "plug-in-separate-import/lastpath", mysc.filename ); } } if( status == GIMP_PDB_SUCCESS && ( run_mode == GIMP_RUN_NONINTERACTIVE || separate_import_dialog( &mysc ) ) ) { gint i, j, x, y; TIFF *in; guint32 width, height, stripSize, stripCount, stripHeight; gint16 bps, spp, step, planerConfig, photometric, inkset, resolutionUnit; float xres, yres; const gchar *layerNames[] = { "C", "M", "Y", "K" }; guchar *buf, *maskbuf[4], *srcbuf, *destbuf[4], *iccProfile; gint32 layers[5], masks[4]; GimpDrawable *drw[4]; GimpPixelRgn rgn[4]; GimpRGB primaries[4] = { { .180, .541, .870, 1.0 }, { .925, .149, .388, 1.0 }, { .929, .862, .129, 1.0 }, { 0, 0, 0, 1.0 } }; gchar *str = NULL; gchar *baseName = g_path_get_basename( gimp_filename_to_utf8( mysc.filename ) ); #ifdef G_OS_WIN32 { gchar *_filename = NULL; // win32 filename encoding(not UTF-8) _filename = g_win32_locale_filename_from_utf8( mysc.filename ); in = TIFFOpen( _filename ? _filename : mysc.filename, "r" ); g_free( _filename ); } #else in = TIFFOpen( mysc.filename, "r" ); #endif if( !in ) { str = g_strdup_printf( _( "Cannot open : \"%s\"" ), baseName ); gimp_message( str ); g_free( str ); status = GIMP_PDB_EXECUTION_ERROR; } else { if( ( TIFFGetField( in, TIFFTAG_BITSPERSAMPLE, &bps ) == FALSE || ( bps != 8 && bps != 16 ) ) || ( TIFFGetField( in, TIFFTAG_SAMPLESPERPIXEL, &spp ) == FALSE || spp != 4 ) || ( TIFFGetField( in, TIFFTAG_PHOTOMETRIC, &photometric ) == FALSE || photometric != PHOTOMETRIC_SEPARATED ) || ( TIFFGetField( in, TIFFTAG_PLANARCONFIG, &planerConfig ) == FALSE || planerConfig != PLANARCONFIG_CONTIG ) || ( TIFFGetField( in, TIFFTAG_INKSET, &inkset ) == TRUE && inkset != INKSET_CMYK ) ) { str = g_strdup_printf( _( "\"%s\" is unsupported." ), baseName ); gimp_message( str ); g_free( str ); status = GIMP_PDB_EXECUTION_ERROR; } else { stripCount = TIFFNumberOfStrips( in ); stripSize = TIFFStripSize( in ); TIFFGetField( in, TIFFTAG_IMAGEWIDTH, &width ); TIFFGetField( in, TIFFTAG_IMAGELENGTH, &height ); TIFFGetField( in, TIFFTAG_ROWSPERSTRIP, &stripHeight ); TIFFGetField( in, TIFFTAG_RESOLUTIONUNIT, &resolutionUnit ); TIFFGetField( in, TIFFTAG_XRESOLUTION, &xres ); TIFFGetField( in, TIFFTAG_YRESOLUTION, &yres ); #if 0 str = g_strdup_printf( "Photometric : %d BPS : %d SPP : %d\nInkset : %d StripCount : %d", photometric, bps, spp, inkset, stripCount ); gimp_message( str ); g_free( str ); #endif step = ( bps == 16 ) ? 2 : 1; buf = g_malloc( stripSize ); values[1].data.d_image = gimp_image_new( width, height, GIMP_RGB ); gimp_image_set_resolution( values[1].data.d_image, xres, yres ); gimp_context_push(); for( i = 0; i < 4; i++ ) { layers[i] = gimp_layer_new( values[1].data.d_image, layerNames[i], width, height, GIMP_RGBA_IMAGE, 100.0, GIMP_DARKEN_ONLY_MODE ); gimp_context_set_foreground( &primaries[i] ); gimp_drawable_fill( layers[i], GIMP_FOREGROUND_FILL ); gimp_image_add_layer( values[1].data.d_image, layers[i], i ); masks[i] = gimp_layer_create_mask( layers[i], GIMP_ADD_BLACK_MASK ); gimp_layer_add_mask( layers[i], masks[i] ); drw[i] = gimp_drawable_get( masks[i] ); maskbuf[i] = g_malloc( width * stripHeight ); } gimp_context_pop(); layers[4] = gimp_layer_new( values[1].data.d_image, _( "Background" ), width, height, GIMP_RGB_IMAGE, 100.0, GIMP_NORMAL_MODE ); gimp_drawable_fill( layers[4], GIMP_WHITE_FILL ); gimp_image_add_layer( values[1].data.d_image, layers[4], 4 ); str = g_strdup_printf( _( "Reading \"%s\"..." ), baseName ); gimp_progress_init( str ); g_free( str ); for( i = 0; i < stripCount; i++ ) { guint32 size = TIFFReadEncodedStrip( in, i, buf, stripSize ); guint32 rowCount = ( size < stripSize ? height % stripHeight : stripHeight ); srcbuf = buf; if( bps == 16 ) srcbuf++; for( j = 0; j < 4; j++ ) { gimp_pixel_rgn_init( &( rgn[j] ), drw[j], 0, stripHeight * i, width, rowCount, FALSE, FALSE ); destbuf[j] = maskbuf[j]; } for( y = 0; y < rowCount; y++ ) { for( x = 0; x < width; x++ ) { *destbuf[0]++ = *srcbuf; srcbuf += step; *destbuf[1]++ = *srcbuf; srcbuf += step; *destbuf[2]++ = *srcbuf; srcbuf += step; *destbuf[3]++ = *srcbuf; srcbuf += step; //srcbuf += spp > 4 ? spp - 4 : 0; } } gimp_pixel_rgn_set_rect( &( rgn[0] ), maskbuf[0], 0, stripHeight * i, width, rowCount ); gimp_pixel_rgn_set_rect( &( rgn[1] ), maskbuf[1], 0, stripHeight * i, width, rowCount ); gimp_pixel_rgn_set_rect( &( rgn[2] ), maskbuf[2], 0, stripHeight * i, width, rowCount ); gimp_pixel_rgn_set_rect( &( rgn[3] ), maskbuf[3], 0, stripHeight * i, width, rowCount ); gimp_progress_update( (gdouble)i / stripCount ); } g_free( buf ); for( i = 0; i < 4; i++ ) { g_free( maskbuf[i] ); gimp_drawable_detach( drw[i] ); } #ifdef ENABLE_COLOR_MANAGEMENT if ( TIFFGetField( in, TIFFTAG_ICCPROFILE, &width, &iccProfile ) ) { GimpParasite *parasite; parasite = gimp_parasite_new( CMYKPROFILE, 0, width, iccProfile ); gimp_image_parasite_attach( values[1].data.d_image, parasite ); gimp_parasite_free( parasite ); //g_free( iccProfile ); // This causes clash on TIFFClose( in ). } #endif } TIFFClose( in ); } g_free( baseName ); } else status = GIMP_PDB_CANCEL; *return_vals = values; values[0].type = GIMP_PDB_STATUS; values[0].data.d_status = status; if( status == GIMP_PDB_SUCCESS ) { *nreturn_vals = 2; values[1].type = GIMP_PDB_IMAGE; if( run_mode != GIMP_RUN_NONINTERACTIVE ) { gimp_image_undo_enable( values[1].data.d_image ); gimp_display_new( values[1].data.d_image ); gimp_displays_flush(); } gimp_set_data( "plug-in-separate-import/lastpath", mysc.filename, strlen( mysc.filename ) + 1 ); } else *nreturn_vals = 1; g_free( mysc.filename ); }
static void run (const gchar *name, gint nparams, const GimpParam *param, gint *nreturn_vals, GimpParam **return_vals) { GimpPDBStatusType status = GIMP_PDB_CALLING_ERROR; gint proc = NONE; GimpRunMode run_mode = GIMP_RUN_NONINTERACTIVE; gint32 image = -1; const gchar *filename = NULL; GimpColorConfig *config = NULL; gboolean dont_ask = FALSE; GimpColorRenderingIntent intent; gboolean bpc; static GimpParam values[6]; INIT_I18N (); values[0].type = GIMP_PDB_STATUS; *nreturn_vals = 1; *return_vals = values; for (proc = 0; proc < G_N_ELEMENTS (procedures); proc++) { if (strcmp (name, procedures[proc].name) == 0) break; } if (proc == NONE) goto done; if (nparams < procedures[proc].min_params) goto done; if (proc != PROC_FILE_INFO) config = gimp_get_color_configuration (); if (config) intent = config->display_intent; else intent = GIMP_COLOR_RENDERING_INTENT_PERCEPTUAL; bpc = (intent == GIMP_COLOR_RENDERING_INTENT_RELATIVE_COLORIMETRIC); switch (proc) { case PROC_SET: run_mode = param[0].data.d_int32; image = param[1].data.d_image; if (nparams > 2) filename = param[2].data.d_string; break; case PROC_APPLY: run_mode = param[0].data.d_int32; image = param[1].data.d_image; if (nparams > 2) filename = param[2].data.d_string; if (nparams > 3) intent = param[3].data.d_int32; if (nparams > 4) bpc = param[4].data.d_int32 ? TRUE : FALSE; break; case PROC_SET_RGB: run_mode = param[0].data.d_int32; image = param[1].data.d_image; break; case PROC_APPLY_RGB: run_mode = param[0].data.d_int32; image = param[1].data.d_image; if (nparams > 2) intent = param[2].data.d_int32; if (nparams > 3) bpc = param[3].data.d_int32 ? TRUE : FALSE; break; case PROC_INFO: image = param[0].data.d_image; break; case PROC_FILE_INFO: filename = param[0].data.d_string; break; } if (run_mode == GIMP_RUN_INTERACTIVE) { LcmsValues values = { intent, bpc }; switch (proc) { case PROC_SET: status = lcms_dialog (config, image, FALSE, &values); goto done; case PROC_APPLY: gimp_get_data (name, &values); status = lcms_dialog (config, image, TRUE, &values); if (status == GIMP_PDB_SUCCESS) gimp_set_data (name, &values, sizeof (LcmsValues)); goto done; default: break; } } cmsErrorAction (LCMS_ERROR_SHOW); switch (proc) { case PROC_SET: case PROC_SET_RGB: status = lcms_icc_set (config, image, filename); break; case PROC_APPLY: case PROC_APPLY_RGB: status = lcms_icc_apply (config, run_mode, image, filename, intent, bpc, &dont_ask); if (run_mode == GIMP_RUN_INTERACTIVE) { *nreturn_vals = 2; values[1].type = GIMP_PDB_INT32; values[1].data.d_int32 = dont_ask; } break; case PROC_INFO: case PROC_FILE_INFO: { gchar *name = NULL; gchar *desc = NULL; gchar *info = NULL; cmsErrorAction (LCMS_ERROR_IGNORE); if (proc == PROC_INFO) status = lcms_icc_info (config, image, &name, &desc, &info); else status = lcms_icc_file_info (filename, &name, &desc, &info); if (status == GIMP_PDB_SUCCESS) { *nreturn_vals = NUM_RETURN_VALS; values[PROFILE_NAME].type = GIMP_PDB_STRING; values[PROFILE_NAME].data.d_string = name; values[PROFILE_DESC].type = GIMP_PDB_STRING; values[PROFILE_DESC].data.d_string = desc; values[PROFILE_INFO].type = GIMP_PDB_STRING; values[PROFILE_INFO].data.d_string = info; } } break; } done: if (run_mode != GIMP_RUN_NONINTERACTIVE) gimp_displays_flush (); if (config) g_object_unref (config); values[0].data.d_status = status; }