< prev index next >

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

Print this page
*** 2978,10 ***
--- 2978,112 ---
  
  
  
  // --------------------------------------------------------------------------------------------------------
  
+ static
+ cmsUInt8Number* PackBytesFromFloat(_cmsTRANSFORM* info,
+                                     cmsFloat32Number wOut[],
+                                     cmsUInt8Number* output,
+                                     cmsUInt32Number Stride)
+ {
+     cmsUInt32Number nChan = T_CHANNELS(info->OutputFormat);
+     cmsUInt32Number DoSwap = T_DOSWAP(info->OutputFormat);
+     cmsUInt32Number Reverse = T_FLAVOR(info->OutputFormat);
+     cmsUInt32Number Extra = T_EXTRA(info->OutputFormat);
+     cmsUInt32Number SwapFirst = T_SWAPFIRST(info->OutputFormat);
+     cmsUInt32Number Planar = T_PLANAR(info->OutputFormat);
+     cmsUInt32Number ExtraFirst = DoSwap ^ SwapFirst;
+     cmsUInt8Number* swap1 = (cmsUInt8Number*)output;
+     cmsFloat64Number v = 0;
+     cmsUInt8Number vv = 0;
+     cmsUInt32Number i, start = 0;
+ 
+     if (ExtraFirst)
+         start = Extra;
+ 
+     for (i = 0; i < nChan; i++) {
+ 
+         cmsUInt32Number index = DoSwap ? (nChan - i - 1) : i;
+ 
+         v = wOut[index] * 65535.0;
+ 
+         if (Reverse)
+             v = 65535.0 - v;
+ 
+         vv =  FROM_16_TO_8(_cmsQuickSaturateWord(v));
+ 
+         if (Planar)
+             ((cmsUInt8Number*)output)[(i + start) * Stride] = vv;
+         else
+             ((cmsUInt8Number*)output)[i + start] = vv;
+     }
+ 
+ 
+     if (Extra == 0 && SwapFirst) {
+ 
+         memmove(swap1 + 1, swap1, (nChan - 1) * sizeof(cmsUInt8Number));
+         *swap1 = vv;
+     }
+ 
+     if (T_PLANAR(info->OutputFormat))
+         return output + sizeof(cmsUInt8Number);
+     else
+         return output + (nChan + Extra) * sizeof(cmsUInt8Number);
+ }
+ 
+ static
+ cmsUInt8Number* PackWordsFromFloat(_cmsTRANSFORM* info,
+                                     cmsFloat32Number wOut[],
+                                     cmsUInt8Number* output,
+                                     cmsUInt32Number Stride)
+ {
+     cmsUInt32Number nChan = T_CHANNELS(info->OutputFormat);
+     cmsUInt32Number DoSwap = T_DOSWAP(info->OutputFormat);
+     cmsUInt32Number Reverse = T_FLAVOR(info->OutputFormat);
+     cmsUInt32Number Extra = T_EXTRA(info->OutputFormat);
+     cmsUInt32Number SwapFirst = T_SWAPFIRST(info->OutputFormat);
+     cmsUInt32Number Planar = T_PLANAR(info->OutputFormat);
+     cmsUInt32Number ExtraFirst = DoSwap ^ SwapFirst;
+     cmsUInt16Number* swap1 = (cmsUInt16Number*)output;
+     cmsFloat64Number v = 0;
+     cmsUInt16Number vv = 0;
+     cmsUInt32Number i, start = 0;
+ 
+     if (ExtraFirst)
+         start = Extra;
+ 
+     for (i = 0; i < nChan; i++) {
+ 
+         cmsUInt32Number index = DoSwap ? (nChan - i - 1) : i;
+ 
+         v = wOut[index] * 65535.0;
+ 
+         if (Reverse)
+             v = 65535.0 - v;
+ 
+         vv = _cmsQuickSaturateWord(v);
+ 
+         if (Planar)
+             ((cmsUInt16Number*)output)[(i + start) * Stride] = vv;
+         else
+             ((cmsUInt16Number*)output)[i + start] = vv;
+     }
+ 
+     if (Extra == 0 && SwapFirst) {
+ 
+         memmove(swap1 + 1, swap1, (nChan - 1) * sizeof(cmsUInt16Number));
+         *swap1 = vv;
+     }
+ 
+     if (T_PLANAR(info->OutputFormat))
+         return output + sizeof(cmsUInt16Number);
+     else
+         return output + (nChan + Extra) * sizeof(cmsUInt16Number);
+ }
+ 
+ 
  static
  cmsUInt8Number* PackFloatsFromFloat(_cmsTRANSFORM* info,
                                      cmsFloat32Number wOut[],
                                      cmsUInt8Number* output,
                                      cmsUInt32Number Stride)

*** 3141,10 ***
--- 3243,81 ---
      }
  
  }
  
  
+ static
+ cmsUInt8Number* PackEncodedBytesLabV2FromFloat(_cmsTRANSFORM* Info,
+                                            cmsFloat32Number wOut[],
+                                            cmsUInt8Number* output,
+                                            cmsUInt32Number Stride)
+ {
+     cmsCIELab Lab;
+     cmsUInt16Number wlab[3];
+ 
+     Lab.L = (cmsFloat64Number)(wOut[0] * 100.0);
+     Lab.a = (cmsFloat64Number)(wOut[1] * 255.0 - 128.0);
+     Lab.b = (cmsFloat64Number)(wOut[2] * 255.0 - 128.0);
+ 
+     cmsFloat2LabEncoded(wlab, &Lab);
+ 
+     if (T_PLANAR(Info -> OutputFormat)) {
+ 
+         Stride /= PixelSize(Info->OutputFormat);
+ 
+         output[0]        = wlab[0] >> 8;
+         output[Stride]   = wlab[1] >> 8;
+         output[Stride*2] = wlab[2] >> 8;
+ 
+         return output + 1;
+     }
+     else {
+ 
+         output[0] = wlab[0] >> 8;
+         output[1] = wlab[1] >> 8;
+         output[2] = wlab[2] >> 8;
+ 
+         return output + (3 + T_EXTRA(Info ->OutputFormat));
+     }
+ }
+ 
+ static
+ cmsUInt8Number* PackEncodedWordsLabV2FromFloat(_cmsTRANSFORM* Info,
+                                            cmsFloat32Number wOut[],
+                                            cmsUInt8Number* output,
+                                            cmsUInt32Number Stride)
+ {
+     cmsCIELab Lab;
+     cmsUInt16Number wlab[3];
+ 
+     Lab.L = (cmsFloat64Number)(wOut[0] * 100.0);
+     Lab.a = (cmsFloat64Number)(wOut[1] * 255.0 - 128.0);
+     Lab.b = (cmsFloat64Number)(wOut[2] * 255.0 - 128.0);
+ 
+     cmsFloat2LabEncodedV2(wlab, &Lab);
+ 
+     if (T_PLANAR(Info -> OutputFormat)) {
+ 
+         Stride /= PixelSize(Info->OutputFormat);
+ 
+         ((cmsUInt16Number*) output)[0]        = wlab[0];
+         ((cmsUInt16Number*) output)[Stride]   = wlab[1];
+         ((cmsUInt16Number*) output)[Stride*2] = wlab[2];
+ 
+         return output + sizeof(cmsUInt16Number);
+     }
+     else {
+ 
+          ((cmsUInt16Number*) output)[0] = wlab[0];
+          ((cmsUInt16Number*) output)[1] = wlab[1];
+          ((cmsUInt16Number*) output)[2] = wlab[2];
+ 
+         return output + (3 + T_EXTRA(Info ->OutputFormat)) * sizeof(cmsUInt16Number);
+     }
+ }
+ 
+ 
  // From 0..1 range to 0..MAX_ENCODEABLE_XYZ
  static
  cmsUInt8Number* PackXYZFloatFromFloat(_cmsTRANSFORM* Info,
                                        cmsFloat32Number wOut[],
                                        cmsUInt8Number* output,

*** 3674,14 ***
--- 3847,24 ---
      {     TYPE_XYZ_FLT,                                                ANYPLANAR|ANYEXTRA,   PackXYZFloatFromFloat},
  
      {     TYPE_Lab_DBL,                                                ANYPLANAR|ANYEXTRA,   PackLabDoubleFromFloat},
      {     TYPE_XYZ_DBL,                                                ANYPLANAR|ANYEXTRA,   PackXYZDoubleFromFloat},
  
+     {     TYPE_LabV2_8,                                                ANYPLANAR|ANYEXTRA,   PackEncodedBytesLabV2FromFloat},
+     {     TYPE_LabV2_16,                                               ANYPLANAR|ANYEXTRA,   PackEncodedWordsLabV2FromFloat},
+ 
      {     FLOAT_SH(1)|BYTES_SH(4), ANYPLANAR|
                               ANYFLAVOR|ANYSWAPFIRST|ANYSWAP|ANYEXTRA|ANYCHANNELS|ANYSPACE,   PackFloatsFromFloat },
      {     FLOAT_SH(1)|BYTES_SH(0), ANYPLANAR|
                               ANYFLAVOR|ANYSWAPFIRST|ANYSWAP|ANYEXTRA|ANYCHANNELS|ANYSPACE,   PackDoublesFromFloat },
+ 
+     {     BYTES_SH(2), ANYPLANAR|
+                              ANYFLAVOR|ANYSWAPFIRST|ANYSWAP|ANYEXTRA|ANYCHANNELS|ANYSPACE,   PackWordsFromFloat },
+ 
+     {     BYTES_SH(1), ANYPLANAR|
+                              ANYFLAVOR|ANYSWAPFIRST|ANYSWAP|ANYEXTRA|ANYCHANNELS|ANYSPACE,   PackBytesFromFloat },
+ 
  #ifndef CMS_NO_HALF_SUPPORT
      {     FLOAT_SH(1)|BYTES_SH(2),
                               ANYFLAVOR|ANYSWAPFIRST|ANYSWAP|ANYEXTRA|ANYCHANNELS|ANYSPACE,   PackHalfFromFloat },
  #endif
  

*** 3888,11 ***
  {
  
      cmsColorSpaceSignature ColorSpace = cmsGetPCS(hProfile);
  
      cmsUInt32Number ColorSpaceBits = (cmsUInt32Number) _cmsLCMScolorSpace(ColorSpace);
!     cmsUInt32Number nOutputChans = cmsChannelsOf(ColorSpace);
      cmsUInt32Number Float = lIsFloat ? 1U : 0;
  
      // Unsupported color space?
      if (nOutputChans < 0) return 0;
  
--- 4071,11 ---
  {
  
      cmsColorSpaceSignature ColorSpace = cmsGetPCS(hProfile);
  
      cmsUInt32Number ColorSpaceBits = (cmsUInt32Number) _cmsLCMScolorSpace(ColorSpace);
!     cmsInt32Number  nOutputChans = cmsChannelsOfColorSpace(ColorSpace);
      cmsUInt32Number Float = lIsFloat ? 1U : 0;
  
      // Unsupported color space?
      if (nOutputChans < 0) return 0;
  
< prev index next >