25#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
43 uint8_t* dst8 = (uint8_t*)
dst;
53 uint16_t* dst16 = (uint16_t*)
dst;
55 dst16[
x] = *((
const uint16_t*)
src);
63 uint32_t* dst32 = (uint32_t*)
dst;
65 dst32[
x] = *((
const uint32_t*)
src);
73 uint8_t* dst8 = (uint8_t*)
dst;
84 uint64_t* dst64 = (uint64_t*)
dst;
86 dst64[
x] = *((
const uint64_t*)
src);
94#define GRAYSCALE_BLACK 0
95#define GRAYSCALE_WHITE 0xFF
107 int bitIndex =
offset % 8;
108 uint8_t currByte = *
src;
112 for (
int x = 1;
x < dstWidth;
x++) {
113 int bitOffset = bitIndex + deltaSrc;
114 bitIndex = bitOffset % 8;
115 currByte = *(
src += bitOffset / 8);
120#undef GRAYSCALE_BLACK
121#undef GRAYSCALE_WHITE
131 int bitIndex =
offset % 8;
132 uint8_t currByte = *
src;
136 for (
int x = 1;
x < dstWidth;
x++) {
137 int bitOffset = bitIndex + deltaSrc;
138 bitIndex = bitOffset % 8;
139 currByte = *(
src += bitOffset / 8);
144#define RGB565_BLACK 0
145#define RGB565_WHITE 0xFFFF
154 int bitIndex =
offset % 8;
155 uint8_t currByte = *
src;
159 for (
int x = 1;
x < dstWidth;
x++) {
160 int bitOffset = bitIndex + deltaSrc;
161 bitIndex = bitOffset % 8;
162 currByte = *(
src += bitOffset / 8);
177 constexpr uint64_t
kBlack = (((uint64_t) 0) << 0) |
178 (((uint64_t) 0) << 16) |
179 (((uint64_t) 0) << 32) |
186 int bitIndex =
offset % 8;
187 uint8_t currByte = *
src;
191 for (
int x = 1;
x < dstWidth;
x++) {
192 int bitOffset = bitIndex + deltaSrc;
193 bitIndex = bitOffset % 8;
194 currByte = *(
src += bitOffset / 8);
205 uint16_t*
dst = (uint16_t*) dstRow;
207 int bitIndex =
offset % 8;
208 uint8_t currByte = *
src;
209 const uint8_t mask = (1 << bpp) - 1;
210 uint8_t index = (currByte >> (8 - bpp - bitIndex)) & mask;
213 for (
int x = 1;
x < dstWidth;
x++) {
214 int bitOffset = bitIndex + deltaSrc;
215 bitIndex = bitOffset % 8;
216 currByte = *(
src += bitOffset / 8);
217 index = (currByte >> (8 - bpp - bitIndex)) & mask;
228 int bitIndex =
offset % 8;
229 uint8_t currByte = *
src;
230 const uint8_t mask = (1 << bpp) - 1;
231 uint8_t index = (currByte >> (8 - bpp - bitIndex)) & mask;
232 dst[0] = ctable[index];
234 for (
int x = 1;
x < dstWidth;
x++) {
235 int bitOffset = bitIndex + deltaSrc;
236 bitIndex = bitOffset % 8;
237 currByte = *(
src += bitOffset / 8);
238 index = (currByte >> (8 - bpp - bitIndex)) & mask;
239 dst[
x] = ctable[index];
251 for (
int x = 0;
x < dstWidth;
x++) {
264 for (
int x = 0;
x < dstWidth;
x++) {
275 int bytesPerPixel,
int deltaSrc,
int offset,
const SkPMColor ctable[]) {
278 for (
int x = 0;
x < dstWidth;
x++) {
292 for (
int x = 0;
x < dstWidth;
x++) {
313 int bytesPerPixel,
int deltaSrc,
int offset,
const SkPMColor ctable[]) {
317 for (
int x = 0;
x < dstWidth;
x++) {
379 uint8_t* dst8 = (uint8_t*)
dst;
394 for (
int x = 0;
x < dstWidth;
x++) {
408 for (
int x = 0;
x < dstWidth;
x++) {
420 for (
int x = 0;
x < dstWidth;
x++) {
427 void*
dst,
const uint8_t*
src,
int width,
int bpp,
int deltaSrc,
438 void*
dst,
const uint8_t*
src,
int width,
int bpp,
int deltaSrc,
450 int bytesPerPixel,
int deltaSrc,
int offset,
const SkPMColor ctable[]) {
454 for (
int x = 0;
x < dstWidth;
x++) {
468 for (
int x = 0;
x < dstWidth;
x++) {
480 for (
int x = 0;
x < dstWidth;
x++) {
487 void*
dst,
const uint8_t*
src,
int width,
int bpp,
int deltaSrc,
498 void*
dst,
const uint8_t*
src,
int width,
int bpp,
int deltaSrc,
514 for (
int x = 0;
x < dstWidth;
x++) {
515 unsigned alpha =
src[3];
537 auto strip16to8 = [](
const uint8_t* ptr) {
538 return 0xFF000000 | (ptr[4] << 16) | (ptr[2] << 8) | ptr[0];
542 uint32_t* dst32 = (uint32_t*)
dst;
544 dst32[
x] = strip16to8(
src);
552 auto strip16to8 = [](
const uint8_t* ptr) {
553 return 0xFF000000 | (ptr[0] << 16) | (ptr[2] << 8) | ptr[4];
557 uint32_t* dst32 = (uint32_t*)
dst;
559 dst32[
x] = strip16to8(
src);
567 auto strip16to565 = [](
const uint8_t* ptr) {
572 uint16_t* dst16 = (uint16_t*)
dst;
574 dst16[
x] = strip16to565(
src);
582 auto strip16to8 = [](
const uint8_t* ptr) {
583 return (ptr[6] << 24) | (ptr[4] << 16) | (ptr[2] << 8) | ptr[0];
587 uint32_t* dst32 = (uint32_t*)
dst;
589 dst32[
x] = strip16to8(
src);
597 auto stripAndPremul16to8 = [](
const uint8_t* ptr) {
602 uint32_t* dst32 = (uint32_t*)
dst;
604 dst32[
x] = stripAndPremul16to8(
src);
612 auto strip16to8 = [](
const uint8_t* ptr) {
613 return (ptr[6] << 24) | (ptr[0] << 16) | (ptr[2] << 8) | ptr[4];
617 uint32_t* dst32 = (uint32_t*)
dst;
619 dst32[
x] = strip16to8(
src);
627 auto stripAndPremul16to8 = [](
const uint8_t* ptr) {
632 uint32_t* dst32 = (uint32_t*)
dst;
634 dst32[
x] = stripAndPremul16to8(
src);
690 for (
int x = 0;
x < dstWidth;
x++) {
706 for (
int x = 0;
x < dstWidth;
x++) {
744 for (
int x = 0;
x < dstWidth;
x++) {
754template <SkSwizzler::RowProc proc>
755void SkSwizzler::SkipLeadingGrayAlphaZerosThen(
760 const uint16_t* src16 = (
const uint16_t*) (
src +
offset);
761 uint32_t* dst32 = (uint32_t*)
dst;
765 while (
width > 0 && *src16 == 0x0000) {
768 src16 += deltaSrc / 2;
770 proc(dst32, (
const uint8_t*)src16,
width, bpp, deltaSrc, 0, ctable);
773template <SkSwizzler::RowProc proc>
774void SkSwizzler::SkipLeading8888ZerosThen(
779 auto src32 = (
const uint32_t*)(
src+
offset);
780 auto dst32 = (uint32_t*)dstRow;
784 while (dstWidth > 0 && *src32 == 0x00000000) {
789 proc(dst32, (
const uint8_t*)src32, dstWidth, bpp, deltaSrc, 0, ctable);
794 RowProc proc =
nullptr;
817 return Make(dstInfo, &
copy, proc,
nullptr , srcBPP,
830 RowProc fastProc =
nullptr;
831 RowProc proc =
nullptr;
836 switch (encodedInfo.
color()) {
887 proc = &SkipLeadingGrayAlphaZerosThen
889 fastProc = &SkipLeadingGrayAlphaZerosThen
897 proc = &SkipLeadingGrayAlphaZerosThen
899 fastProc = &SkipLeadingGrayAlphaZerosThen
1005 proc = &SkipLeading8888ZerosThen<swizzle_rgba_to_rgba_premul>;
1006 fastProc = &SkipLeading8888ZerosThen
1014 proc = &SkipLeading8888ZerosThen<sample4>;
1015 fastProc = &SkipLeading8888ZerosThen<copy>;
1032 proc = &SkipLeading8888ZerosThen<swizzle_rgba_to_bgra_premul>;
1033 fastProc = &SkipLeading8888ZerosThen
1041 proc = &SkipLeading8888ZerosThen<swizzle_rgba_to_bgra_unpremul>;
1042 fastProc = &SkipLeading8888ZerosThen
1091 proc = &SkipLeading8888ZerosThen<swizzle_rgba_to_rgba_premul>;
1092 fastProc = &SkipLeading8888ZerosThen
1100 proc = &SkipLeading8888ZerosThen<sample4>;
1101 fastProc = &SkipLeading8888ZerosThen<copy>;
1111 proc = &SkipLeading8888ZerosThen<swizzle_rgba_to_bgra_premul>;
1112 fastProc = &SkipLeading8888ZerosThen
1120 proc = &SkipLeading8888ZerosThen<swizzle_rgba_to_bgra_unpremul>;
1121 fastProc = &SkipLeading8888ZerosThen
1156 int srcBPP =
SkIsAlign8(bitsPerPixel) ? bitsPerPixel / 8 : bitsPerPixel;
1158 return Make(dstInfo, fastProc, proc, ctable, srcBPP, dstBPP,
options,
frame);
1162 RowProc fastProc, RowProc proc,
const SkPMColor* ctable,
int srcBPP,
1165 int srcWidth = dstInfo.
width();
1167 int dstWidth = srcWidth;
1172 srcOffset =
options.fSubset->left();
1173 srcWidth =
options.fSubset->width();
1174 dstWidth = srcWidth;
1176 dstOffset =
frame->left();
1177 srcWidth =
frame->width();
1180 return std::unique_ptr<SkSwizzler>(
new SkSwizzler(fastProc, proc, ctable, srcOffset, srcWidth,
1181 dstOffset, dstWidth, srcBPP, dstBPP));
1184SkSwizzler::SkSwizzler(RowProc fastProc, RowProc proc,
const SkPMColor* ctable,
int srcOffset,
1185 int srcWidth,
int dstOffset,
int dstWidth,
int srcBPP,
int dstBPP)
1186 : fFastProc(fastProc)
1188 , fActualProc(fFastProc ? fFastProc : fSlowProc)
1189 , fColorTable(ctable)
1190 , fSrcOffset(srcOffset)
1191 , fDstOffset(dstOffset)
1192 , fSrcOffsetUnits(srcOffset * srcBPP)
1193 , fDstOffsetBytes(dstOffset * dstBPP)
1194 , fSrcWidth(srcWidth)
1195 , fDstWidth(dstWidth)
1196 , fSwizzleWidth(srcWidth)
1197 , fAllocatedWidth(dstWidth)
1203int SkSwizzler::onSetSampleX(
int sampleX) {
1207 fDstOffsetBytes = (fDstOffset /
sampleX) * fDstBPP;
1212 if (fSrcWidth < fDstWidth) {
1219 frameSampleX = fSrcWidth / fSwizzleWidth;
1221 fSrcOffsetUnits = (
get_start_coord(frameSampleX) + fSrcOffset) * fSrcBPP;
1223 if (fDstOffsetBytes > 0) {
1224 const size_t dstSwizzleBytes = fSwizzleWidth * fDstBPP;
1225 const size_t dstAllocatedBytes = fAllocatedWidth * fDstBPP;
1226 if (fDstOffsetBytes + dstSwizzleBytes > dstAllocatedBytes) {
1227#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
1228 SkAndroidFrameworkUtils::SafetyNetLog(
"118143775");
1230 SkASSERT(dstSwizzleBytes <= dstAllocatedBytes);
1231 fDstOffsetBytes = dstAllocatedBytes - dstSwizzleBytes;
1238 if (1 == fSampleX && fFastProc) {
1239 fActualProc = fFastProc;
1241 fActualProc = fSlowProc;
1244 return fAllocatedWidth;
1249 fActualProc(SkTAddOffset<void>(
dst, fDstOffsetBytes),
src, fSwizzleWidth, fSrcBPP,
1250 fSampleX * fSrcBPP, fSrcOffsetUnits, fColorTable);
static constexpr bool SkIsAlign8(T x)
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
static int get_scaled_dimension(int srcDimension, int sampleSize)
static SkPMColor premultiply_argb_as_rgba(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
static SkPMColor premultiply_argb_as_bgra(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
static int get_start_coord(int sampleFactor)
static uint32_t SkPackARGB_as_RGBA(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
static U16CPU SkPack888ToRGB16(U8CPU r, U8CPU g, U8CPU b)
static U16CPU SkPixel32ToPixel16(SkPMColor c)
static uint32_t SkPackARGB_as_BGRA(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
static SkPMColor SkPackARGB32NoCheck(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
@ kBGRA_8888_SkColorType
pixel with 8 bits for blue, green, red, alpha; in 32-bit word
@ kRGBA_F16_SkColorType
pixel with half floats for red, green, blue, alpha;
@ kAlpha_8_SkColorType
pixel with alpha in 8-bit byte
@ kGray_8_SkColorType
pixel with grayscale level in 8-bit byte
@ kRGB_565_SkColorType
pixel with 5 bits red, 6 bits green, 5 bits blue, in 16-bit word
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
@ kBGR_101010x_XR_SkColorType
pixel with 10 bits each for blue, green, red; in 32-bit word, extended range
constexpr SkColor SK_ColorBLACK
constexpr SkColor SK_ColorWHITE
static constexpr uint16_t SK_Half1
static U8CPU SkMulDiv255Round(U16CPU a, U16CPU b)
static void swizzle_cmyk_to_bgra(void *SK_RESTRICT dstRow, const uint8_t *SK_RESTRICT src, int dstWidth, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void sample8(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void swizzle_bgr_to_565(void *SK_RESTRICT dstRow, const uint8_t *SK_RESTRICT src, int dstWidth, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void fast_swizzle_grayalpha_to_n32_premul(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void swizzle_gray_to_565(void *SK_RESTRICT dstRow, const uint8_t *SK_RESTRICT src, int dstWidth, int bytesPerPixel, int deltaSrc, int offset, const SkPMColor ctable[])
static void fast_swizzle_cmyk_to_rgba(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void swizzle_rgb_to_565(void *SK_RESTRICT dstRow, const uint8_t *SK_RESTRICT src, int dstWidth, int bytesPerPixel, int deltaSrc, int offset, const SkPMColor ctable[])
static void fast_swizzle_cmyk_to_bgra(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void swizzle_rgba16_to_bgra_premul(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void swizzle_rgb16_to_565(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void swizzle_rgb_to_rgba(void *SK_RESTRICT dstRow, const uint8_t *SK_RESTRICT src, int dstWidth, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void swizzle_gray_to_n32(void *SK_RESTRICT dstRow, const uint8_t *SK_RESTRICT src, int dstWidth, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void fast_swizzle_rgb_to_rgba(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void swizzle_rgba16_to_rgba_premul(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void swizzle_rgba_to_bgra_unpremul(void *SK_RESTRICT dstRow, const uint8_t *SK_RESTRICT src, int dstWidth, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void swizzle_rgb16_to_bgra(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void sample1(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void swizzle_bit_to_n32(void *SK_RESTRICT dstRow, const uint8_t *SK_RESTRICT src, int dstWidth, int bpp, int deltaSrc, int offset, const SkPMColor *)
static void sample6(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void swizzle_rgba_to_rgba_premul(void *SK_RESTRICT dstRow, const uint8_t *SK_RESTRICT src, int dstWidth, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void swizzle_grayalpha_to_n32_premul(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void fast_swizzle_rgba_to_rgba_premul(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void swizzle_rgba16_to_rgba_unpremul(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void swizzle_rgba16_to_bgra_unpremul(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void swizzle_grayalpha_to_n32_unpremul(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void swizzle_rgb16_to_rgba(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void fast_swizzle_grayalpha_to_n32_unpremul(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void fast_swizzle_gray_to_n32(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void fast_swizzle_rgba_to_bgra_premul(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void swizzle_small_index_to_565(void *SK_RESTRICT dstRow, const uint8_t *SK_RESTRICT src, int dstWidth, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void swizzle_cmyk_to_565(void *SK_RESTRICT dstRow, const uint8_t *SK_RESTRICT src, int dstWidth, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void swizzle_bit_to_f16(void *SK_RESTRICT dstRow, const uint8_t *SK_RESTRICT src, int dstWidth, int bpp, int deltaSrc, int offset, const SkPMColor *)
static void swizzle_cmyk_to_rgba(void *SK_RESTRICT dstRow, const uint8_t *SK_RESTRICT src, int dstWidth, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void swizzle_small_index_to_n32(void *SK_RESTRICT dstRow, const uint8_t *SK_RESTRICT src, int dstWidth, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void copy(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void sample4(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void fast_swizzle_rgb_to_bgra(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void swizzle_index_to_n32(void *SK_RESTRICT dstRow, const uint8_t *SK_RESTRICT src, int dstWidth, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void swizzle_grayalpha_to_a8(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor[])
static void swizzle_rgba_to_bgra_premul(void *SK_RESTRICT dstRow, const uint8_t *SK_RESTRICT src, int dstWidth, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void swizzle_rgb_to_bgra(void *SK_RESTRICT dstRow, const uint8_t *SK_RESTRICT src, int dstWidth, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void swizzle_index_to_n32_skipZ(void *SK_RESTRICT dstRow, const uint8_t *SK_RESTRICT src, int dstWidth, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void swizzle_bit_to_grayscale(void *SK_RESTRICT dstRow, const uint8_t *SK_RESTRICT src, int dstWidth, int bpp, int deltaSrc, int offset, const SkPMColor *)
static void swizzle_index_to_565(void *SK_RESTRICT dstRow, const uint8_t *SK_RESTRICT src, int dstWidth, int bytesPerPixel, int deltaSrc, int offset, const SkPMColor ctable[])
static void sample2(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void fast_swizzle_rgba_to_bgra_unpremul(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void swizzle_bit_to_565(void *SK_RESTRICT dstRow, const uint8_t *SK_RESTRICT src, int dstWidth, int bpp, int deltaSrc, int offset, const SkPMColor *)
static std::unique_ptr< SkSwizzler > MakeSimple(int srcBPP, const SkImageInfo &dstInfo, const SkCodec::Options &)
static std::unique_ptr< SkSwizzler > Make(const SkEncodedInfo &encodedInfo, const SkPMColor *ctable, const SkImageInfo &dstInfo, const SkCodec::Options &, const SkIRect *frame=nullptr)
void swizzle(void *dst, const uint8_t *SK_RESTRICT src)
constexpr SkColor4f kWhite
constexpr SkColor4f kBlack
Swizzle_8888_u8 gray_to_RGB1
Swizzle_8888_u32 RGBA_to_rgbA
Swizzle_8888_u8 RGB_to_RGB1
Swizzle_8888_u8 grayA_to_rgbA
Swizzle_8888_u8 RGB_to_BGR1
Swizzle_8888_u8 grayA_to_RGBA
Swizzle_8888_u32 RGBA_to_BGRA
Swizzle_8888_u32 RGBA_to_bgrA
Swizzle_8888_u32 inverted_CMYK_to_BGR1
Swizzle_8888_u32 inverted_CMYK_to_RGB1
uint8_t bitsPerPixel() const
uint8_t bitsPerComponent() const
int bytesPerPixel() const
SkAlphaType alphaType() const
SkColorType colorType() const