< prev index next >

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

Print this page




  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  */
  24 
  25 // This file is available under and governed by the GNU General Public
  26 // License version 2 only, as published by the Free Software Foundation.
  27 // However, the following notice accompanied the original version of this
  28 // file:
  29 //
  30 //---------------------------------------------------------------------------------
  31 //
  32 //  Little Color Management System
  33 //  Copyright (c) 1998-2012 Marti Maria Saguer
  34 //
  35 // Permission is hereby granted, free of charge, to any person obtaining
  36 // a copy of this software and associated documentation files (the "Software"),
  37 // to deal in the Software without restriction, including without limitation
  38 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
  39 // and/or sell copies of the Software, and to permit persons to whom the Software
  40 // is furnished to do so, subject to the following conditions:
  41 //
  42 // The above copyright notice and this permission notice shall be included in
  43 // all copies or substantial portions of the Software.
  44 //
  45 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  46 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  47 // THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  48 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  49 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  50 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  51 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  52 //
  53 //---------------------------------------------------------------------------------


 517 void* CLUTElemDup(cmsStage* mpe)
 518 {
 519     _cmsStageCLutData* Data = (_cmsStageCLutData*) mpe ->Data;
 520     _cmsStageCLutData* NewElem;
 521 
 522 
 523     NewElem = (_cmsStageCLutData*) _cmsMallocZero(mpe ->ContextID, sizeof(_cmsStageCLutData));
 524     if (NewElem == NULL) return NULL;
 525 
 526     NewElem ->nEntries       = Data ->nEntries;
 527     NewElem ->HasFloatValues = Data ->HasFloatValues;
 528 
 529     if (Data ->Tab.T) {
 530 
 531         if (Data ->HasFloatValues) {
 532             NewElem ->Tab.TFloat = (cmsFloat32Number*) _cmsDupMem(mpe ->ContextID, Data ->Tab.TFloat, Data ->nEntries * sizeof (cmsFloat32Number));
 533             if (NewElem ->Tab.TFloat == NULL)
 534                 goto Error;
 535         } else {
 536             NewElem ->Tab.T = (cmsUInt16Number*) _cmsDupMem(mpe ->ContextID, Data ->Tab.T, Data ->nEntries * sizeof (cmsUInt16Number));
 537             if (NewElem ->Tab.TFloat == NULL)
 538                 goto Error;
 539         }
 540     }
 541 
 542     NewElem ->Params   = _cmsComputeInterpParamsEx(mpe ->ContextID,
 543                                                    Data ->Params ->nSamples,
 544                                                    Data ->Params ->nInputs,
 545                                                    Data ->Params ->nOutputs,
 546                                                    NewElem ->Tab.T,
 547                                                    Data ->Params ->dwFlags);
 548     if (NewElem->Params != NULL)
 549         return (void*) NewElem;
 550  Error:
 551     if (NewElem->Tab.T)
 552         // This works for both types
 553         _cmsFree(mpe ->ContextID, NewElem -> Tab.T);
 554     _cmsFree(mpe ->ContextID, NewElem);
 555     return NULL;
 556 }
 557 


1465 
1466     NewLUT = cmsPipelineAlloc(lut ->ContextID, lut ->InputChannels, lut ->OutputChannels);
1467     if (NewLUT == NULL) return NULL;
1468 
1469     for (mpe = lut ->Elements;
1470          mpe != NULL;
1471          mpe = mpe ->Next) {
1472 
1473              NewMPE = cmsStageDup(mpe);
1474 
1475              if (NewMPE == NULL) {
1476                  cmsPipelineFree(NewLUT);
1477                  return NULL;
1478              }
1479 
1480              if (First) {
1481                  NewLUT ->Elements = NewMPE;
1482                  First = FALSE;
1483              }
1484              else {

1485                 Anterior ->Next = NewMPE;
1486              }
1487 
1488             Anterior = NewMPE;
1489     }
1490 
1491     NewLUT ->Eval16Fn    = lut ->Eval16Fn;
1492     NewLUT ->EvalFloatFn = lut ->EvalFloatFn;
1493     NewLUT ->DupDataFn   = lut ->DupDataFn;
1494     NewLUT ->FreeDataFn  = lut ->FreeDataFn;
1495 
1496     if (NewLUT ->DupDataFn != NULL)
1497         NewLUT ->Data = NewLUT ->DupDataFn(lut ->ContextID, lut->Data);
1498 
1499 
1500     NewLUT ->SaveAs8Bits    = lut ->SaveAs8Bits;
1501 
1502     BlessLUT(NewLUT);
1503     return NewLUT;
1504 }


1819         tmp2.n[2] = fx[2] - Target[2];
1820 
1821         if (!_cmsMAT3solve(&tmp, &Jacobian, &tmp2))
1822             return FALSE;
1823 
1824         // Move our guess
1825         x[0] -= (cmsFloat32Number) tmp.n[0];
1826         x[1] -= (cmsFloat32Number) tmp.n[1];
1827         x[2] -= (cmsFloat32Number) tmp.n[2];
1828 
1829         // Some clipping....
1830         for (j=0; j < 3; j++) {
1831             if (x[j] < 0) x[j] = 0;
1832             else
1833                 if (x[j] > 1.0) x[j] = 1.0;
1834         }
1835     }
1836 
1837     return TRUE;
1838 }




  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  */
  24 
  25 // This file is available under and governed by the GNU General Public
  26 // License version 2 only, as published by the Free Software Foundation.
  27 // However, the following notice accompanied the original version of this
  28 // file:
  29 //
  30 //---------------------------------------------------------------------------------
  31 //
  32 //  Little Color Management System
  33 //  Copyright (c) 1998-2016 Marti Maria Saguer
  34 //
  35 // Permission is hereby granted, free of charge, to any person obtaining
  36 // a copy of this software and associated documentation files (the "Software"),
  37 // to deal in the Software without restriction, including without limitation
  38 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
  39 // and/or sell copies of the Software, and to permit persons to whom the Software
  40 // is furnished to do so, subject to the following conditions:
  41 //
  42 // The above copyright notice and this permission notice shall be included in
  43 // all copies or substantial portions of the Software.
  44 //
  45 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  46 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  47 // THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  48 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  49 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  50 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  51 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  52 //
  53 //---------------------------------------------------------------------------------


 517 void* CLUTElemDup(cmsStage* mpe)
 518 {
 519     _cmsStageCLutData* Data = (_cmsStageCLutData*) mpe ->Data;
 520     _cmsStageCLutData* NewElem;
 521 
 522 
 523     NewElem = (_cmsStageCLutData*) _cmsMallocZero(mpe ->ContextID, sizeof(_cmsStageCLutData));
 524     if (NewElem == NULL) return NULL;
 525 
 526     NewElem ->nEntries       = Data ->nEntries;
 527     NewElem ->HasFloatValues = Data ->HasFloatValues;
 528 
 529     if (Data ->Tab.T) {
 530 
 531         if (Data ->HasFloatValues) {
 532             NewElem ->Tab.TFloat = (cmsFloat32Number*) _cmsDupMem(mpe ->ContextID, Data ->Tab.TFloat, Data ->nEntries * sizeof (cmsFloat32Number));
 533             if (NewElem ->Tab.TFloat == NULL)
 534                 goto Error;
 535         } else {
 536             NewElem ->Tab.T = (cmsUInt16Number*) _cmsDupMem(mpe ->ContextID, Data ->Tab.T, Data ->nEntries * sizeof (cmsUInt16Number));
 537             if (NewElem ->Tab.T == NULL)
 538                 goto Error;
 539         }
 540     }
 541 
 542     NewElem ->Params   = _cmsComputeInterpParamsEx(mpe ->ContextID,
 543                                                    Data ->Params ->nSamples,
 544                                                    Data ->Params ->nInputs,
 545                                                    Data ->Params ->nOutputs,
 546                                                    NewElem ->Tab.T,
 547                                                    Data ->Params ->dwFlags);
 548     if (NewElem->Params != NULL)
 549         return (void*) NewElem;
 550  Error:
 551     if (NewElem->Tab.T)
 552         // This works for both types
 553         _cmsFree(mpe ->ContextID, NewElem -> Tab.T);
 554     _cmsFree(mpe ->ContextID, NewElem);
 555     return NULL;
 556 }
 557 


1465 
1466     NewLUT = cmsPipelineAlloc(lut ->ContextID, lut ->InputChannels, lut ->OutputChannels);
1467     if (NewLUT == NULL) return NULL;
1468 
1469     for (mpe = lut ->Elements;
1470          mpe != NULL;
1471          mpe = mpe ->Next) {
1472 
1473              NewMPE = cmsStageDup(mpe);
1474 
1475              if (NewMPE == NULL) {
1476                  cmsPipelineFree(NewLUT);
1477                  return NULL;
1478              }
1479 
1480              if (First) {
1481                  NewLUT ->Elements = NewMPE;
1482                  First = FALSE;
1483              }
1484              else {
1485                 if (Anterior != NULL)
1486                     Anterior ->Next = NewMPE;
1487              }
1488 
1489             Anterior = NewMPE;
1490     }
1491 
1492     NewLUT ->Eval16Fn    = lut ->Eval16Fn;
1493     NewLUT ->EvalFloatFn = lut ->EvalFloatFn;
1494     NewLUT ->DupDataFn   = lut ->DupDataFn;
1495     NewLUT ->FreeDataFn  = lut ->FreeDataFn;
1496 
1497     if (NewLUT ->DupDataFn != NULL)
1498         NewLUT ->Data = NewLUT ->DupDataFn(lut ->ContextID, lut->Data);
1499 
1500 
1501     NewLUT ->SaveAs8Bits    = lut ->SaveAs8Bits;
1502 
1503     BlessLUT(NewLUT);
1504     return NewLUT;
1505 }


1820         tmp2.n[2] = fx[2] - Target[2];
1821 
1822         if (!_cmsMAT3solve(&tmp, &Jacobian, &tmp2))
1823             return FALSE;
1824 
1825         // Move our guess
1826         x[0] -= (cmsFloat32Number) tmp.n[0];
1827         x[1] -= (cmsFloat32Number) tmp.n[1];
1828         x[2] -= (cmsFloat32Number) tmp.n[2];
1829 
1830         // Some clipping....
1831         for (j=0; j < 3; j++) {
1832             if (x[j] < 0) x[j] = 0;
1833             else
1834                 if (x[j] > 1.0) x[j] = 1.0;
1835         }
1836     }
1837 
1838     return TRUE;
1839 }
1840 
1841 
< prev index next >