Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Extract color model and transfer functions into their own files
https://bugs.webkit.org/show_bug.cgi?id=221105 Reviewed by Tim Horton. Things are getting a bit cramped in ColorTypes.h and ColorConversions. This extracts the color models into ColorModels.h and gamma transfer functions into ColorTransferFunctions.h and generalized the transfer functions a bit to reduce the code size. * Headers.cmake: * WebCore.xcodeproj/project.pbxproj: * platform/graphics/ColorModels.h: Added. * platform/graphics/ColorTransferFunctions.h: Added. * platform/graphics/ColorConversion.cpp: * platform/graphics/ColorConversion.h: * platform/graphics/ColorTypes.h: Move code to new files. Canonical link: https://commits.webkit.org/233485@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@272066 268f45cc-cd09-0410-ab3c-d52691b4dbfc
- Loading branch information
Showing
9 changed files
with
274 additions
and
200 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/* | ||
* Copyright (C) 2021 Apple Inc. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS | ||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | ||
* THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#pragma once | ||
|
||
namespace WebCore { | ||
|
||
template<typename> struct AlphaTraits; | ||
template<typename> struct ColorComponentRange; | ||
template<typename> struct ExtendedRGBModel; | ||
template<typename> struct HSLModel; | ||
template<typename> struct LCHModel; | ||
template<typename> struct LabModel; | ||
template<typename> struct RGBModel; | ||
template<typename> struct XYZModel; | ||
|
||
|
||
template<> struct AlphaTraits<float> { | ||
static constexpr float transparent = 0.0f; | ||
static constexpr float opaque = 1.0f; | ||
}; | ||
|
||
template<> struct AlphaTraits<uint8_t> { | ||
static constexpr uint8_t transparent = 0; | ||
static constexpr uint8_t opaque = 255; | ||
}; | ||
|
||
template<typename T> struct ColorComponentRange { | ||
T min; | ||
T max; | ||
}; | ||
|
||
template<> struct ExtendedRGBModel<float> { | ||
static constexpr std::array<ColorComponentRange<float>, 3> ranges { { | ||
{ -std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity() }, | ||
{ -std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity() }, | ||
{ -std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity() } | ||
} }; | ||
static constexpr bool isInvertible = false; | ||
}; | ||
|
||
template<> struct HSLModel<float> { | ||
static constexpr std::array<ColorComponentRange<float>, 3> ranges { { | ||
{ 0, 360 }, | ||
{ 0, 100 }, | ||
{ 0, 100 } | ||
} }; | ||
static constexpr bool isInvertible = true; | ||
}; | ||
|
||
template<> struct LabModel<float> { | ||
static constexpr std::array<ColorComponentRange<float>, 3> ranges { { | ||
{ 0, std::numeric_limits<float>::infinity() }, | ||
{ -std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity() }, | ||
{ -std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity() } | ||
} }; | ||
static constexpr bool isInvertible = false; | ||
}; | ||
|
||
template<> struct LCHModel<float> { | ||
static constexpr std::array<ColorComponentRange<float>, 3> ranges { { | ||
{ 0, std::numeric_limits<float>::infinity() }, | ||
{ 0, std::numeric_limits<float>::infinity() }, | ||
{ 0, 360 } | ||
} }; | ||
static constexpr bool isInvertible = false; | ||
}; | ||
|
||
template<> struct RGBModel<float> { | ||
static constexpr std::array<ColorComponentRange<float>, 3> ranges { { | ||
{ 0, 1 }, | ||
{ 0, 1 }, | ||
{ 0, 1 } | ||
} }; | ||
static constexpr bool isInvertible = true; | ||
}; | ||
|
||
template<> struct RGBModel<uint8_t> { | ||
static constexpr std::array<ColorComponentRange<uint8_t>, 3> ranges { { | ||
{ 0, 255 }, | ||
{ 0, 255 }, | ||
{ 0, 255 } | ||
} }; | ||
static constexpr bool isInvertible = true; | ||
}; | ||
|
||
template<> struct XYZModel<float> { | ||
static constexpr std::array<ColorComponentRange<float>, 3> ranges { { | ||
{ -std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity() }, | ||
{ -std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity() }, | ||
{ -std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity() } | ||
} }; | ||
static constexpr bool isInvertible = false; | ||
}; | ||
|
||
} |
Oops, something went wrong.