static VALUE transform_convert(int argc, VALUE *argv, VALUE self){ if(argc != 4){ return Qnil; } cmsHPROFILE hInProfile, hOutProfile; cmsHTRANSFORM hTransform; VALUE in = rb_iv_get(self, "@in"); VALUE out = rb_iv_get(self, "@out"); hInProfile = cmsOpenProfileFromFile(RSTRING(in)->ptr, "r"); hOutProfile = cmsOpenProfileFromFile(RSTRING(out)->ptr, "r"); hTransform = cmsCreateTransform(hInProfile, TYPE_CMYK_8, hOutProfile, TYPE_RGB_8, INTENT_PERCEPTUAL, 0); cmsCloseProfile(hInProfile); cmsCloseProfile(hOutProfile); //TODO: Remove duplication cmsUInt8Number cmyk_temp[4] = { NUM2INT(argv[0]), NUM2INT(argv[1]), NUM2INT(argv[2]), NUM2INT(argv[3]) };; cmsUInt8Number rgb_temp[3]; // printf("Transfrom result is cmyk(%d, %d, %d, %d)\n", cmyk_temp[0], cmyk_temp[1], cmyk_temp[2], cmyk_temp[3]); cmsDoTransform(hTransform, cmyk_temp, rgb_temp, 1); // printf("Transfrom result is rgb(%d, %d, %d)\n", rgb_temp[0], rgb_temp[1], rgb_temp[2]); return rb_ary_new3(3, INT2FIX(rgb_temp[0]), INT2FIX(rgb_temp[1]), INT2FIX(rgb_temp[2])); }
/** * cd_icc_effect_generate_cogl_color_data: **/ static CoglHandle cd_icc_effect_generate_cogl_color_data (const gchar *filename, GError **error) { CoglHandle tex = NULL; cmsHPROFILE device_profile; cmsHPROFILE srgb_profile; cmsUInt8Number *data; cmsHTRANSFORM transform; guint array_size; guint r, g, b; guint8 *p; cmsSetLogErrorHandler (cd_icc_effect_error_cb); srgb_profile = cmsCreate_sRGBProfile (); device_profile = cmsOpenProfileFromFile (filename, "r"); /* create a cube and cut itup into parts */ array_size = GCM_GLSL_LOOKUP_SIZE * GCM_GLSL_LOOKUP_SIZE * GCM_GLSL_LOOKUP_SIZE; data = g_new0 (cmsUInt8Number, 3 * array_size); transform = cmsCreateTransform (srgb_profile, TYPE_RGB_8, device_profile, TYPE_RGB_8, INTENT_PERCEPTUAL, 0); /* we failed */ if (transform == NULL) { g_set_error (error, 1, 0, "could not create transform"); goto out; } /* create mapping (blue->r, green->t, red->s) */ for (p = data, b = 0; b < GCM_GLSL_LOOKUP_SIZE; b++) { for (g = 0; g < GCM_GLSL_LOOKUP_SIZE; g++) { for (r = 0; r < GCM_GLSL_LOOKUP_SIZE; r++) { *(p++) = (r * 255) / (GCM_GLSL_LOOKUP_SIZE - 1); *(p++) = (g * 255) / (GCM_GLSL_LOOKUP_SIZE - 1); *(p++) = (b * 255) / (GCM_GLSL_LOOKUP_SIZE - 1); } } } cmsDoTransform (transform, data, data, array_size); /* creates a cogl texture from the data */ tex = cogl_texture_3d_new_from_data (GCM_GLSL_LOOKUP_SIZE, /* width */ GCM_GLSL_LOOKUP_SIZE, /* height */ GCM_GLSL_LOOKUP_SIZE, /* depth */ COGL_TEXTURE_NO_AUTO_MIPMAP, COGL_PIXEL_FORMAT_RGB_888, COGL_PIXEL_FORMAT_ANY, /* data is tightly packed so we can pass zero */ 0, 0, data, error); out: cmsCloseProfile (device_profile); cmsCloseProfile (srgb_profile); if (transform != NULL) cmsDeleteTransform (transform); g_free (data); return tex; }
static cmsHPROFILE OpenProfile(const char* File) { if (!File) return cmsCreate_sRGBProfile(); if (stricmp(File, "*sRGB") == 0) return cmsCreate_sRGBProfile(NULL); if (stricmp(File, "*Lab") == 0) return cmsCreateLabProfile(NULL); if (stricmp(File, "*LabD65") == 0) { cmsCIExyY D65xyY; cmsWhitePointFromTemp(6504, &D65xyY); return cmsCreateLabProfile(&D65xyY); } if (stricmp(File, "*XYZ") == 0) return cmsCreateXYZProfile(); if (stricmp(File, "*Gray22") == 0) { LPGAMMATABLE Gamma = cmsBuildGamma(256, 2.2); cmsHPROFILE hProfile = cmsCreateGrayProfile(cmsD50_xyY(), Gamma); cmsFreeGamma(Gamma); return hProfile; } return cmsOpenProfileFromFile(File, "r"); }
void GetMonitorProfile(wxString& profileName, cmsHPROFILE& profile) { ColorsyncIteratorData data; data.dispuuid = CGDisplayCreateUUIDFromDisplayID(CGMainDisplayID()); if (data.dispuuid == NULL) { DEBUG_INFO("CGDisplayCreateUUIDFromDisplayID() failed."); return; } data.url = NULL; ColorSyncIterateDeviceProfiles(ColorSyncIterateCallback, (void *)&data); CFRelease(data.dispuuid); CFStringRef urlstr = CFURLCopyFileSystemPath(data.url, kCFURLPOSIXPathStyle); CFRelease(data.url); if (urlstr == NULL) { DEBUG_INFO("Failed to get URL in CFString"); } else { CFRetain(urlstr); profileName = wxCFStringRef(urlstr).AsString(wxLocale::GetSystemEncoding()); profile = cmsOpenProfileFromFile(profileName.c_str(), "r"); DEBUG_INFO("Found profile: " << profileName.c_str()); }; };
static cmsHPROFILE cdisplay_lcms_get_rgb_profile (CdisplayLcms *lcms) { GimpColorConfig *config; GimpColorManaged *managed; cmsHPROFILE profile = NULL; managed = gimp_color_display_get_managed (GIMP_COLOR_DISPLAY (lcms)); if (managed) { gsize len; const guint8 *data = gimp_color_managed_get_icc_profile (managed, &len); if (data) profile = cmsOpenProfileFromMem ((gpointer) data, len); if (profile && ! cdisplay_lcms_profile_is_rgb (profile)) { cmsCloseProfile (profile); profile = NULL; } } if (! profile) { config = gimp_color_display_get_config (GIMP_COLOR_DISPLAY (lcms)); if (config->rgb_profile) profile = cmsOpenProfileFromFile (config->rgb_profile, "r"); } return profile; }
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 }
cmsHPROFILE dt_colorspaces_create_output_profile(const int imgid) { char profile[1024]; profile[0] = '\0'; // db lookup colorout params, and dt_conf_() for override gchar *overprofile = dt_conf_get_string("plugins/lighttable/export/iccprofile"); if(!overprofile || !strcmp(overprofile, "image")) { const dt_iop_colorout_params_t *params; // sqlite: sqlite3_stmt *stmt; DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "select op_params from history where imgid=?1 and operation='colorout'", -1, &stmt, NULL); DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, imgid); if(sqlite3_step(stmt) == SQLITE_ROW) { params = sqlite3_column_blob(stmt, 0); g_strlcpy(profile, params->iccprofile, 1024); } sqlite3_finalize(stmt); } if(!overprofile && profile[0] == '\0') { g_strlcpy(profile, "sRGB", 1024); } else if(profile[0] == '\0') { g_strlcpy(profile, overprofile, 1024); } if(overprofile) { g_free(overprofile); } cmsHPROFILE output = NULL; if(!strcmp(profile, "sRGB")) output = dt_colorspaces_create_srgb_profile(); else if(!strcmp(profile, "linear_rgb")) output = dt_colorspaces_create_linear_rgb_profile(); else if(!strcmp(profile, "XYZ")) output = dt_colorspaces_create_xyz_profile(); else if(!strcmp(profile, "adobergb")) output = dt_colorspaces_create_adobergb_profile(); else if(!strcmp(profile, "X profile") && darktable.control->xprofile_data) output = cmsOpenProfileFromMem(darktable.control->xprofile_data, darktable.control->xprofile_size); else { // else: load file name char filename[1024]; dt_colorspaces_find_profile(filename, 1024, profile, "out"); output = cmsOpenProfileFromFile(filename, "r"); } if(!output) output = dt_colorspaces_create_srgb_profile(); return output; }
int main(void) { cmsHPROFILE hInProfile, hOutProfile; cmsHTRANSFORM hTransform; int i; hInProfile = cmsOpenProfileFromFile("USWebCoatedSWOP.icc", "r"); hOutProfile = cmsOpenProfileFromFile("AdobeRGB1998.icc", "r"); hTransform = cmsCreateTransform(hInProfile, TYPE_CMYK_8, hOutProfile, TYPE_RGB_8, INTENT_PERCEPTUAL, 0); cmsCloseProfile(hInProfile); cmsCloseProfile(hOutProfile); return 0; }
static cmsHPROFILE cdisplay_lcms_get_printer_profile (CdisplayLcms *lcms) { GimpColorConfig *config; config = gimp_color_display_get_config (GIMP_COLOR_DISPLAY (lcms)); if (config->printer_profile) return cmsOpenProfileFromFile (config->printer_profile, "r"); return NULL; }
struct weston_color_profile * weston_cms_load_profile(const char *filename) { struct weston_color_profile *p = NULL; #ifdef HAVE_LCMS cmsHPROFILE lcms_profile; lcms_profile = cmsOpenProfileFromFile(filename, "r"); if (lcms_profile) p = weston_cms_create_profile(filename, lcms_profile); #endif return p; }
void* convert_space (const void *source_data_ptr, int width, int height) { // Assign the memory for the transform void *YourOutputBuffer = malloc(sizeof(void)*width*height*4); // Create the required variables cmsHPROFILE hInProfile, hOutProfile; cmsHTRANSFORM hTransform; // Load the colour profiles hInProfile = cmsOpenProfileFromFile("/Library/Application Support/Nikon/Profiles/NKAdobe.icm", "r"); hOutProfile = cmsCreate_sRGBProfile(); // Create the transform matrix hTransform = cmsCreateTransform(hInProfile, TYPE_RGBA_8, hOutProfile, TYPE_RGBA_8, INTENT_PERCEPTUAL, 0); // Convert the image colours cmsDoTransform(hTransform, source_data_ptr, YourOutputBuffer, width*height); // Delete the opened stuff cmsDeleteTransform(hTransform); cmsCloseProfile(hInProfile); cmsCloseProfile(hOutProfile); // Create the return data object // CFDataRef ret_val = CFDataCreate (NULL, YourOutputBuffer, height * width * 4); // release the old image // CFRelease (source_data_ptr); // Null the pointer after releasing source_data_ptr = NULL; // NULL the pointer source_data_ptr = NULL; // Free the temp buffer for the colour space image // free(YourOutputBuffer); fprintf(stdout, "Colour space converted."); // return the new image return YourOutputBuffer; }
static void cdisplay_proof_combo_box_set_active (GimpColorProfileComboBox *combo, const gchar *filename) { cmsHPROFILE profile = NULL; gchar *label = NULL; if (filename) profile = cmsOpenProfileFromFile (filename, "r"); if (profile) { cmsUInt32Number descSize; gchar *descData; descSize = cmsGetProfileInfoASCII (profile, cmsInfoDescription, "en", "US", NULL, 0); if (descSize > 0) { descData = g_new (gchar, descSize + 1); descSize = cmsGetProfileInfoASCII (profile, cmsInfoDescription, "en", "US", descData, descSize); if (descSize > 0) label = gimp_any_to_utf8 (descData, -1, NULL); g_free (descData); } if (! label) { descSize = cmsGetProfileInfoASCII (profile, cmsInfoModel, "en", "US", NULL, 0); if (descSize > 0) { descData = g_new (gchar, descSize + 1); descSize = cmsGetProfileInfoASCII (profile, cmsInfoModel, "en", "US", descData, descSize); if (descSize > 0) label = gimp_any_to_utf8 (descData, -1, NULL); g_free (descData); } } cmsCloseProfile (profile); } gimp_color_profile_combo_box_set_active (combo, filename, label); g_free (label); }
int main(int argc, char* argv[]) { int r, g, b; cmsUInt8Number RGB[3], RGB_OUT[3]; cmsHTRANSFORM xform; cmsHPROFILE hProfile; double err, SumX=0, SumX2=0, Peak = 0, n = 0; if (argc != 2) { printf("roundtrip <RGB icc profile>\n"); return 1; } hProfile = cmsOpenProfileFromFile(argv[1], "r"); xform = cmsCreateTransform(hProfile,TYPE_RGB_8, hProfile, TYPE_RGB_8, INTENT_RELATIVE_COLORIMETRIC, cmsFLAGS_NOOPTIMIZE); for (r=0; r< 256; r++) { printf("%d \r", r); for (g=0; g < 256; g++) { for (b=0; b < 256; b++) { RGB[0] = r; RGB[1] = g; RGB[2] = b; cmsDoTransform(xform, RGB, RGB_OUT, 1); err = VecDist(RGB, RGB_OUT); SumX += err; SumX2 += err * err; n += 1.0; if (err > Peak) Peak = err; } } } printf("Average %g\n", SumX / n); printf("Max %g\n", Peak); printf("Std %g\n", sqrt((n*SumX2 - SumX * SumX) / (n*(n-1)))); cmsCloseProfile(hProfile); cmsDeleteTransform(xform); return 0; }
static cmsHPROFILE OpenProfile(const char* File) { cmsHPROFILE h; if (!File) return cmsCreate_sRGBProfile(); if (stricmp(File, "*Lab") == 0) return cmsCreateLabProfile(NULL); if (stricmp(File, "*XYZ") == 0) return cmsCreateXYZProfile(); if (stricmp(File, "*srgb") == 0) return cmsCreate_sRGBProfile(); if (stricmp(File, "*Gray22") == 0) { LPGAMMATABLE Gamma = cmsBuildGamma(256, 2.2); cmsHPROFILE hProfile = cmsCreateGrayProfile(cmsD50_xyY(), Gamma); cmsFreeGamma(Gamma); return hProfile; } if (stricmp(File, "*Lin2222") == 0) { LPGAMMATABLE Gamma = cmsBuildGamma(256, 2.2); LPGAMMATABLE Gamma4[4]; cmsHPROFILE hProfile; Gamma4[0] = Gamma4[1] = Gamma4[2] = Gamma4[3] = Gamma; hProfile = cmsCreateLinearizationDeviceLink(icSigCmykData, Gamma4); cmsFreeGamma(Gamma); return hProfile; } h = cmsOpenProfileFromFile(File, "r"); if (cmsGetDeviceClass(h) == icSigNamedColorClass) FatalError("ERROR: Cannot make devicelink of named color profiles!"); return h; }
// retrieve monitor profile from Windows // TODO: support for multi-monitor setups void GetMonitorProfile(wxString& profileName, cmsHPROFILE& profile) { // look up monitor profile in system HDC hdc = GetDC(NULL); if (hdc) { wxChar filename[MAX_PATH]; DWORD len; if (GetICMProfile(hdc, &len, filename)) { profileName = filename; profile = cmsOpenProfileFromFile(profileName.c_str(), "r"); }; ReleaseDC(NULL, hdc); }; };
static PyObject* cms_profile_open(PyObject* self, PyObject* args) { cmsHPROFILE hProfile; char* sProfile; if (!PyArg_ParseTuple(args, "s:profile_open", &sProfile)) return NULL; hProfile = cmsOpenProfileFromFile(sProfile, "r"); if (!hProfile) { PyErr_SetString(PyExc_IOError, "cannot open profile file"); return NULL; } return cms_profile_new(hProfile); }
static void GenerateCSA(void) { cmsHPROFILE hProfile = cmsOpenProfileFromFile(cInProf, "r"); size_t n; char* Buffer; n = cmsGetPostScriptCSA(hProfile, Intent, NULL, 0); if (n == 0) return; Buffer = (char*) _cmsMalloc(n + 1); cmsGetPostScriptCSA(hProfile, Intent, Buffer, n); Buffer[n] = 0; fprintf(OutFile, "%s", Buffer); _cmsFree(Buffer); cmsCloseProfile(hProfile); }
static cmsHPROFILE _create_profile(gchar *iccprofile) { cmsHPROFILE profile = NULL; if(!strcmp(iccprofile, "sRGB")) { // default: sRGB profile = dt_colorspaces_create_srgb_profile(); } else if(!strcmp(iccprofile, "linear_rec709_rgb") || !strcmp(iccprofile, "linear_rgb")) { profile = dt_colorspaces_create_linear_rec709_rgb_profile(); } else if(!strcmp(iccprofile, "linear_rec2020_rgb")) { profile = dt_colorspaces_create_linear_rec2020_rgb_profile(); } else if(!strcmp(iccprofile, "adobergb")) { profile = dt_colorspaces_create_adobergb_profile(); } else if(!strcmp(iccprofile, "X profile")) { // x default pthread_rwlock_rdlock(&darktable.control->xprofile_lock); if(darktable.control->xprofile_data) profile = cmsOpenProfileFromMem(darktable.control->xprofile_data, darktable.control->xprofile_size); pthread_rwlock_unlock(&darktable.control->xprofile_lock); } else { // else: load file name char filename[PATH_MAX]; dt_colorspaces_find_profile(filename, sizeof(filename), iccprofile, "out"); profile = cmsOpenProfileFromFile(filename, "r"); } /* if no match lets fallback to srgb profile */ if (!profile) profile = dt_colorspaces_create_srgb_profile(); return profile; }
static PyObject * pycms_OpenProfile(PyObject *self, PyObject *args) { char *profile = NULL; cmsHPROFILE hProfile; if (!PyArg_ParseTuple(args, "s", &profile)){ Py_INCREF(Py_None); return Py_None; } 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 void cdisplay_proof_changed (GimpColorDisplay *display) { CdisplayProof *proof = CDISPLAY_PROOF (display); cmsHPROFILE rgbProfile; cmsHPROFILE proofProfile; if (proof->transform) { cmsDeleteTransform (proof->transform); proof->transform = NULL; } if (! proof->profile) return; rgbProfile = cmsCreate_sRGBProfile (); proofProfile = cmsOpenProfileFromFile (proof->profile, "r"); if (proofProfile) { DWORD flags = cmsFLAGS_SOFTPROOFING; if (proof->bpc) flags |= cmsFLAGS_BLACKPOINTCOMPENSATION; proof->transform = cmsCreateProofingTransform (rgbProfile, TYPE_RGB_8, rgbProfile, TYPE_RGB_8, proofProfile, proof->intent, proof->intent, flags); cmsCloseProfile (proofProfile); } cmsCloseProfile (rgbProfile); }
static void cdisplay_proof_combo_box_set_active (GimpColorProfileComboBox *combo, const gchar *filename) { cmsHPROFILE profile = NULL; gchar *label = NULL; if (filename) profile = cmsOpenProfileFromFile (filename, "r"); if (profile) { label = gimp_any_to_utf8 (cmsTakeProductDesc (profile), -1, NULL); if (! label) label = gimp_any_to_utf8 (cmsTakeProductName (profile), -1, NULL); cmsCloseProfile (profile); } gimp_color_profile_combo_box_set_active (combo, filename, label); g_free (label); }
int main(int argc, char *argv[]) { LPLUT AToB0; cmsHPROFILE hProfile; fprintf(stderr, "Creating grayer.icm..."); unlink("grayer.icm"); hProfile = cmsOpenProfileFromFile("grayer.icm", "w"); AToB0 = cmsAllocLUT(); cmsAlloc3DGrid(AToB0, GRID_POINTS, 3, 3); cmsSample3DGrid(AToB0, Forward, NULL, 0); cmsAddTag(hProfile, icSigAToB0Tag, AToB0); cmsSetColorSpace(hProfile, icSigLabData); cmsSetPCS(hProfile, icSigLabData); cmsSetDeviceClass(hProfile, icSigAbstractClass); cmsAddTag(hProfile, icSigProfileDescriptionTag, "Little cms Grayifier"); cmsAddTag(hProfile, icSigCopyrightTag, "Copyright (c) Marti Maria 2003. All rights reserved."); cmsAddTag(hProfile, icSigDeviceMfgDescTag, "Little cms"); cmsAddTag(hProfile, icSigDeviceModelDescTag, "Grayifier abstract profile"); cmsCloseProfile(hProfile); cmsFreeLUT(AToB0); fprintf(stderr, "Done.\n"); return 0; }
static cmsHPROFILE _create_profile(gchar *iccprofile) { cmsHPROFILE profile = NULL; if(!strcmp(iccprofile, "sRGB")) { // default: sRGB profile = dt_colorspaces_create_srgb_profile(); } else if(!strcmp(iccprofile, "linear_rgb")) { profile = dt_colorspaces_create_linear_rgb_profile(); } else if(!strcmp(iccprofile, "adobergb")) { profile = dt_colorspaces_create_adobergb_profile(); } else if(!strcmp(iccprofile, "X profile")) { // x default if(darktable.control->xprofile_data) profile = cmsOpenProfileFromMem(darktable.control->xprofile_data, darktable.control->xprofile_size); else profile = NULL; } else { // else: load file name char filename[1024]; dt_colorspaces_find_profile(filename, 1024, iccprofile, "out"); profile = cmsOpenProfileFromFile(filename, "r"); } /* if no match lets fallback to srgb profile */ if (!profile) profile = dt_colorspaces_create_srgb_profile(); return profile; }
static void GenerateCRD(void) { cmsHPROFILE hProfile = cmsOpenProfileFromFile(cOutProf, "r"); size_t n; char* Buffer; DWORD dwFlags = 0; if (BlackPointCompensation) dwFlags |= cmsFLAGS_BLACKPOINTCOMPENSATION; if (Undecorated) dwFlags |= cmsFLAGS_NODEFAULTRESOURCEDEF; switch (PrecalcMode) { case 0: dwFlags |= cmsFLAGS_LOWRESPRECALC; break; case 2: dwFlags |= cmsFLAGS_HIGHRESPRECALC; break; case 1: if (NumOfGridPoints > 0) dwFlags |= cmsFLAGS_GRIDPOINTS(NumOfGridPoints); break; default: FatalError("ERROR: Unknown precalculation mode '%d'", PrecalcMode); } n = cmsGetPostScriptCRDEx(hProfile, Intent, dwFlags, NULL, 0); if (n == 0) return; Buffer = (char*) _cmsMalloc(n + 1); cmsGetPostScriptCRDEx(hProfile, Intent, dwFlags, Buffer, n); Buffer[n] = 0; fprintf(OutFile, "%s", Buffer); _cmsFree(Buffer); cmsCloseProfile(hProfile); }
static GimpPDBStatusType lcms_icc_file_info (const gchar *filename, gchar **name, gchar **desc, gchar **info) { cmsHPROFILE profile; if (! g_file_test (filename, G_FILE_TEST_IS_REGULAR)) return GIMP_PDB_EXECUTION_ERROR; profile = cmsOpenProfileFromFile (filename, "r"); if (! profile) return GIMP_PDB_EXECUTION_ERROR; *name = lcms_icc_profile_get_name (profile); *desc = lcms_icc_profile_get_desc (profile); *info = lcms_icc_profile_get_info (profile); cmsCloseProfile (profile); return GIMP_PDB_SUCCESS; }
QString ProfileUtils::profileHash(QFile &profile) { QString checksum; cmsHPROFILE lcms_profile = NULL; /* get the internal profile id, if it exists */ lcms_profile = cmsOpenProfileFromFile(profile.fileName().toUtf8(), "r"); if (lcms_profile == NULL) { // Compute the hash from the whole file.. return QCryptographicHash::hash(profile.readAll(), QCryptographicHash::Md5).toHex(); } else { checksum = getPrecookedMd5(lcms_profile); if (lcms_profile != NULL) { cmsCloseProfile (lcms_profile); } if (checksum.isNull()) { // Compute the hash from the whole file.. return QCryptographicHash::hash(profile.readAll(), QCryptographicHash::Md5).toHex(); } else { return checksum; } } }
static cmsHPROFILE color_man_cache_load_profile(ColorManProfileType type, const gchar *file, guchar *data, guint data_len) { cmsHPROFILE profile = NULL; switch (type) { case COLOR_PROFILE_FILE: if (file) { gchar *pathl; pathl = path_from_utf8(file); profile = cmsOpenProfileFromFile(pathl, "r"); g_free(pathl); } break; case COLOR_PROFILE_SRGB: profile = cmsCreate_sRGBProfile(); break; case COLOR_PROFILE_ADOBERGB: profile = color_man_create_adobe_comp(); break; case COLOR_PROFILE_MEM: if (data) { profile = cmsOpenProfileFromMem(data, data_len); } break; case COLOR_PROFILE_NONE: default: break; } return profile; }
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 }
/* Get ICC Profile handle from file ptr */ gcmmhprofile_t gscms_get_profile_handle_file(const char *filename) { return(cmsOpenProfileFromFile(filename, "r")); }
void gui_init(struct dt_iop_module_t *self) { self->gui_data = malloc(sizeof(dt_iop_colorout_gui_data_t)); memset(self->gui_data,0,sizeof(dt_iop_colorout_gui_data_t)); dt_iop_colorout_gui_data_t *g = (dt_iop_colorout_gui_data_t *)self->gui_data; g->profiles = NULL; dt_iop_color_profile_t *prof = (dt_iop_color_profile_t *)g_malloc0(sizeof(dt_iop_color_profile_t)); g_strlcpy(prof->filename, "sRGB", sizeof(prof->filename)); g_strlcpy(prof->name, "sRGB", sizeof(prof->name)); int pos; int display_pos; prof->pos = 0; prof->display_pos = 0; g->profiles = g_list_append(g->profiles, prof); prof = (dt_iop_color_profile_t *)g_malloc0(sizeof(dt_iop_color_profile_t)); g_strlcpy(prof->filename, "adobergb", sizeof(prof->filename)); g_strlcpy(prof->name, "adobergb", sizeof(prof->name)); prof->pos = 1; prof->display_pos = 1; g->profiles = g_list_append(g->profiles, prof); prof = (dt_iop_color_profile_t *)g_malloc0(sizeof(dt_iop_color_profile_t)); g_strlcpy(prof->filename, "X profile", sizeof(prof->filename)); g_strlcpy(prof->name, "X profile", sizeof(prof->name)); prof->pos = -1; prof->display_pos = 2; g->profiles = g_list_append(g->profiles, prof); prof = (dt_iop_color_profile_t *)g_malloc0(sizeof(dt_iop_color_profile_t)); g_strlcpy(prof->filename, "linear_rgb", sizeof(prof->filename)); g_strlcpy(prof->name, "linear_rgb", sizeof(prof->name)); pos = prof->pos = 2; display_pos = prof->display_pos = 3; g->profiles = g_list_append(g->profiles, prof); // read {conf,data}dir/color/out/*.icc char datadir[DT_MAX_PATH_LEN]; char confdir[DT_MAX_PATH_LEN]; char dirname[DT_MAX_PATH_LEN]; char filename[DT_MAX_PATH_LEN]; dt_loc_get_user_config_dir(confdir, DT_MAX_PATH_LEN); dt_loc_get_datadir(datadir, DT_MAX_PATH_LEN); snprintf(dirname, DT_MAX_PATH_LEN, "%s/color/out", confdir); if(!g_file_test(dirname, G_FILE_TEST_IS_DIR)) snprintf(dirname, DT_MAX_PATH_LEN, "%s/color/out", datadir); cmsHPROFILE tmpprof; const gchar *d_name; GDir *dir = g_dir_open(dirname, 0, NULL); if(dir) { while((d_name = g_dir_read_name(dir))) { snprintf(filename, DT_MAX_PATH_LEN, "%s/%s", dirname, d_name); tmpprof = cmsOpenProfileFromFile(filename, "r"); if(tmpprof) { char *lang = getenv("LANG"); if (!lang) lang = "en_US"; dt_iop_color_profile_t *prof = (dt_iop_color_profile_t *)g_malloc0(sizeof(dt_iop_color_profile_t)); char name[1024]; cmsGetProfileInfoASCII(tmpprof, cmsInfoDescription, lang, lang+3, name, 1024); g_strlcpy(prof->name, name, sizeof(prof->name)); g_strlcpy(prof->filename, d_name, sizeof(prof->filename)); prof->pos = ++pos; prof->display_pos = ++display_pos; cmsCloseProfile(tmpprof); g->profiles = g_list_append(g->profiles, prof); } } g_dir_close(dir); } self->widget = gtk_vbox_new(TRUE, DT_BAUHAUS_SPACE); // TODO: g->cbox1 = dt_bauhaus_combobox_new(self); gtk_box_pack_start(GTK_BOX(self->widget), g->cbox1, TRUE, TRUE, 0); dt_bauhaus_widget_set_label(g->cbox1, _("output intent")); dt_bauhaus_combobox_add(g->cbox1, _("perceptual")); dt_bauhaus_combobox_add(g->cbox1, _("relative colorimetric")); dt_bauhaus_combobox_add(g->cbox1, C_("rendering intent", "saturation")); dt_bauhaus_combobox_add(g->cbox1, _("absolute colorimetric")); g->cbox4 = dt_bauhaus_combobox_new(self); dt_bauhaus_widget_set_label(g->cbox4, _("display intent")); gtk_box_pack_start(GTK_BOX(self->widget), g->cbox4, TRUE, TRUE, 0); dt_bauhaus_combobox_add(g->cbox4, _("perceptual")); dt_bauhaus_combobox_add(g->cbox4, _("relative colorimetric")); dt_bauhaus_combobox_add(g->cbox4, C_("rendering intent", "saturation")); dt_bauhaus_combobox_add(g->cbox4, _("absolute colorimetric")); g->cbox2 = dt_bauhaus_combobox_new(self); g->cbox3 = dt_bauhaus_combobox_new(self); g->cbox5 = dt_bauhaus_combobox_new(self); dt_bauhaus_widget_set_label(g->cbox2, _("output profile")); dt_bauhaus_widget_set_label(g->cbox5, _("softproof profile")); dt_bauhaus_widget_set_label(g->cbox3, _("display profile")); gtk_box_pack_start(GTK_BOX(self->widget), g->cbox2, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(self->widget), g->cbox5, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(self->widget), g->cbox3, TRUE, TRUE, 0); GList *l = g->profiles; while(l) { dt_iop_color_profile_t *prof = (dt_iop_color_profile_t *)l->data; if(!strcmp(prof->name, "X profile")) { // the system display profile is only suitable for display purposes dt_bauhaus_combobox_add(g->cbox3, _("system display profile")); } else if(!strcmp(prof->name, "linear_rgb")) { dt_bauhaus_combobox_add(g->cbox2, _("linear RGB")); dt_bauhaus_combobox_add(g->cbox3, _("linear RGB")); dt_bauhaus_combobox_add(g->cbox5, _("linear RGB")); } else if(!strcmp(prof->name, "sRGB")) { dt_bauhaus_combobox_add(g->cbox2, _("sRGB (web-safe)")); dt_bauhaus_combobox_add(g->cbox3, _("sRGB (web-safe)")); dt_bauhaus_combobox_add(g->cbox5, _("sRGB (web-safe)")); } else if(!strcmp(prof->name, "adobergb")) { dt_bauhaus_combobox_add(g->cbox2, _("Adobe RGB")); dt_bauhaus_combobox_add(g->cbox3, _("Adobe RGB")); dt_bauhaus_combobox_add(g->cbox5, _("Adobe RGB")); } else { dt_bauhaus_combobox_add(g->cbox2, prof->name); dt_bauhaus_combobox_add(g->cbox3, prof->name); dt_bauhaus_combobox_add(g->cbox5, prof->name); } l = g_list_next(l); } char tooltip[1024]; g_object_set(G_OBJECT(g->cbox1), "tooltip-text", _("rendering intent"), (char *)NULL); snprintf(tooltip, 1024, _("icc profiles in %s/color/out or %s/color/out"), confdir, datadir); g_object_set(G_OBJECT(g->cbox2), "tooltip-text", tooltip, (char *)NULL); snprintf(tooltip, 1024, _("display icc profiles in %s/color/out or %s/color/out"), confdir, datadir); g_object_set(G_OBJECT(g->cbox3), "tooltip-text", tooltip, (char *)NULL); snprintf(tooltip, 1024, _("softproof icc profiles in %s/color/out or %s/color/out"), confdir, datadir); g_object_set(G_OBJECT(g->cbox5), "tooltip-text", tooltip, (char *)NULL); g_signal_connect (G_OBJECT (g->cbox1), "value-changed", G_CALLBACK (intent_changed), (gpointer)self); g_signal_connect (G_OBJECT (g->cbox4), "value-changed", G_CALLBACK (display_intent_changed), (gpointer)self); g_signal_connect (G_OBJECT (g->cbox2), "value-changed", G_CALLBACK (output_profile_changed), (gpointer)self); g_signal_connect (G_OBJECT (g->cbox3), "value-changed", G_CALLBACK (display_profile_changed), (gpointer)self); g_signal_connect (G_OBJECT (g->cbox5), "value-changed", G_CALLBACK (softproof_profile_changed), (gpointer)self); // reload the profiles when the display profile changed! dt_control_signal_connect(darktable.signals, DT_SIGNAL_CONTROL_PROFILE_CHANGED, G_CALLBACK(_signal_profile_changed), self); }