swscale.c 35 KB

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