OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. | 2 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. |
3 * | 3 * |
4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
8 * | 8 * |
9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 ASSERT((i >= 0) && i < 3); | 287 ASSERT((i >= 0) && i < 3); |
288 return m_planes[i]; | 288 return m_planes[i]; |
289 } | 289 } |
290 | 290 |
291 size_t ImagePlanes::rowBytes(int i) const | 291 size_t ImagePlanes::rowBytes(int i) const |
292 { | 292 { |
293 ASSERT((i >= 0) && i < 3); | 293 ASSERT((i >= 0) && i < 3); |
294 return m_rowBytes[i]; | 294 return m_rowBytes[i]; |
295 } | 295 } |
296 | 296 |
| 297 namespace { |
| 298 |
297 #if USE(QCMSLIB) | 299 #if USE(QCMSLIB) |
298 namespace { | |
299 | 300 |
300 const unsigned kIccColorProfileHeaderLength = 128; | 301 const unsigned kIccColorProfileHeaderLength = 128; |
301 | 302 |
302 bool rgbColorProfile(const char* profileData, unsigned profileLength) | 303 bool rgbColorProfile(const char* profileData, unsigned profileLength) |
303 { | 304 { |
304 ASSERT_UNUSED(profileLength, profileLength >= kIccColorProfileHeaderLength); | 305 ASSERT_UNUSED(profileLength, profileLength >= kIccColorProfileHeaderLength); |
305 | 306 |
306 return !memcmp(&profileData[16], "RGB ", 4); | 307 return !memcmp(&profileData[16], "RGB ", 4); |
307 } | 308 } |
308 | 309 |
309 bool inputDeviceColorProfile(const char* profileData, unsigned profileLength) | 310 bool inputDeviceColorProfile(const char* profileData, unsigned profileLength) |
310 { | 311 { |
311 ASSERT_UNUSED(profileLength, profileLength >= kIccColorProfileHeaderLength); | 312 ASSERT_UNUSED(profileLength, profileLength >= kIccColorProfileHeaderLength); |
312 | 313 |
313 return !memcmp(&profileData[12], "mntr", 4) || !memcmp(&profileData[12], "sc
nr", 4); | 314 return !memcmp(&profileData[12], "mntr", 4) || !memcmp(&profileData[12], "sc
nr", 4); |
314 } | 315 } |
315 | 316 |
316 // The output device color profile is global and shared across multiple threads. | 317 // The output device color profile is global and shared across multiple threads. |
317 SpinLock gTargetColorProfileLock; | 318 SpinLock gTargetColorProfileLock; |
318 qcms_profile* gTargetColorProfile = nullptr; | 319 qcms_profile* gTargetColorProfile = nullptr; |
319 | 320 |
| 321 #endif // USE(QCMSLIB) |
| 322 |
320 } // namespace | 323 } // namespace |
321 | 324 |
322 // static | 325 // static |
323 void ImageDecoder::setTargetColorProfile(const WebVector<char>& profile) | 326 void ImageDecoder::setTargetColorProfile(const WebVector<char>& profile) |
324 { | 327 { |
| 328 #if USE(QCMSLIB) |
325 if (profile.isEmpty()) | 329 if (profile.isEmpty()) |
326 return; | 330 return; |
327 | 331 |
328 // Take a lock around initializing and accessing the global device color pro
file. | 332 // Take a lock around initializing and accessing the global device color pro
file. |
329 SpinLock::Guard guard(gTargetColorProfileLock); | 333 SpinLock::Guard guard(gTargetColorProfileLock); |
330 | 334 |
331 // Layout tests expect that only the first call will take effect. | 335 // Layout tests expect that only the first call will take effect. |
332 if (gTargetColorProfile) | 336 if (gTargetColorProfile) |
333 return; | 337 return; |
334 | 338 |
335 { | 339 { |
336 sk_sp<SkColorSpace> colorSpace = SkColorSpace::NewICC(profile.data(), pr
ofile.size()); | 340 sk_sp<SkColorSpace> colorSpace = SkColorSpace::NewICC(profile.data(), pr
ofile.size()); |
337 BitmapImageMetrics::countGamma(colorSpace.get()); | 341 BitmapImageMetrics::countGamma(colorSpace.get()); |
338 } | 342 } |
339 | 343 |
340 // FIXME: Add optional ICCv4 support and support for multiple monitors. | 344 // FIXME: Add optional ICCv4 support and support for multiple monitors. |
341 gTargetColorProfile = qcms_profile_from_memory(profile.data(), profile.size(
)); | 345 gTargetColorProfile = qcms_profile_from_memory(profile.data(), profile.size(
)); |
342 if (!gTargetColorProfile) | 346 if (!gTargetColorProfile) |
343 return; | 347 return; |
344 | 348 |
345 if (qcms_profile_is_bogus(gTargetColorProfile)) { | 349 if (qcms_profile_is_bogus(gTargetColorProfile)) { |
346 qcms_profile_release(gTargetColorProfile); | 350 qcms_profile_release(gTargetColorProfile); |
347 gTargetColorProfile = nullptr; | 351 gTargetColorProfile = nullptr; |
348 return; | 352 return; |
349 } | 353 } |
350 | 354 |
351 qcms_profile_precache_output_transform(gTargetColorProfile); | 355 qcms_profile_precache_output_transform(gTargetColorProfile); |
| 356 #endif // USE(QCMSLIB) |
352 } | 357 } |
353 | 358 |
354 bool ImageDecoder::hasColorProfile() const | 359 void ImageDecoder::setColorProfileAndComputeTransform(const char* iccData, unsig
ned iccLength, bool hasAlpha, bool useSRGB) |
355 { | 360 { |
356 return m_sourceToOutputDeviceColorTransform.get(); | 361 // Sub-classes should not call this if they were instructed to ignore embedd
ed color profiles. |
357 } | 362 DCHECK(!m_ignoreGammaAndColorProfile); |
358 | 363 |
359 void ImageDecoder::setColorProfileAndTransform(const char* iccData, unsigned icc
Length, bool hasAlpha, bool useSRGB) | 364 m_colorProfile.assign(iccData, iccLength); |
360 { | 365 m_hasColorProfile = true; |
| 366 |
| 367 #if USE(QCMSLIB) |
361 m_sourceToOutputDeviceColorTransform.reset(); | 368 m_sourceToOutputDeviceColorTransform.reset(); |
362 | 369 |
363 // Create the input profile | 370 // Create the input profile |
364 QCMSProfileUniquePtr inputProfile; | 371 QCMSProfileUniquePtr inputProfile; |
365 if (useSRGB) { | 372 if (useSRGB) { |
366 inputProfile.reset(qcms_profile_sRGB()); | 373 inputProfile.reset(qcms_profile_sRGB()); |
367 } else { | 374 } else { |
368 // Only accept RGB color profiles from input class devices. | 375 // Only accept RGB color profiles from input class devices. |
369 if (iccLength < kIccColorProfileHeaderLength) | 376 if (iccLength < kIccColorProfileHeaderLength) |
370 return; | 377 return; |
(...skipping 18 matching lines...) Expand all Loading... |
389 qcms_profile_precache_output_transform(gTargetColorProfile); | 396 qcms_profile_precache_output_transform(gTargetColorProfile); |
390 } | 397 } |
391 | 398 |
392 if (qcms_profile_match(inputProfile.get(), gTargetColorProfile)) | 399 if (qcms_profile_match(inputProfile.get(), gTargetColorProfile)) |
393 return; | 400 return; |
394 | 401 |
395 qcms_data_type dataFormat = hasAlpha ? QCMS_DATA_RGBA_8 : QCMS_DATA_RGB_8; | 402 qcms_data_type dataFormat = hasAlpha ? QCMS_DATA_RGBA_8 : QCMS_DATA_RGB_8; |
396 | 403 |
397 // FIXME: Don't force perceptual intent if the image profile contains an int
ent. | 404 // FIXME: Don't force perceptual intent if the image profile contains an int
ent. |
398 m_sourceToOutputDeviceColorTransform.reset(qcms_transform_create(inputProfil
e.get(), dataFormat, gTargetColorProfile, QCMS_DATA_RGBA_8, QCMS_INTENT_PERCEPTU
AL)); | 405 m_sourceToOutputDeviceColorTransform.reset(qcms_transform_create(inputProfil
e.get(), dataFormat, gTargetColorProfile, QCMS_DATA_RGBA_8, QCMS_INTENT_PERCEPTU
AL)); |
| 406 #endif // USE(QCMSLIB) |
399 } | 407 } |
400 | 408 |
401 #else // USE(QCMSLIB) | |
402 | |
403 void ImageDecoder::setTargetColorProfile(const WebVector<char>&) | |
404 { | |
405 } | |
406 | |
407 bool ImageDecoder::hasColorProfile() const | |
408 { | |
409 return false; | |
410 } | |
411 | |
412 #endif // USE(QCMSLIB) | |
413 | |
414 } // namespace blink | 409 } // namespace blink |
OLD | NEW |