| 1 |
/* |
| 2 |
* Copyright 2018 Google Inc. |
| 3 |
* |
| 4 |
* Use of this source code is governed by a BSD-style license that can be |
| 5 |
* found in the LICENSE file. |
| 6 |
*/ |
| 7 |
|
| 8 |
#include "include/private/SkEncodedInfo.h" |
| 9 |
|
| 10 |
#include "src/codec/SkCodecPriv.h" |
| 11 |
|
| 12 |
SkImageInfo SkEncodedInfo::makeImageInfo() const { |
| 13 |
auto ct = kGray_Color == fColor ? kGray_8_SkColorType : |
| 14 |
kXAlpha_Color == fColor ? kAlpha_8_SkColorType : |
| 15 |
k565_Color == fColor ? kRGB_565_SkColorType : |
| 16 |
kN32_SkColorType ; |
| 17 |
auto alpha = kOpaque_Alpha == fAlpha ? kOpaque_SkAlphaType |
| 18 |
: kUnpremul_SkAlphaType; |
| 19 |
auto cs = fColorProfile ? fColorProfile->getExactColorSpace() : SkColorSpace::MakeSRGB(); |
| 20 |
if (!cs) { |
| 21 |
cs = SkColorSpace::MakeSRGB(); |
| 22 |
} |
| 23 |
return SkImageInfo::Make(fWidth, fHeight, ct, alpha, std::move(cs)); |
| 24 |
} |
| 25 |
|
| 26 |
// static |
| 27 |
SkEncodedInfo SkEncodedInfo::Make( |
| 28 |
int width, int height, Color color, Alpha alpha, int bitsPerComponent) { |
| 29 |
return Make(width, height, color, alpha, bitsPerComponent, nullptr); |
| 30 |
} |
| 31 |
|
| 32 |
// static |
| 33 |
SkEncodedInfo SkEncodedInfo::Make( |
| 34 |
int width, int height, Color color, Alpha alpha, int bitsPerComponent, |
| 35 |
std::unique_ptr<SkCodecs::ColorProfile> profile) { |
| 36 |
return Make(width, height, color, alpha, /*bitsPerComponent*/ bitsPerComponent, |
| 37 |
std::move(profile), /*colorDepth*/ bitsPerComponent); |
| 38 |
} |
| 39 |
|
| 40 |
// static |
| 41 |
SkEncodedInfo SkEncodedInfo::Make( |
| 42 |
int width, int height, Color color, Alpha alpha, int bitsPerComponent, |
| 43 |
std::unique_ptr<SkCodecs::ColorProfile> profile, int colorDepth) { |
| 44 |
return Make(width, height, color, alpha, bitsPerComponent, colorDepth, std::move(profile), |
| 45 |
skhdr::Metadata::MakeEmpty()); |
| 46 |
} |
| 47 |
|
| 48 |
// static |
| 49 |
SkEncodedInfo SkEncodedInfo::Make( |
| 50 |
int width, int height, Color color, Alpha alpha, int bitsPerComponent, int colorDepth, |
| 51 |
std::unique_ptr<SkCodecs::ColorProfile> profile, const skhdr::Metadata& hdrMetadata) { |
| 52 |
SkASSERT(1 == bitsPerComponent || |
| 53 |
2 == bitsPerComponent || |
| 54 |
4 == bitsPerComponent || |
| 55 |
8 == bitsPerComponent || |
| 56 |
16 == bitsPerComponent); |
| 57 |
VerifyColor(color, alpha, bitsPerComponent); |
| 58 |
return SkEncodedInfo(width, height, color, alpha, SkToU8(bitsPerComponent), SkToU8(colorDepth), |
| 59 |
std::move(profile), hdrMetadata); |
| 60 |
} |
| 61 |
|
| 62 |
const skcms_ICCProfile* SkEncodedInfo::profile() const { |
| 63 |
if (!fColorProfile) return nullptr; |
| 64 |
return fColorProfile->profile(); |
| 65 |
} |
| 66 |
|
| 67 |
sk_sp<const SkData> SkEncodedInfo::profileData() const { |
| 68 |
if (!fColorProfile) return nullptr; |
| 69 |
return fColorProfile->data(); |
| 70 |
} |
| 71 |
|
| 72 |
SkEncodedInfo SkEncodedInfo::copy() const { |
| 73 |
return SkEncodedInfo( |
| 74 |
fWidth, fHeight, fColor, fAlpha, fBitsPerComponent, fColorDepth, |
| 75 |
fColorProfile ? fColorProfile->clone() : nullptr, fHdrMetadata); |
| 76 |
} |
| 77 |
|
| 78 |
SkEncodedInfo::SkEncodedInfo(SkEncodedInfo&& orig) = default; |
| 79 |
SkEncodedInfo& SkEncodedInfo::operator=(SkEncodedInfo&&) = default; |
| 80 |
SkEncodedInfo::~SkEncodedInfo() = default; |
| 81 |
|
| 82 |
SkEncodedInfo::SkEncodedInfo( |
| 83 |
int width, int height, Color color, Alpha alpha, uint8_t bitsPerComponent, |
| 84 |
uint8_t colorDepth, |
| 85 |
std::unique_ptr<SkCodecs::ColorProfile> profile, const skhdr::Metadata& hdrMetadata) |
| 86 |
: fWidth(width) |
| 87 |
, fHeight(height) |
| 88 |
, fColor(color) |
| 89 |
, fAlpha(alpha) |
| 90 |
, fBitsPerComponent(bitsPerComponent) |
| 91 |
, fColorDepth(colorDepth) |
| 92 |
, fColorProfile(std::move(profile)) |
| 93 |
, fHdrMetadata(hdrMetadata) {} |
| 94 |
|