Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Side by Side Diff: third_party/WebKit/Source/platform/image-decoders/ImageDecoder.cpp

Issue 1796293003: Image decode color: Push color profile from browser to renderer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: leave empty check Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 ASSERT((i >= 0) && i < 3); 270 ASSERT((i >= 0) && i < 3);
271 return m_planes[i]; 271 return m_planes[i];
272 } 272 }
273 273
274 size_t ImagePlanes::rowBytes(int i) const 274 size_t ImagePlanes::rowBytes(int i) const
275 { 275 {
276 ASSERT((i >= 0) && i < 3); 276 ASSERT((i >= 0) && i < 3);
277 return m_rowBytes[i]; 277 return m_rowBytes[i];
278 } 278 }
279 279
280 bool ImageDecoder::hasColorProfile() const
281 {
282 #if USE(QCMSLIB)
283 return m_sourceToOutputDeviceColorTransform.get();
284 #else
285 return false;
286 #endif
287 }
288
289 #if USE(QCMSLIB) 280 #if USE(QCMSLIB)
290 namespace { 281 namespace {
291 282
292 const unsigned kIccColorProfileHeaderLength = 128; 283 const unsigned kIccColorProfileHeaderLength = 128;
293 284
294 bool rgbColorProfile(const char* profileData, unsigned profileLength) 285 bool rgbColorProfile(const char* profileData, unsigned profileLength)
295 { 286 {
296 ASSERT_UNUSED(profileLength, profileLength >= kIccColorProfileHeaderLength); 287 ASSERT_UNUSED(profileLength, profileLength >= kIccColorProfileHeaderLength);
297 288
298 return !memcmp(&profileData[16], "RGB ", 4); 289 return !memcmp(&profileData[16], "RGB ", 4);
299 } 290 }
300 291
301 bool inputDeviceColorProfile(const char* profileData, unsigned profileLength) 292 bool inputDeviceColorProfile(const char* profileData, unsigned profileLength)
302 { 293 {
303 ASSERT_UNUSED(profileLength, profileLength >= kIccColorProfileHeaderLength); 294 ASSERT_UNUSED(profileLength, profileLength >= kIccColorProfileHeaderLength);
304 295
305 return !memcmp(&profileData[12], "mntr", 4) || !memcmp(&profileData[12], "sc nr", 4); 296 return !memcmp(&profileData[12], "mntr", 4) || !memcmp(&profileData[12], "sc nr", 4);
306 } 297 }
307 298
308 // The output device color profile is global and shared across multiple threads. 299 // The output device color profile is global and shared across multiple threads.
309 SpinLock gOutputDeviceProfileLock; 300 SpinLock gTargetColorProfileLock;
310 qcms_profile* gOutputDeviceProfile = nullptr; 301 qcms_profile* gTargetColorProfile = nullptr;
311 302
312 } // namespace 303 } // namespace
313 304
314 // static 305 // static
306 void ImageDecoder::setTargetColorProfile(const WebVector<char>& profile)
307 {
308 if (profile.isEmpty())
309 return;
310
311 // Take a lock around initializing and accessing the global device color pro file.
312 SpinLock::Guard guard(gTargetColorProfileLock);
313
314 // Layout tests expect that only the first call will take effect.
315 if (gTargetColorProfile)
316 return;
317
318 // FIXME: Add optional ICCv4 support and support for multiple monitors.
319 gTargetColorProfile = qcms_profile_from_memory(profile.data(), profile.size( ));
320
321 if (gTargetColorProfile && qcms_profile_is_bogus(gTargetColorProfile)) {
322 qcms_profile_release(gTargetColorProfile);
323 gTargetColorProfile = nullptr;
324 return;
325 }
326
327 qcms_profile_precache_output_transform(gTargetColorProfile);
328 }
329
330 bool ImageDecoder::hasColorProfile() const
331 {
332 return m_sourceToOutputDeviceColorTransform.get();
333 }
334
315 void ImageDecoder::setColorProfileAndTransform(const char* iccData, unsigned icc Length, bool hasAlpha, bool useSRGB) 335 void ImageDecoder::setColorProfileAndTransform(const char* iccData, unsigned icc Length, bool hasAlpha, bool useSRGB)
316 { 336 {
317 m_sourceToOutputDeviceColorTransform.reset(); 337 m_sourceToOutputDeviceColorTransform.reset();
318 338
319 // Create the input profile 339 // Create the input profile
320 QCMSProfileUniquePtr inputProfile; 340 QCMSProfileUniquePtr inputProfile;
321 if (useSRGB) { 341 if (useSRGB) {
322 inputProfile.reset(qcms_profile_sRGB()); 342 inputProfile.reset(qcms_profile_sRGB());
323 } else { 343 } else {
324 // Only accept RGB color profiles from input class devices. 344 // Only accept RGB color profiles from input class devices.
325 if (iccLength < kIccColorProfileHeaderLength) 345 if (iccLength < kIccColorProfileHeaderLength)
326 return; 346 return;
327 if (!rgbColorProfile(iccData, iccLength)) 347 if (!rgbColorProfile(iccData, iccLength))
328 return; 348 return;
329 if (!inputDeviceColorProfile(iccData, iccLength)) 349 if (!inputDeviceColorProfile(iccData, iccLength))
330 return; 350 return;
331 inputProfile.reset(qcms_profile_from_memory(iccData, iccLength)); 351 inputProfile.reset(qcms_profile_from_memory(iccData, iccLength));
332 } 352 }
333 if (!inputProfile) 353 if (!inputProfile)
334 return; 354 return;
335 355
336 // We currently only support color profiles for RGB profiled images. 356 // We currently only support color profiles for RGB profiled images.
337 ASSERT(rgbData == qcms_profile_get_color_space(inputProfile.get())); 357 ASSERT(rgbData == qcms_profile_get_color_space(inputProfile.get()));
338 358
339 // Take a lock around initializing and accessing the global device color pro file. 359 // Take a lock around initializing and accessing the global device color pro file.
340 SpinLock::Guard guard(gOutputDeviceProfileLock); 360 SpinLock::Guard guard(gTargetColorProfileLock);
341 361
342 // Initialize the output device profile. 362 // Initialize the output device profile to sRGB if it has not yet been initi alized.
343 if (!gOutputDeviceProfile) { 363 if (!gTargetColorProfile) {
344 // FIXME: Add optional ICCv4 support and support for multiple monitors. 364 gTargetColorProfile = qcms_profile_sRGB();
345 WebVector<char> profile; 365 qcms_profile_precache_output_transform(gTargetColorProfile);
346 Platform::current()->screenColorProfile(&profile);
347
348 if (!profile.isEmpty())
349 gOutputDeviceProfile = qcms_profile_from_memory(profile.data(), prof ile.size());
350
351 if (gOutputDeviceProfile && qcms_profile_is_bogus(gOutputDeviceProfile)) {
352 qcms_profile_release(gOutputDeviceProfile);
353 gOutputDeviceProfile = nullptr;
354 }
355
356 if (!gOutputDeviceProfile)
357 gOutputDeviceProfile = qcms_profile_sRGB();
358
359 qcms_profile_precache_output_transform(gOutputDeviceProfile);
360 } 366 }
361 367
362 if (qcms_profile_match(inputProfile.get(), gOutputDeviceProfile)) 368 if (qcms_profile_match(inputProfile.get(), gTargetColorProfile))
363 return; 369 return;
364 370
365 qcms_data_type dataFormat = hasAlpha ? QCMS_DATA_RGBA_8 : QCMS_DATA_RGB_8; 371 qcms_data_type dataFormat = hasAlpha ? QCMS_DATA_RGBA_8 : QCMS_DATA_RGB_8;
366 372
367 // FIXME: Don't force perceptual intent if the image profile contains an int ent. 373 // FIXME: Don't force perceptual intent if the image profile contains an int ent.
368 m_sourceToOutputDeviceColorTransform.reset(qcms_transform_create(inputProfil e.get(), dataFormat, gOutputDeviceProfile, QCMS_DATA_RGBA_8, QCMS_INTENT_PERCEPT UAL)); 374 m_sourceToOutputDeviceColorTransform.reset(qcms_transform_create(inputProfil e.get(), dataFormat, gTargetColorProfile, QCMS_DATA_RGBA_8, QCMS_INTENT_PERCEPTU AL));
375 }
376
377 #else // USE(QCMSLIB)
378
379 void ImageDecoder::setTargetColorProfile(const WebVector<char>&)
380 {
381 }
382
383 bool ImageDecoder::hasColorProfile() const
384 {
385 return false;
369 } 386 }
370 387
371 #endif // USE(QCMSLIB) 388 #endif // USE(QCMSLIB)
372 389
373 } // namespace blink 390 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/image-decoders/ImageDecoder.h ('k') | third_party/WebKit/Source/web/WebViewImpl.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698