Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "ui/gfx/color_space.h" | 10 #include "ui/gfx/color_space.h" |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 280 float c1 = 3424.0f / 4096.0f; | 280 float c1 = 3424.0f / 4096.0f; |
| 281 float c2 = (2413.0f / 4096.0f) * 32.0f; | 281 float c2 = (2413.0f / 4096.0f) * 32.0f; |
| 282 float c3 = (2392.0f / 4096.0f) * 32.0f; | 282 float c3 = (2392.0f / 4096.0f) * 32.0f; |
| 283 return powf((c1 + c2 * powf(v, m1)) / (1.0f + c3 * powf(v, m1)), m2); | 283 return powf((c1 + c2 * powf(v, m1)) / (1.0f + c3 * powf(v, m1)), m2); |
| 284 } | 284 } |
| 285 | 285 |
| 286 case ColorSpace::TransferID::SMPTEST428_1: | 286 case ColorSpace::TransferID::SMPTEST428_1: |
| 287 v = fmax(0.0f, v); | 287 v = fmax(0.0f, v); |
| 288 return powf(48.0f * v + 52.37f, 1.0f / 2.6f); | 288 return powf(48.0f * v + 52.37f, 1.0f / 2.6f); |
| 289 | 289 |
| 290 // Spec: http://www.arib.or.jp/english/html/overview/doc/2-STD-B67v1_0.pdf | |
| 291 case ColorSpace::TransferID::ARIB_STD_B67: { | |
| 292 float a = 0.17883277f; | |
| 293 float b = 0.28466892f; | |
| 294 float c = 0.55991073f; | |
| 295 float Lmax = 12.0f; | |
| 296 v = Lmax * fmax(0.0f, v); | |
| 297 if (v <= 1) | |
| 298 return 0.5f * sqrtf(v); | |
| 299 else | |
| 300 return a * log(v - b) + c; | |
| 301 } | |
| 302 | |
| 290 // Chrome-specific values below | 303 // Chrome-specific values below |
| 291 case ColorSpace::TransferID::GAMMA24: | 304 case ColorSpace::TransferID::GAMMA24: |
| 292 v = fmax(0.0f, v); | 305 v = fmax(0.0f, v); |
| 293 return powf(v, 1.0f / 2.4f); | 306 return powf(v, 1.0f / 2.4f); |
| 294 } | 307 } |
| 295 } | 308 } |
| 296 | 309 |
| 297 GFX_EXPORT float ToLinear(ColorSpace::TransferID id, float v) { | 310 GFX_EXPORT float ToLinear(ColorSpace::TransferID id, float v) { |
| 298 switch (id) { | 311 switch (id) { |
| 299 default: | 312 default: |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 395 return (powf(v, 2.6f) - 52.37f) / 48.0f; | 408 return (powf(v, 2.6f) - 52.37f) / 48.0f; |
| 396 | 409 |
| 397 // Chrome-specific values below | 410 // Chrome-specific values below |
| 398 case ColorSpace::TransferID::GAMMA24: | 411 case ColorSpace::TransferID::GAMMA24: |
| 399 v = fmax(0.0f, v); | 412 v = fmax(0.0f, v); |
| 400 return powf(v, 2.4f); | 413 return powf(v, 2.4f); |
| 401 | 414 |
| 402 case ColorSpace::TransferID::SMPTEST2084_NON_HDR: | 415 case ColorSpace::TransferID::SMPTEST2084_NON_HDR: |
| 403 v = fmax(0.0f, v); | 416 v = fmax(0.0f, v); |
| 404 return fmin(2.3f * pow(v, 2.8f), v / 5.0f + 0.8f); | 417 return fmin(2.3f * pow(v, 2.8f), v / 5.0f + 0.8f); |
| 418 | |
| 419 // Spec: http://www.arib.or.jp/english/html/overview/doc/2-STD-B67v1_0.pdf | |
| 420 case ColorSpace::TransferID::ARIB_STD_B67: { | |
| 421 v = fmax(0.0f, v); | |
| 422 float a = 0.17883277f; | |
| 423 float b = 0.28466892f; | |
| 424 float c = 0.55991073f; | |
| 425 float Lmax = 12.0f; | |
| 426 float v_ = 0.0f; | |
| 427 if (v <= 0.5f) { | |
| 428 v_ = (v * 2.0f) * (v * 2.0f); | |
| 429 } else { | |
| 430 v_ = exp(v - c) / a + b; | |
|
hubbe
2016/09/15 20:58:06
Hmm, shouldn't this be exp((v - c) / a) + b ?
servolk
2016/09/15 21:12:50
Ah, right, that was it, gfx_unittests pass now. Th
| |
| 431 } | |
| 432 return v_ / Lmax; | |
| 433 } | |
| 405 } | 434 } |
| 406 } | 435 } |
| 407 | 436 |
| 408 namespace { | 437 namespace { |
| 409 // Assumes bt2020 | 438 // Assumes bt2020 |
| 410 float Luma(const ColorTransform::TriStim& c) { | 439 float Luma(const ColorTransform::TriStim& c) { |
| 411 return c.x() * 0.2627f + c.y() * 0.6780f + c.z() * 0.0593f; | 440 return c.x() * 0.2627f + c.y() * 0.6780f + c.z() * 0.0593f; |
| 412 } | 441 } |
| 413 }; | 442 }; |
| 414 | 443 |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 699 std::unique_ptr<ColorTransform>( | 728 std::unique_ptr<ColorTransform>( |
| 700 new QCMSColorTransform(GetXYZD50Profile(), to_profile)))); | 729 new QCMSColorTransform(GetXYZD50Profile(), to_profile)))); |
| 701 } else { | 730 } else { |
| 702 return std::unique_ptr<ColorTransform>( | 731 return std::unique_ptr<ColorTransform>( |
| 703 new ColorSpaceToColorSpaceTransform(from, to, intent)); | 732 new ColorSpaceToColorSpaceTransform(from, to, intent)); |
| 704 } | 733 } |
| 705 } | 734 } |
| 706 } | 735 } |
| 707 | 736 |
| 708 } // namespace gfx | 737 } // namespace gfx |
| OLD | NEW |