* found in the LICENSE file.
*/
-#include "SkBitmap.h"
-#include "SkCanvas.h"
#include "SkColorSpaceXform.h"
#include "SkColorSpaceXformPriv.h"
-#include "SkConfig8888.h"
-#include "SkColorPriv.h"
-#include "SkDither.h"
+#include "SkColorTable.h"
+#include "SkConvertPixels.h"
#include "SkImageInfoPriv.h"
-#include "SkMathPriv.h"
#include "SkOpts.h"
#include "SkPM4fPriv.h"
#include "SkRasterPipeline.h"
+#include "SkUnPreMultiply.h"
#include "SkUnPreMultiplyPriv.h"
// Fast Path 1: The memcpy() case.
SkColorSpace::Equals(dstInfo.colorSpace(), srcInfo.colorSpace());
}
+// Fast Path 2: Simple swizzles and premuls.
enum AlphaVerb {
kNothing_AlphaVerb,
kPremul_AlphaVerb,
SkUnpremultiplyRow<kSwapRB>(dst, (const uint32_t*) src, count);
}
-// Fast Path 2: Simple swizzles and premuls.
void swizzle_and_multiply(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRB,
const SkImageInfo& srcInfo, const void* srcPixels, size_t srcRB) {
void (*proc)(uint32_t* dst, const void* src, int count);
}
}
-// Default: Use the pipeline.
-static void copy_pipeline_pixels(const SkImageInfo& dstInfo, void* dstRow, size_t dstRB,
- const SkImageInfo& srcInfo, const void* srcRow, size_t srcRB,
- bool isColorAware) {
- SkRasterPipeline pipeline;
- switch (srcInfo.colorType()) {
- case kRGBA_8888_SkColorType:
- pipeline.append(SkRasterPipeline::load_8888, &srcRow);
- break;
- case kBGRA_8888_SkColorType:
- pipeline.append(SkRasterPipeline::load_8888, &srcRow);
- pipeline.append(SkRasterPipeline::swap_rb);
- break;
- case kRGB_565_SkColorType:
- pipeline.append(SkRasterPipeline::load_565, &srcRow);
- break;
- case kRGBA_F16_SkColorType:
- pipeline.append(SkRasterPipeline::load_f16, &srcRow);
- break;
- case kGray_8_SkColorType:
- pipeline.append(SkRasterPipeline::load_g8, &srcRow);
- break;
- case kARGB_4444_SkColorType:
- pipeline.append(SkRasterPipeline::load_4444, &srcRow);
- break;
- default:
- SkASSERT(false);
- break;
- }
-
- if (isColorAware && srcInfo.gammaCloseToSRGB()) {
- pipeline.append_from_srgb(srcInfo.alphaType());
- }
-
- float matrix[12];
- if (isColorAware) {
- SkAssertResult(append_gamut_transform(&pipeline, matrix, srcInfo.colorSpace(),
- dstInfo.colorSpace()));
- }
-
- SkAlphaType sat = srcInfo.alphaType();
- SkAlphaType dat = dstInfo.alphaType();
- if (sat == kPremul_SkAlphaType && dat == kUnpremul_SkAlphaType) {
- pipeline.append(SkRasterPipeline::unpremul);
- } else if (sat == kUnpremul_SkAlphaType && dat == kPremul_SkAlphaType) {
- pipeline.append(SkRasterPipeline::premul);
- }
-
- if (isColorAware && dstInfo.gammaCloseToSRGB()) {
- pipeline.append(SkRasterPipeline::to_srgb);
- }
-
- switch (dstInfo.colorType()) {
- case kRGBA_8888_SkColorType:
- pipeline.append(SkRasterPipeline::store_8888, &dstRow);
- break;
- case kBGRA_8888_SkColorType:
- pipeline.append(SkRasterPipeline::swap_rb);
- pipeline.append(SkRasterPipeline::store_8888, &dstRow);
- break;
- case kRGB_565_SkColorType:
- pipeline.append(SkRasterPipeline::store_565, &dstRow);
- break;
- case kRGBA_F16_SkColorType:
- pipeline.append(SkRasterPipeline::store_f16, &dstRow);
- break;
- case kAlpha_8_SkColorType:
- pipeline.append(SkRasterPipeline::store_a8, &dstRow);
- break;
- case kARGB_4444_SkColorType:
- pipeline.append(SkRasterPipeline::store_4444, &dstRow);
- break;
- default:
- SkASSERT(false);
- break;
- }
-
- auto p = pipeline.compile();
-
- for (int y = 0; y < srcInfo.height(); ++y) {
- p(0,srcInfo.width());
- // The pipeline has pointers to srcRow and dstRow, so we just need to update them in the
- // loop to move between rows of src/dst.
- dstRow = SkTAddOffset<void>(dstRow, dstRB);
- srcRow = SkTAddOffset<const void>(srcRow, srcRB);
- }
-}
-
// Fast Path 3: Color space xform.
static inline bool optimized_color_xform(const SkImageInfo& dstInfo, const SkImageInfo& srcInfo) {
if (kUnpremul_SkAlphaType == dstInfo.alphaType() && kPremul_SkAlphaType == srcInfo.alphaType())
SkImageInfo srcInfo8888 = srcInfo.makeColorType(kN32_SkColorType).makeWH(count, 1);
SkImageInfo dstInfoCT = dstInfo.makeWH(count, 1);
size_t rowBytes = count * sizeof(T);
- SkPixelInfo::CopyPixels(dstInfoCT, dstCTable, rowBytes, srcInfo8888, ctable->readColors(),
- rowBytes, nullptr);
+ SkConvertPixels(dstInfoCT, dstCTable, rowBytes, srcInfo8888, ctable->readColors(), rowBytes,
+ nullptr);
for (int y = 0; y < dstInfo.height(); y++) {
for (int x = 0; x < dstInfo.width(); x++) {
}
}
-void xform_from_index8(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRB,
- const SkImageInfo& srcInfo, const uint8_t* srcPixels, size_t srcRB,
- SkColorTable* ctable) {
+void convert_from_index8(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRB,
+ const SkImageInfo& srcInfo, const uint8_t* srcPixels, size_t srcRB,
+ SkColorTable* ctable) {
switch (dstInfo.colorType()) {
case kAlpha_8_SkColorType:
do_index8(dstInfo, (uint8_t*) dstPixels, dstRB, srcInfo, srcPixels, srcRB, ctable);
}
}
-void SkPixelInfo::CopyPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRB,
- const SkImageInfo& srcInfo, const void* srcPixels, size_t srcRB,
- SkColorTable* ctable) {
+// Default: Use the pipeline.
+static void convert_with_pipeline(const SkImageInfo& dstInfo, void* dstRow, size_t dstRB,
+ const SkImageInfo& srcInfo, const void* srcRow, size_t srcRB,
+ bool isColorAware) {
+ SkRasterPipeline pipeline;
+ switch (srcInfo.colorType()) {
+ case kRGBA_8888_SkColorType:
+ pipeline.append(SkRasterPipeline::load_8888, &srcRow);
+ break;
+ case kBGRA_8888_SkColorType:
+ pipeline.append(SkRasterPipeline::load_8888, &srcRow);
+ pipeline.append(SkRasterPipeline::swap_rb);
+ break;
+ case kRGB_565_SkColorType:
+ pipeline.append(SkRasterPipeline::load_565, &srcRow);
+ break;
+ case kRGBA_F16_SkColorType:
+ pipeline.append(SkRasterPipeline::load_f16, &srcRow);
+ break;
+ case kGray_8_SkColorType:
+ pipeline.append(SkRasterPipeline::load_g8, &srcRow);
+ break;
+ case kARGB_4444_SkColorType:
+ pipeline.append(SkRasterPipeline::load_4444, &srcRow);
+ break;
+ default:
+ SkASSERT(false);
+ break;
+ }
+
+ if (isColorAware && srcInfo.gammaCloseToSRGB()) {
+ pipeline.append_from_srgb(srcInfo.alphaType());
+ }
+
+ float matrix[12];
+ if (isColorAware) {
+ SkAssertResult(append_gamut_transform(&pipeline, matrix, srcInfo.colorSpace(),
+ dstInfo.colorSpace()));
+ }
+
+ SkAlphaType sat = srcInfo.alphaType();
+ SkAlphaType dat = dstInfo.alphaType();
+ if (sat == kPremul_SkAlphaType && dat == kUnpremul_SkAlphaType) {
+ pipeline.append(SkRasterPipeline::unpremul);
+ } else if (sat == kUnpremul_SkAlphaType && dat == kPremul_SkAlphaType) {
+ pipeline.append(SkRasterPipeline::premul);
+ }
+
+ if (isColorAware && dstInfo.gammaCloseToSRGB()) {
+ pipeline.append(SkRasterPipeline::to_srgb);
+ }
+
+ switch (dstInfo.colorType()) {
+ case kRGBA_8888_SkColorType:
+ pipeline.append(SkRasterPipeline::store_8888, &dstRow);
+ break;
+ case kBGRA_8888_SkColorType:
+ pipeline.append(SkRasterPipeline::swap_rb);
+ pipeline.append(SkRasterPipeline::store_8888, &dstRow);
+ break;
+ case kRGB_565_SkColorType:
+ pipeline.append(SkRasterPipeline::store_565, &dstRow);
+ break;
+ case kRGBA_F16_SkColorType:
+ pipeline.append(SkRasterPipeline::store_f16, &dstRow);
+ break;
+ case kAlpha_8_SkColorType:
+ pipeline.append(SkRasterPipeline::store_a8, &dstRow);
+ break;
+ case kARGB_4444_SkColorType:
+ pipeline.append(SkRasterPipeline::store_4444, &dstRow);
+ break;
+ default:
+ SkASSERT(false);
+ break;
+ }
+
+ auto p = pipeline.compile();
+
+ for (int y = 0; y < srcInfo.height(); ++y) {
+ p(0,srcInfo.width());
+ // The pipeline has pointers to srcRow and dstRow, so we just need to update them in the
+ // loop to move between rows of src/dst.
+ dstRow = SkTAddOffset<void>(dstRow, dstRB);
+ srcRow = SkTAddOffset<const void>(srcRow, srcRB);
+ }
+}
+
+void SkConvertPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRB,
+ const SkImageInfo& srcInfo, const void* srcPixels, size_t srcRB,
+ SkColorTable* ctable) {
SkASSERT(dstInfo.dimensions() == srcInfo.dimensions());
SkASSERT(SkImageInfoValidConversion(dstInfo, srcInfo));
// Fast Path 4: Index 8 sources.
if (kIndex_8_SkColorType == srcInfo.colorType()) {
SkASSERT(ctable);
- xform_from_index8(dstInfo, dstPixels, dstRB, srcInfo, (const uint8_t*) srcPixels, srcRB,
- ctable);
+ convert_from_index8(dstInfo, dstPixels, dstRB, srcInfo, (const uint8_t*) srcPixels, srcRB,
+ ctable);
return;
}
// Default: Use the pipeline.
- copy_pipeline_pixels(dstInfo, dstPixels, dstRB, srcInfo, srcPixels, srcRB, isColorAware);
+ convert_with_pipeline(dstInfo, dstPixels, dstRB, srcInfo, srcPixels, srcRB, isColorAware);
}