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

Side by Side Diff: ui/gfx/color_transform.cc

Issue 2640393002: HDR preparations (Closed)
Patch Set: scRGB -> scRGBLinear Created 3 years, 11 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
« no previous file with comments | « ui/gfx/color_space.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/gfx/color_transform.h" 5 #include "ui/gfx/color_transform.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 v = fmax(0.0f, v); 281 v = fmax(0.0f, v);
282 float a = 1.055f; 282 float a = 1.055f;
283 float b = 0.0031308f; 283 float b = 0.0031308f;
284 if (v < b) { 284 if (v < b) {
285 return 12.92f * v; 285 return 12.92f * v;
286 } else { 286 } else {
287 return a * powf(v, 1.0f / 2.4f) - (a - 1.0f); 287 return a * powf(v, 1.0f / 2.4f) - (a - 1.0f);
288 } 288 }
289 } 289 }
290 case ColorSpace::TransferID::SMPTEST2084: { 290 case ColorSpace::TransferID::SMPTEST2084: {
291 // Go from scRGB levels to 0-1.
292 v *= 80.0f / 10000.0f;
291 v = fmax(0.0f, v); 293 v = fmax(0.0f, v);
292 float m1 = (2610.0f / 4096.0f) / 4.0f; 294 float m1 = (2610.0f / 4096.0f) / 4.0f;
293 float m2 = (2523.0f / 4096.0f) * 128.0f; 295 float m2 = (2523.0f / 4096.0f) * 128.0f;
294 float c1 = 3424.0f / 4096.0f; 296 float c1 = 3424.0f / 4096.0f;
295 float c2 = (2413.0f / 4096.0f) * 32.0f; 297 float c2 = (2413.0f / 4096.0f) * 32.0f;
296 float c3 = (2392.0f / 4096.0f) * 32.0f; 298 float c3 = (2392.0f / 4096.0f) * 32.0f;
297 return powf((c1 + c2 * powf(v, m1)) / (1.0f + c3 * powf(v, m1)), m2); 299 return powf((c1 + c2 * powf(v, m1)) / (1.0f + c3 * powf(v, m1)), m2);
298 } 300 }
299 301
300 case ColorSpace::TransferID::SMPTEST428_1: 302 case ColorSpace::TransferID::SMPTEST428_1:
301 v = fmax(0.0f, v); 303 v = fmax(0.0f, v);
302 return powf(48.0f * v + 52.37f, 1.0f / 2.6f); 304 return powf(48.0f * v + 52.37f, 1.0f / 2.6f);
303 305
304 // Spec: http://www.arib.or.jp/english/html/overview/doc/2-STD-B67v1_0.pdf 306 // Spec: http://www.arib.or.jp/english/html/overview/doc/2-STD-B67v1_0.pdf
305 case ColorSpace::TransferID::ARIB_STD_B67: { 307 case ColorSpace::TransferID::ARIB_STD_B67: {
306 const float a = 0.17883277f; 308 const float a = 0.17883277f;
307 const float b = 0.28466892f; 309 const float b = 0.28466892f;
308 const float c = 0.55991073f; 310 const float c = 0.55991073f;
309 const float Lmax = 12.0f; 311 v = fmax(0.0f, v);
310 v = Lmax * fmax(0.0f, v);
311 if (v <= 1) 312 if (v <= 1)
312 return 0.5f * sqrtf(v); 313 return 0.5f * sqrtf(v);
313 else 314 else
314 return a * log(v - b) + c; 315 return a * log(v - b) + c;
315 } 316 }
316 317
317 // Chrome-specific values below 318 // Chrome-specific values below
318 case ColorSpace::TransferID::GAMMA24: 319 case ColorSpace::TransferID::GAMMA24:
319 v = fmax(0.0f, v); 320 v = fmax(0.0f, v);
320 return powf(v, 1.0f / 2.4f); 321 return powf(v, 1.0f / 2.4f);
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 } 417 }
417 } 418 }
418 419
419 case ColorSpace::TransferID::SMPTEST2084: { 420 case ColorSpace::TransferID::SMPTEST2084: {
420 v = fmax(0.0f, v); 421 v = fmax(0.0f, v);
421 float m1 = (2610.0f / 4096.0f) / 4.0f; 422 float m1 = (2610.0f / 4096.0f) / 4.0f;
422 float m2 = (2523.0f / 4096.0f) * 128.0f; 423 float m2 = (2523.0f / 4096.0f) * 128.0f;
423 float c1 = 3424.0f / 4096.0f; 424 float c1 = 3424.0f / 4096.0f;
424 float c2 = (2413.0f / 4096.0f) * 32.0f; 425 float c2 = (2413.0f / 4096.0f) * 32.0f;
425 float c3 = (2392.0f / 4096.0f) * 32.0f; 426 float c3 = (2392.0f / 4096.0f) * 32.0f;
426 return powf( 427 v = powf(
427 fmax(powf(v, 1.0f / m2) - c1, 0) / (c2 - c3 * powf(v, 1.0f / m2)), 428 fmax(powf(v, 1.0f / m2) - c1, 0) / (c2 - c3 * powf(v, 1.0f / m2)),
428 1.0f / m1); 429 1.0f / m1);
430 // This matches the scRGB definition that 1.0 means 80 nits.
431 // TODO(hubbe): It would be *nice* if 1.0 meant more than that, but
432 // that might be difficult to do right now.
433 v *= 10000.0f / 80.0f;
434 return v;
429 } 435 }
430 436
431 case ColorSpace::TransferID::SMPTEST428_1: 437 case ColorSpace::TransferID::SMPTEST428_1:
432 return (powf(v, 2.6f) - 52.37f) / 48.0f; 438 return (powf(v, 2.6f) - 52.37f) / 48.0f;
433 439
434 // Chrome-specific values below 440 // Chrome-specific values below
435 case ColorSpace::TransferID::GAMMA24: 441 case ColorSpace::TransferID::GAMMA24:
436 v = fmax(0.0f, v); 442 v = fmax(0.0f, v);
437 return powf(v, 2.4f); 443 return powf(v, 2.4f);
438 444
439 case ColorSpace::TransferID::SMPTEST2084_NON_HDR: 445 case ColorSpace::TransferID::SMPTEST2084_NON_HDR:
440 v = fmax(0.0f, v); 446 v = fmax(0.0f, v);
441 return fmin(2.3f * pow(v, 2.8f), v / 5.0f + 0.8f); 447 return fmin(2.3f * pow(v, 2.8f), v / 5.0f + 0.8f);
442 448
443 // Spec: http://www.arib.or.jp/english/html/overview/doc/2-STD-B67v1_0.pdf 449 // Spec: http://www.arib.or.jp/english/html/overview/doc/2-STD-B67v1_0.pdf
444 case ColorSpace::TransferID::ARIB_STD_B67: { 450 case ColorSpace::TransferID::ARIB_STD_B67: {
445 v = fmax(0.0f, v); 451 v = fmax(0.0f, v);
446 const float a = 0.17883277f; 452 const float a = 0.17883277f;
447 const float b = 0.28466892f; 453 const float b = 0.28466892f;
448 const float c = 0.55991073f; 454 const float c = 0.55991073f;
449 const float Lmax = 12.0f;
450 float v_ = 0.0f; 455 float v_ = 0.0f;
451 if (v <= 0.5f) { 456 if (v <= 0.5f) {
452 v_ = (v * 2.0f) * (v * 2.0f); 457 v_ = (v * 2.0f) * (v * 2.0f);
453 } else { 458 } else {
454 v_ = exp((v - c) / a) + b; 459 v_ = exp((v - c) / a) + b;
455 } 460 }
456 return v_ / Lmax; 461 return v_;
457 } 462 }
458 } 463 }
459 464
460 v = fmax(0.0f, v); 465 v = fmax(0.0f, v);
461 float a = 1.099296826809442f; 466 float a = 1.099296826809442f;
462 float b = 0.018053968510807f; 467 float b = 0.018053968510807f;
463 if (v < FromLinear(ColorSpace::TransferID::BT709, b)) { 468 if (v < FromLinear(ColorSpace::TransferID::BT709, b)) {
464 return v / 4.5f; 469 return v / 4.5f;
465 } else { 470 } else {
466 return powf((v + a - 1.0f) / a, 1.0f / 0.45f); 471 return powf((v + a - 1.0f) / a, 1.0f / 0.45f);
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after
1052 to_profile ? ColorSpace::CreateXYZD50() : to, intent, &builder); 1057 to_profile ? ColorSpace::CreateXYZD50() : to, intent, &builder);
1053 if (to_profile) { 1058 if (to_profile) {
1054 builder.Append(std::unique_ptr<ColorTransformInternal>( 1059 builder.Append(std::unique_ptr<ColorTransformInternal>(
1055 new QCMSColorTransform(GetXYZD50Profile(), to_profile))); 1060 new QCMSColorTransform(GetXYZD50Profile(), to_profile)));
1056 } 1061 }
1057 1062
1058 return builder.GetTransform(); 1063 return builder.GetTransform();
1059 } 1064 }
1060 1065
1061 } // namespace gfx 1066 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/color_space.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698