1 // ------------------------------------------------------------------------------------------------
2 // MODULE : CorrectLut
3 // LANGAGE : C++
4 // CREATEUR : Laurent Saboret
5 // DATE : Lundi 21 F�vrier 1994
6 // DESCRIPTION : Lookup table for a RGB pixel
7 // COMMENTAIRE :
8 // SCCSID : @(#)corr_lut.cpp 1.1 11:46:37 18 Dec 1996
9 // ----------------------------------------------------------------------------
10 // Copyright (c) 1999 Digital Imaging Group, Inc.
11 // For conditions of distribution and use, see copyright notice
12 // in Flashpix.h
13 // ----------------------------------------------------------------------------
14 // ------------------------------------------------------------------------------------------------
15 #include "corr_lut.h"
16 // ------------------------------------------------------------------------------------------------
17
18 // Includes
19 // --------
20
21 #ifndef Fichier_h
22 #include "a_file.h"
23 #endif
24
25 // Constantes
26 // ----------
27
28 const short lut_NbContraintes = 3; // For backward compatibility with LP 1.5�1
29
30 // Variables
31 // ---------
32
33 // ------------------------------------------------------------------------------------------------
34 #ifdef macintosh
35 #pragma segment CorrectLut
36 #endif
37 // ------------------------------------------------------------------------------------------------
38
39 // ------------------------------------------------------------------------------------------------
40 // Fonctions internes
41 // ------------------------------------------------------------------------------------------------
42
43 // ------------------------------------------------------------------------------------------------
44 // Methodes
45 // ------------------------------------------------------------------------------------------------
46
47 // Creates Identity LUT
CorrectLut()48 CorrectLut::CorrectLut()
49 {
50 active = FALSE;
51 }
52
53 // Creates a classic LUT
CorrectLut(const Lut r,const Lut g,const Lut b)54 CorrectLut::CorrectLut(const Lut r, const Lut g, const Lut b)
55
56 {
57 active = TRUE;
58
59 // Copy LUTs
60 BlockMove(r, red, 256);
61 BlockMove(g, green, 256);
62 BlockMove(b, blue, 256);
63 }
64
65 // The 'rgb' LUT is applied on each channel, after the 3 other luts.
CorrectLut(const Lut rgb,const Lut r,const Lut g,const Lut b)66 CorrectLut::CorrectLut(const Lut rgb, const Lut r, const Lut g, const Lut b)
67
68 {
69 int i;
70
71 active = TRUE;
72
73 // Convert 4 LUTs into 3 LUTs
74 for ( i=0 ; i < 256 ; i++ )
75 {
76 red[i] = rgb[ r[i] ];
77 green[i] = rgb[ g[i] ];
78 blue[i] = rgb[ b[i] ];
79 }
80 }
81
CorrectLut(const CorrectLut & toCopy)82 CorrectLut::CorrectLut(const CorrectLut& toCopy)
83
84 {
85 active = toCopy.active;
86
87 BlockMove(toCopy.red, red, 256);
88 BlockMove(toCopy.green, green, 256);
89 BlockMove(toCopy.blue, blue, 256);
90 }
91
operator =(const CorrectLut & toCopy)92 CorrectLut& CorrectLut::operator=(const CorrectLut& toCopy)
93
94 {
95 active = toCopy.active;
96
97 BlockMove(toCopy.red, red, 256);
98 BlockMove(toCopy.green, green, 256);
99 BlockMove(toCopy.blue, blue, 256);
100
101 return *this;
102 }
103
104
105 // Get the lookup table's description
GetLuts(Lut r,Lut g,Lut b) const106 void CorrectLut::GetLuts(Lut r, Lut g, Lut b) const
107
108 {
109 int i;
110
111 if (r != NULL)
112 {
113 if (active) {
114 BlockMove(red, r, 256);
115 } else {
116 for ( i=0 ; i<256 ; i++ )
117 r[i] = i;
118 }
119 }
120
121 if (g != NULL)
122 {
123 if (active) {
124 BlockMove(green, g, 256);
125 } else {
126 for ( i=0 ; i<256 ; i++ )
127 g[i] = i;
128 }
129 }
130
131 if (b != NULL)
132 {
133 if (active) {
134 BlockMove(blue, b, 256);
135 } else {
136 for ( i=0 ; i<256 ; i++ )
137 b[i] = i;
138 }
139 }
140 }
141
142
143 // Compute a*b
operator *(const CorrectLut & a,const CorrectLut & b)144 CorrectLut operator*(const CorrectLut& a, const CorrectLut& b)
145
146 {
147 if (!a.active)
148 {
149 return b;
150 }
151 else if (!b.active)
152 {
153 return a;
154 }
155 else
156 {
157 CorrectLut ab; // == a * b
158 int i;
159
160 ab.active = TRUE;
161 for ( i=0 ; i < 256 ; i++ )
162 {
163 ab.red[i] = a.red[b.red[i]];
164 ab.green[i] = a.green[b.green[i]];
165 ab.blue[i] = a.blue[b.blue[i]];
166 }
167 return ab;
168 }
169 }
170
171
Save(ref_Fichier file)172 void CorrectLut::Save(ref_Fichier file)
173
174 {
175 RGBColor colorTarget={0,0,0};
176 Boolean valide=FALSE;
177 int i;
178
179 file.Ecriture(active);
180 if (active)
181 {
182 file.EcritureTableau((unsigned char*)red, 256);
183 file.EcritureTableau((unsigned char*)green, 256);
184 file.EcritureTableau((unsigned char*)blue, 256);
185
186 // For backward compatibility with LP 1.5�1
187 for (i=0; i<2*lut_NbContraintes; i++)
188 file.Ecriture(colorTarget);
189 for (i=0; i<lut_NbContraintes; i++)
190 file.Ecriture(valide);
191 file.Ecriture((short)0);
192 }
193 }
194
Load(ref_Fichier file,long)195 void CorrectLut::Load(ref_Fichier file, long)
196
197 {
198 RGBColor colorTarget={0,0,0};
199 Boolean valide=FALSE;
200 short int influence=0;
201 int i;
202
203 file.Lecture(&active);
204 if (active)
205 {
206 file.LectureTableau((unsigned char*)red, 256);
207 file.LectureTableau((unsigned char*)green, 256);
208 file.LectureTableau((unsigned char*)blue, 256);
209
210 for (i=0; i<2*lut_NbContraintes; i++) // Items unused after LP 1.5�1
211 file.Lecture(&colorTarget); // For backward compatibility
212 for (i=0; i<lut_NbContraintes; i++)
213 file.Lecture(&valide);
214 file.Lecture(&influence);
215 }
216 }
217
218
219 // ------------------------------------------------------------------------------------------------
220 // Fonctions externes
221 // ------------------------------------------------------------------------------------------------
222
223