Add SkColorType getter on SkImage.

Bug: skia:
Change-Id: I131fb5f7faf3f54e0eb6d31b800d224e6d4963ce
Reviewed-on: https://skia-review.googlesource.com/114464
Reviewed-by: Cary Clark <caryclark@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
This commit is contained in:
Greg Daniel 2018-03-14 15:33:42 -04:00 committed by Skia Commit-Bot
parent a421112ac4
commit 56008aac75
8 changed files with 42 additions and 1 deletions

View File

@ -1070,6 +1070,24 @@ or was parsed from encoded data.
# ------------------------------------------------------------------------------
#Method SkColorType colorType() const
#In Property
#Line # returns Color_Type ##
Returns Color_Type if known; otherwise, returns kUnknown_SkColorType.
#Return Color_Type of Image ##
#Example
// incomplete
##
#SeeAlso SkImageInfo::colorType
#Method ##
# ------------------------------------------------------------------------------
#Method SkColorSpace* colorSpace() const
#In Property
#Line # returns Color_Space ##

View File

@ -500,6 +500,12 @@ public:
*/
SkAlphaType alphaType() const;
/** Returns SkColorType if known; otherwise, returns kUnknown_SkColorType.
@return SkColorType of SkImage
*/
SkColorType colorType() const;
/** Returns SkColorSpace, the range of colors, associated with SkImage. The
reference count of SkColorSpace is unchanged. The returned SkColorSpace is
immutable.

View File

@ -74,6 +74,10 @@ bool SkImage::scalePixels(const SkPixmap& dst, SkFilterQuality quality, CachingH
///////////////////////////////////////////////////////////////////////////////////////////////////
SkColorType SkImage::colorType() const {
return as_IB(this)->onColorType();
}
SkAlphaType SkImage::alphaType() const {
return as_IB(this)->onAlphaType();
}

View File

@ -35,6 +35,7 @@ public:
// Implementors: if you can not return the value, return an invalid ImageInfo with w=0 & h=0
// & unknown color space.
virtual SkImageInfo onImageInfo() const = 0;
virtual SkColorType onColorType() const = 0;
virtual SkAlphaType onAlphaType() const = 0;
virtual bool onPeekPixels(SkPixmap*) const { return false; }

View File

@ -60,11 +60,16 @@ SkImage_Gpu::~SkImage_Gpu() {
}
SkImageInfo SkImage_Gpu::onImageInfo() const {
return SkImageInfo::Make(fProxy->width(), fProxy->height(), this->onColorType(), fAlphaType,
fColorSpace);
}
SkColorType SkImage_Gpu::onColorType() const {
SkColorType ct;
if (!GrPixelConfigToColorType(fProxy->config(), &ct)) {
ct = kUnknown_SkColorType;
}
return SkImageInfo::Make(fProxy->width(), fProxy->height(), ct, fAlphaType, fColorSpace);
return ct;
}
bool SkImage_Gpu::getROPixels(SkBitmap* dst, SkColorSpace*, CachingHint chint) const {

View File

@ -28,6 +28,7 @@ public:
~SkImage_Gpu() override;
SkImageInfo onImageInfo() const override;
SkColorType onColorType() const override;
SkAlphaType onAlphaType() const override { return fAlphaType; }
bool getROPixels(SkBitmap*, SkColorSpace* dstColorSpace, CachingHint) const override;

View File

@ -70,6 +70,9 @@ public:
SkImageInfo onImageInfo() const override {
return fInfo;
}
SkColorType onColorType() const override {
return kUnknown_SkColorType;
}
SkAlphaType onAlphaType() const override {
return fInfo.alphaType();
}

View File

@ -77,6 +77,9 @@ public:
SkImageInfo onImageInfo() const override {
return fBitmap.info();
}
SkColorType onColorType() const override {
return fBitmap.colorType();
}
SkAlphaType onAlphaType() const override {
return fBitmap.alphaType();
}