< prev index next >

src/java.desktop/share/native/liblcms/cmsvirt.c

Print this page
*** 433,14 ***
          return NULL;
      }
  
      if (Limit < 0.0 || Limit > 400) {
  
!         cmsSignalError(ContextID, cmsERROR_RANGE, "InkLimiting: Limit should be between 0..400");
!         if (Limit < 0) Limit = 0;
          if (Limit > 400) Limit = 400;
- 
      }
  
      hICC = cmsCreateProfilePlaceholder(ContextID);
      if (!hICC)                          // can't allocate
          return NULL;
--- 433,13 ---
          return NULL;
      }
  
      if (Limit < 0.0 || Limit > 400) {
  
!         cmsSignalError(ContextID, cmsERROR_RANGE, "InkLimiting: Limit should be between 1..400");
!         if (Limit < 1) Limit = 1;
          if (Limit > 400) Limit = 400;
      }
  
      hICC = cmsCreateProfilePlaceholder(ContextID);
      if (!hICC)                          // can't allocate
          return NULL;

*** 699,10 ***
--- 698,131 ---
  cmsHPROFILE CMSEXPORT cmsCreate_sRGBProfile(void)
  {
      return cmsCreate_sRGBProfileTHR(NULL);
  }
  
+ /**
+ * Oklab colorspace profile (experimental)
+ *
+ * This virtual profile cannot be saved as an ICC file
+ */
+ cmsHPROFILE cmsCreate_OkLabProfile(cmsContext ctx)
+ {
+     cmsStage* XYZPCS = _cmsStageNormalizeFromXyzFloat(ctx);
+     cmsStage* PCSXYZ = _cmsStageNormalizeToXyzFloat(ctx);
+ 
+     const double M_D65_D50[] =
+     {
+        1.047886, 0.022919, -0.050216,
+        0.029582, 0.990484, -0.017079,
+       -0.009252, 0.015073,  0.751678
+     };
+ 
+     const double M_D50_D65[] =
+     {
+          0.955512609517083, -0.023073214184645,  0.063308961782107,
+         -0.028324949364887,  1.009942432477107,  0.021054814890112,
+          0.012328875695483, -0.020535835374141,  1.330713916450354
+     };
+ 
+     cmsStage* D65toD50 = cmsStageAllocMatrix(ctx, 3, 3, M_D65_D50, NULL);
+     cmsStage* D50toD65 = cmsStageAllocMatrix(ctx, 3, 3, M_D50_D65, NULL);
+ 
+     const double M_D65_LMS[] =
+     {
+         0.8189330101, 0.3618667424, -0.1288597137,
+         0.0329845436, 0.9293118715,  0.0361456387,
+         0.0482003018, 0.2643662691,  0.6338517070
+     };
+ 
+     const double M_LMS_D65[] =
+     {
+         1.227013851103521, -0.557799980651822,  0.281256148966468,
+        -0.040580178423281,  1.112256869616830, -0.071676678665601,
+        -0.076381284505707, -0.421481978418013,  1.586163220440795
+     };
+ 
+     cmsStage* D65toLMS = cmsStageAllocMatrix(ctx, 3, 3, M_D65_LMS, NULL);
+     cmsStage* LMStoD65 = cmsStageAllocMatrix(ctx, 3, 3, M_LMS_D65, NULL);
+ 
+     cmsToneCurve* CubeRoot = cmsBuildGamma(ctx, 1.0 / 3.0);
+     cmsToneCurve* Cube     = cmsBuildGamma(ctx,  3.0);
+ 
+     cmsToneCurve* Roots[3] = { CubeRoot, CubeRoot, CubeRoot };
+     cmsToneCurve* Cubes[3] = { Cube, Cube, Cube };
+ 
+     cmsStage* NonLinearityFw = cmsStageAllocToneCurves(ctx, 3, Roots);
+     cmsStage* NonLinearityRv = cmsStageAllocToneCurves(ctx, 3, Cubes);
+ 
+     const double M_LMSprime_OkLab[] =
+     {
+         0.2104542553,  0.7936177850, -0.0040720468,
+         1.9779984951, -2.4285922050,  0.4505937099,
+         0.0259040371,  0.7827717662, -0.8086757660
+     };
+ 
+     const double M_OkLab_LMSprime[] =
+     {
+         0.999999998450520,  0.396337792173768,  0.215803758060759,
+         1.000000008881761, -0.105561342323656, -0.063854174771706,
+         1.000000054672411, -0.089484182094966, -1.291485537864092
+     };
+ 
+     cmsStage* LMSprime_OkLab = cmsStageAllocMatrix(ctx, 3, 3, M_LMSprime_OkLab, NULL);
+     cmsStage* OkLab_LMSprime = cmsStageAllocMatrix(ctx, 3, 3, M_OkLab_LMSprime, NULL);
+ 
+     cmsPipeline* AToB = cmsPipelineAlloc(ctx, 3, 3);
+     cmsPipeline* BToA = cmsPipelineAlloc(ctx, 3, 3);
+ 
+     cmsHPROFILE hProfile = cmsCreateProfilePlaceholder(ctx);
+ 
+     cmsSetProfileVersion(hProfile, 4.4);
+ 
+     cmsSetDeviceClass(hProfile, cmsSigColorSpaceClass);
+     cmsSetColorSpace(hProfile, cmsSig3colorData);
+     cmsSetPCS(hProfile, cmsSigXYZData);
+ 
+     cmsSetHeaderRenderingIntent(hProfile, INTENT_RELATIVE_COLORIMETRIC);
+ 
+     /**
+     * Conversion PCS (XYZ/D50) to OkLab
+     */
+     if (!cmsPipelineInsertStage(BToA, cmsAT_END, PCSXYZ)) goto error;
+     if (!cmsPipelineInsertStage(BToA, cmsAT_END, D50toD65)) goto error;
+     if (!cmsPipelineInsertStage(BToA, cmsAT_END, D65toLMS)) goto error;
+     if (!cmsPipelineInsertStage(BToA, cmsAT_END, NonLinearityFw)) goto error;
+     if (!cmsPipelineInsertStage(BToA, cmsAT_END, LMSprime_OkLab)) goto error;
+ 
+     if (!cmsWriteTag(hProfile, cmsSigBToA0Tag, BToA)) goto error;
+ 
+     if (!cmsPipelineInsertStage(AToB, cmsAT_END, OkLab_LMSprime)) goto error;
+     if (!cmsPipelineInsertStage(AToB, cmsAT_END, NonLinearityRv)) goto error;
+     if (!cmsPipelineInsertStage(AToB, cmsAT_END, LMStoD65)) goto error;
+     if (!cmsPipelineInsertStage(AToB, cmsAT_END, D65toD50)) goto error;
+     if (!cmsPipelineInsertStage(AToB, cmsAT_END, XYZPCS)) goto error;
+ 
+     if (!cmsWriteTag(hProfile, cmsSigAToB0Tag, AToB)) goto error;
+ 
+     cmsPipelineFree(BToA);
+     cmsPipelineFree(AToB);
+ 
+     cmsFreeToneCurve(CubeRoot);
+     cmsFreeToneCurve(Cube);
+ 
+     return hProfile;
+ 
+ error:
+     cmsPipelineFree(BToA);
+     cmsPipelineFree(AToB);
+ 
+     cmsFreeToneCurve(CubeRoot);
+     cmsFreeToneCurve(Cube);
+     cmsCloseProfile(hProfile);
+ 
+     return NULL;
+ 
+ }
  
  
  typedef struct {
                  cmsFloat64Number Brightness;
                  cmsFloat64Number Contrast;

*** 1058,11 ***
      cmsStage* mpe;
      int n;
  
      for (n=0, mpe = Lut ->Elements; mpe != NULL; mpe = mpe ->Next, n++) {
  
!         if (n > Tab ->nTypes) return FALSE;
          if (cmsStageType(mpe) != Tab ->MpeTypes[n]) return FALSE;
      }
  
      return (n == Tab ->nTypes);
  }
--- 1178,11 ---
      cmsStage* mpe;
      int n;
  
      for (n=0, mpe = Lut ->Elements; mpe != NULL; mpe = mpe ->Next, n++) {
  
!         if (n >= Tab ->nTypes) return FALSE;
          if (cmsStageType(mpe) != Tab ->MpeTypes[n]) return FALSE;
      }
  
      return (n == Tab ->nTypes);
  }

*** 1089,23 ***
  
  // Does convert a transform into a device link profile
  cmsHPROFILE CMSEXPORT cmsTransform2DeviceLink(cmsHTRANSFORM hTransform, cmsFloat64Number Version, cmsUInt32Number dwFlags)
  {
      cmsHPROFILE hProfile = NULL;
!         cmsUInt32Number FrmIn, FrmOut;
!         cmsInt32Number ChansIn, ChansOut;
!         int ColorSpaceBitsIn, ColorSpaceBitsOut;
      _cmsTRANSFORM* xform = (_cmsTRANSFORM*) hTransform;
      cmsPipeline* LUT = NULL;
      cmsStage* mpe;
      cmsContext ContextID = cmsGetTransformContextID(hTransform);
      const cmsAllowedLUT* AllowedLUT;
      cmsTagSignature DestinationTag;
      cmsProfileClassSignature deviceClass;
  
      _cmsAssert(hTransform != NULL);
  
      // Get the first mpe to check for named color
      mpe = cmsPipelineGetPtrToFirstStage(xform ->Lut);
  
      // Check if is a named color transform
      if (mpe != NULL) {
--- 1209,26 ---
  
  // Does convert a transform into a device link profile
  cmsHPROFILE CMSEXPORT cmsTransform2DeviceLink(cmsHTRANSFORM hTransform, cmsFloat64Number Version, cmsUInt32Number dwFlags)
  {
      cmsHPROFILE hProfile = NULL;
!     cmsUInt32Number FrmIn, FrmOut;
!     cmsInt32Number ChansIn, ChansOut;
!     int ColorSpaceBitsIn, ColorSpaceBitsOut;
      _cmsTRANSFORM* xform = (_cmsTRANSFORM*) hTransform;
      cmsPipeline* LUT = NULL;
      cmsStage* mpe;
      cmsContext ContextID = cmsGetTransformContextID(hTransform);
      const cmsAllowedLUT* AllowedLUT;
      cmsTagSignature DestinationTag;
      cmsProfileClassSignature deviceClass;
  
      _cmsAssert(hTransform != NULL);
  
+     // Check if the pipeline holding is valid
+     if (xform -> Lut == NULL) return NULL;
+ 
      // Get the first mpe to check for named color
      mpe = cmsPipelineGetPtrToFirstStage(xform ->Lut);
  
      // Check if is a named color transform
      if (mpe != NULL) {
< prev index next >