SkMaskSwizzler.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  1. /*
  2. * Copyright 2015 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. #include "include/private/SkColorData.h"
  8. #include "src/codec/SkCodecPriv.h"
  9. #include "src/codec/SkMaskSwizzler.h"
  10. static void swizzle_mask16_to_rgba_opaque(
  11. void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
  12. uint32_t startX, uint32_t sampleX) {
  13. // Use the masks to decode to the destination
  14. uint16_t* srcPtr = ((uint16_t*) srcRow) + startX;
  15. SkPMColor* dstPtr = (SkPMColor*) dstRow;
  16. for (int i = 0; i < width; i++) {
  17. uint16_t p = srcPtr[0];
  18. uint8_t red = masks->getRed(p);
  19. uint8_t green = masks->getGreen(p);
  20. uint8_t blue = masks->getBlue(p);
  21. dstPtr[i] = SkPackARGB_as_RGBA(0xFF, red, green, blue);
  22. srcPtr += sampleX;
  23. }
  24. }
  25. static void swizzle_mask16_to_bgra_opaque(
  26. void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
  27. uint32_t startX, uint32_t sampleX) {
  28. // Use the masks to decode to the destination
  29. uint16_t* srcPtr = ((uint16_t*) srcRow) + startX;
  30. SkPMColor* dstPtr = (SkPMColor*) dstRow;
  31. for (int i = 0; i < width; i++) {
  32. uint16_t p = srcPtr[0];
  33. uint8_t red = masks->getRed(p);
  34. uint8_t green = masks->getGreen(p);
  35. uint8_t blue = masks->getBlue(p);
  36. dstPtr[i] = SkPackARGB_as_BGRA(0xFF, red, green, blue);
  37. srcPtr += sampleX;
  38. }
  39. }
  40. static void swizzle_mask16_to_rgba_unpremul(
  41. void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
  42. uint32_t startX, uint32_t sampleX) {
  43. // Use the masks to decode to the destination
  44. uint16_t* srcPtr = ((uint16_t*) srcRow) + startX;
  45. SkPMColor* dstPtr = (SkPMColor*) dstRow;
  46. for (int i = 0; i < width; i++) {
  47. uint16_t p = srcPtr[0];
  48. uint8_t red = masks->getRed(p);
  49. uint8_t green = masks->getGreen(p);
  50. uint8_t blue = masks->getBlue(p);
  51. uint8_t alpha = masks->getAlpha(p);
  52. dstPtr[i] = SkPackARGB_as_RGBA(alpha, red, green, blue);
  53. srcPtr += sampleX;
  54. }
  55. }
  56. static void swizzle_mask16_to_bgra_unpremul(
  57. void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
  58. uint32_t startX, uint32_t sampleX) {
  59. // Use the masks to decode to the destination
  60. uint16_t* srcPtr = ((uint16_t*) srcRow) + startX;
  61. SkPMColor* dstPtr = (SkPMColor*) dstRow;
  62. for (int i = 0; i < width; i++) {
  63. uint16_t p = srcPtr[0];
  64. uint8_t red = masks->getRed(p);
  65. uint8_t green = masks->getGreen(p);
  66. uint8_t blue = masks->getBlue(p);
  67. uint8_t alpha = masks->getAlpha(p);
  68. dstPtr[i] = SkPackARGB_as_BGRA(alpha, red, green, blue);
  69. srcPtr += sampleX;
  70. }
  71. }
  72. static void swizzle_mask16_to_rgba_premul(
  73. void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
  74. uint32_t startX, uint32_t sampleX) {
  75. // Use the masks to decode to the destination
  76. uint16_t* srcPtr = ((uint16_t*) srcRow) + startX;
  77. SkPMColor* dstPtr = (SkPMColor*) dstRow;
  78. for (int i = 0; i < width; i++) {
  79. uint16_t p = srcPtr[0];
  80. uint8_t red = masks->getRed(p);
  81. uint8_t green = masks->getGreen(p);
  82. uint8_t blue = masks->getBlue(p);
  83. uint8_t alpha = masks->getAlpha(p);
  84. dstPtr[i] = premultiply_argb_as_rgba(alpha, red, green, blue);
  85. srcPtr += sampleX;
  86. }
  87. }
  88. static void swizzle_mask16_to_bgra_premul(
  89. void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
  90. uint32_t startX, uint32_t sampleX) {
  91. // Use the masks to decode to the destination
  92. uint16_t* srcPtr = ((uint16_t*) srcRow) + startX;
  93. SkPMColor* dstPtr = (SkPMColor*) dstRow;
  94. for (int i = 0; i < width; i++) {
  95. uint16_t p = srcPtr[0];
  96. uint8_t red = masks->getRed(p);
  97. uint8_t green = masks->getGreen(p);
  98. uint8_t blue = masks->getBlue(p);
  99. uint8_t alpha = masks->getAlpha(p);
  100. dstPtr[i] = premultiply_argb_as_bgra(alpha, red, green, blue);
  101. srcPtr += sampleX;
  102. }
  103. }
  104. // TODO (msarett): We have promoted a two byte per pixel image to 8888, only to
  105. // convert it back to 565. Instead, we should swizzle to 565 directly.
  106. static void swizzle_mask16_to_565(
  107. void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
  108. uint32_t startX, uint32_t sampleX) {
  109. // Use the masks to decode to the destination
  110. uint16_t* srcPtr = ((uint16_t*) srcRow) + startX;
  111. uint16_t* dstPtr = (uint16_t*) dstRow;
  112. for (int i = 0; i < width; i++) {
  113. uint16_t p = srcPtr[0];
  114. uint8_t red = masks->getRed(p);
  115. uint8_t green = masks->getGreen(p);
  116. uint8_t blue = masks->getBlue(p);
  117. dstPtr[i] = SkPack888ToRGB16(red, green, blue);
  118. srcPtr += sampleX;
  119. }
  120. }
  121. static void swizzle_mask24_to_rgba_opaque(
  122. void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
  123. uint32_t startX, uint32_t sampleX) {
  124. // Use the masks to decode to the destination
  125. srcRow += 3 * startX;
  126. SkPMColor* dstPtr = (SkPMColor*) dstRow;
  127. for (int i = 0; i < width; i++) {
  128. uint32_t p = srcRow[0] | (srcRow[1] << 8) | srcRow[2] << 16;
  129. uint8_t red = masks->getRed(p);
  130. uint8_t green = masks->getGreen(p);
  131. uint8_t blue = masks->getBlue(p);
  132. dstPtr[i] = SkPackARGB_as_RGBA(0xFF, red, green, blue);
  133. srcRow += 3 * sampleX;
  134. }
  135. }
  136. static void swizzle_mask24_to_bgra_opaque(
  137. void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
  138. uint32_t startX, uint32_t sampleX) {
  139. // Use the masks to decode to the destination
  140. srcRow += 3 * startX;
  141. SkPMColor* dstPtr = (SkPMColor*) dstRow;
  142. for (int i = 0; i < width; i++) {
  143. uint32_t p = srcRow[0] | (srcRow[1] << 8) | srcRow[2] << 16;
  144. uint8_t red = masks->getRed(p);
  145. uint8_t green = masks->getGreen(p);
  146. uint8_t blue = masks->getBlue(p);
  147. dstPtr[i] = SkPackARGB_as_BGRA(0xFF, red, green, blue);
  148. srcRow += 3 * sampleX;
  149. }
  150. }
  151. static void swizzle_mask24_to_rgba_unpremul(
  152. void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
  153. uint32_t startX, uint32_t sampleX) {
  154. // Use the masks to decode to the destination
  155. srcRow += 3 * startX;
  156. SkPMColor* dstPtr = (SkPMColor*) dstRow;
  157. for (int i = 0; i < width; i++) {
  158. uint32_t p = srcRow[0] | (srcRow[1] << 8) | srcRow[2] << 16;
  159. uint8_t red = masks->getRed(p);
  160. uint8_t green = masks->getGreen(p);
  161. uint8_t blue = masks->getBlue(p);
  162. uint8_t alpha = masks->getAlpha(p);
  163. dstPtr[i] = SkPackARGB_as_RGBA(alpha, red, green, blue);
  164. srcRow += 3 * sampleX;
  165. }
  166. }
  167. static void swizzle_mask24_to_bgra_unpremul(
  168. void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
  169. uint32_t startX, uint32_t sampleX) {
  170. // Use the masks to decode to the destination
  171. srcRow += 3 * startX;
  172. SkPMColor* dstPtr = (SkPMColor*) dstRow;
  173. for (int i = 0; i < width; i++) {
  174. uint32_t p = srcRow[0] | (srcRow[1] << 8) | srcRow[2] << 16;
  175. uint8_t red = masks->getRed(p);
  176. uint8_t green = masks->getGreen(p);
  177. uint8_t blue = masks->getBlue(p);
  178. uint8_t alpha = masks->getAlpha(p);
  179. dstPtr[i] = SkPackARGB_as_BGRA(alpha, red, green, blue);
  180. srcRow += 3 * sampleX;
  181. }
  182. }
  183. static void swizzle_mask24_to_rgba_premul(
  184. void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
  185. uint32_t startX, uint32_t sampleX) {
  186. // Use the masks to decode to the destination
  187. srcRow += 3 * startX;
  188. SkPMColor* dstPtr = (SkPMColor*) dstRow;
  189. for (int i = 0; i < width; i++) {
  190. uint32_t p = srcRow[0] | (srcRow[1] << 8) | srcRow[2] << 16;
  191. uint8_t red = masks->getRed(p);
  192. uint8_t green = masks->getGreen(p);
  193. uint8_t blue = masks->getBlue(p);
  194. uint8_t alpha = masks->getAlpha(p);
  195. dstPtr[i] = premultiply_argb_as_rgba(alpha, red, green, blue);
  196. srcRow += 3 * sampleX;
  197. }
  198. }
  199. static void swizzle_mask24_to_bgra_premul(
  200. void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
  201. uint32_t startX, uint32_t sampleX) {
  202. // Use the masks to decode to the destination
  203. srcRow += 3 * startX;
  204. SkPMColor* dstPtr = (SkPMColor*) dstRow;
  205. for (int i = 0; i < width; i++) {
  206. uint32_t p = srcRow[0] | (srcRow[1] << 8) | srcRow[2] << 16;
  207. uint8_t red = masks->getRed(p);
  208. uint8_t green = masks->getGreen(p);
  209. uint8_t blue = masks->getBlue(p);
  210. uint8_t alpha = masks->getAlpha(p);
  211. dstPtr[i] = premultiply_argb_as_bgra(alpha, red, green, blue);
  212. srcRow += 3 * sampleX;
  213. }
  214. }
  215. static void swizzle_mask24_to_565(
  216. void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
  217. uint32_t startX, uint32_t sampleX) {
  218. // Use the masks to decode to the destination
  219. srcRow += 3 * startX;
  220. uint16_t* dstPtr = (uint16_t*) dstRow;
  221. for (int i = 0; i < width; i++) {
  222. uint32_t p = srcRow[0] | (srcRow[1] << 8) | srcRow[2] << 16;
  223. uint8_t red = masks->getRed(p);
  224. uint8_t green = masks->getGreen(p);
  225. uint8_t blue = masks->getBlue(p);
  226. dstPtr[i] = SkPack888ToRGB16(red, green, blue);
  227. srcRow += 3 * sampleX;
  228. }
  229. }
  230. static void swizzle_mask32_to_rgba_opaque(
  231. void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
  232. uint32_t startX, uint32_t sampleX) {
  233. // Use the masks to decode to the destination
  234. uint32_t* srcPtr = ((uint32_t*) srcRow) + startX;
  235. SkPMColor* dstPtr = (SkPMColor*) dstRow;
  236. for (int i = 0; i < width; i++) {
  237. uint32_t p = srcPtr[0];
  238. uint8_t red = masks->getRed(p);
  239. uint8_t green = masks->getGreen(p);
  240. uint8_t blue = masks->getBlue(p);
  241. dstPtr[i] = SkPackARGB_as_RGBA(0xFF, red, green, blue);
  242. srcPtr += sampleX;
  243. }
  244. }
  245. static void swizzle_mask32_to_bgra_opaque(
  246. void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
  247. uint32_t startX, uint32_t sampleX) {
  248. // Use the masks to decode to the destination
  249. uint32_t* srcPtr = ((uint32_t*) srcRow) + startX;
  250. SkPMColor* dstPtr = (SkPMColor*) dstRow;
  251. for (int i = 0; i < width; i++) {
  252. uint32_t p = srcPtr[0];
  253. uint8_t red = masks->getRed(p);
  254. uint8_t green = masks->getGreen(p);
  255. uint8_t blue = masks->getBlue(p);
  256. dstPtr[i] = SkPackARGB_as_BGRA(0xFF, red, green, blue);
  257. srcPtr += sampleX;
  258. }
  259. }
  260. static void swizzle_mask32_to_rgba_unpremul(
  261. void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
  262. uint32_t startX, uint32_t sampleX) {
  263. // Use the masks to decode to the destination
  264. uint32_t* srcPtr = ((uint32_t*) srcRow) + startX;
  265. SkPMColor* dstPtr = (SkPMColor*) dstRow;
  266. for (int i = 0; i < width; i++) {
  267. uint32_t p = srcPtr[0];
  268. uint8_t red = masks->getRed(p);
  269. uint8_t green = masks->getGreen(p);
  270. uint8_t blue = masks->getBlue(p);
  271. uint8_t alpha = masks->getAlpha(p);
  272. dstPtr[i] = SkPackARGB_as_RGBA(alpha, red, green, blue);
  273. srcPtr += sampleX;
  274. }
  275. }
  276. static void swizzle_mask32_to_bgra_unpremul(
  277. void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
  278. uint32_t startX, uint32_t sampleX) {
  279. // Use the masks to decode to the destination
  280. uint32_t* srcPtr = ((uint32_t*) srcRow) + startX;
  281. SkPMColor* dstPtr = (SkPMColor*) dstRow;
  282. for (int i = 0; i < width; i++) {
  283. uint32_t p = srcPtr[0];
  284. uint8_t red = masks->getRed(p);
  285. uint8_t green = masks->getGreen(p);
  286. uint8_t blue = masks->getBlue(p);
  287. uint8_t alpha = masks->getAlpha(p);
  288. dstPtr[i] = SkPackARGB_as_BGRA(alpha, red, green, blue);
  289. srcPtr += sampleX;
  290. }
  291. }
  292. static void swizzle_mask32_to_rgba_premul(
  293. void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
  294. uint32_t startX, uint32_t sampleX) {
  295. // Use the masks to decode to the destination
  296. uint32_t* srcPtr = ((uint32_t*) srcRow) + startX;
  297. SkPMColor* dstPtr = (SkPMColor*) dstRow;
  298. for (int i = 0; i < width; i++) {
  299. uint32_t p = srcPtr[0];
  300. uint8_t red = masks->getRed(p);
  301. uint8_t green = masks->getGreen(p);
  302. uint8_t blue = masks->getBlue(p);
  303. uint8_t alpha = masks->getAlpha(p);
  304. dstPtr[i] = premultiply_argb_as_rgba(alpha, red, green, blue);
  305. srcPtr += sampleX;
  306. }
  307. }
  308. static void swizzle_mask32_to_bgra_premul(
  309. void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
  310. uint32_t startX, uint32_t sampleX) {
  311. // Use the masks to decode to the destination
  312. uint32_t* srcPtr = ((uint32_t*) srcRow) + startX;
  313. SkPMColor* dstPtr = (SkPMColor*) dstRow;
  314. for (int i = 0; i < width; i++) {
  315. uint32_t p = srcPtr[0];
  316. uint8_t red = masks->getRed(p);
  317. uint8_t green = masks->getGreen(p);
  318. uint8_t blue = masks->getBlue(p);
  319. uint8_t alpha = masks->getAlpha(p);
  320. dstPtr[i] = premultiply_argb_as_bgra(alpha, red, green, blue);
  321. srcPtr += sampleX;
  322. }
  323. }
  324. static void swizzle_mask32_to_565(
  325. void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
  326. uint32_t startX, uint32_t sampleX) {
  327. // Use the masks to decode to the destination
  328. uint32_t* srcPtr = ((uint32_t*) srcRow) + startX;
  329. uint16_t* dstPtr = (uint16_t*) dstRow;
  330. for (int i = 0; i < width; i++) {
  331. uint32_t p = srcPtr[0];
  332. uint8_t red = masks->getRed(p);
  333. uint8_t green = masks->getGreen(p);
  334. uint8_t blue = masks->getBlue(p);
  335. dstPtr[i] = SkPack888ToRGB16(red, green, blue);
  336. srcPtr += sampleX;
  337. }
  338. }
  339. /*
  340. *
  341. * Create a new mask swizzler
  342. *
  343. */
  344. SkMaskSwizzler* SkMaskSwizzler::CreateMaskSwizzler(const SkImageInfo& dstInfo,
  345. bool srcIsOpaque, SkMasks* masks, uint32_t bitsPerPixel,
  346. const SkCodec::Options& options) {
  347. // Choose the appropriate row procedure
  348. RowProc proc = nullptr;
  349. switch (bitsPerPixel) {
  350. case 16:
  351. switch (dstInfo.colorType()) {
  352. case kRGBA_8888_SkColorType:
  353. if (srcIsOpaque) {
  354. proc = &swizzle_mask16_to_rgba_opaque;
  355. } else {
  356. switch (dstInfo.alphaType()) {
  357. case kUnpremul_SkAlphaType:
  358. proc = &swizzle_mask16_to_rgba_unpremul;
  359. break;
  360. case kPremul_SkAlphaType:
  361. proc = &swizzle_mask16_to_rgba_premul;
  362. break;
  363. default:
  364. break;
  365. }
  366. }
  367. break;
  368. case kBGRA_8888_SkColorType:
  369. if (srcIsOpaque) {
  370. proc = &swizzle_mask16_to_bgra_opaque;
  371. } else {
  372. switch (dstInfo.alphaType()) {
  373. case kUnpremul_SkAlphaType:
  374. proc = &swizzle_mask16_to_bgra_unpremul;
  375. break;
  376. case kPremul_SkAlphaType:
  377. proc = &swizzle_mask16_to_bgra_premul;
  378. break;
  379. default:
  380. break;
  381. }
  382. }
  383. break;
  384. case kRGB_565_SkColorType:
  385. proc = &swizzle_mask16_to_565;
  386. break;
  387. default:
  388. break;
  389. }
  390. break;
  391. case 24:
  392. switch (dstInfo.colorType()) {
  393. case kRGBA_8888_SkColorType:
  394. if (srcIsOpaque) {
  395. proc = &swizzle_mask24_to_rgba_opaque;
  396. } else {
  397. switch (dstInfo.alphaType()) {
  398. case kUnpremul_SkAlphaType:
  399. proc = &swizzle_mask24_to_rgba_unpremul;
  400. break;
  401. case kPremul_SkAlphaType:
  402. proc = &swizzle_mask24_to_rgba_premul;
  403. break;
  404. default:
  405. break;
  406. }
  407. }
  408. break;
  409. case kBGRA_8888_SkColorType:
  410. if (srcIsOpaque) {
  411. proc = &swizzle_mask24_to_bgra_opaque;
  412. } else {
  413. switch (dstInfo.alphaType()) {
  414. case kUnpremul_SkAlphaType:
  415. proc = &swizzle_mask24_to_bgra_unpremul;
  416. break;
  417. case kPremul_SkAlphaType:
  418. proc = &swizzle_mask24_to_bgra_premul;
  419. break;
  420. default:
  421. break;
  422. }
  423. }
  424. break;
  425. case kRGB_565_SkColorType:
  426. proc = &swizzle_mask24_to_565;
  427. break;
  428. default:
  429. break;
  430. }
  431. break;
  432. case 32:
  433. switch (dstInfo.colorType()) {
  434. case kRGBA_8888_SkColorType:
  435. if (srcIsOpaque) {
  436. proc = &swizzle_mask32_to_rgba_opaque;
  437. } else {
  438. switch (dstInfo.alphaType()) {
  439. case kUnpremul_SkAlphaType:
  440. proc = &swizzle_mask32_to_rgba_unpremul;
  441. break;
  442. case kPremul_SkAlphaType:
  443. proc = &swizzle_mask32_to_rgba_premul;
  444. break;
  445. default:
  446. break;
  447. }
  448. }
  449. break;
  450. case kBGRA_8888_SkColorType:
  451. if (srcIsOpaque) {
  452. proc = &swizzle_mask32_to_bgra_opaque;
  453. } else {
  454. switch (dstInfo.alphaType()) {
  455. case kUnpremul_SkAlphaType:
  456. proc = &swizzle_mask32_to_bgra_unpremul;
  457. break;
  458. case kPremul_SkAlphaType:
  459. proc = &swizzle_mask32_to_bgra_premul;
  460. break;
  461. default:
  462. break;
  463. }
  464. }
  465. break;
  466. case kRGB_565_SkColorType:
  467. proc = &swizzle_mask32_to_565;
  468. break;
  469. default:
  470. break;
  471. }
  472. break;
  473. default:
  474. SkASSERT(false);
  475. return nullptr;
  476. }
  477. int srcOffset = 0;
  478. int srcWidth = dstInfo.width();
  479. if (options.fSubset) {
  480. srcOffset = options.fSubset->left();
  481. srcWidth = options.fSubset->width();
  482. }
  483. return new SkMaskSwizzler(masks, proc, srcOffset, srcWidth);
  484. }
  485. /*
  486. *
  487. * Constructor for mask swizzler
  488. *
  489. */
  490. SkMaskSwizzler::SkMaskSwizzler(SkMasks* masks, RowProc proc, int srcOffset, int subsetWidth)
  491. : fMasks(masks)
  492. , fRowProc(proc)
  493. , fSubsetWidth(subsetWidth)
  494. , fDstWidth(subsetWidth)
  495. , fSampleX(1)
  496. , fSrcOffset(srcOffset)
  497. , fX0(srcOffset)
  498. {}
  499. int SkMaskSwizzler::onSetSampleX(int sampleX) {
  500. // FIXME: Share this function with SkSwizzler?
  501. SkASSERT(sampleX > 0); // Surely there is an upper limit? Should there be
  502. // way to report failure?
  503. fSampleX = sampleX;
  504. fX0 = get_start_coord(sampleX) + fSrcOffset;
  505. fDstWidth = get_scaled_dimension(fSubsetWidth, sampleX);
  506. // check that fX0 is valid
  507. SkASSERT(fX0 >= 0);
  508. return fDstWidth;
  509. }
  510. /*
  511. *
  512. * Swizzle the specified row
  513. *
  514. */
  515. void SkMaskSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRICT src) {
  516. SkASSERT(nullptr != dst && nullptr != src);
  517. fRowProc(dst, src, fDstWidth, fMasks, fX0, fSampleX);
  518. }