void* dst = fDst.get();
void* src = fSrc.get();
for (int y = 0; y < fSrcInfo.height(); y++) {
- // Transform in place
- FLAGS_half ?
- xform->applyToF16((uint64_t*) dst, (uint32_t*) src, fSrcInfo.width()) :
- xform->applyToRGBA((SkPMColor*) dst, (uint32_t*) src, fSrcInfo.width());
+ xform->apply(dst, (uint32_t*) src, fSrcInfo.width(), fDstInfo.colorType(),
+ fDstInfo.alphaType());
dst = SkTAddOffset<void>(dst, fDstInfo.minRowBytes());
src = SkTAddOffset<void>(src, fSrcInfo.minRowBytes());
}
return Error::Nonfatal("No need to test color correction to 565 backend.");
}
- if (nullptr == canvas->imageInfo().colorSpace() && kRGBA_F16_SkColorType == fColorType) {
- return Error::Nonfatal("F16 does not draw in legacy mode.");
+ bool runInLegacyMode = kBaseline_Mode == fMode;
+#if defined(SK_TEST_QCMS)
+ runInLegacyMode = runInLegacyMode || kQCMS_HPZR30w_Mode == fMode;
+#endif
+
+ if (runInLegacyMode && canvas->imageInfo().colorSpace()) {
+ return Error::Nonfatal("Skipping tests that are only interesting in legacy mode.");
+ } else if (!runInLegacyMode && !canvas->imageInfo().colorSpace()) {
+ return Error::Nonfatal("Skipping tests that are only interesting in srgb mode.");
}
sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str()));
}
SkImageInfo decodeInfo = codec->getInfo().makeColorType(fColorType).makeColorSpace(dstSpace);
+ if (kUnpremul_SkAlphaType == decodeInfo.alphaType()) {
+ decodeInfo = decodeInfo.makeAlphaType(kPremul_SkAlphaType);
+ }
+
SkImageInfo bitmapInfo = decodeInfo;
if (kRGBA_8888_SkColorType == decodeInfo.colorType() ||
kBGRA_8888_SkColorType == decodeInfo.colorType())
#if defined(SK_TEST_QCMS)
case kQCMS_HPZR30w_Mode: {
sk_sp<SkData> srcData = codec->getICCData();
+ if (!srcData) {
+ return Error::Nonfatal("No ICC profile data. Cannot test with QCMS.\n");
+ }
+
SkAutoTCallVProc<qcms_profile, qcms_profile_release>
srcSpace(qcms_profile_from_memory(srcData->data(), srcData->size()));
if (!srcSpace) {
#endif
// FIXME: Consider sharing with dm, nanbench, and tools.
-inline float get_scale_from_sample_size(int sampleSize) {
+static inline float get_scale_from_sample_size(int sampleSize) {
return 1.0f / ((float) sampleSize);
}
-inline bool is_valid_subset(const SkIRect& subset, const SkISize& imageDims) {
+static inline bool is_valid_subset(const SkIRect& subset, const SkISize& imageDims) {
return SkIRect::MakeSize(imageDims).contains(subset);
}
* NOTE: we round down here for scaled dimension to match the behavior of SkImageDecoder
* FIXME: I think we should call this get_sampled_dimension().
*/
-inline int get_scaled_dimension(int srcDimension, int sampleSize) {
+static inline int get_scaled_dimension(int srcDimension, int sampleSize) {
if (sampleSize > srcDimension) {
return 1;
}
*
* This does not need to be called and is not called when sampleFactor == 1.
*/
-inline int get_start_coord(int sampleFactor) { return sampleFactor / 2; };
+static inline int get_start_coord(int sampleFactor) { return sampleFactor / 2; };
/*
* Given a coordinate in the original image, this returns the corresponding
*
* This does not need to be called and is not called when sampleFactor == 1.
*/
-inline int get_dst_coord(int srcCoord, int sampleFactor) { return srcCoord / sampleFactor; };
+static inline int get_dst_coord(int srcCoord, int sampleFactor) { return srcCoord / sampleFactor; };
/*
* When scaling, we will discard certain y-coordinates (rows) and
*
* This does not need to be called and is not called when sampleFactor == 1.
*/
-inline bool is_coord_necessary(int srcCoord, int sampleFactor, int scaledDim) {
+static inline bool is_coord_necessary(int srcCoord, int sampleFactor, int scaledDim) {
// Get the first coordinate that we want to keep
int startCoord = get_start_coord(sampleFactor);
return ((srcCoord - startCoord) % sampleFactor) == 0;
}
-inline bool valid_alpha(SkAlphaType dstAlpha, SkAlphaType srcAlpha) {
+static inline bool valid_alpha(SkAlphaType dstAlpha, SkAlphaType srcAlpha) {
if (kUnknown_SkAlphaType == dstAlpha) {
return false;
}
/*
* Most of our codecs support the same conversions:
- * - profileType must be the same
* - opaque to any alpha type
* - 565 only if opaque
* - premul to unpremul and vice versa
* - always support N32
* - otherwise match the src color type
*/
-inline bool conversion_possible(const SkImageInfo& dst, const SkImageInfo& src) {
- // FIXME: skbug.com/4895
- // Currently, we ignore the SkColorProfileType on the SkImageInfo. We
- // will treat the encoded data as linear regardless of what the client
- // requests.
-
+static inline bool conversion_possible(const SkImageInfo& dst, const SkImageInfo& src) {
// Ensure the alpha type is valid
if (!valid_alpha(dst.alphaType(), src.alphaType())) {
return false;
/*
* If there is a color table, get a pointer to the colors, otherwise return nullptr
*/
-inline const SkPMColor* get_color_ptr(SkColorTable* colorTable) {
+static inline const SkPMColor* get_color_ptr(SkColorTable* colorTable) {
return nullptr != colorTable ? colorTable->readColors() : nullptr;
}
/*
* Given that the encoded image uses a color table, return the fill value
*/
-inline uint32_t get_color_table_fill_value(SkColorType colorType, const SkPMColor* colorPtr,
+static inline uint32_t get_color_table_fill_value(SkColorType colorType, const SkPMColor* colorPtr,
uint8_t fillIndex) {
SkASSERT(nullptr != colorPtr);
switch (colorType) {
*
* Copy the codec color table back to the client when kIndex8 color type is requested
*/
-inline void copy_color_table(const SkImageInfo& dstInfo, SkColorTable* colorTable,
+static inline void copy_color_table(const SkImageInfo& dstInfo, SkColorTable* colorTable,
SkPMColor* inputColorPtr, int* inputColorCount) {
if (kIndex_8_SkColorType == dstInfo.colorType()) {
SkASSERT(nullptr != inputColorPtr);
/*
* Compute row bytes for an image using pixels per byte
*/
-inline size_t compute_row_bytes_ppb(int width, uint32_t pixelsPerByte) {
+static inline size_t compute_row_bytes_ppb(int width, uint32_t pixelsPerByte) {
return (width + pixelsPerByte - 1) / pixelsPerByte;
}
/*
* Compute row bytes for an image using bytes per pixel
*/
-inline size_t compute_row_bytes_bpp(int width, uint32_t bytesPerPixel) {
+static inline size_t compute_row_bytes_bpp(int width, uint32_t bytesPerPixel) {
return width * bytesPerPixel;
}
/*
* Compute row bytes for an image
*/
-inline size_t compute_row_bytes(int width, uint32_t bitsPerPixel) {
+static inline size_t compute_row_bytes(int width, uint32_t bitsPerPixel) {
if (bitsPerPixel < 16) {
SkASSERT(0 == 8 % bitsPerPixel);
const uint32_t pixelsPerByte = 8 / bitsPerPixel;
* Get a byte from a buffer
* This method is unsafe, the caller is responsible for performing a check
*/
-inline uint8_t get_byte(uint8_t* buffer, uint32_t i) {
+static inline uint8_t get_byte(uint8_t* buffer, uint32_t i) {
return buffer[i];
}
* Get a short from a buffer
* This method is unsafe, the caller is responsible for performing a check
*/
-inline uint16_t get_short(uint8_t* buffer, uint32_t i) {
+static inline uint16_t get_short(uint8_t* buffer, uint32_t i) {
uint16_t result;
memcpy(&result, &(buffer[i]), 2);
#ifdef SK_CPU_BENDIAN
* Get an int from a buffer
* This method is unsafe, the caller is responsible for performing a check
*/
-inline uint32_t get_int(uint8_t* buffer, uint32_t i) {
+static inline uint32_t get_int(uint8_t* buffer, uint32_t i) {
uint32_t result;
memcpy(&result, &(buffer[i]), 4);
#ifdef SK_CPU_BENDIAN
* Indicates if the data is little endian
* Is unaffected on false returns
*/
-inline bool is_valid_endian_marker(const uint8_t* data, bool* isLittleEndian) {
+static inline bool is_valid_endian_marker(const uint8_t* data, bool* isLittleEndian) {
// II indicates Intel (little endian) and MM indicates motorola (big endian).
if (('I' != data[0] || 'I' != data[1]) && ('M' != data[0] || 'M' != data[1])) {
return false;
return true;
}
-inline uint16_t get_endian_short(const uint8_t* data, bool littleEndian) {
+static inline uint16_t get_endian_short(const uint8_t* data, bool littleEndian) {
if (littleEndian) {
return (data[1] << 8) | (data[0]);
}
return (data[0] << 8) | (data[1]);
}
-inline SkPMColor premultiply_argb_as_rgba(U8CPU a, U8CPU r, U8CPU g, U8CPU b) {
+static inline SkPMColor premultiply_argb_as_rgba(U8CPU a, U8CPU r, U8CPU g, U8CPU b) {
if (a != 255) {
r = SkMulDiv255Round(r, a);
g = SkMulDiv255Round(g, a);
return SkPackARGB_as_RGBA(a, r, g, b);
}
-inline SkPMColor premultiply_argb_as_bgra(U8CPU a, U8CPU r, U8CPU g, U8CPU b) {
+static inline SkPMColor premultiply_argb_as_bgra(U8CPU a, U8CPU r, U8CPU g, U8CPU b) {
if (a != 255) {
r = SkMulDiv255Round(r, a);
g = SkMulDiv255Round(g, a);
return SkPackARGB_as_BGRA(a, r, g, b);
}
-inline bool is_rgba(SkColorType colorType) {
+static inline bool is_rgba(SkColorType colorType) {
#ifdef SK_PMCOLOR_IS_RGBA
return (kBGRA_8888_SkColorType != colorType);
#else
// Method for coverting to a 32 bit pixel.
typedef uint32_t (*PackColorProc)(U8CPU a, U8CPU r, U8CPU g, U8CPU b);
-inline PackColorProc choose_pack_color_proc(bool isPremul, SkColorType colorType) {
+static inline PackColorProc choose_pack_color_proc(bool isPremul, SkColorType colorType) {
bool isRGBA = is_rgba(colorType);
if (isPremul) {
if (isRGBA) {
}
}
+static inline bool needs_color_xform(const SkImageInfo& dstInfo, const SkImageInfo& srcInfo) {
+ return (kRGBA_F16_SkColorType == dstInfo.colorType()) ||
+ (dstInfo.colorSpace() && !SkColorSpace::Equals(srcInfo.colorSpace(),
+ dstInfo.colorSpace()));
+}
+
#endif // SkCodecPriv_DEFINED
return true;
}
-static bool needs_color_xform(const SkImageInfo& dstInfo, const SkImageInfo& srcInfo) {
- return (kRGBA_F16_SkColorType == dstInfo.colorType()) ||
- (dstInfo.colorSpace() && !SkColorSpace::Equals(srcInfo.colorSpace(),
- dstInfo.colorSpace()));
-}
-
int SkJpegCodec::readRows(const SkImageInfo& dstInfo, void* dst, size_t rowBytes, int count) {
// Set the jump location for libjpeg-turbo errors
if (setjmp(fDecoderMgr->getJmpBuf())) {
}
if (fColorXform) {
- int width = dstInfo.width();
- switch (dstInfo.colorType()) {
- case kRGBA_8888_SkColorType:
- fColorXform->applyToRGBA((uint32_t*) dst, swizzleDst, width);
- break;
- case kBGRA_8888_SkColorType:
- fColorXform->applyToBGRA((uint32_t*) dst, swizzleDst, width);
- break;
- case kRGBA_F16_SkColorType:
- fColorXform->applyToF16((uint64_t*) dst, swizzleDst, width);
- break;
- default:
- SkASSERT(false);
- break;
- }
-
+ fColorXform->apply(dst, swizzleDst, dstInfo.width(), dstInfo.colorType(),
+ kOpaque_SkAlphaType);
dst = SkTAddOffset<void>(dst, rowBytes);
}
size_t xformBytes = 0;
if (kRGBA_F16_SkColorType == dstInfo.colorType()) {
SkASSERT(fColorXform);
- xformBytes = dstInfo.width() * sizeof(SkColorSpaceXform::RGBA32);
+ xformBytes = dstInfo.width() * sizeof(uint32_t);
}
size_t totalBytes = swizzleBytes + xformBytes;
};
#define AutoCleanPng(...) SK_REQUIRE_LOCAL_VAR(AutoCleanPng)
-// Note: SkColorTable claims to store SkPMColors, which is not necessarily
-// the case here.
-// TODO: If we add support for non-native swizzles, we'll need to handle that here.
+// Note: SkColorTable claims to store SkPMColors, which is not necessarily the case here.
bool SkPngCodec::createColorTable(SkColorType dstColorType, bool premultiply, int* ctableCount) {
int numColors;
return bitsPerPixel / 8;
}
-// Subclass of SkPngCodec which supports scanline decoding
-class SkPngScanlineDecoder : public SkPngCodec {
+static bool png_conversion_possible(const SkImageInfo& dst, const SkImageInfo& src) {
+ // Ensure the alpha type is valid
+ if (!valid_alpha(dst.alphaType(), src.alphaType())) {
+ return false;
+ }
+
+ // Check for supported color types
+ switch (dst.colorType()) {
+ case kRGBA_8888_SkColorType:
+ case kBGRA_8888_SkColorType:
+ case kRGBA_F16_SkColorType:
+ return true;
+ case kRGB_565_SkColorType:
+ return kOpaque_SkAlphaType == src.alphaType();
+ default:
+ return dst.colorType() == src.colorType();
+ }
+}
+
+void SkPngCodec::allocateStorage(const SkImageInfo& dstInfo) {
+ const int width = this->getInfo().width();
+ size_t colorXformBytes = fColorXform ? width * sizeof(uint32_t) : 0;
+
+ fStorage.reset(SkAlign4(fSrcRowBytes) + colorXformBytes);
+ fSwizzlerSrcRow = fStorage.get();
+ fColorXformSrcRow =
+ fColorXform ? SkTAddOffset<uint32_t>(fSwizzlerSrcRow, SkAlign4(fSrcRowBytes)) : 0;
+}
+
+class SkPngNormalCodec : public SkPngCodec {
public:
- SkPngScanlineDecoder(int width, int height, const SkEncodedInfo& info, SkStream* stream,
+ SkPngNormalCodec(int width, int height, const SkEncodedInfo& info, SkStream* stream,
SkPngChunkReader* chunkReader, png_structp png_ptr, png_infop info_ptr, int bitDepth,
sk_sp<SkColorSpace> colorSpace)
: INHERITED(width, height, info, stream, chunkReader, png_ptr, info_ptr, bitDepth, 1,
colorSpace)
- , fSrcRow(nullptr)
{}
Result onStartScanlineDecode(const SkImageInfo& dstInfo, const Options& options,
SkPMColor ctable[], int* ctableCount) override {
- if (!conversion_possible(dstInfo, this->getInfo())) {
+ if (!png_conversion_possible(dstInfo, this->getInfo()) ||
+ !this->initializeXforms(dstInfo, options, ctable, ctableCount))
+ {
return kInvalidConversion;
}
- const Result result = this->initializeSwizzler(dstInfo, options, ctable,
- ctableCount);
- if (result != kSuccess) {
- return result;
- }
-
- fStorage.reset(this->getInfo().width() *
- (bytes_per_pixel(this->getEncodedInfo().bitsPerPixel())));
- fSrcRow = fStorage.get();
-
+ this->allocateStorage(dstInfo);
return kSuccess;
}
- int onGetScanlines(void* dst, int count, size_t rowBytes) override {
+ int readRows(const SkImageInfo& dstInfo, void* dst, size_t rowBytes, int count, int startRow)
+ override {
+ SkASSERT(0 == startRow);
+
// Assume that an error in libpng indicates an incomplete input.
- int row = 0;
- if (setjmp(png_jmpbuf(this->png_ptr()))) {
- SkCodecPrintf("setjmp long jump!\n");
- return row;
+ int y = 0;
+ if (setjmp(png_jmpbuf(fPng_ptr))) {
+ SkCodecPrintf("Failed to read row.\n");
+ return y;
}
- void* dstRow = dst;
- for (; row < count; row++) {
- png_read_row(this->png_ptr(), fSrcRow, nullptr);
- this->swizzler()->swizzle(dstRow, fSrcRow);
- dstRow = SkTAddOffset<void>(dstRow, rowBytes);
+ void* swizzlerDstRow = dst;
+ size_t swizzlerDstRowBytes = rowBytes;
+ if (fColorXform) {
+ swizzlerDstRow = fColorXformSrcRow;
+ swizzlerDstRowBytes = 0;
}
- return row;
+ SkAlphaType xformAlphaType = (kOpaque_SkAlphaType == this->getInfo().alphaType()) ?
+ kOpaque_SkAlphaType : dstInfo.alphaType();
+ for (; y < count; y++) {
+ png_read_row(fPng_ptr, fSwizzlerSrcRow, nullptr);
+ fSwizzler->swizzle(swizzlerDstRow, fSwizzlerSrcRow);
+
+ if (fColorXform) {
+ fColorXform->apply(dst, (const uint32_t*) swizzlerDstRow, dstInfo.width(),
+ dstInfo.colorType(), xformAlphaType);
+ dst = SkTAddOffset<void>(dst, rowBytes);
+ }
+
+ swizzlerDstRow = SkTAddOffset<void>(swizzlerDstRow, swizzlerDstRowBytes);
+ }
+
+ return y;
+ }
+
+ int onGetScanlines(void* dst, int count, size_t rowBytes) override {
+ return this->readRows(this->dstInfo(), dst, rowBytes, count, 0);
}
bool onSkipScanlines(int count) override {
- // Assume that an error in libpng indicates an incomplete input.
- if (setjmp(png_jmpbuf(this->png_ptr()))) {
- SkCodecPrintf("setjmp long jump!\n");
+ if (setjmp(png_jmpbuf(fPng_ptr))) {
+ SkCodecPrintf("Failed to skip row.\n");
return false;
}
for (int row = 0; row < count; row++) {
- png_read_row(this->png_ptr(), fSrcRow, nullptr);
+ png_read_row(fPng_ptr, fSwizzlerSrcRow, nullptr);
}
return true;
}
-private:
- SkAutoTMalloc<uint8_t> fStorage;
- uint8_t* fSrcRow;
-
typedef SkPngCodec INHERITED;
};
-class SkPngInterlacedScanlineDecoder : public SkPngCodec {
+class SkPngInterlacedCodec : public SkPngCodec {
public:
- SkPngInterlacedScanlineDecoder(int width, int height, const SkEncodedInfo& info,
+ SkPngInterlacedCodec(int width, int height, const SkEncodedInfo& info,
SkStream* stream, SkPngChunkReader* chunkReader, png_structp png_ptr,
png_infop info_ptr, int bitDepth, int numberPasses, sk_sp<SkColorSpace> colorSpace)
: INHERITED(width, height, info, stream, chunkReader, png_ptr, info_ptr, bitDepth,
numberPasses, colorSpace)
- , fHeight(-1)
, fCanSkipRewind(false)
{
SkASSERT(numberPasses != 1);
Result onStartScanlineDecode(const SkImageInfo& dstInfo, const Options& options,
SkPMColor ctable[], int* ctableCount) override {
- if (!conversion_possible(dstInfo, this->getInfo())) {
+ if (!png_conversion_possible(dstInfo, this->getInfo()) ||
+ !this->initializeXforms(dstInfo, options, ctable, ctableCount))
+ {
return kInvalidConversion;
}
- const Result result = this->initializeSwizzler(dstInfo, options, ctable,
- ctableCount);
- if (result != kSuccess) {
- return result;
+ this->allocateStorage(dstInfo);
+ fCanSkipRewind = true;
+ return SkCodec::kSuccess;
+ }
+
+ int readRows(const SkImageInfo& dstInfo, void* dst, size_t rowBytes, int count, int startRow)
+ override {
+ if (setjmp(png_jmpbuf(fPng_ptr))) {
+ SkCodecPrintf("Failed to get scanlines.\n");
+ // FIXME (msarett): Returning 0 is pessimistic. If we can complete a single pass,
+ // we may be able to report that all of the memory has been initialized. Even if we
+ // fail on the first pass, we can still report than some scanlines are initialized.
+ return 0;
+ }
+
+ SkAutoTMalloc<uint8_t> storage(count * fSrcRowBytes);
+ uint8_t* srcRow;
+ for (int i = 0; i < fNumberPasses; i++) {
+ // Discard rows that we planned to skip.
+ for (int y = 0; y < startRow; y++){
+ png_read_row(fPng_ptr, fSwizzlerSrcRow, nullptr);
+ }
+ // Read rows we care about into storage.
+ srcRow = storage.get();
+ for (int y = 0; y < count; y++) {
+ png_read_row(fPng_ptr, srcRow, nullptr);
+ srcRow += fSrcRowBytes;
+ }
+ // Discard rows that we don't need.
+ for (int y = 0; y < this->getInfo().height() - startRow - count; y++) {
+ png_read_row(fPng_ptr, fSwizzlerSrcRow, nullptr);
+ }
}
- fHeight = dstInfo.height();
- // FIXME: This need not be called on a second call to onStartScanlineDecode.
- fSrcRowBytes = this->getInfo().width() *
- (bytes_per_pixel(this->getEncodedInfo().bitsPerPixel()));
- fGarbageRow.reset(fSrcRowBytes);
- fGarbageRowPtr = static_cast<uint8_t*>(fGarbageRow.get());
- fCanSkipRewind = true;
+ // Swizzle and xform the rows we care about
+ void* swizzlerDstRow = dst;
+ size_t swizzlerDstRowBytes = rowBytes;
+ if (fColorXform) {
+ swizzlerDstRow = fColorXformSrcRow;
+ swizzlerDstRowBytes = 0;
+ }
- return SkCodec::kSuccess;
+ SkAlphaType xformAlphaType = (kOpaque_SkAlphaType == this->getInfo().alphaType()) ?
+ kOpaque_SkAlphaType : dstInfo.alphaType();
+ srcRow = storage.get();
+ for (int y = 0; y < count; y++) {
+ fSwizzler->swizzle(swizzlerDstRow, srcRow);
+ srcRow = SkTAddOffset<uint8_t>(srcRow, fSrcRowBytes);
+
+ if (fColorXform) {
+ if (fColorXform) {
+ fColorXform->apply(dst, (const uint32_t*) swizzlerDstRow, dstInfo.width(),
+ dstInfo.colorType(), xformAlphaType);
+ dst = SkTAddOffset<void>(dst, rowBytes);
+ }
+ }
+
+ swizzlerDstRow = SkTAddOffset<void>(swizzlerDstRow, swizzlerDstRowBytes);
+ }
+
+ return count;
}
- int onGetScanlines(void* dst, int count, size_t dstRowBytes) override {
+ int onGetScanlines(void* dst, int count, size_t rowBytes) override {
// rewind stream if have previously called onGetScanlines,
// since we need entire progressive image to get scanlines
if (fCanSkipRewind) {
this->updateCurrScanline(currScanline);
}
- if (setjmp(png_jmpbuf(this->png_ptr()))) {
- SkCodecPrintf("setjmp long jump!\n");
- // FIXME (msarett): Returning 0 is pessimistic. If we can complete a single pass,
- // we may be able to report that all of the memory has been initialized. Even if we
- // fail on the first pass, we can still report than some scanlines are initialized.
- return 0;
- }
- SkAutoTMalloc<uint8_t> storage(count * fSrcRowBytes);
- uint8_t* storagePtr = storage.get();
- uint8_t* srcRow;
- const int startRow = this->nextScanline();
- for (int i = 0; i < this->numberPasses(); i++) {
- // read rows we planned to skip into garbage row
- for (int y = 0; y < startRow; y++){
- png_read_row(this->png_ptr(), fGarbageRowPtr, nullptr);
- }
- // read rows we care about into buffer
- srcRow = storagePtr;
- for (int y = 0; y < count; y++) {
- png_read_row(this->png_ptr(), srcRow, nullptr);
- srcRow += fSrcRowBytes;
- }
- // read rows we don't want into garbage buffer
- for (int y = 0; y < fHeight - startRow - count; y++) {
- png_read_row(this->png_ptr(), fGarbageRowPtr, nullptr);
- }
- }
- //swizzle the rows we care about
- srcRow = storagePtr;
- void* dstRow = dst;
- for (int y = 0; y < count; y++) {
- this->swizzler()->swizzle(dstRow, srcRow);
- dstRow = SkTAddOffset<void>(dstRow, dstRowBytes);
- srcRow += fSrcRowBytes;
- }
-
- return count;
+ return this->readRows(this->dstInfo(), dst, rowBytes, count, this->nextScanline());
}
bool onSkipScanlines(int count) override {
}
private:
- int fHeight;
- size_t fSrcRowBytes;
- SkAutoMalloc fGarbageRow;
- uint8_t* fGarbageRowPtr;
// FIXME: This imitates behavior in SkCodec::rewindIfNeeded. That function
// is called whenever some action is taken that reads the stream and
// therefore the next call will require a rewind. So it modifies a boolean
// to note that the *next* time it is called a rewind is needed.
- // SkPngInterlacedScanlineDecoder has an extra wrinkle - calling
+ // SkPngInterlacedCodec has an extra wrinkle - calling
// onStartScanlineDecode followed by onGetScanlines does *not* require a
// rewind. Since rewindIfNeeded does not have this flexibility, we need to
// add another layer.
SkEncodedInfo info = SkEncodedInfo::Make(color, alpha, 8);
if (1 == numberPasses) {
- *outCodec = new SkPngScanlineDecoder(origWidth, origHeight, info, stream,
+ *outCodec = new SkPngNormalCodec(origWidth, origHeight, info, stream,
chunkReader, png_ptr, info_ptr, bitDepth, colorSpace);
} else {
- *outCodec = new SkPngInterlacedScanlineDecoder(origWidth, origHeight, info, stream,
+ *outCodec = new SkPngInterlacedCodec(origWidth, origHeight, info, stream,
chunkReader, png_ptr, info_ptr, bitDepth, numberPasses, colorSpace);
}
}
, fPngChunkReader(SkSafeRef(chunkReader))
, fPng_ptr(png_ptr)
, fInfo_ptr(info_ptr)
+ , fSwizzlerSrcRow(nullptr)
+ , fColorXformSrcRow(nullptr)
+ , fSrcRowBytes(width * (bytes_per_pixel(this->getEncodedInfo().bitsPerPixel())))
, fNumberPasses(numberPasses)
, fBitDepth(bitDepth)
{}
// Getting the pixels
///////////////////////////////////////////////////////////////////////////////
-SkCodec::Result SkPngCodec::initializeSwizzler(const SkImageInfo& requestedInfo,
- const Options& options,
- SkPMColor ctable[],
- int* ctableCount) {
- // FIXME: Could we use the return value of setjmp to specify the type of
- // error?
+bool SkPngCodec::initializeXforms(const SkImageInfo& dstInfo, const Options& options,
+ SkPMColor ctable[], int* ctableCount) {
if (setjmp(png_jmpbuf(fPng_ptr))) {
- SkCodecPrintf("setjmp long jump!\n");
- return kInvalidInput;
+ SkCodecPrintf("Failed on png_read_update_info.\n");
+ return false;
}
png_read_update_info(fPng_ptr, fInfo_ptr);
+ // It's important to reset fColorXform to nullptr. We don't do this on rewinding
+ // because the interlaced scanline decoder may need to rewind.
+ fColorXform = nullptr;
+ SkImageInfo swizzlerInfo = dstInfo;
+ bool needsColorXform = needs_color_xform(dstInfo, this->getInfo());
+ if (needsColorXform) {
+ switch (dstInfo.colorType()) {
+ case kRGBA_8888_SkColorType:
+ case kBGRA_8888_SkColorType:
+ case kRGBA_F16_SkColorType:
+ swizzlerInfo = swizzlerInfo.makeColorType(kRGBA_8888_SkColorType);
+ if (kPremul_SkAlphaType == dstInfo.alphaType()) {
+ swizzlerInfo = swizzlerInfo.makeAlphaType(kUnpremul_SkAlphaType);
+ }
+ break;
+ default:
+ return false;
+ }
+
+ fColorXform = SkColorSpaceXform::New(sk_ref_sp(this->getInfo().colorSpace()),
+ sk_ref_sp(dstInfo.colorSpace()));
+
+ if (!fColorXform && kRGBA_F16_SkColorType == dstInfo.colorType()) {
+ return false;
+ }
+ }
+
if (SkEncodedInfo::kPalette_Color == this->getEncodedInfo().color()) {
- if (!this->createColorTable(requestedInfo.colorType(),
- kPremul_SkAlphaType == requestedInfo.alphaType(), ctableCount)) {
- return kInvalidInput;
+ if (!this->createColorTable(swizzlerInfo.colorType(),
+ kPremul_SkAlphaType == swizzlerInfo.alphaType(), ctableCount)) {
+ return false;
}
}
// Copy the color table to the client if they request kIndex8 mode
- copy_color_table(requestedInfo, fColorTable, ctable, ctableCount);
+ copy_color_table(swizzlerInfo, fColorTable, ctable, ctableCount);
// Create the swizzler. SkPngCodec retains ownership of the color table.
const SkPMColor* colors = get_color_ptr(fColorTable.get());
- fSwizzler.reset(SkSwizzler::CreateSwizzler(this->getEncodedInfo(), colors, requestedInfo,
- options));
+ fSwizzler.reset(SkSwizzler::CreateSwizzler(this->getEncodedInfo(), colors, swizzlerInfo,
+ options));
SkASSERT(fSwizzler);
-
- return kSuccess;
+ return true;
}
-
bool SkPngCodec::onRewind() {
// This sets fPng_ptr and fInfo_ptr to nullptr. If read_header
// succeeds, they will be repopulated, and if it fails, they will
return true;
}
-SkCodec::Result SkPngCodec::onGetPixels(const SkImageInfo& requestedInfo, void* dst,
- size_t dstRowBytes, const Options& options,
+SkCodec::Result SkPngCodec::onGetPixels(const SkImageInfo& dstInfo, void* dst,
+ size_t rowBytes, const Options& options,
SkPMColor ctable[], int* ctableCount,
int* rowsDecoded) {
- if (!conversion_possible(requestedInfo, this->getInfo())) {
+ if (!png_conversion_possible(dstInfo, this->getInfo()) ||
+ !this->initializeXforms(dstInfo, options, ctable, ctableCount))
+ {
return kInvalidConversion;
}
+
if (options.fSubset) {
- // Subsets are not supported.
return kUnimplemented;
}
- // Note that ctable and ctableCount may be modified if there is a color table
- const Result result = this->initializeSwizzler(requestedInfo, options, ctable, ctableCount);
- if (result != kSuccess) {
- return result;
- }
-
- const int width = requestedInfo.width();
- const int height = requestedInfo.height();
- const int bpp = bytes_per_pixel(this->getEncodedInfo().bitsPerPixel());
- const size_t srcRowBytes = width * bpp;
-
- // FIXME: Could we use the return value of setjmp to specify the type of
- // error?
- int row = 0;
- // This must be declared above the call to setjmp to avoid memory leaks on incomplete images.
- SkAutoTMalloc<uint8_t> storage;
- if (setjmp(png_jmpbuf(fPng_ptr))) {
- // Assume that any error that occurs while reading rows is caused by an incomplete input.
- if (fNumberPasses > 1) {
- // FIXME (msarett): Handle incomplete interlaced pngs.
- return (row == height) ? kSuccess : kInvalidInput;
- }
- // FIXME: We do a poor job on incomplete pngs compared to other decoders (ex: Chromium,
- // Ubuntu Image Viewer). This is because we use the default buffer size in libpng (8192
- // bytes), and if we can't fill the buffer, we immediately fail.
- // For example, if we try to read 8192 bytes, and the image (incorrectly) only contains
- // half that, which may have been enough to contain a non-zero number of lines, we fail
- // when we could have decoded a few more lines and then failed.
- // The read function that we provide for libpng has no way of indicating that we have
- // made a partial read.
- // Making our buffer size smaller improves our incomplete decodes, but what impact does
- // it have on regular decode performance? Should we investigate using a different API
- // instead of png_read_row? Chromium uses png_process_data.
- *rowsDecoded = row;
- return (row == height) ? kSuccess : kIncompleteInput;
- }
-
- // FIXME: We could split these out based on subclass.
- void* dstRow = dst;
- if (fNumberPasses > 1) {
- storage.reset(height * srcRowBytes);
- uint8_t* const base = storage.get();
-
- for (int i = 0; i < fNumberPasses; i++) {
- uint8_t* srcRow = base;
- for (int y = 0; y < height; y++) {
- png_read_row(fPng_ptr, srcRow, nullptr);
- srcRow += srcRowBytes;
- }
- }
-
- // Now swizzle it.
- uint8_t* srcRow = base;
- for (; row < height; row++) {
- fSwizzler->swizzle(dstRow, srcRow);
- dstRow = SkTAddOffset<void>(dstRow, dstRowBytes);
- srcRow += srcRowBytes;
- }
- } else {
- storage.reset(srcRowBytes);
- uint8_t* srcRow = storage.get();
- for (; row < height; row++) {
- png_read_row(fPng_ptr, srcRow, nullptr);
- fSwizzler->swizzle(dstRow, srcRow);
- dstRow = SkTAddOffset<void>(dstRow, dstRowBytes);
- }
+ this->allocateStorage(dstInfo);
+ int count = this->readRows(dstInfo, dst, rowBytes, dstInfo.height(), 0);
+ if (count > dstInfo.height()) {
+ *rowsDecoded = count;
+ return kIncompleteInput;
}
- // read rest of file, and get additional comment and time chunks in info_ptr
- png_read_end(fPng_ptr, fInfo_ptr);
-
return kSuccess;
}
*/
#include "SkCodec.h"
+#include "SkColorSpaceXform.h"
#include "SkColorTable.h"
#include "SkPngChunkReader.h"
#include "SkEncodedFormat.h"
bool onRewind() override;
uint32_t onGetFillValue(SkColorType) const override;
- // Helper to set up swizzler and color table. Also calls png_read_update_info.
- Result initializeSwizzler(const SkImageInfo& requestedInfo, const Options&,
- SkPMColor*, int* ctableCount);
+ // Helper to set up swizzler, color xforms, and color table. Also calls png_read_update_info.
+ bool initializeXforms(const SkImageInfo& requestedInfo, const Options&, SkPMColor* colorPtr,
+ int* colorCount);
SkSampler* getSampler(bool createIfNecessary) override {
SkASSERT(fSwizzler);
return fSwizzler;
}
+ void allocateStorage(const SkImageInfo& dstInfo);
+
+ virtual int readRows(const SkImageInfo& dstInfo, void* dst, size_t rowBytes, int count,
+ int startRow) = 0;
SkPngCodec(int width, int height, const SkEncodedInfo&, SkStream*, SkPngChunkReader*,
png_structp, png_infop, int, int, sk_sp<SkColorSpace>);
- png_structp png_ptr() { return fPng_ptr; }
- SkSwizzler* swizzler() { return fSwizzler; }
- int numberPasses() const { return fNumberPasses; }
-
-private:
- SkAutoTUnref<SkPngChunkReader> fPngChunkReader;
- png_structp fPng_ptr;
- png_infop fInfo_ptr;
+ SkAutoTUnref<SkPngChunkReader> fPngChunkReader;
+ png_structp fPng_ptr;
+ png_infop fInfo_ptr;
// These are stored here so they can be used both by normal decoding and scanline decoding.
- SkAutoTUnref<SkColorTable> fColorTable; // May be unpremul.
- SkAutoTDelete<SkSwizzler> fSwizzler;
+ SkAutoTUnref<SkColorTable> fColorTable; // May be unpremul.
+ SkAutoTDelete<SkSwizzler> fSwizzler;
+ std::unique_ptr<SkColorSpaceXform> fColorXform;
+ SkAutoTMalloc<uint8_t> fStorage;
+ uint8_t* fSwizzlerSrcRow;
+ uint32_t* fColorXformSrcRow;
+ size_t fSrcRowBytes;
- const int fNumberPasses;
- int fBitDepth;
+ const int fNumberPasses;
+ int fBitDepth;
+private:
bool createColorTable(SkColorType dstColorType, bool premultiply, int* ctableCount);
void destroyReadStruct();
dstSpace, kFromLinear);
}
-template <>
-void SkColorSpaceXform_Base<SkColorSpace::kSRGB_GammaNamed>
-::applyToRGBA(RGBA32* dst, const RGBA32* src, int len) const
-{
- if (fColorLUT) {
- handle_color_lut(dst, src, len, fColorLUT.get());
- src = dst;
- }
-
- color_xform_RGBA<SkColorSpace::kSRGB_GammaNamed, false, false>
- (dst, src, len, fSrcGammaTables, fSrcToDst, fDstGammaTables);
-}
-
-template <>
-void SkColorSpaceXform_Base<SkColorSpace::k2Dot2Curve_GammaNamed>
-::applyToRGBA(RGBA32* dst, const RGBA32* src, int len) const
-{
- if (fColorLUT) {
- handle_color_lut(dst, src, len, fColorLUT.get());
- src = dst;
- }
-
- color_xform_RGBA<SkColorSpace::k2Dot2Curve_GammaNamed, false, false>
- (dst, src, len, fSrcGammaTables, fSrcToDst, fDstGammaTables);
-}
-
-template <>
-void SkColorSpaceXform_Base<SkColorSpace::kNonStandard_GammaNamed>
-::applyToRGBA(RGBA32* dst, const RGBA32* src, int len) const
-{
- if (fColorLUT) {
- handle_color_lut(dst, src, len, fColorLUT.get());
- src = dst;
- }
-
- color_xform_RGBA<SkColorSpace::kNonStandard_GammaNamed, false, false>
- (dst, src, len, fSrcGammaTables, fSrcToDst, fDstGammaTables);
-}
-
-template <>
-void SkColorSpaceXform_Base<SkColorSpace::kSRGB_GammaNamed>
-::applyToBGRA(BGRA32* dst, const RGBA32* src, int len) const
-{
- if (fColorLUT) {
- handle_color_lut(dst, src, len, fColorLUT.get());
- src = dst;
- }
-
- color_xform_RGBA<SkColorSpace::kSRGB_GammaNamed, false, true>
- (dst, src, len, fSrcGammaTables, fSrcToDst, fDstGammaTables);
-}
-
-template <>
-void SkColorSpaceXform_Base<SkColorSpace::k2Dot2Curve_GammaNamed>
-::applyToBGRA(BGRA32* dst, const RGBA32* src, int len) const
-{
- if (fColorLUT) {
- handle_color_lut(dst, src, len, fColorLUT.get());
- src = dst;
- }
-
- color_xform_RGBA<SkColorSpace::k2Dot2Curve_GammaNamed, false, true>
- (dst, src, len, fSrcGammaTables, fSrcToDst, fDstGammaTables);
-}
-
-template <>
-void SkColorSpaceXform_Base<SkColorSpace::kNonStandard_GammaNamed>
-::applyToBGRA(BGRA32* dst, const RGBA32* src, int len) const
-{
- if (fColorLUT) {
- handle_color_lut(dst, src, len, fColorLUT.get());
- src = dst;
- }
-
- color_xform_RGBA<SkColorSpace::kNonStandard_GammaNamed, false, true>
- (dst, src, len, fSrcGammaTables, fSrcToDst, fDstGammaTables);
-}
-
-template <SkColorSpace::GammaNamed T>
-void SkColorSpaceXform_Base<T>
-::applyToF16(RGBAF16* dst, const RGBA32* src, int len) const
+template <SkColorSpace::GammaNamed kDst>
+void SkColorSpaceXform_Base<kDst>
+::apply(void* dst, const uint32_t* src, int len, SkColorType dstColorType, SkAlphaType dstAlphaType)
+const
{
if (fColorLUT) {
- size_t storageBytes = len * sizeof(RGBA32);
+ size_t storageBytes = len * sizeof(uint32_t);
#if defined(GOOGLE3)
// Stack frame size is limited in GOOGLE3.
- SkAutoSMalloc<256 * sizeof(RGBA32)> storage(storageBytes);
+ SkAutoSMalloc<256 * sizeof(uint32_t)> storage(storageBytes);
#else
- SkAutoSMalloc<1024 * sizeof(RGBA32)> storage(storageBytes);
+ SkAutoSMalloc<1024 * sizeof(uint32_t)> storage(storageBytes);
#endif
- handle_color_lut((RGBA32*) storage.get(), src, len, fColorLUT.get());
- src = (const RGBA32*) storage.get();
+ handle_color_lut((uint32_t*) storage.get(), src, len, fColorLUT.get());
+ src = (const uint32_t*) storage.get();
}
- color_xform_RGBA<SkColorSpace::kLinear_GammaNamed, false, false>
- (dst, src, len, fSrcGammaTables, fSrcToDst, fDstGammaTables);
+ switch (dstAlphaType) {
+ case kPremul_SkAlphaType:
+ switch (dstColorType) {
+ case kRGBA_8888_SkColorType:
+ return color_xform_RGBA<kDst, kPremul_SkAlphaType, kNo_SwapRB>
+ (dst, src, len, fSrcGammaTables, fSrcToDst, fDstGammaTables);
+ case kBGRA_8888_SkColorType:
+ return color_xform_RGBA<kDst, kPremul_SkAlphaType, kYes_SwapRB>
+ (dst, src, len, fSrcGammaTables, fSrcToDst, fDstGammaTables);
+ case kRGBA_F16_SkColorType:
+ return color_xform_RGBA
+ <SkColorSpace::kLinear_GammaNamed, kPremul_SkAlphaType, kNo_SwapRB>
+ (dst, src, len, fSrcGammaTables, fSrcToDst, fDstGammaTables);
+ default:
+ SkASSERT(false);
+ return;
+ }
+ break;
+ case kUnpremul_SkAlphaType:
+ switch (dstColorType) {
+ case kRGBA_8888_SkColorType:
+ return color_xform_RGBA<kDst, kUnpremul_SkAlphaType, kNo_SwapRB>
+ (dst, src, len, fSrcGammaTables, fSrcToDst, fDstGammaTables);
+ case kBGRA_8888_SkColorType:
+ return color_xform_RGBA<kDst, kUnpremul_SkAlphaType, kYes_SwapRB>
+ (dst, src, len, fSrcGammaTables, fSrcToDst, fDstGammaTables);
+ case kRGBA_F16_SkColorType:
+ return color_xform_RGBA
+ <SkColorSpace::kLinear_GammaNamed, kUnpremul_SkAlphaType, kNo_SwapRB>
+ (dst, src, len, fSrcGammaTables, fSrcToDst, fDstGammaTables);
+ default:
+ SkASSERT(false);
+ return;
+ }
+ case kOpaque_SkAlphaType:
+ switch (dstColorType) {
+ case kRGBA_8888_SkColorType:
+ return color_xform_RGBA<kDst, kOpaque_SkAlphaType, kNo_SwapRB>
+ (dst, src, len, fSrcGammaTables, fSrcToDst, fDstGammaTables);
+ case kBGRA_8888_SkColorType:
+ return color_xform_RGBA<kDst, kOpaque_SkAlphaType, kYes_SwapRB>
+ (dst, src, len, fSrcGammaTables, fSrcToDst, fDstGammaTables);
+ case kRGBA_F16_SkColorType:
+ return color_xform_RGBA
+ <SkColorSpace::kLinear_GammaNamed, kOpaque_SkAlphaType, kNo_SwapRB>
+ (dst, src, len, fSrcGammaTables, fSrcToDst, fDstGammaTables);
+ default:
+ SkASSERT(false);
+ return;
+ }
+ default:
+ SkASSERT(false);
+ return;
+ }
}
#include "SkColorSpace.h"
#include "SkColorSpace_Base.h"
+#include "SkImageInfo.h"
class SkColorSpaceXform : SkNoncopyable {
public:
- typedef uint32_t RGBA32;
- typedef uint32_t BGRA32;
- typedef uint64_t RGBAF16;
-
/**
* Create an object to handle color space conversions.
*
/**
* Apply the color conversion to a src buffer, storing the output in the dst buffer.
- * The src is stored as RGBA (8888) and is treated as opaque.
- * TODO (msarett): Support non-opaque srcs.
+ * The src is stored as RGBA (8888). The dst is stored in the format indicated by
+ * |dstColorType| and is premultiplied by alpha if |premul| is set.
*/
- virtual void applyToRGBA(RGBA32* dst, const RGBA32* src, int len) const = 0;
- virtual void applyToBGRA(BGRA32* dst, const RGBA32* src, int len) const = 0;
- virtual void applyToF16(RGBAF16* dst, const RGBA32* src, int len) const = 0;
+ virtual void apply(void* dst, const uint32_t* src, int len, SkColorType dstColorType,
+ SkAlphaType dstAlphaType) const = 0;
virtual ~SkColorSpaceXform() {}
};
-template <SkColorSpace::GammaNamed Dst>
+template <SkColorSpace::GammaNamed kDst>
class SkColorSpaceXform_Base : public SkColorSpaceXform {
public:
- void applyToRGBA(RGBA32* dst, const RGBA32* src, int len) const override;
- void applyToBGRA(BGRA32* dst, const RGBA32* src, int len) const override;
- void applyToF16(RGBAF16* dst, const RGBA32* src, int len) const override;
+ void apply(void* dst, const uint32_t* src, int len, SkColorType dstColorType,
+ SkAlphaType dstAlphaType) const override;
static constexpr int kDstGammaTableSize = 1024;
#include "SkSRGB.h"
#include "SkTemplates.h"
+enum SwapRB {
+ kNo_SwapRB,
+ kYes_SwapRB,
+};
+
static inline void load_matrix(const float matrix[16],
Sk4f& rXgXbX, Sk4f& rYgYbY, Sk4f& rZgZbZ, Sk4f& rTgTbT) {
rXgXbX = Sk4f::Load(matrix + 0);
static inline void store_srgb(void* dst, const uint32_t* src,
Sk4f& dr, Sk4f& dg, Sk4f& db, Sk4f&,
- const uint8_t* const[3], bool kSwapRB) {
+ const uint8_t* const[3], SwapRB kSwapRB) {
int kRShift = 0;
int kGShift = 8;
int kBShift = 16;
- int kAShift = 24;
- if (kSwapRB) {
+ if (kYes_SwapRB == kSwapRB) {
kBShift = 0;
kRShift = 16;
}
dg = sk_clamp_0_255(dg);
db = sk_clamp_0_255(db);
- Sk4i da = SkNx_cast<int32_t>(Sk4u::Load(src) >> 24);
+ Sk4i da = Sk4i::Load(src) & 0xFF000000;
Sk4i rgba = (SkNx_cast<int>(dr) << kRShift)
| (SkNx_cast<int>(dg) << kGShift)
| (SkNx_cast<int>(db) << kBShift)
- | (da << kAShift);
+ | (da );
rgba.store(dst);
}
static inline void store_srgb_1(void* dst, const uint32_t* src,
Sk4f& rgba, const Sk4f&,
- const uint8_t* const[3], bool kSwapRB) {
+ const uint8_t* const[3], SwapRB kSwapRB) {
rgba = sk_clamp_0_255(sk_linear_to_srgb_needs_trunc(rgba));
uint32_t tmp;
SkNx_cast<uint8_t>(SkNx_cast<int32_t>(rgba)).store(&tmp);
tmp = (*src & 0xFF000000) | (tmp & 0x00FFFFFF);
- if (kSwapRB) {
+ if (kYes_SwapRB == kSwapRB) {
tmp = SkSwizzle_RB(tmp);
}
static inline void store_2dot2(void* dst, const uint32_t* src,
Sk4f& dr, Sk4f& dg, Sk4f& db, Sk4f&,
- const uint8_t* const[3], bool kSwapRB) {
+ const uint8_t* const[3], SwapRB kSwapRB) {
int kRShift = 0;
int kGShift = 8;
int kBShift = 16;
- int kAShift = 24;
- if (kSwapRB) {
+ if (kYes_SwapRB == kSwapRB) {
kBShift = 0;
kRShift = 16;
}
dg = sk_clamp_0_255(dg);
db = sk_clamp_0_255(db);
- Sk4i da = SkNx_cast<int32_t>(Sk4u::Load(src) >> 24);
+ Sk4i da = Sk4i::Load(src) & 0xFF000000;
Sk4i rgba = (Sk4f_round(dr) << kRShift)
| (Sk4f_round(dg) << kGShift)
| (Sk4f_round(db) << kBShift)
- | (da << kAShift);
+ | (da );
rgba.store(dst);
}
static inline void store_2dot2_1(void* dst, const uint32_t* src,
Sk4f& rgba, const Sk4f&,
- const uint8_t* const[3], bool kSwapRB) {
+ const uint8_t* const[3], SwapRB kSwapRB) {
rgba = sk_clamp_0_255(linear_to_2dot2(rgba));
uint32_t tmp;
SkNx_cast<uint8_t>(Sk4f_round(rgba)).store(&tmp);
tmp = (*src & 0xFF000000) | (tmp & 0x00FFFFFF);
- if (kSwapRB) {
+ if (kYes_SwapRB == kSwapRB) {
tmp = SkSwizzle_RB(tmp);
}
static inline void store_f16(void* dst, const uint32_t* src,
Sk4f& dr, Sk4f& dg, Sk4f& db, Sk4f& da,
- const uint8_t* const[3], bool kSwapRB) {
+ const uint8_t* const[3], SwapRB) {
Sk4h_store4(dst, SkFloatToHalf_finite(dr),
SkFloatToHalf_finite(dg),
SkFloatToHalf_finite(db),
SkFloatToHalf_finite(da));
- dst = SkTAddOffset<void>(dst, 4 * sizeof(uint64_t));
}
static inline void store_f16_1(void* dst, const uint32_t* src,
Sk4f& rgba, const Sk4f& a,
- const uint8_t* const[3], bool kSwapRB) {
+ const uint8_t* const[3], SwapRB kSwapRB) {
rgba = Sk4f(rgba[0], rgba[1], rgba[2], a[3]);
SkFloatToHalf_finite(rgba).store((uint64_t*) dst);
}
+static inline void store_f16_opaque(void* dst, const uint32_t* src,
+ Sk4f& dr, Sk4f& dg, Sk4f& db, Sk4f& da,
+ const uint8_t* const[3], SwapRB) {
+ Sk4h_store4(dst, SkFloatToHalf_finite(dr),
+ SkFloatToHalf_finite(dg),
+ SkFloatToHalf_finite(db),
+ SK_Half1);
+}
+
+static inline void store_f16_1_opaque(void* dst, const uint32_t* src,
+ Sk4f& rgba, const Sk4f& a,
+ const uint8_t* const[3], SwapRB kSwapRB) {
+ uint64_t tmp;
+ SkFloatToHalf_finite(rgba).store(&tmp);
+ tmp |= static_cast<uint64_t>(SK_Half1) << 48;
+ *((uint64_t*) dst) = tmp;
+}
+
static inline void store_generic(void* dst, const uint32_t* src,
Sk4f& dr, Sk4f& dg, Sk4f& db, Sk4f&,
- const uint8_t* const dstTables[3], bool kSwapRB) {
+ const uint8_t* const dstTables[3], SwapRB kSwapRB) {
int kRShift = 0;
int kGShift = 8;
int kBShift = 16;
- int kAShift = 24;
- if (kSwapRB) {
+ if (kYes_SwapRB == kSwapRB) {
kBShift = 0;
kRShift = 16;
}
Sk4i ig = Sk4f_round(dg);
Sk4i ib = Sk4f_round(db);
- Sk4i da = SkNx_cast<int32_t>(Sk4u::Load(src) >> 24);
+ Sk4i da = Sk4i::Load(src) & 0xFF000000;
uint32_t* dst32 = (uint32_t*) dst;
dst32[0] = dstTables[0][ir[0]] << kRShift
| dstTables[1][ig[0]] << kGShift
| dstTables[2][ib[0]] << kBShift
- | da[0] << kAShift;
+ | da[0];
dst32[1] = dstTables[0][ir[1]] << kRShift
| dstTables[1][ig[1]] << kGShift
| dstTables[2][ib[1]] << kBShift
- | da[1] << kAShift;
+ | da[1];
dst32[2] = dstTables[0][ir[2]] << kRShift
| dstTables[1][ig[2]] << kGShift
| dstTables[2][ib[2]] << kBShift
- | da[2] << kAShift;
+ | da[2];
dst32[3] = dstTables[0][ir[3]] << kRShift
| dstTables[1][ig[3]] << kGShift
| dstTables[2][ib[3]] << kBShift
- | da[3] << kAShift;
+ | da[3];
}
static inline void store_generic_1(void* dst, const uint32_t* src,
Sk4f& rgba, const Sk4f&,
- const uint8_t* const dstTables[3], bool kSwapRB) {
+ const uint8_t* const dstTables[3], SwapRB kSwapRB) {
rgba = Sk4f::Min(Sk4f::Max(1023.0f * rgba, 0.0f), 1023.0f);
Sk4i indices = Sk4f_round(rgba);
| (*src & 0xFF000000);
}
-template <SkColorSpace::GammaNamed kDstGamma, bool kPremul, bool kSwapRB>
+template <SkColorSpace::GammaNamed kDstGamma, SkAlphaType kAlphaType, SwapRB kSwapRB>
static void color_xform_RGBA(void* dst, const uint32_t* src, int len,
const float* const srcTables[3], const float matrix[16],
const uint8_t* const dstTables[3]) {
size_t sizeOfDstPixel;
switch (kDstGamma) {
case SkColorSpace::kSRGB_GammaNamed:
- load = kPremul ? load_rgba_from_tables : load_rgb_from_tables;
- load_1 = kPremul ? load_rgba_from_tables_1 : load_rgb_from_tables_1;
+ load = (kPremul_SkAlphaType == kAlphaType) ? load_rgba_from_tables :
+ load_rgb_from_tables;
+ load_1 = (kPremul_SkAlphaType == kAlphaType) ? load_rgba_from_tables_1 :
+ load_rgb_from_tables_1;
store = store_srgb;
store_1 = store_srgb_1;
sizeOfDstPixel = 4;
break;
case SkColorSpace::k2Dot2Curve_GammaNamed:
- load = kPremul ? load_rgba_from_tables : load_rgb_from_tables;
- load_1 = kPremul ? load_rgba_from_tables_1 : load_rgb_from_tables_1;
+ load = (kPremul_SkAlphaType == kAlphaType) ? load_rgba_from_tables :
+ load_rgb_from_tables;
+ load_1 = (kPremul_SkAlphaType == kAlphaType) ? load_rgba_from_tables_1 :
+ load_rgb_from_tables_1;
store = store_2dot2;
store_1 = store_2dot2_1;
sizeOfDstPixel = 4;
case SkColorSpace::kLinear_GammaNamed:
load = load_rgba_from_tables;
load_1 = load_rgba_from_tables_1;
- store = store_f16;
- store_1 = store_f16_1;
+ store = (kOpaque_SkAlphaType == kAlphaType) ? store_f16_opaque :
+ store_f16;
+ store_1 = (kOpaque_SkAlphaType == kAlphaType) ? store_f16_1_opaque :
+ store_f16_1;
sizeOfDstPixel = 8;
break;
case SkColorSpace::kNonStandard_GammaNamed:
- load = kPremul ? load_rgba_from_tables : load_rgb_from_tables;
- load_1 = kPremul ? load_rgba_from_tables_1 : load_rgb_from_tables_1;
+ load = (kPremul_SkAlphaType == kAlphaType) ? load_rgba_from_tables :
+ load_rgb_from_tables;
+ load_1 = (kPremul_SkAlphaType == kAlphaType) ? load_rgba_from_tables_1 :
+ load_rgb_from_tables_1;
store = store_generic;
store_1 = store_generic_1;
sizeOfDstPixel = 4;
transform_gamut(r, g, b, a, rXgXbX, rYgYbY, rZgZbZ, dr, dg, db, da);
translate_gamut(rTgTbT, dr, dg, db);
- if (kPremul) {
+ if (kPremul_SkAlphaType == kAlphaType) {
premultiply(dr, dg, db, da);
}
transform_gamut(r, g, b, a, rXgXbX, rYgYbY, rZgZbZ, dr, dg, db, da);
translate_gamut(rTgTbT, dr, dg, db);
- if (kPremul) {
+ if (kPremul_SkAlphaType == kAlphaType) {
premultiply(dr, dg, db, da);
}
// Create and perform an identity xform.
std::unique_ptr<SkColorSpaceXform> xform = ColorSpaceXformTest::CreateIdentityXform(gammas);
- xform->applyToRGBA(dstPixels, srcPixels, width);
+ xform->apply(dstPixels, srcPixels, width, kRGBA_8888_SkColorType, kOpaque_SkAlphaType);
// Since the src->dst matrix is the identity, and the gamma curves match,
// the pixels should be unchanged.