summaryrefslogtreecommitdiff
path: root/third_party/lcms/src/cmspack.c
diff options
context:
space:
mode:
authorNicolas Pena <npm@chromium.org>2017-08-14 10:36:01 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-08-14 15:02:17 +0000
commit0bd847232a1f430c70dd9d8df177ce68a3cde010 (patch)
tree15cec8c11493549f1974ae2f6aeac58234c176d2 /third_party/lcms/src/cmspack.c
parentdff02cee2d2410d81a55c59345fb38b5aac8a457 (diff)
downloadpdfium-0bd847232a1f430c70dd9d8df177ce68a3cde010.tar.xz
LCMS: upgrade to 2.8
This CL upgrades LCMS from version 2.6 to 2.8. All changes from LCMS original version 2.8 are stored in patch files: - Patch 0: memory management modifications to use PDFium methods. This was previously not in any patch, so the changes were manually applied. - Patches 1-5: new patch files corresponding to old changes that can be seen in the history, but did not previously have patch files. - Patches 6-25: previous patches (patch numbers shifted by 6). The one for from16-to-8-overflow.patch was deleted as it was already upstream. Some patches did not apply cleanly so their .patch files were modified. - Patch 26: as I just moved files directly, unsupported characters were moved in unchanged, so I had to fix all of them: e with tilde and other characters were replaced to allow compilation on Windows. - Patch 27: Went over the code and re-applied changes that included comments clearly indicating this was Foxit. These changes are all already seen in the initial PDFium commit. Change-Id: Ic1d84e54803ef9e6b280ef7619bbf0b757312fbf Reviewed-on: https://pdfium-review.googlesource.com/10590 Commit-Queue: Nicolás Peña <npm@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'third_party/lcms/src/cmspack.c')
-rw-r--r--third_party/lcms/src/cmspack.c341
1 files changed, 163 insertions, 178 deletions
diff --git a/third_party/lcms/src/cmspack.c b/third_party/lcms/src/cmspack.c
index 9323b53ec5..6ed41da870 100644
--- a/third_party/lcms/src/cmspack.c
+++ b/third_party/lcms/src/cmspack.c
@@ -1,7 +1,7 @@
//---------------------------------------------------------------------------------
//
// Little Color Management System
-// Copyright (c) 1998-2010 Marti Maria Saguer
+// Copyright (c) 1998-2016 Marti Maria Saguer
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the "Software"),
@@ -23,6 +23,7 @@
//
//---------------------------------------------------------------------------------
//
+
#include "lcms2_internal.h"
// This module handles all formats supported by lcms. There are two flavors, 16 bits and
@@ -80,7 +81,7 @@ typedef struct {
#define ANYFLAVOR FLAVOR_SH(1)
-// Supress waning about info never being used
+// Suppress waning about info never being used
#ifdef _MSC_VER
#pragma warning(disable : 4100)
@@ -2408,9 +2409,6 @@ cmsUInt8Number* PackDoubleFrom16(register _cmsTRANSFORM* info,
((cmsFloat64Number*) output)[i + start] = v;
}
- if (!ExtraFirst) {
- output += Extra * sizeof(cmsFloat64Number);
- }
if (Extra == 0 && SwapFirst) {
@@ -2421,7 +2419,7 @@ cmsUInt8Number* PackDoubleFrom16(register _cmsTRANSFORM* info,
if (T_PLANAR(info -> OutputFormat))
return output + sizeof(cmsFloat64Number);
else
- return output + nChan * sizeof(cmsFloat64Number);
+ return output + (nChan + Extra) * sizeof(cmsFloat64Number);
}
@@ -2432,50 +2430,47 @@ cmsUInt8Number* PackFloatFrom16(register _cmsTRANSFORM* info,
register cmsUInt8Number* output,
register cmsUInt32Number Stride)
{
- int nChan = T_CHANNELS(info -> OutputFormat);
- int DoSwap = T_DOSWAP(info ->OutputFormat);
- int Reverse = T_FLAVOR(info ->OutputFormat);
- int Extra = T_EXTRA(info -> OutputFormat);
- int SwapFirst = T_SWAPFIRST(info -> OutputFormat);
- int Planar = T_PLANAR(info -> OutputFormat);
- int ExtraFirst = DoSwap ^ SwapFirst;
- cmsFloat64Number maximum = IsInkSpace(info ->OutputFormat) ? 655.35 : 65535.0;
- cmsFloat64Number v = 0;
- cmsFloat32Number* swap1 = (cmsFloat32Number*) output;
- int i, start = 0;
+ int nChan = T_CHANNELS(info->OutputFormat);
+ int DoSwap = T_DOSWAP(info->OutputFormat);
+ int Reverse = T_FLAVOR(info->OutputFormat);
+ int Extra = T_EXTRA(info->OutputFormat);
+ int SwapFirst = T_SWAPFIRST(info->OutputFormat);
+ int Planar = T_PLANAR(info->OutputFormat);
+ int ExtraFirst = DoSwap ^ SwapFirst;
+ cmsFloat64Number maximum = IsInkSpace(info->OutputFormat) ? 655.35 : 65535.0;
+ cmsFloat64Number v = 0;
+ cmsFloat32Number* swap1 = (cmsFloat32Number*)output;
+ int i, start = 0;
- if (ExtraFirst)
- start = Extra;
+ if (ExtraFirst)
+ start = Extra;
- for (i=0; i < nChan; i++) {
+ for (i = 0; i < nChan; i++) {
- int index = DoSwap ? (nChan - i - 1) : i;
+ int index = DoSwap ? (nChan - i - 1) : i;
- v = (cmsFloat64Number) wOut[index] / maximum;
-
- if (Reverse)
- v = maximum - v;
+ v = (cmsFloat64Number)wOut[index] / maximum;
- if (Planar)
- ((cmsFloat32Number*) output)[(i + start ) * Stride]= (cmsFloat32Number) v;
- else
- ((cmsFloat32Number*) output)[i + start] = (cmsFloat32Number) v;
- }
+ if (Reverse)
+ v = maximum - v;
- if (!ExtraFirst) {
- output += Extra * sizeof(cmsFloat32Number);
- }
+ if (Planar)
+ ((cmsFloat32Number*)output)[(i + start) * Stride] = (cmsFloat32Number)v;
+ else
+ ((cmsFloat32Number*)output)[i + start] = (cmsFloat32Number)v;
+ }
- if (Extra == 0 && SwapFirst) {
+
+ if (Extra == 0 && SwapFirst) {
- memmove(swap1 + 1, swap1, (nChan-1)* sizeof(cmsFloat32Number));
- *swap1 = (cmsFloat32Number) v;
- }
+ memmove(swap1 + 1, swap1, (nChan - 1)* sizeof(cmsFloat32Number));
+ *swap1 = (cmsFloat32Number)v;
+ }
- if (T_PLANAR(info -> OutputFormat))
- return output + sizeof(cmsFloat32Number);
- else
- return output + nChan * sizeof(cmsFloat32Number);
+ if (T_PLANAR(info->OutputFormat))
+ return output + sizeof(cmsFloat32Number);
+ else
+ return output + (nChan + Extra) * sizeof(cmsFloat32Number);
}
@@ -2488,50 +2483,47 @@ cmsUInt8Number* PackFloatsFromFloat(_cmsTRANSFORM* info,
cmsUInt8Number* output,
cmsUInt32Number Stride)
{
- int nChan = T_CHANNELS(info -> OutputFormat);
- int DoSwap = T_DOSWAP(info ->OutputFormat);
- int Reverse = T_FLAVOR(info ->OutputFormat);
- int Extra = T_EXTRA(info -> OutputFormat);
- int SwapFirst = T_SWAPFIRST(info -> OutputFormat);
- int Planar = T_PLANAR(info -> OutputFormat);
- int ExtraFirst = DoSwap ^ SwapFirst;
- cmsFloat64Number maximum = IsInkSpace(info ->OutputFormat) ? 100.0 : 1.0;
- cmsFloat32Number* swap1 = (cmsFloat32Number*) output;
- cmsFloat64Number v = 0;
- int i, start = 0;
+ int nChan = T_CHANNELS(info->OutputFormat);
+ int DoSwap = T_DOSWAP(info->OutputFormat);
+ int Reverse = T_FLAVOR(info->OutputFormat);
+ int Extra = T_EXTRA(info->OutputFormat);
+ int SwapFirst = T_SWAPFIRST(info->OutputFormat);
+ int Planar = T_PLANAR(info->OutputFormat);
+ int ExtraFirst = DoSwap ^ SwapFirst;
+ cmsFloat64Number maximum = IsInkSpace(info->OutputFormat) ? 100.0 : 1.0;
+ cmsFloat32Number* swap1 = (cmsFloat32Number*)output;
+ cmsFloat64Number v = 0;
+ int i, start = 0;
- if (ExtraFirst)
- start = Extra;
+ if (ExtraFirst)
+ start = Extra;
- for (i=0; i < nChan; i++) {
+ for (i = 0; i < nChan; i++) {
- int index = DoSwap ? (nChan - i - 1) : i;
+ int index = DoSwap ? (nChan - i - 1) : i;
- v = wOut[index] * maximum;
+ v = wOut[index] * maximum;
- if (Reverse)
- v = maximum - v;
+ if (Reverse)
+ v = maximum - v;
- if (Planar)
- ((cmsFloat32Number*) output)[(i + start)* Stride]= (cmsFloat32Number) v;
- else
- ((cmsFloat32Number*) output)[i + start] = (cmsFloat32Number) v;
- }
+ if (Planar)
+ ((cmsFloat32Number*)output)[(i + start)* Stride] = (cmsFloat32Number)v;
+ else
+ ((cmsFloat32Number*)output)[i + start] = (cmsFloat32Number)v;
+ }
- if (!ExtraFirst) {
- output += Extra * sizeof(cmsFloat32Number);
- }
- if (Extra == 0 && SwapFirst) {
+ if (Extra == 0 && SwapFirst) {
- memmove(swap1 + 1, swap1, (nChan-1)* sizeof(cmsFloat32Number));
- *swap1 = (cmsFloat32Number) v;
- }
+ memmove(swap1 + 1, swap1, (nChan - 1)* sizeof(cmsFloat32Number));
+ *swap1 = (cmsFloat32Number)v;
+ }
- if (T_PLANAR(info -> OutputFormat))
- return output + sizeof(cmsFloat32Number);
- else
- return output + nChan * sizeof(cmsFloat32Number);
+ if (T_PLANAR(info->OutputFormat))
+ return output + sizeof(cmsFloat32Number);
+ else
+ return output + (nChan + Extra) * sizeof(cmsFloat32Number);
}
static
@@ -2540,51 +2532,47 @@ cmsUInt8Number* PackDoublesFromFloat(_cmsTRANSFORM* info,
cmsUInt8Number* output,
cmsUInt32Number Stride)
{
- int nChan = T_CHANNELS(info -> OutputFormat);
- int DoSwap = T_DOSWAP(info ->OutputFormat);
- int Reverse = T_FLAVOR(info ->OutputFormat);
- int Extra = T_EXTRA(info -> OutputFormat);
- int SwapFirst = T_SWAPFIRST(info -> OutputFormat);
- int Planar = T_PLANAR(info -> OutputFormat);
- int ExtraFirst = DoSwap ^ SwapFirst;
- cmsFloat64Number maximum = IsInkSpace(info ->OutputFormat) ? 100.0 : 1.0;
- cmsFloat64Number v = 0;
- cmsFloat64Number* swap1 = (cmsFloat64Number*) output;
- int i, start = 0;
+ int nChan = T_CHANNELS(info->OutputFormat);
+ int DoSwap = T_DOSWAP(info->OutputFormat);
+ int Reverse = T_FLAVOR(info->OutputFormat);
+ int Extra = T_EXTRA(info->OutputFormat);
+ int SwapFirst = T_SWAPFIRST(info->OutputFormat);
+ int Planar = T_PLANAR(info->OutputFormat);
+ int ExtraFirst = DoSwap ^ SwapFirst;
+ cmsFloat64Number maximum = IsInkSpace(info->OutputFormat) ? 100.0 : 1.0;
+ cmsFloat64Number v = 0;
+ cmsFloat64Number* swap1 = (cmsFloat64Number*)output;
+ int i, start = 0;
- if (ExtraFirst)
- start = Extra;
+ if (ExtraFirst)
+ start = Extra;
- for (i=0; i < nChan; i++) {
+ for (i = 0; i < nChan; i++) {
- int index = DoSwap ? (nChan - i - 1) : i;
+ int index = DoSwap ? (nChan - i - 1) : i;
- v = wOut[index] * maximum;
+ v = wOut[index] * maximum;
- if (Reverse)
- v = maximum - v;
+ if (Reverse)
+ v = maximum - v;
- if (Planar)
- ((cmsFloat64Number*) output)[(i + start) * Stride] = v;
- else
- ((cmsFloat64Number*) output)[i + start] = v;
- }
+ if (Planar)
+ ((cmsFloat64Number*)output)[(i + start) * Stride] = v;
+ else
+ ((cmsFloat64Number*)output)[i + start] = v;
+ }
- if (!ExtraFirst) {
- output += Extra * sizeof(cmsFloat64Number);
- }
+ if (Extra == 0 && SwapFirst) {
- if (Extra == 0 && SwapFirst) {
+ memmove(swap1 + 1, swap1, (nChan - 1)* sizeof(cmsFloat64Number));
+ *swap1 = v;
+ }
- memmove(swap1 + 1, swap1, (nChan-1)* sizeof(cmsFloat64Number));
- *swap1 = v;
- }
-
- if (T_PLANAR(info -> OutputFormat))
- return output + sizeof(cmsFloat64Number);
- else
- return output + nChan * sizeof(cmsFloat64Number);
+ if (T_PLANAR(info->OutputFormat))
+ return output + sizeof(cmsFloat64Number);
+ else
+ return output + (nChan + Extra) * sizeof(cmsFloat64Number);
}
@@ -2820,50 +2808,47 @@ cmsUInt8Number* PackHalfFrom16(register _cmsTRANSFORM* info,
register cmsUInt8Number* output,
register cmsUInt32Number Stride)
{
- int nChan = T_CHANNELS(info -> OutputFormat);
- int DoSwap = T_DOSWAP(info ->OutputFormat);
- int Reverse = T_FLAVOR(info ->OutputFormat);
- int Extra = T_EXTRA(info -> OutputFormat);
- int SwapFirst = T_SWAPFIRST(info -> OutputFormat);
- int Planar = T_PLANAR(info -> OutputFormat);
- int ExtraFirst = DoSwap ^ SwapFirst;
- cmsFloat32Number maximum = IsInkSpace(info ->OutputFormat) ? 655.35F : 65535.0F;
- cmsFloat32Number v = 0;
- cmsUInt16Number* swap1 = (cmsUInt16Number*) output;
- int i, start = 0;
+ int nChan = T_CHANNELS(info->OutputFormat);
+ int DoSwap = T_DOSWAP(info->OutputFormat);
+ int Reverse = T_FLAVOR(info->OutputFormat);
+ int Extra = T_EXTRA(info->OutputFormat);
+ int SwapFirst = T_SWAPFIRST(info->OutputFormat);
+ int Planar = T_PLANAR(info->OutputFormat);
+ int ExtraFirst = DoSwap ^ SwapFirst;
+ cmsFloat32Number maximum = IsInkSpace(info->OutputFormat) ? 655.35F : 65535.0F;
+ cmsFloat32Number v = 0;
+ cmsUInt16Number* swap1 = (cmsUInt16Number*)output;
+ int i, start = 0;
- if (ExtraFirst)
- start = Extra;
+ if (ExtraFirst)
+ start = Extra;
- for (i=0; i < nChan; i++) {
+ for (i = 0; i < nChan; i++) {
- int index = DoSwap ? (nChan - i - 1) : i;
+ int index = DoSwap ? (nChan - i - 1) : i;
- v = (cmsFloat32Number) wOut[index] / maximum;
+ v = (cmsFloat32Number)wOut[index] / maximum;
- if (Reverse)
- v = maximum - v;
+ if (Reverse)
+ v = maximum - v;
- if (Planar)
- ((cmsUInt16Number*) output)[(i + start ) * Stride]= _cmsFloat2Half(v);
- else
- ((cmsUInt16Number*) output)[i + start] = _cmsFloat2Half(v);
- }
+ if (Planar)
+ ((cmsUInt16Number*)output)[(i + start) * Stride] = _cmsFloat2Half(v);
+ else
+ ((cmsUInt16Number*)output)[i + start] = _cmsFloat2Half(v);
+ }
- if (!ExtraFirst) {
- output += Extra * sizeof(cmsUInt16Number);
- }
- if (Extra == 0 && SwapFirst) {
+ if (Extra == 0 && SwapFirst) {
- memmove(swap1 + 1, swap1, (nChan-1)* sizeof(cmsUInt16Number));
- *swap1 = _cmsFloat2Half(v);
- }
+ memmove(swap1 + 1, swap1, (nChan - 1)* sizeof(cmsUInt16Number));
+ *swap1 = _cmsFloat2Half(v);
+ }
- if (T_PLANAR(info -> OutputFormat))
- return output + sizeof(cmsUInt16Number);
- else
- return output + nChan * sizeof(cmsUInt16Number);
+ if (T_PLANAR(info->OutputFormat))
+ return output + sizeof(cmsUInt16Number);
+ else
+ return output + (nChan + Extra) * sizeof(cmsUInt16Number);
}
@@ -2874,50 +2859,47 @@ cmsUInt8Number* PackHalfFromFloat(_cmsTRANSFORM* info,
cmsUInt8Number* output,
cmsUInt32Number Stride)
{
- int nChan = T_CHANNELS(info -> OutputFormat);
- int DoSwap = T_DOSWAP(info ->OutputFormat);
- int Reverse = T_FLAVOR(info ->OutputFormat);
- int Extra = T_EXTRA(info -> OutputFormat);
- int SwapFirst = T_SWAPFIRST(info -> OutputFormat);
- int Planar = T_PLANAR(info -> OutputFormat);
- int ExtraFirst = DoSwap ^ SwapFirst;
- cmsFloat32Number maximum = IsInkSpace(info ->OutputFormat) ? 100.0F : 1.0F;
- cmsUInt16Number* swap1 = (cmsUInt16Number*) output;
- cmsFloat32Number v = 0;
- int i, start = 0;
+ int nChan = T_CHANNELS(info->OutputFormat);
+ int DoSwap = T_DOSWAP(info->OutputFormat);
+ int Reverse = T_FLAVOR(info->OutputFormat);
+ int Extra = T_EXTRA(info->OutputFormat);
+ int SwapFirst = T_SWAPFIRST(info->OutputFormat);
+ int Planar = T_PLANAR(info->OutputFormat);
+ int ExtraFirst = DoSwap ^ SwapFirst;
+ cmsFloat32Number maximum = IsInkSpace(info->OutputFormat) ? 100.0F : 1.0F;
+ cmsUInt16Number* swap1 = (cmsUInt16Number*)output;
+ cmsFloat32Number v = 0;
+ int i, start = 0;
- if (ExtraFirst)
- start = Extra;
+ if (ExtraFirst)
+ start = Extra;
- for (i=0; i < nChan; i++) {
+ for (i = 0; i < nChan; i++) {
- int index = DoSwap ? (nChan - i - 1) : i;
+ int index = DoSwap ? (nChan - i - 1) : i;
- v = wOut[index] * maximum;
+ v = wOut[index] * maximum;
- if (Reverse)
- v = maximum - v;
+ if (Reverse)
+ v = maximum - v;
- if (Planar)
- ((cmsUInt16Number*) output)[(i + start)* Stride]= _cmsFloat2Half( v );
- else
- ((cmsUInt16Number*) output)[i + start] = _cmsFloat2Half( v );
- }
+ if (Planar)
+ ((cmsUInt16Number*)output)[(i + start)* Stride] = _cmsFloat2Half(v);
+ else
+ ((cmsUInt16Number*)output)[i + start] = _cmsFloat2Half(v);
+ }
- if (!ExtraFirst) {
- output += Extra * sizeof(cmsUInt16Number);
- }
- if (Extra == 0 && SwapFirst) {
+ if (Extra == 0 && SwapFirst) {
- memmove(swap1 + 1, swap1, (nChan-1)* sizeof(cmsUInt16Number));
- *swap1 = (cmsUInt16Number) _cmsFloat2Half( v );
- }
+ memmove(swap1 + 1, swap1, (nChan - 1)* sizeof(cmsUInt16Number));
+ *swap1 = (cmsUInt16Number)_cmsFloat2Half(v);
+ }
- if (T_PLANAR(info -> OutputFormat))
- return output + sizeof(cmsUInt16Number);
- else
- return output + nChan * sizeof(cmsUInt16Number);
+ if (T_PLANAR(info->OutputFormat))
+ return output + sizeof(cmsUInt16Number);
+ else
+ return output + (nChan + Extra)* sizeof(cmsUInt16Number);
}
#endif
@@ -3177,6 +3159,8 @@ cmsFormatter _cmsGetStockOutputFormatter(cmsUInt32Number dwInput, cmsUInt32Numbe
cmsUInt32Number i;
cmsFormatter fr;
+ // Optimization is only a hint
+ dwInput &= ~OPTIMIZED_SH(1);
switch (dwFlags)
{
@@ -3367,3 +3351,4 @@ cmsUInt32Number CMSEXPORT cmsFormatterForPCSOfProfile(cmsHPROFILE hProfile, cmsU
// Create a fake formatter for result
return FLOAT_SH(Float) | COLORSPACE_SH(ColorSpaceBits) | BYTES_SH(nBytes) | CHANNELS_SH(nOutputChans);
}
+