~ubuntu-branches/ubuntu/saucy/digikam/saucy

« back to all changes in this revision

Viewing changes to libs/dimg/dcolor.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2010-12-21 23:19:11 UTC
  • mfrom: (1.2.33 upstream) (3.1.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20101221231911-z9jip7s5aht1jqn9
Tags: 2:1.7.0-1ubuntu1
* Merge from Debian Experimental. Remaining Ubuntu changes:
  - Export .pot name and copy to plugins in debian/rules
  - Version build-depends on kipi-plugins-dev to ensure build is against the
    same version on all archs
* Drop debian/patches/kubuntu_01_linker.diff, incoporated upstream
* Remove patches directory and unused patches

Show diffs side-by-side

added added

removed removed

Lines of Context:
62
62
        m_green = 0;
63
63
        m_blue  = 0;
64
64
    }
 
65
 
65
66
    m_alpha      = 255;
66
67
    m_sixteenBit = false;
67
68
 
68
69
    // convert to sixteen bit if requested
69
70
    if (sixteenBit)
 
71
    {
70
72
        convertToSixteenBit();
 
73
    }
71
74
}
72
75
 
73
76
/*
97
100
void DColor::convertToSixteenBit()
98
101
{
99
102
    if (m_sixteenBit)
 
103
    {
100
104
        return;
 
105
    }
101
106
 
102
107
    m_red        = (m_red + 1) * 256 - 1;
103
108
    m_green      = (m_green + 1) * 256 - 1;
109
114
void DColor::convertToEightBit()
110
115
{
111
116
    if (!m_sixteenBit)
 
117
    {
112
118
        return;
 
119
    }
113
120
 
114
121
    m_red        = (m_red + 1) / 256 - 1;
115
122
    m_green      = (m_green + 1) / 256 - 1;
139
146
    if (red > green)
140
147
    {
141
148
        if (red > blue)
 
149
        {
142
150
            max = red;
 
151
        }
143
152
        else
 
153
        {
144
154
            max = blue;
 
155
        }
145
156
 
146
157
        if (green < blue)
 
158
        {
147
159
            min = green;
 
160
        }
148
161
        else
 
162
        {
149
163
            min = blue;
 
164
        }
150
165
    }
151
166
    else
152
167
    {
153
168
        if (green > blue)
 
169
        {
154
170
            max = green;
 
171
        }
155
172
        else
 
173
        {
156
174
            max = blue;
 
175
        }
157
176
 
158
177
        if (red < blue)
 
178
        {
159
179
            min = red;
 
180
        }
160
181
        else
 
182
        {
161
183
            min = blue;
 
184
        }
162
185
    }
163
186
 
164
187
    sum = max + min;
172
195
        delta = max - min;
173
196
 
174
197
        if (lig <= 0.5)
 
198
        {
175
199
            sat = delta / sum;
 
200
        }
176
201
        else
 
202
        {
177
203
            sat = delta / (2 - sum);
 
204
        }
178
205
 
179
206
        if (red == max)
 
207
        {
180
208
            hue = (green - blue) / delta;
 
209
        }
181
210
        else if (green == max)
 
211
        {
182
212
            hue = 2 + (blue - red) / delta;
 
213
        }
183
214
        else if (blue == max)
 
215
        {
184
216
            hue = 4 + (red - green) / delta;
 
217
        }
185
218
 
186
219
        if (hue < 0)
 
220
        {
187
221
            hue += 6;
 
222
        }
 
223
 
188
224
        if (hue > 6)
 
225
        {
189
226
            hue -= 6;
 
227
        }
190
228
 
191
229
        hue *= 60;
192
230
    }
219
257
        saturation = (double)(s / range);
220
258
 
221
259
        if (lightness <= 0.5)
 
260
        {
222
261
            m2 = lightness * (1 + saturation);
 
262
        }
223
263
        else
 
264
        {
224
265
            m2 = lightness + saturation - lightness * saturation;
 
266
        }
225
267
 
226
268
        m1 = 2 * lightness - m2;
227
269
 
228
270
        double mh;
229
271
 
230
272
        mh = hue + 120;
 
273
 
231
274
        while (mh > 360)
 
275
        {
232
276
            mh -= 360;
 
277
        }
 
278
 
233
279
        while (mh < 0)
 
280
        {
234
281
            mh += 360;
 
282
        }
235
283
 
236
284
        if (mh < 60)
 
285
        {
237
286
            r = m1 + (m2 - m1) * mh / 60;
 
287
        }
238
288
        else if (mh < 180)
 
289
        {
239
290
            r = m2;
 
291
        }
240
292
        else if (mh < 240)
 
293
        {
241
294
            r = m1 + (m2 - m1) * (240 - mh) / 60;
 
295
        }
242
296
        else
 
297
        {
243
298
            r = m1;
 
299
        }
244
300
 
245
301
        mh = hue;
 
302
 
246
303
        while (mh > 360)
 
304
        {
247
305
            mh -= 360;
 
306
        }
 
307
 
248
308
        while (mh < 0)
 
309
        {
249
310
            mh += 360;
 
311
        }
250
312
 
251
313
        if (mh < 60)
 
314
        {
252
315
            g = m1 + (m2 - m1) * mh / 60;
 
316
        }
253
317
        else if (mh < 180)
 
318
        {
254
319
            g = m2;
 
320
        }
255
321
        else if (mh < 240)
 
322
        {
256
323
            g = m1 + (m2 - m1) * (240 - mh) / 60;
 
324
        }
257
325
        else
 
326
        {
258
327
            g = m1;
 
328
        }
259
329
 
260
330
        mh = hue - 120;
 
331
 
261
332
        while (mh > 360)
 
333
        {
262
334
            mh -= 360;
 
335
        }
 
336
 
263
337
        while (mh < 0)
 
338
        {
264
339
            mh += 360;
 
340
        }
265
341
 
266
342
        if (mh < 60)
 
343
        {
267
344
            b = m1 + (m2 - m1) * mh / 60;
 
345
        }
268
346
        else if (mh < 180)
 
347
        {
269
348
            b = m2;
 
349
        }
270
350
        else if (mh < 240)
 
351
        {
271
352
            b = m1 + (m2 - m1) * (240 - mh) / 60;
 
353
        }
272
354
        else
 
355
        {
273
356
            b = m1;
 
357
        }
274
358
 
275
359
        m_red   = lround(r * range);
276
360
        m_green = lround(g * range);
281
365
 
282
366
    // Fully opaque color.
283
367
    if (m_sixteenBit)
 
368
    {
284
369
        m_alpha = 65535;
 
370
    }
285
371
    else
 
372
    {
286
373
        m_alpha = 255;
 
374
    }
287
375
}
288
376
 
289
377
void DColor::getYCbCr(double* y, double* cb, double* cr) const
302
390
    double g = y - 0.34414 * (cb - 0.5) - 0.71414 * (cr - 0.5);
303
391
    double b = y + 1.77200 * (cb - 0.5);
304
392
    double q = (sixteenBit ? 65535.0 : 255.0);
305
 
    
 
393
 
306
394
    m_red    = CLAMP((int)lround(r * q), 0, (int)q);
307
395
    m_green  = CLAMP((int)lround(g * q), 0, (int)q);
308
396
    m_blue   = CLAMP((int)lround(b * q), 0, (int)q);
309
397
 
310
398
    m_sixteenBit = sixteenBit;
311
 
    
 
399
 
312
400
    // Fully opaque color.
313
401
    if (m_sixteenBit)
 
402
    {
314
403
        m_alpha = 65535;
 
404
    }
315
405
    else
 
406
    {
316
407
        m_alpha = 255;
 
408
    }
317
409
}
318
410
 
319
411
}  // namespace Digikam