swscale.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985
  1. /*
  2. * Copyright (C) 2001-2011 Michael Niedermayer <michaelni@gmx.at>
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include <inttypes.h>
  21. #include <math.h>
  22. #include <stdio.h>
  23. #include <string.h>
  24. #include "libavutil/avassert.h"
  25. #include "libavutil/avutil.h"
  26. #include "libavutil/bswap.h"
  27. #include "libavutil/cpu.h"
  28. #include "libavutil/imgutils.h"
  29. #include "libavutil/intreadwrite.h"
  30. #include "libavutil/mathematics.h"
  31. #include "libavutil/pixdesc.h"
  32. #include "config.h"
  33. #include "rgb2rgb.h"
  34. #include "swscale_internal.h"
  35. #include "swscale.h"
  36. DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_128)[9][8] = {
  37. { 36, 68, 60, 92, 34, 66, 58, 90, },
  38. { 100, 4, 124, 28, 98, 2, 122, 26, },
  39. { 52, 84, 44, 76, 50, 82, 42, 74, },
  40. { 116, 20, 108, 12, 114, 18, 106, 10, },
  41. { 32, 64, 56, 88, 38, 70, 62, 94, },
  42. { 96, 0, 120, 24, 102, 6, 126, 30, },
  43. { 48, 80, 40, 72, 54, 86, 46, 78, },
  44. { 112, 16, 104, 8, 118, 22, 110, 14, },
  45. { 36, 68, 60, 92, 34, 66, 58, 90, },
  46. };
  47. DECLARE_ALIGNED(8, static const uint8_t, sws_pb_64)[8] = {
  48. 64, 64, 64, 64, 64, 64, 64, 64
  49. };
  50. static av_always_inline void fillPlane(uint8_t *plane, int stride, int width,
  51. int height, int y, uint8_t val)
  52. {
  53. int i;
  54. uint8_t *ptr = plane + stride * y;
  55. for (i = 0; i < height; i++) {
  56. memset(ptr, val, width);
  57. ptr += stride;
  58. }
  59. }
  60. static void hScale16To19_c(SwsContext *c, int16_t *_dst, int dstW,
  61. const uint8_t *_src, const int16_t *filter,
  62. const int32_t *filterPos, int filterSize)
  63. {
  64. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->srcFormat);
  65. int i;
  66. int32_t *dst = (int32_t *) _dst;
  67. const uint16_t *src = (const uint16_t *) _src;
  68. int bits = desc->comp[0].depth - 1;
  69. int sh = bits - 4;
  70. if ((isAnyRGB(c->srcFormat) || c->srcFormat==AV_PIX_FMT_PAL8) && desc->comp[0].depth<16) {
  71. sh = 9;
  72. } else if (desc->flags & AV_PIX_FMT_FLAG_FLOAT) { /* float input are process like uint 16bpc */
  73. sh = 16 - 1 - 4;
  74. }
  75. for (i = 0; i < dstW; i++) {
  76. int j;
  77. int srcPos = filterPos[i];
  78. int val = 0;
  79. for (j = 0; j < filterSize; j++) {
  80. val += src[srcPos + j] * filter[filterSize * i + j];
  81. }
  82. // filter=14 bit, input=16 bit, output=30 bit, >> 11 makes 19 bit
  83. dst[i] = FFMIN(val >> sh, (1 << 19) - 1);
  84. }
  85. }
  86. static void hScale16To15_c(SwsContext *c, int16_t *dst, int dstW,
  87. const uint8_t *_src, const int16_t *filter,
  88. const int32_t *filterPos, int filterSize)
  89. {
  90. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->srcFormat);
  91. int i;
  92. const uint16_t *src = (const uint16_t *) _src;
  93. int sh = desc->comp[0].depth - 1;
  94. if (sh<15) {
  95. sh = isAnyRGB(c->srcFormat) || c->srcFormat==AV_PIX_FMT_PAL8 ? 13 : (desc->comp[0].depth - 1);
  96. } else if (desc->flags & AV_PIX_FMT_FLAG_FLOAT) { /* float input are process like uint 16bpc */
  97. sh = 16 - 1;
  98. }
  99. for (i = 0; i < dstW; i++) {
  100. int j;
  101. int srcPos = filterPos[i];
  102. int val = 0;
  103. for (j = 0; j < filterSize; j++) {
  104. val += src[srcPos + j] * filter[filterSize * i + j];
  105. }
  106. // filter=14 bit, input=16 bit, output=30 bit, >> 15 makes 15 bit
  107. dst[i] = FFMIN(val >> sh, (1 << 15) - 1);
  108. }
  109. }
  110. // bilinear / bicubic scaling
  111. static void hScale8To15_c(SwsContext *c, int16_t *dst, int dstW,
  112. const uint8_t *src, const int16_t *filter,
  113. const int32_t *filterPos, int filterSize)
  114. {
  115. int i;
  116. for (i = 0; i < dstW; i++) {
  117. int j;
  118. int srcPos = filterPos[i];
  119. int val = 0;
  120. for (j = 0; j < filterSize; j++) {
  121. val += ((int)src[srcPos + j]) * filter[filterSize * i + j];
  122. }
  123. dst[i] = FFMIN(val >> 7, (1 << 15) - 1); // the cubic equation does overflow ...
  124. }
  125. }
  126. static void hScale8To19_c(SwsContext *c, int16_t *_dst, int dstW,
  127. const uint8_t *src, const int16_t *filter,
  128. const int32_t *filterPos, int filterSize)
  129. {
  130. int i;
  131. int32_t *dst = (int32_t *) _dst;
  132. for (i = 0; i < dstW; i++) {
  133. int j;
  134. int srcPos = filterPos[i];
  135. int val = 0;
  136. for (j = 0; j < filterSize; j++) {
  137. val += ((int)src[srcPos + j]) * filter[filterSize * i + j];
  138. }
  139. dst[i] = FFMIN(val >> 3, (1 << 19) - 1); // the cubic equation does overflow ...
  140. }
  141. }
  142. // FIXME all pal and rgb srcFormats could do this conversion as well
  143. // FIXME all scalers more complex than bilinear could do half of this transform
  144. static void chrRangeToJpeg_c(int16_t *dstU, int16_t *dstV, int width)
  145. {
  146. int i;
  147. for (i = 0; i < width; i++) {
  148. dstU[i] = (FFMIN(dstU[i], 30775) * 4663 - 9289992) >> 12; // -264
  149. dstV[i] = (FFMIN(dstV[i], 30775) * 4663 - 9289992) >> 12; // -264
  150. }
  151. }
  152. static void chrRangeFromJpeg_c(int16_t *dstU, int16_t *dstV, int width)
  153. {
  154. int i;
  155. for (i = 0; i < width; i++) {
  156. dstU[i] = (dstU[i] * 1799 + 4081085) >> 11; // 1469
  157. dstV[i] = (dstV[i] * 1799 + 4081085) >> 11; // 1469
  158. }
  159. }
  160. static void lumRangeToJpeg_c(int16_t *dst, int width)
  161. {
  162. int i;
  163. for (i = 0; i < width; i++)
  164. dst[i] = (FFMIN(dst[i], 30189) * 19077 - 39057361) >> 14;
  165. }
  166. static void lumRangeFromJpeg_c(int16_t *dst, int width)
  167. {
  168. int i;
  169. for (i = 0; i < width; i++)
  170. dst[i] = (dst[i] * 14071 + 33561947) >> 14;
  171. }
  172. static void chrRangeToJpeg16_c(int16_t *_dstU, int16_t *_dstV, int width)
  173. {
  174. int i;
  175. int32_t *dstU = (int32_t *) _dstU;
  176. int32_t *dstV = (int32_t *) _dstV;
  177. for (i = 0; i < width; i++) {
  178. dstU[i] = (FFMIN(dstU[i], 30775 << 4) * 4663 - (9289992 << 4)) >> 12; // -264
  179. dstV[i] = (FFMIN(dstV[i], 30775 << 4) * 4663 - (9289992 << 4)) >> 12; // -264
  180. }
  181. }
  182. static void chrRangeFromJpeg16_c(int16_t *_dstU, int16_t *_dstV, int width)
  183. {
  184. int i;
  185. int32_t *dstU = (int32_t *) _dstU;
  186. int32_t *dstV = (int32_t *) _dstV;
  187. for (i = 0; i < width; i++) {
  188. dstU[i] = (dstU[i] * 1799 + (4081085 << 4)) >> 11; // 1469
  189. dstV[i] = (dstV[i] * 1799 + (4081085 << 4)) >> 11; // 1469
  190. }
  191. }
  192. static void lumRangeToJpeg16_c(int16_t *_dst, int width)
  193. {
  194. int i;
  195. int32_t *dst = (int32_t *) _dst;
  196. for (i = 0; i < width; i++) {
  197. dst[i] = ((int)(FFMIN(dst[i], 30189 << 4) * 4769U - (39057361 << 2))) >> 12;
  198. }
  199. }
  200. static void lumRangeFromJpeg16_c(int16_t *_dst, int width)
  201. {
  202. int i;
  203. int32_t *dst = (int32_t *) _dst;
  204. for (i = 0; i < width; i++)
  205. dst[i] = (dst[i]*(14071/4) + (33561947<<4)/4)>>12;
  206. }
  207. #define DEBUG_SWSCALE_BUFFERS 0
  208. #define DEBUG_BUFFERS(...) \
  209. if (DEBUG_SWSCALE_BUFFERS) \
  210. av_log(c, AV_LOG_DEBUG, __VA_ARGS__)
  211. static int swscale(SwsContext *c, const uint8_t *src[],
  212. int srcStride[], int srcSliceY,
  213. int srcSliceH, uint8_t *dst[], int dstStride[])
  214. {
  215. /* load a few things into local vars to make the code more readable?
  216. * and faster */
  217. const int dstW = c->dstW;
  218. const int dstH = c->dstH;
  219. const enum AVPixelFormat dstFormat = c->dstFormat;
  220. const int flags = c->flags;
  221. int32_t *vLumFilterPos = c->vLumFilterPos;
  222. int32_t *vChrFilterPos = c->vChrFilterPos;
  223. const int vLumFilterSize = c->vLumFilterSize;
  224. const int vChrFilterSize = c->vChrFilterSize;
  225. yuv2planar1_fn yuv2plane1 = c->yuv2plane1;
  226. yuv2planarX_fn yuv2planeX = c->yuv2planeX;
  227. yuv2interleavedX_fn yuv2nv12cX = c->yuv2nv12cX;
  228. yuv2packed1_fn yuv2packed1 = c->yuv2packed1;
  229. yuv2packed2_fn yuv2packed2 = c->yuv2packed2;
  230. yuv2packedX_fn yuv2packedX = c->yuv2packedX;
  231. yuv2anyX_fn yuv2anyX = c->yuv2anyX;
  232. const int chrSrcSliceY = srcSliceY >> c->chrSrcVSubSample;
  233. const int chrSrcSliceH = AV_CEIL_RSHIFT(srcSliceH, c->chrSrcVSubSample);
  234. int should_dither = isNBPS(c->srcFormat) ||
  235. is16BPS(c->srcFormat);
  236. int lastDstY;
  237. /* vars which will change and which we need to store back in the context */
  238. int dstY = c->dstY;
  239. int lastInLumBuf = c->lastInLumBuf;
  240. int lastInChrBuf = c->lastInChrBuf;
  241. int lumStart = 0;
  242. int lumEnd = c->descIndex[0];
  243. int chrStart = lumEnd;
  244. int chrEnd = c->descIndex[1];
  245. int vStart = chrEnd;
  246. int vEnd = c->numDesc;
  247. SwsSlice *src_slice = &c->slice[lumStart];
  248. SwsSlice *hout_slice = &c->slice[c->numSlice-2];
  249. SwsSlice *vout_slice = &c->slice[c->numSlice-1];
  250. SwsFilterDescriptor *desc = c->desc;
  251. int needAlpha = c->needAlpha;
  252. int hasLumHoles = 1;
  253. int hasChrHoles = 1;
  254. if (isPacked(c->srcFormat)) {
  255. src[1] =
  256. src[2] =
  257. src[3] = src[0];
  258. srcStride[1] =
  259. srcStride[2] =
  260. srcStride[3] = srcStride[0];
  261. }
  262. srcStride[1] *= 1 << c->vChrDrop;
  263. srcStride[2] *= 1 << c->vChrDrop;
  264. DEBUG_BUFFERS("swscale() %p[%d] %p[%d] %p[%d] %p[%d] -> %p[%d] %p[%d] %p[%d] %p[%d]\n",
  265. src[0], srcStride[0], src[1], srcStride[1],
  266. src[2], srcStride[2], src[3], srcStride[3],
  267. dst[0], dstStride[0], dst[1], dstStride[1],
  268. dst[2], dstStride[2], dst[3], dstStride[3]);
  269. DEBUG_BUFFERS("srcSliceY: %d srcSliceH: %d dstY: %d dstH: %d\n",
  270. srcSliceY, srcSliceH, dstY, dstH);
  271. DEBUG_BUFFERS("vLumFilterSize: %d vChrFilterSize: %d\n",
  272. vLumFilterSize, vChrFilterSize);
  273. if (dstStride[0]&15 || dstStride[1]&15 ||
  274. dstStride[2]&15 || dstStride[3]&15) {
  275. static int warnedAlready = 0; // FIXME maybe move this into the context
  276. if (flags & SWS_PRINT_INFO && !warnedAlready) {
  277. av_log(c, AV_LOG_WARNING,
  278. "Warning: dstStride is not aligned!\n"
  279. " ->cannot do aligned memory accesses anymore\n");
  280. warnedAlready = 1;
  281. }
  282. }
  283. if ( (uintptr_t)dst[0]&15 || (uintptr_t)dst[1]&15 || (uintptr_t)dst[2]&15
  284. || (uintptr_t)src[0]&15 || (uintptr_t)src[1]&15 || (uintptr_t)src[2]&15
  285. || dstStride[0]&15 || dstStride[1]&15 || dstStride[2]&15 || dstStride[3]&15
  286. || srcStride[0]&15 || srcStride[1]&15 || srcStride[2]&15 || srcStride[3]&15
  287. ) {
  288. static int warnedAlready=0;
  289. int cpu_flags = av_get_cpu_flags();
  290. if (HAVE_MMXEXT && (cpu_flags & AV_CPU_FLAG_SSE2) && !warnedAlready){
  291. av_log(c, AV_LOG_WARNING, "Warning: data is not aligned! This can lead to a speed loss\n");
  292. warnedAlready=1;
  293. }
  294. }
  295. /* Note the user might start scaling the picture in the middle so this
  296. * will not get executed. This is not really intended but works
  297. * currently, so people might do it. */
  298. if (srcSliceY == 0) {
  299. dstY = 0;
  300. lastInLumBuf = -1;
  301. lastInChrBuf = -1;
  302. }
  303. if (!should_dither) {
  304. c->chrDither8 = c->lumDither8 = sws_pb_64;
  305. }
  306. lastDstY = dstY;
  307. ff_init_vscale_pfn(c, yuv2plane1, yuv2planeX, yuv2nv12cX,
  308. yuv2packed1, yuv2packed2, yuv2packedX, yuv2anyX, c->use_mmx_vfilter);
  309. ff_init_slice_from_src(src_slice, (uint8_t**)src, srcStride, c->srcW,
  310. srcSliceY, srcSliceH, chrSrcSliceY, chrSrcSliceH, 1);
  311. ff_init_slice_from_src(vout_slice, (uint8_t**)dst, dstStride, c->dstW,
  312. dstY, dstH, dstY >> c->chrDstVSubSample,
  313. AV_CEIL_RSHIFT(dstH, c->chrDstVSubSample), 0);
  314. if (srcSliceY == 0) {
  315. hout_slice->plane[0].sliceY = lastInLumBuf + 1;
  316. hout_slice->plane[1].sliceY = lastInChrBuf + 1;
  317. hout_slice->plane[2].sliceY = lastInChrBuf + 1;
  318. hout_slice->plane[3].sliceY = lastInLumBuf + 1;
  319. hout_slice->plane[0].sliceH =
  320. hout_slice->plane[1].sliceH =
  321. hout_slice->plane[2].sliceH =
  322. hout_slice->plane[3].sliceH = 0;
  323. hout_slice->width = dstW;
  324. }
  325. for (; dstY < dstH; dstY++) {
  326. const int chrDstY = dstY >> c->chrDstVSubSample;
  327. int use_mmx_vfilter= c->use_mmx_vfilter;
  328. // First line needed as input
  329. const int firstLumSrcY = FFMAX(1 - vLumFilterSize, vLumFilterPos[dstY]);
  330. const int firstLumSrcY2 = FFMAX(1 - vLumFilterSize, vLumFilterPos[FFMIN(dstY | ((1 << c->chrDstVSubSample) - 1), dstH - 1)]);
  331. // First line needed as input
  332. const int firstChrSrcY = FFMAX(1 - vChrFilterSize, vChrFilterPos[chrDstY]);
  333. // Last line needed as input
  334. int lastLumSrcY = FFMIN(c->srcH, firstLumSrcY + vLumFilterSize) - 1;
  335. int lastLumSrcY2 = FFMIN(c->srcH, firstLumSrcY2 + vLumFilterSize) - 1;
  336. int lastChrSrcY = FFMIN(c->chrSrcH, firstChrSrcY + vChrFilterSize) - 1;
  337. int enough_lines;
  338. int i;
  339. int posY, cPosY, firstPosY, lastPosY, firstCPosY, lastCPosY;
  340. // handle holes (FAST_BILINEAR & weird filters)
  341. if (firstLumSrcY > lastInLumBuf) {
  342. hasLumHoles = lastInLumBuf != firstLumSrcY - 1;
  343. if (hasLumHoles) {
  344. hout_slice->plane[0].sliceY = firstLumSrcY;
  345. hout_slice->plane[3].sliceY = firstLumSrcY;
  346. hout_slice->plane[0].sliceH =
  347. hout_slice->plane[3].sliceH = 0;
  348. }
  349. lastInLumBuf = firstLumSrcY - 1;
  350. }
  351. if (firstChrSrcY > lastInChrBuf) {
  352. hasChrHoles = lastInChrBuf != firstChrSrcY - 1;
  353. if (hasChrHoles) {
  354. hout_slice->plane[1].sliceY = firstChrSrcY;
  355. hout_slice->plane[2].sliceY = firstChrSrcY;
  356. hout_slice->plane[1].sliceH =
  357. hout_slice->plane[2].sliceH = 0;
  358. }
  359. lastInChrBuf = firstChrSrcY - 1;
  360. }
  361. DEBUG_BUFFERS("dstY: %d\n", dstY);
  362. DEBUG_BUFFERS("\tfirstLumSrcY: %d lastLumSrcY: %d lastInLumBuf: %d\n",
  363. firstLumSrcY, lastLumSrcY, lastInLumBuf);
  364. DEBUG_BUFFERS("\tfirstChrSrcY: %d lastChrSrcY: %d lastInChrBuf: %d\n",
  365. firstChrSrcY, lastChrSrcY, lastInChrBuf);
  366. // Do we have enough lines in this slice to output the dstY line
  367. enough_lines = lastLumSrcY2 < srcSliceY + srcSliceH &&
  368. lastChrSrcY < AV_CEIL_RSHIFT(srcSliceY + srcSliceH, c->chrSrcVSubSample);
  369. if (!enough_lines) {
  370. lastLumSrcY = srcSliceY + srcSliceH - 1;
  371. lastChrSrcY = chrSrcSliceY + chrSrcSliceH - 1;
  372. DEBUG_BUFFERS("buffering slice: lastLumSrcY %d lastChrSrcY %d\n",
  373. lastLumSrcY, lastChrSrcY);
  374. }
  375. av_assert0((lastLumSrcY - firstLumSrcY + 1) <= hout_slice->plane[0].available_lines);
  376. av_assert0((lastChrSrcY - firstChrSrcY + 1) <= hout_slice->plane[1].available_lines);
  377. posY = hout_slice->plane[0].sliceY + hout_slice->plane[0].sliceH;
  378. if (posY <= lastLumSrcY && !hasLumHoles) {
  379. firstPosY = FFMAX(firstLumSrcY, posY);
  380. lastPosY = FFMIN(firstLumSrcY + hout_slice->plane[0].available_lines - 1, srcSliceY + srcSliceH - 1);
  381. } else {
  382. firstPosY = posY;
  383. lastPosY = lastLumSrcY;
  384. }
  385. cPosY = hout_slice->plane[1].sliceY + hout_slice->plane[1].sliceH;
  386. if (cPosY <= lastChrSrcY && !hasChrHoles) {
  387. firstCPosY = FFMAX(firstChrSrcY, cPosY);
  388. lastCPosY = FFMIN(firstChrSrcY + hout_slice->plane[1].available_lines - 1, AV_CEIL_RSHIFT(srcSliceY + srcSliceH, c->chrSrcVSubSample) - 1);
  389. } else {
  390. firstCPosY = cPosY;
  391. lastCPosY = lastChrSrcY;
  392. }
  393. ff_rotate_slice(hout_slice, lastPosY, lastCPosY);
  394. if (posY < lastLumSrcY + 1) {
  395. for (i = lumStart; i < lumEnd; ++i)
  396. desc[i].process(c, &desc[i], firstPosY, lastPosY - firstPosY + 1);
  397. }
  398. lastInLumBuf = lastLumSrcY;
  399. if (cPosY < lastChrSrcY + 1) {
  400. for (i = chrStart; i < chrEnd; ++i)
  401. desc[i].process(c, &desc[i], firstCPosY, lastCPosY - firstCPosY + 1);
  402. }
  403. lastInChrBuf = lastChrSrcY;
  404. if (!enough_lines)
  405. break; // we can't output a dstY line so let's try with the next slice
  406. #if HAVE_MMX_INLINE
  407. ff_updateMMXDitherTables(c, dstY);
  408. #endif
  409. if (should_dither) {
  410. c->chrDither8 = ff_dither_8x8_128[chrDstY & 7];
  411. c->lumDither8 = ff_dither_8x8_128[dstY & 7];
  412. }
  413. if (dstY >= dstH - 2) {
  414. /* hmm looks like we can't use MMX here without overwriting
  415. * this array's tail */
  416. ff_sws_init_output_funcs(c, &yuv2plane1, &yuv2planeX, &yuv2nv12cX,
  417. &yuv2packed1, &yuv2packed2, &yuv2packedX, &yuv2anyX);
  418. use_mmx_vfilter= 0;
  419. ff_init_vscale_pfn(c, yuv2plane1, yuv2planeX, yuv2nv12cX,
  420. yuv2packed1, yuv2packed2, yuv2packedX, yuv2anyX, use_mmx_vfilter);
  421. }
  422. {
  423. for (i = vStart; i < vEnd; ++i)
  424. desc[i].process(c, &desc[i], dstY, 1);
  425. }
  426. }
  427. if (isPlanar(dstFormat) && isALPHA(dstFormat) && !needAlpha) {
  428. int length = dstW;
  429. int height = dstY - lastDstY;
  430. if (is16BPS(dstFormat) || isNBPS(dstFormat)) {
  431. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(dstFormat);
  432. fillPlane16(dst[3], dstStride[3], length, height, lastDstY,
  433. 1, desc->comp[3].depth,
  434. isBE(dstFormat));
  435. } else if (is32BPS(dstFormat)) {
  436. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(dstFormat);
  437. fillPlane32(dst[3], dstStride[3], length, height, lastDstY,
  438. 1, desc->comp[3].depth,
  439. isBE(dstFormat), desc->flags & AV_PIX_FMT_FLAG_FLOAT);
  440. } else
  441. fillPlane(dst[3], dstStride[3], length, height, lastDstY, 255);
  442. }
  443. #if HAVE_MMXEXT_INLINE
  444. if (av_get_cpu_flags() & AV_CPU_FLAG_MMXEXT)
  445. __asm__ volatile ("sfence" ::: "memory");
  446. #endif
  447. emms_c();
  448. /* store changed local vars back in the context */
  449. c->dstY = dstY;
  450. c->lastInLumBuf = lastInLumBuf;
  451. c->lastInChrBuf = lastInChrBuf;
  452. return dstY - lastDstY;
  453. }
  454. av_cold void ff_sws_init_range_convert(SwsContext *c)
  455. {
  456. c->lumConvertRange = NULL;
  457. c->chrConvertRange = NULL;
  458. if (c->srcRange != c->dstRange && !isAnyRGB(c->dstFormat)) {
  459. if (c->dstBpc <= 14) {
  460. if (c->srcRange) {
  461. c->lumConvertRange = lumRangeFromJpeg_c;
  462. c->chrConvertRange = chrRangeFromJpeg_c;
  463. } else {
  464. c->lumConvertRange = lumRangeToJpeg_c;
  465. c->chrConvertRange = chrRangeToJpeg_c;
  466. }
  467. } else {
  468. if (c->srcRange) {
  469. c->lumConvertRange = lumRangeFromJpeg16_c;
  470. c->chrConvertRange = chrRangeFromJpeg16_c;
  471. } else {
  472. c->lumConvertRange = lumRangeToJpeg16_c;
  473. c->chrConvertRange = chrRangeToJpeg16_c;
  474. }
  475. }
  476. }
  477. }
  478. static av_cold void sws_init_swscale(SwsContext *c)
  479. {
  480. enum AVPixelFormat srcFormat = c->srcFormat;
  481. ff_sws_init_output_funcs(c, &c->yuv2plane1, &c->yuv2planeX,
  482. &c->yuv2nv12cX, &c->yuv2packed1,
  483. &c->yuv2packed2, &c->yuv2packedX, &c->yuv2anyX);
  484. ff_sws_init_input_funcs(c);
  485. if (c->srcBpc == 8) {
  486. if (c->dstBpc <= 14) {
  487. c->hyScale = c->hcScale = hScale8To15_c;
  488. if (c->flags & SWS_FAST_BILINEAR) {
  489. c->hyscale_fast = ff_hyscale_fast_c;
  490. c->hcscale_fast = ff_hcscale_fast_c;
  491. }
  492. } else {
  493. c->hyScale = c->hcScale = hScale8To19_c;
  494. }
  495. } else {
  496. c->hyScale = c->hcScale = c->dstBpc > 14 ? hScale16To19_c
  497. : hScale16To15_c;
  498. }
  499. ff_sws_init_range_convert(c);
  500. if (!(isGray(srcFormat) || isGray(c->dstFormat) ||
  501. srcFormat == AV_PIX_FMT_MONOBLACK || srcFormat == AV_PIX_FMT_MONOWHITE))
  502. c->needs_hcscale = 1;
  503. }
  504. SwsFunc ff_getSwsFunc(SwsContext *c)
  505. {
  506. sws_init_swscale(c);
  507. if (ARCH_PPC)
  508. ff_sws_init_swscale_ppc(c);
  509. if (ARCH_X86)
  510. ff_sws_init_swscale_x86(c);
  511. if (ARCH_AARCH64)
  512. ff_sws_init_swscale_aarch64(c);
  513. if (ARCH_ARM)
  514. ff_sws_init_swscale_arm(c);
  515. return swscale;
  516. }
  517. static void reset_ptr(const uint8_t *src[], enum AVPixelFormat format)
  518. {
  519. if (!isALPHA(format))
  520. src[3] = NULL;
  521. if (!isPlanar(format)) {
  522. src[3] = src[2] = NULL;
  523. if (!usePal(format))
  524. src[1] = NULL;
  525. }
  526. }
  527. static int check_image_pointers(const uint8_t * const data[4], enum AVPixelFormat pix_fmt,
  528. const int linesizes[4])
  529. {
  530. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
  531. int i;
  532. av_assert2(desc);
  533. for (i = 0; i < 4; i++) {
  534. int plane = desc->comp[i].plane;
  535. if (!data[plane] || !linesizes[plane])
  536. return 0;
  537. }
  538. return 1;
  539. }
  540. static void xyz12Torgb48(struct SwsContext *c, uint16_t *dst,
  541. const uint16_t *src, int stride, int h)
  542. {
  543. int xp,yp;
  544. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->srcFormat);
  545. for (yp=0; yp<h; yp++) {
  546. for (xp=0; xp+2<stride; xp+=3) {
  547. int x, y, z, r, g, b;
  548. if (desc->flags & AV_PIX_FMT_FLAG_BE) {
  549. x = AV_RB16(src + xp + 0);
  550. y = AV_RB16(src + xp + 1);
  551. z = AV_RB16(src + xp + 2);
  552. } else {
  553. x = AV_RL16(src + xp + 0);
  554. y = AV_RL16(src + xp + 1);
  555. z = AV_RL16(src + xp + 2);
  556. }
  557. x = c->xyzgamma[x>>4];
  558. y = c->xyzgamma[y>>4];
  559. z = c->xyzgamma[z>>4];
  560. // convert from XYZlinear to sRGBlinear
  561. r = c->xyz2rgb_matrix[0][0] * x +
  562. c->xyz2rgb_matrix[0][1] * y +
  563. c->xyz2rgb_matrix[0][2] * z >> 12;
  564. g = c->xyz2rgb_matrix[1][0] * x +
  565. c->xyz2rgb_matrix[1][1] * y +
  566. c->xyz2rgb_matrix[1][2] * z >> 12;
  567. b = c->xyz2rgb_matrix[2][0] * x +
  568. c->xyz2rgb_matrix[2][1] * y +
  569. c->xyz2rgb_matrix[2][2] * z >> 12;
  570. // limit values to 12-bit depth
  571. r = av_clip_uintp2(r, 12);
  572. g = av_clip_uintp2(g, 12);
  573. b = av_clip_uintp2(b, 12);
  574. // convert from sRGBlinear to RGB and scale from 12bit to 16bit
  575. if (desc->flags & AV_PIX_FMT_FLAG_BE) {
  576. AV_WB16(dst + xp + 0, c->rgbgamma[r] << 4);
  577. AV_WB16(dst + xp + 1, c->rgbgamma[g] << 4);
  578. AV_WB16(dst + xp + 2, c->rgbgamma[b] << 4);
  579. } else {
  580. AV_WL16(dst + xp + 0, c->rgbgamma[r] << 4);
  581. AV_WL16(dst + xp + 1, c->rgbgamma[g] << 4);
  582. AV_WL16(dst + xp + 2, c->rgbgamma[b] << 4);
  583. }
  584. }
  585. src += stride;
  586. dst += stride;
  587. }
  588. }
  589. static void rgb48Toxyz12(struct SwsContext *c, uint16_t *dst,
  590. const uint16_t *src, int stride, int h)
  591. {
  592. int xp,yp;
  593. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->dstFormat);
  594. for (yp=0; yp<h; yp++) {
  595. for (xp=0; xp+2<stride; xp+=3) {
  596. int x, y, z, r, g, b;
  597. if (desc->flags & AV_PIX_FMT_FLAG_BE) {
  598. r = AV_RB16(src + xp + 0);
  599. g = AV_RB16(src + xp + 1);
  600. b = AV_RB16(src + xp + 2);
  601. } else {
  602. r = AV_RL16(src + xp + 0);
  603. g = AV_RL16(src + xp + 1);
  604. b = AV_RL16(src + xp + 2);
  605. }
  606. r = c->rgbgammainv[r>>4];
  607. g = c->rgbgammainv[g>>4];
  608. b = c->rgbgammainv[b>>4];
  609. // convert from sRGBlinear to XYZlinear
  610. x = c->rgb2xyz_matrix[0][0] * r +
  611. c->rgb2xyz_matrix[0][1] * g +
  612. c->rgb2xyz_matrix[0][2] * b >> 12;
  613. y = c->rgb2xyz_matrix[1][0] * r +
  614. c->rgb2xyz_matrix[1][1] * g +
  615. c->rgb2xyz_matrix[1][2] * b >> 12;
  616. z = c->rgb2xyz_matrix[2][0] * r +
  617. c->rgb2xyz_matrix[2][1] * g +
  618. c->rgb2xyz_matrix[2][2] * b >> 12;
  619. // limit values to 12-bit depth
  620. x = av_clip_uintp2(x, 12);
  621. y = av_clip_uintp2(y, 12);
  622. z = av_clip_uintp2(z, 12);
  623. // convert from XYZlinear to X'Y'Z' and scale from 12bit to 16bit
  624. if (desc->flags & AV_PIX_FMT_FLAG_BE) {
  625. AV_WB16(dst + xp + 0, c->xyzgammainv[x] << 4);
  626. AV_WB16(dst + xp + 1, c->xyzgammainv[y] << 4);
  627. AV_WB16(dst + xp + 2, c->xyzgammainv[z] << 4);
  628. } else {
  629. AV_WL16(dst + xp + 0, c->xyzgammainv[x] << 4);
  630. AV_WL16(dst + xp + 1, c->xyzgammainv[y] << 4);
  631. AV_WL16(dst + xp + 2, c->xyzgammainv[z] << 4);
  632. }
  633. }
  634. src += stride;
  635. dst += stride;
  636. }
  637. }
  638. /**
  639. * swscale wrapper, so we don't need to export the SwsContext.
  640. * Assumes planar YUV to be in YUV order instead of YVU.
  641. */
  642. int attribute_align_arg sws_scale(struct SwsContext *c,
  643. const uint8_t * const srcSlice[],
  644. const int srcStride[], int srcSliceY,
  645. int srcSliceH, uint8_t *const dst[],
  646. const int dstStride[])
  647. {
  648. int i, ret;
  649. const uint8_t *src2[4];
  650. uint8_t *dst2[4];
  651. uint8_t *rgb0_tmp = NULL;
  652. int macro_height = isBayer(c->srcFormat) ? 2 : (1 << c->chrSrcVSubSample);
  653. // copy strides, so they can safely be modified
  654. int srcStride2[4];
  655. int dstStride2[4];
  656. int srcSliceY_internal = srcSliceY;
  657. if (!srcStride || !dstStride || !dst || !srcSlice) {
  658. av_log(c, AV_LOG_ERROR, "One of the input parameters to sws_scale() is NULL, please check the calling code\n");
  659. return 0;
  660. }
  661. for (i=0; i<4; i++) {
  662. srcStride2[i] = srcStride[i];
  663. dstStride2[i] = dstStride[i];
  664. }
  665. if ((srcSliceY & (macro_height-1)) ||
  666. ((srcSliceH& (macro_height-1)) && srcSliceY + srcSliceH != c->srcH) ||
  667. srcSliceY + srcSliceH > c->srcH ||
  668. (isBayer(c->srcFormat) && srcSliceH <= 1)) {
  669. av_log(c, AV_LOG_ERROR, "Slice parameters %d, %d are invalid\n", srcSliceY, srcSliceH);
  670. return AVERROR(EINVAL);
  671. }
  672. if (c->gamma_flag && c->cascaded_context[0]) {
  673. ret = sws_scale(c->cascaded_context[0],
  674. srcSlice, srcStride, srcSliceY, srcSliceH,
  675. c->cascaded_tmp, c->cascaded_tmpStride);
  676. if (ret < 0)
  677. return ret;
  678. if (c->cascaded_context[2])
  679. ret = sws_scale(c->cascaded_context[1], (const uint8_t * const *)c->cascaded_tmp, c->cascaded_tmpStride, srcSliceY, srcSliceH, c->cascaded1_tmp, c->cascaded1_tmpStride);
  680. else
  681. ret = sws_scale(c->cascaded_context[1], (const uint8_t * const *)c->cascaded_tmp, c->cascaded_tmpStride, srcSliceY, srcSliceH, dst, dstStride);
  682. if (ret < 0)
  683. return ret;
  684. if (c->cascaded_context[2]) {
  685. ret = sws_scale(c->cascaded_context[2],
  686. (const uint8_t * const *)c->cascaded1_tmp, c->cascaded1_tmpStride, c->cascaded_context[1]->dstY - ret, c->cascaded_context[1]->dstY,
  687. dst, dstStride);
  688. }
  689. return ret;
  690. }
  691. if (c->cascaded_context[0] && srcSliceY == 0 && srcSliceH == c->cascaded_context[0]->srcH) {
  692. ret = sws_scale(c->cascaded_context[0],
  693. srcSlice, srcStride, srcSliceY, srcSliceH,
  694. c->cascaded_tmp, c->cascaded_tmpStride);
  695. if (ret < 0)
  696. return ret;
  697. ret = sws_scale(c->cascaded_context[1],
  698. (const uint8_t * const * )c->cascaded_tmp, c->cascaded_tmpStride, 0, c->cascaded_context[0]->dstH,
  699. dst, dstStride);
  700. return ret;
  701. }
  702. memcpy(src2, srcSlice, sizeof(src2));
  703. memcpy(dst2, dst, sizeof(dst2));
  704. // do not mess up sliceDir if we have a "trailing" 0-size slice
  705. if (srcSliceH == 0)
  706. return 0;
  707. if (!check_image_pointers(srcSlice, c->srcFormat, srcStride)) {
  708. av_log(c, AV_LOG_ERROR, "bad src image pointers\n");
  709. return 0;
  710. }
  711. if (!check_image_pointers((const uint8_t* const*)dst, c->dstFormat, dstStride)) {
  712. av_log(c, AV_LOG_ERROR, "bad dst image pointers\n");
  713. return 0;
  714. }
  715. if (c->sliceDir == 0 && srcSliceY != 0 && srcSliceY + srcSliceH != c->srcH) {
  716. av_log(c, AV_LOG_ERROR, "Slices start in the middle!\n");
  717. return 0;
  718. }
  719. if (c->sliceDir == 0) {
  720. if (srcSliceY == 0) c->sliceDir = 1; else c->sliceDir = -1;
  721. }
  722. if (usePal(c->srcFormat)) {
  723. for (i = 0; i < 256; i++) {
  724. int r, g, b, y, u, v, a = 0xff;
  725. if (c->srcFormat == AV_PIX_FMT_PAL8) {
  726. uint32_t p = ((const uint32_t *)(srcSlice[1]))[i];
  727. a = (p >> 24) & 0xFF;
  728. r = (p >> 16) & 0xFF;
  729. g = (p >> 8) & 0xFF;
  730. b = p & 0xFF;
  731. } else if (c->srcFormat == AV_PIX_FMT_RGB8) {
  732. r = ( i >> 5 ) * 36;
  733. g = ((i >> 2) & 7) * 36;
  734. b = ( i & 3) * 85;
  735. } else if (c->srcFormat == AV_PIX_FMT_BGR8) {
  736. b = ( i >> 6 ) * 85;
  737. g = ((i >> 3) & 7) * 36;
  738. r = ( i & 7) * 36;
  739. } else if (c->srcFormat == AV_PIX_FMT_RGB4_BYTE) {
  740. r = ( i >> 3 ) * 255;
  741. g = ((i >> 1) & 3) * 85;
  742. b = ( i & 1) * 255;
  743. } else if (c->srcFormat == AV_PIX_FMT_GRAY8 || c->srcFormat == AV_PIX_FMT_GRAY8A) {
  744. r = g = b = i;
  745. } else {
  746. av_assert1(c->srcFormat == AV_PIX_FMT_BGR4_BYTE);
  747. b = ( i >> 3 ) * 255;
  748. g = ((i >> 1) & 3) * 85;
  749. r = ( i & 1) * 255;
  750. }
  751. #define RGB2YUV_SHIFT 15
  752. #define BY ( (int) (0.114 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
  753. #define BV (-(int) (0.081 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
  754. #define BU ( (int) (0.500 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
  755. #define GY ( (int) (0.587 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
  756. #define GV (-(int) (0.419 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
  757. #define GU (-(int) (0.331 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
  758. #define RY ( (int) (0.299 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
  759. #define RV ( (int) (0.500 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
  760. #define RU (-(int) (0.169 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
  761. y = av_clip_uint8((RY * r + GY * g + BY * b + ( 33 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT);
  762. u = av_clip_uint8((RU * r + GU * g + BU * b + (257 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT);
  763. v = av_clip_uint8((RV * r + GV * g + BV * b + (257 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT);
  764. c->pal_yuv[i]= y + (u<<8) + (v<<16) + ((unsigned)a<<24);
  765. switch (c->dstFormat) {
  766. case AV_PIX_FMT_BGR32:
  767. #if !HAVE_BIGENDIAN
  768. case AV_PIX_FMT_RGB24:
  769. #endif
  770. c->pal_rgb[i]= r + (g<<8) + (b<<16) + ((unsigned)a<<24);
  771. break;
  772. case AV_PIX_FMT_BGR32_1:
  773. #if HAVE_BIGENDIAN
  774. case AV_PIX_FMT_BGR24:
  775. #endif
  776. c->pal_rgb[i]= a + (r<<8) + (g<<16) + ((unsigned)b<<24);
  777. break;
  778. case AV_PIX_FMT_RGB32_1:
  779. #if HAVE_BIGENDIAN
  780. case AV_PIX_FMT_RGB24:
  781. #endif
  782. c->pal_rgb[i]= a + (b<<8) + (g<<16) + ((unsigned)r<<24);
  783. break;
  784. case AV_PIX_FMT_RGB32:
  785. #if !HAVE_BIGENDIAN
  786. case AV_PIX_FMT_BGR24:
  787. #endif
  788. default:
  789. c->pal_rgb[i]= b + (g<<8) + (r<<16) + ((unsigned)a<<24);
  790. }
  791. }
  792. }
  793. if (c->src0Alpha && !c->dst0Alpha && isALPHA(c->dstFormat)) {
  794. uint8_t *base;
  795. int x,y;
  796. rgb0_tmp = av_malloc(FFABS(srcStride[0]) * srcSliceH + 32);
  797. if (!rgb0_tmp)
  798. return AVERROR(ENOMEM);
  799. base = srcStride[0] < 0 ? rgb0_tmp - srcStride[0] * (srcSliceH-1) : rgb0_tmp;
  800. for (y=0; y<srcSliceH; y++){
  801. memcpy(base + srcStride[0]*y, src2[0] + srcStride[0]*y, 4*c->srcW);
  802. for (x=c->src0Alpha-1; x<4*c->srcW; x+=4) {
  803. base[ srcStride[0]*y + x] = 0xFF;
  804. }
  805. }
  806. src2[0] = base;
  807. }
  808. if (c->srcXYZ && !(c->dstXYZ && c->srcW==c->dstW && c->srcH==c->dstH)) {
  809. uint8_t *base;
  810. rgb0_tmp = av_malloc(FFABS(srcStride[0]) * srcSliceH + 32);
  811. if (!rgb0_tmp)
  812. return AVERROR(ENOMEM);
  813. base = srcStride[0] < 0 ? rgb0_tmp - srcStride[0] * (srcSliceH-1) : rgb0_tmp;
  814. xyz12Torgb48(c, (uint16_t*)base, (const uint16_t*)src2[0], srcStride[0]/2, srcSliceH);
  815. src2[0] = base;
  816. }
  817. if (!srcSliceY && (c->flags & SWS_BITEXACT) && c->dither == SWS_DITHER_ED && c->dither_error[0])
  818. for (i = 0; i < 4; i++)
  819. memset(c->dither_error[i], 0, sizeof(c->dither_error[0][0]) * (c->dstW+2));
  820. if (c->sliceDir != 1) {
  821. // slices go from bottom to top => we flip the image internally
  822. for (i=0; i<4; i++) {
  823. srcStride2[i] *= -1;
  824. dstStride2[i] *= -1;
  825. }
  826. src2[0] += (srcSliceH - 1) * srcStride[0];
  827. if (!usePal(c->srcFormat))
  828. src2[1] += ((srcSliceH >> c->chrSrcVSubSample) - 1) * srcStride[1];
  829. src2[2] += ((srcSliceH >> c->chrSrcVSubSample) - 1) * srcStride[2];
  830. src2[3] += (srcSliceH - 1) * srcStride[3];
  831. dst2[0] += ( c->dstH - 1) * dstStride[0];
  832. dst2[1] += ((c->dstH >> c->chrDstVSubSample) - 1) * dstStride[1];
  833. dst2[2] += ((c->dstH >> c->chrDstVSubSample) - 1) * dstStride[2];
  834. dst2[3] += ( c->dstH - 1) * dstStride[3];
  835. srcSliceY_internal = c->srcH-srcSliceY-srcSliceH;
  836. }
  837. reset_ptr(src2, c->srcFormat);
  838. reset_ptr((void*)dst2, c->dstFormat);
  839. /* reset slice direction at end of frame */
  840. if (srcSliceY_internal + srcSliceH == c->srcH)
  841. c->sliceDir = 0;
  842. ret = c->swscale(c, src2, srcStride2, srcSliceY_internal, srcSliceH, dst2, dstStride2);
  843. if (c->dstXYZ && !(c->srcXYZ && c->srcW==c->dstW && c->srcH==c->dstH)) {
  844. int dstY = c->dstY ? c->dstY : srcSliceY + srcSliceH;
  845. uint16_t *dst16 = (uint16_t*)(dst2[0] + (dstY - ret) * dstStride2[0]);
  846. av_assert0(dstY >= ret);
  847. av_assert0(ret >= 0);
  848. av_assert0(c->dstH >= dstY);
  849. /* replace on the same data */
  850. rgb48Toxyz12(c, dst16, dst16, dstStride2[0]/2, ret);
  851. }
  852. av_free(rgb0_tmp);
  853. return ret;
  854. }