~ubuntu-branches/ubuntu/natty/lcms/natty

« back to all changes in this revision

Viewing changes to src/cmslut.c

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2009-04-03 13:55:00 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20090403135500-psa3ox0my6u6a5cp
Tags: 1.18.dfsg-0ubuntu1
* New upstream release
* Remove 11_security_CVE-2009-0581_0723_0733.dpatch, security 
  issues fixed upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
183
183
}
184
184
 
185
185
 
 
186
LCMSBOOL _cmsValidateLUT(LPLUT NewLUT)
 
187
{
 
188
    unsigned int calc = 1;
 
189
    unsigned int oldCalc;
 
190
    unsigned int power = NewLUT -> InputChan;
 
191
 
 
192
    if (NewLUT -> cLutPoints > 100) return FALSE;
 
193
    if (NewLUT -> InputChan > MAXCHANNELS)  return FALSE;
 
194
    if (NewLUT -> OutputChan > MAXCHANNELS) return FALSE;
 
195
 
 
196
    if (NewLUT -> cLutPoints == 0) return TRUE;
 
197
    
 
198
    for (; power > 0; power--) {
 
199
 
 
200
      oldCalc = calc;
 
201
      calc *= NewLUT -> cLutPoints;
 
202
 
 
203
      if (calc / NewLUT -> cLutPoints != oldCalc) {
 
204
        return FALSE;
 
205
      }
 
206
    }
 
207
 
 
208
    oldCalc = calc;
 
209
    calc *= NewLUT -> OutputChan;
 
210
    if (NewLUT -> OutputChan && calc / NewLUT -> OutputChan != oldCalc) {
 
211
      return FALSE;
 
212
    }
 
213
 
 
214
    return TRUE;
 
215
}
 
216
 
186
217
LPLUT LCMSEXPORT cmsAlloc3DGrid(LPLUT NewLUT, int clutPoints, int inputChan, int outputChan)
187
218
{
188
219
    DWORD nTabSize;
192
223
       NewLUT -> InputChan     = inputChan;
193
224
       NewLUT -> OutputChan    = outputChan;
194
225
 
195
 
 
196
 
       nTabSize = (NewLUT -> OutputChan * UIpow(NewLUT->cLutPoints,
197
 
                                                NewLUT->InputChan)
198
 
                                                * sizeof(WORD));
199
 
 
200
 
       NewLUT -> T = (LPWORD) _cmsMalloc(nTabSize);
 
226
       if (!_cmsValidateLUT(NewLUT)) {
 
227
         return NULL;
 
228
       }
 
229
 
 
230
       nTabSize = NewLUT -> OutputChan * UIpow(NewLUT->cLutPoints,
 
231
                                               NewLUT->InputChan);
 
232
 
 
233
       NewLUT -> T = (LPWORD) _cmsCalloc(sizeof(WORD), nTabSize);
 
234
       nTabSize *= sizeof(WORD);
201
235
       if (NewLUT -> T == NULL) return NULL;
202
236
 
203
237
       ZeroMemory(NewLUT -> T, nTabSize);
233
267
 
234
268
                     NewLUT -> L1[i] = PtrW;
235
269
                     CopyMemory(PtrW, Tables[i]->GammaTable, sizeof(WORD) * NewLUT -> InputEntries);
236
 
                                         CopyMemory(&NewLUT -> LCurvesSeed[0][i], &Tables[i] -> Seed, sizeof(LCMSGAMMAPARAMS));
 
270
                     CopyMemory(&NewLUT -> LCurvesSeed[0][i], &Tables[i] -> Seed, sizeof(LCMSGAMMAPARAMS));
237
271
               }
238
 
                           
 
272
               
239
273
 
240
274
               break;
241
275
 
249
283
 
250
284
                     NewLUT -> L2[i] = PtrW;
251
285
                     CopyMemory(PtrW, Tables[i]->GammaTable, sizeof(WORD) * NewLUT -> OutputEntries);
252
 
                                         CopyMemory(&NewLUT -> LCurvesSeed[1][i], &Tables[i] -> Seed, sizeof(LCMSGAMMAPARAMS));
 
286
                     CopyMemory(&NewLUT -> LCurvesSeed[1][i], &Tables[i] -> Seed, sizeof(LCMSGAMMAPARAMS));
253
287
               }
254
288
               break;
255
289
 
268
302
 
269
303
                     NewLUT -> L3[i] = PtrW;
270
304
                     CopyMemory(PtrW, Tables[i]->GammaTable, sizeof(WORD) * NewLUT -> L3Entries);
271
 
                                         CopyMemory(&NewLUT -> LCurvesSeed[2][i], &Tables[i] -> Seed, sizeof(LCMSGAMMAPARAMS));
 
305
                     CopyMemory(&NewLUT -> LCurvesSeed[2][i], &Tables[i] -> Seed, sizeof(LCMSGAMMAPARAMS));
272
306
               }
273
307
               break;
274
308
 
283
317
 
284
318
                     NewLUT -> L4[i] = PtrW;
285
319
                     CopyMemory(PtrW, Tables[i]->GammaTable, sizeof(WORD) * NewLUT -> L4Entries);
286
 
                                         CopyMemory(&NewLUT -> LCurvesSeed[3][i], &Tables[i] -> Seed, sizeof(LCMSGAMMAPARAMS));
 
320
                     CopyMemory(&NewLUT -> LCurvesSeed[3][i], &Tables[i] -> Seed, sizeof(LCMSGAMMAPARAMS));
287
321
               }
288
322
               break;
289
323
               
679
713
    wIn[3] = FixedK;
680
714
 
681
715
    cmsEvalLUT(Lut, wIn, wOut);     
682
 
        cmsLabEncoded2Float(Out, wOut);
 
716
    cmsLabEncoded2Float(Out, wOut);
683
717
}
684
718
 
685
719
// Builds a Jacobian CMY->Lab
703
737
        IncDelta(&ColorantD.n[j]);
704
738
 
705
739
        EvalLUTdoubleKLab(Lut, &ColorantD, K, &LabD);
706
 
                                
707
 
                Jacobian->v[0].n[j] = ((LabD.L - Lab.L) / JACOBIAN_EPSILON);
708
 
                Jacobian->v[1].n[j] = ((LabD.a - Lab.a) / JACOBIAN_EPSILON);
709
 
                Jacobian->v[2].n[j] = ((LabD.b - Lab.b) / JACOBIAN_EPSILON);
 
740
                
 
741
        Jacobian->v[0].n[j] = ((LabD.L - Lab.L) / JACOBIAN_EPSILON);
 
742
        Jacobian->v[1].n[j] = ((LabD.a - Lab.a) / JACOBIAN_EPSILON);
 
743
        Jacobian->v[2].n[j] = ((LabD.b - Lab.b) / JACOBIAN_EPSILON);
710
744
        
711
745
    }
712
746
}
779
813
        // Obtain slope
780
814
        ComputeJacobianLab(Lut, &Jacobian, &x, FixedK);
781
815
 
782
 
                // Solve system
783
 
                tmp2.n[0] = fx.L - Goal.L;
784
 
                tmp2.n[1] = fx.a - Goal.a;
785
 
                tmp2.n[2] = fx.b - Goal.b;
 
816
        // Solve system
 
817
        tmp2.n[0] = fx.L - Goal.L;
 
818
        tmp2.n[1] = fx.a - Goal.a;
 
819
        tmp2.n[2] = fx.b - Goal.b;
786
820
 
787
 
                if (!MAT3solve(&tmp, &Jacobian, &tmp2))
788
 
                        break;
789
 
                
790
 
        // Move our guess
791
 
                x.n[0] -= tmp.n[0];
792
 
            x.n[1] -= tmp.n[1];
793
 
                x.n[2] -= tmp.n[2];
 
821
        if (!MAT3solve(&tmp, &Jacobian, &tmp2))
 
822
            break;
 
823
        
 
824
        // Move our guess
 
825
        x.n[0] -= tmp.n[0];
 
826
        x.n[1] -= tmp.n[1];
 
827
        x.n[2] -= tmp.n[2];
794
828
               
795
829
        // Some clipping....
796
830
        VEC3saturate(&x);