swscale.c 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002
  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 lumBufIndex = c->lumBufIndex;
  240. int chrBufIndex = c->chrBufIndex;
  241. int lastInLumBuf = c->lastInLumBuf;
  242. int lastInChrBuf = c->lastInChrBuf;
  243. int lumStart = 0;
  244. int lumEnd = c->descIndex[0];
  245. int chrStart = lumEnd;
  246. int chrEnd = c->descIndex[1];
  247. int vStart = chrEnd;
  248. int vEnd = c->numDesc;
  249. SwsSlice *src_slice = &c->slice[lumStart];
  250. SwsSlice *hout_slice = &c->slice[c->numSlice-2];
  251. SwsSlice *vout_slice = &c->slice[c->numSlice-1];
  252. SwsFilterDescriptor *desc = c->desc;
  253. int needAlpha = c->needAlpha;
  254. int hasLumHoles = 1;
  255. int hasChrHoles = 1;
  256. if (isPacked(c->srcFormat)) {
  257. src[0] =
  258. src[1] =
  259. src[2] =
  260. src[3] = src[0];
  261. srcStride[0] =
  262. srcStride[1] =
  263. srcStride[2] =
  264. srcStride[3] = srcStride[0];
  265. }
  266. srcStride[1] *= 1 << c->vChrDrop;
  267. srcStride[2] *= 1 << c->vChrDrop;
  268. DEBUG_BUFFERS("swscale() %p[%d] %p[%d] %p[%d] %p[%d] -> %p[%d] %p[%d] %p[%d] %p[%d]\n",
  269. src[0], srcStride[0], src[1], srcStride[1],
  270. src[2], srcStride[2], src[3], srcStride[3],
  271. dst[0], dstStride[0], dst[1], dstStride[1],
  272. dst[2], dstStride[2], dst[3], dstStride[3]);
  273. DEBUG_BUFFERS("srcSliceY: %d srcSliceH: %d dstY: %d dstH: %d\n",
  274. srcSliceY, srcSliceH, dstY, dstH);
  275. DEBUG_BUFFERS("vLumFilterSize: %d vChrFilterSize: %d\n",
  276. vLumFilterSize, vChrFilterSize);
  277. if (dstStride[0]&15 || dstStride[1]&15 ||
  278. dstStride[2]&15 || dstStride[3]&15) {
  279. static int warnedAlready = 0; // FIXME maybe move this into the context
  280. if (flags & SWS_PRINT_INFO && !warnedAlready) {
  281. av_log(c, AV_LOG_WARNING,
  282. "Warning: dstStride is not aligned!\n"
  283. " ->cannot do aligned memory accesses anymore\n");
  284. warnedAlready = 1;
  285. }
  286. }
  287. if ( (uintptr_t)dst[0]&15 || (uintptr_t)dst[1]&15 || (uintptr_t)dst[2]&15
  288. || (uintptr_t)src[0]&15 || (uintptr_t)src[1]&15 || (uintptr_t)src[2]&15
  289. || dstStride[0]&15 || dstStride[1]&15 || dstStride[2]&15 || dstStride[3]&15
  290. || srcStride[0]&15 || srcStride[1]&15 || srcStride[2]&15 || srcStride[3]&15
  291. ) {
  292. static int warnedAlready=0;
  293. int cpu_flags = av_get_cpu_flags();
  294. if (HAVE_MMXEXT && (cpu_flags & AV_CPU_FLAG_SSE2) && !warnedAlready){
  295. av_log(c, AV_LOG_WARNING, "Warning: data is not aligned! This can lead to a speed loss\n");
  296. warnedAlready=1;
  297. }
  298. }
  299. /* Note the user might start scaling the picture in the middle so this
  300. * will not get executed. This is not really intended but works
  301. * currently, so people might do it. */
  302. if (srcSliceY == 0) {
  303. lumBufIndex = -1;
  304. chrBufIndex = -1;
  305. dstY = 0;
  306. lastInLumBuf = -1;
  307. lastInChrBuf = -1;
  308. }
  309. if (!should_dither) {
  310. c->chrDither8 = c->lumDither8 = sws_pb_64;
  311. }
  312. lastDstY = dstY;
  313. ff_init_vscale_pfn(c, yuv2plane1, yuv2planeX, yuv2nv12cX,
  314. yuv2packed1, yuv2packed2, yuv2packedX, yuv2anyX, c->use_mmx_vfilter);
  315. ff_init_slice_from_src(src_slice, (uint8_t**)src, srcStride, c->srcW,
  316. srcSliceY, srcSliceH, chrSrcSliceY, chrSrcSliceH, 1);
  317. ff_init_slice_from_src(vout_slice, (uint8_t**)dst, dstStride, c->dstW,
  318. dstY, dstH, dstY >> c->chrDstVSubSample,
  319. AV_CEIL_RSHIFT(dstH, c->chrDstVSubSample), 0);
  320. if (srcSliceY == 0) {
  321. hout_slice->plane[0].sliceY = lastInLumBuf + 1;
  322. hout_slice->plane[1].sliceY = lastInChrBuf + 1;
  323. hout_slice->plane[2].sliceY = lastInChrBuf + 1;
  324. hout_slice->plane[3].sliceY = lastInLumBuf + 1;
  325. hout_slice->plane[0].sliceH =
  326. hout_slice->plane[1].sliceH =
  327. hout_slice->plane[2].sliceH =
  328. hout_slice->plane[3].sliceH = 0;
  329. hout_slice->width = dstW;
  330. }
  331. for (; dstY < dstH; dstY++) {
  332. const int chrDstY = dstY >> c->chrDstVSubSample;
  333. int use_mmx_vfilter= c->use_mmx_vfilter;
  334. // First line needed as input
  335. const int firstLumSrcY = FFMAX(1 - vLumFilterSize, vLumFilterPos[dstY]);
  336. const int firstLumSrcY2 = FFMAX(1 - vLumFilterSize, vLumFilterPos[FFMIN(dstY | ((1 << c->chrDstVSubSample) - 1), dstH - 1)]);
  337. // First line needed as input
  338. const int firstChrSrcY = FFMAX(1 - vChrFilterSize, vChrFilterPos[chrDstY]);
  339. // Last line needed as input
  340. int lastLumSrcY = FFMIN(c->srcH, firstLumSrcY + vLumFilterSize) - 1;
  341. int lastLumSrcY2 = FFMIN(c->srcH, firstLumSrcY2 + vLumFilterSize) - 1;
  342. int lastChrSrcY = FFMIN(c->chrSrcH, firstChrSrcY + vChrFilterSize) - 1;
  343. int enough_lines;
  344. int i;
  345. int posY, cPosY, firstPosY, lastPosY, firstCPosY, lastCPosY;
  346. // handle holes (FAST_BILINEAR & weird filters)
  347. if (firstLumSrcY > lastInLumBuf) {
  348. hasLumHoles = lastInLumBuf != firstLumSrcY - 1;
  349. if (hasLumHoles) {
  350. hout_slice->plane[0].sliceY = firstLumSrcY;
  351. hout_slice->plane[3].sliceY = firstLumSrcY;
  352. hout_slice->plane[0].sliceH =
  353. hout_slice->plane[3].sliceH = 0;
  354. }
  355. lastInLumBuf = firstLumSrcY - 1;
  356. }
  357. if (firstChrSrcY > lastInChrBuf) {
  358. hasChrHoles = lastInChrBuf != firstChrSrcY - 1;
  359. if (hasChrHoles) {
  360. hout_slice->plane[1].sliceY = firstChrSrcY;
  361. hout_slice->plane[2].sliceY = firstChrSrcY;
  362. hout_slice->plane[1].sliceH =
  363. hout_slice->plane[2].sliceH = 0;
  364. }
  365. lastInChrBuf = firstChrSrcY - 1;
  366. }
  367. DEBUG_BUFFERS("dstY: %d\n", dstY);
  368. DEBUG_BUFFERS("\tfirstLumSrcY: %d lastLumSrcY: %d lastInLumBuf: %d\n",
  369. firstLumSrcY, lastLumSrcY, lastInLumBuf);
  370. DEBUG_BUFFERS("\tfirstChrSrcY: %d lastChrSrcY: %d lastInChrBuf: %d\n",
  371. firstChrSrcY, lastChrSrcY, lastInChrBuf);
  372. // Do we have enough lines in this slice to output the dstY line
  373. enough_lines = lastLumSrcY2 < srcSliceY + srcSliceH &&
  374. lastChrSrcY < AV_CEIL_RSHIFT(srcSliceY + srcSliceH, c->chrSrcVSubSample);
  375. if (!enough_lines) {
  376. lastLumSrcY = srcSliceY + srcSliceH - 1;
  377. lastChrSrcY = chrSrcSliceY + chrSrcSliceH - 1;
  378. DEBUG_BUFFERS("buffering slice: lastLumSrcY %d lastChrSrcY %d\n",
  379. lastLumSrcY, lastChrSrcY);
  380. }
  381. av_assert0((lastLumSrcY - firstLumSrcY + 1) <= hout_slice->plane[0].available_lines);
  382. av_assert0((lastChrSrcY - firstChrSrcY + 1) <= hout_slice->plane[1].available_lines);
  383. posY = hout_slice->plane[0].sliceY + hout_slice->plane[0].sliceH;
  384. if (posY <= lastLumSrcY && !hasLumHoles) {
  385. firstPosY = FFMAX(firstLumSrcY, posY);
  386. lastPosY = FFMIN(firstLumSrcY + hout_slice->plane[0].available_lines - 1, srcSliceY + srcSliceH - 1);
  387. } else {
  388. firstPosY = posY;
  389. lastPosY = lastLumSrcY;
  390. }
  391. cPosY = hout_slice->plane[1].sliceY + hout_slice->plane[1].sliceH;
  392. if (cPosY <= lastChrSrcY && !hasChrHoles) {
  393. firstCPosY = FFMAX(firstChrSrcY, cPosY);
  394. lastCPosY = FFMIN(firstChrSrcY + hout_slice->plane[1].available_lines - 1, AV_CEIL_RSHIFT(srcSliceY + srcSliceH, c->chrSrcVSubSample) - 1);
  395. } else {
  396. firstCPosY = cPosY;
  397. lastCPosY = lastChrSrcY;
  398. }
  399. ff_rotate_slice(hout_slice, lastPosY, lastCPosY);
  400. if (posY < lastLumSrcY + 1) {
  401. for (i = lumStart; i < lumEnd; ++i)
  402. desc[i].process(c, &desc[i], firstPosY, lastPosY - firstPosY + 1);
  403. }
  404. lumBufIndex += lastLumSrcY - lastInLumBuf;
  405. lastInLumBuf = lastLumSrcY;
  406. if (cPosY < lastChrSrcY + 1) {
  407. for (i = chrStart; i < chrEnd; ++i)
  408. desc[i].process(c, &desc[i], firstCPosY, lastCPosY - firstCPosY + 1);
  409. }
  410. chrBufIndex += lastChrSrcY - lastInChrBuf;
  411. lastInChrBuf = lastChrSrcY;
  412. // wrap buf index around to stay inside the ring buffer
  413. if (lumBufIndex >= vLumFilterSize)
  414. lumBufIndex -= vLumFilterSize;
  415. if (chrBufIndex >= vChrFilterSize)
  416. chrBufIndex -= vChrFilterSize;
  417. if (!enough_lines)
  418. break; // we can't output a dstY line so let's try with the next slice
  419. #if HAVE_MMX_INLINE
  420. ff_updateMMXDitherTables(c, dstY, lumBufIndex, chrBufIndex,
  421. lastInLumBuf, lastInChrBuf);
  422. #endif
  423. if (should_dither) {
  424. c->chrDither8 = ff_dither_8x8_128[chrDstY & 7];
  425. c->lumDither8 = ff_dither_8x8_128[dstY & 7];
  426. }
  427. if (dstY >= dstH - 2) {
  428. /* hmm looks like we can't use MMX here without overwriting
  429. * this array's tail */
  430. ff_sws_init_output_funcs(c, &yuv2plane1, &yuv2planeX, &yuv2nv12cX,
  431. &yuv2packed1, &yuv2packed2, &yuv2packedX, &yuv2anyX);
  432. use_mmx_vfilter= 0;
  433. ff_init_vscale_pfn(c, yuv2plane1, yuv2planeX, yuv2nv12cX,
  434. yuv2packed1, yuv2packed2, yuv2packedX, yuv2anyX, use_mmx_vfilter);
  435. }
  436. {
  437. for (i = vStart; i < vEnd; ++i)
  438. desc[i].process(c, &desc[i], dstY, 1);
  439. }
  440. }
  441. if (isPlanar(dstFormat) && isALPHA(dstFormat) && !needAlpha) {
  442. int length = dstW;
  443. int height = dstY - lastDstY;
  444. if (is16BPS(dstFormat) || isNBPS(dstFormat)) {
  445. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(dstFormat);
  446. fillPlane16(dst[3], dstStride[3], length, height, lastDstY,
  447. 1, desc->comp[3].depth,
  448. isBE(dstFormat));
  449. } else
  450. fillPlane(dst[3], dstStride[3], length, height, lastDstY, 255);
  451. }
  452. #if HAVE_MMXEXT_INLINE
  453. if (av_get_cpu_flags() & AV_CPU_FLAG_MMXEXT)
  454. __asm__ volatile ("sfence" ::: "memory");
  455. #endif
  456. emms_c();
  457. /* store changed local vars back in the context */
  458. c->dstY = dstY;
  459. c->lumBufIndex = lumBufIndex;
  460. c->chrBufIndex = chrBufIndex;
  461. c->lastInLumBuf = lastInLumBuf;
  462. c->lastInChrBuf = lastInChrBuf;
  463. return dstY - lastDstY;
  464. }
  465. av_cold void ff_sws_init_range_convert(SwsContext *c)
  466. {
  467. c->lumConvertRange = NULL;
  468. c->chrConvertRange = NULL;
  469. if (c->srcRange != c->dstRange && !isAnyRGB(c->dstFormat)) {
  470. if (c->dstBpc <= 14) {
  471. if (c->srcRange) {
  472. c->lumConvertRange = lumRangeFromJpeg_c;
  473. c->chrConvertRange = chrRangeFromJpeg_c;
  474. } else {
  475. c->lumConvertRange = lumRangeToJpeg_c;
  476. c->chrConvertRange = chrRangeToJpeg_c;
  477. }
  478. } else {
  479. if (c->srcRange) {
  480. c->lumConvertRange = lumRangeFromJpeg16_c;
  481. c->chrConvertRange = chrRangeFromJpeg16_c;
  482. } else {
  483. c->lumConvertRange = lumRangeToJpeg16_c;
  484. c->chrConvertRange = chrRangeToJpeg16_c;
  485. }
  486. }
  487. }
  488. }
  489. static av_cold void sws_init_swscale(SwsContext *c)
  490. {
  491. enum AVPixelFormat srcFormat = c->srcFormat;
  492. ff_sws_init_output_funcs(c, &c->yuv2plane1, &c->yuv2planeX,
  493. &c->yuv2nv12cX, &c->yuv2packed1,
  494. &c->yuv2packed2, &c->yuv2packedX, &c->yuv2anyX);
  495. ff_sws_init_input_funcs(c);
  496. if (c->srcBpc == 8) {
  497. if (c->dstBpc <= 14) {
  498. c->hyScale = c->hcScale = hScale8To15_c;
  499. if (c->flags & SWS_FAST_BILINEAR) {
  500. c->hyscale_fast = ff_hyscale_fast_c;
  501. c->hcscale_fast = ff_hcscale_fast_c;
  502. }
  503. } else {
  504. c->hyScale = c->hcScale = hScale8To19_c;
  505. }
  506. } else {
  507. c->hyScale = c->hcScale = c->dstBpc > 14 ? hScale16To19_c
  508. : hScale16To15_c;
  509. }
  510. ff_sws_init_range_convert(c);
  511. if (!(isGray(srcFormat) || isGray(c->dstFormat) ||
  512. srcFormat == AV_PIX_FMT_MONOBLACK || srcFormat == AV_PIX_FMT_MONOWHITE))
  513. c->needs_hcscale = 1;
  514. }
  515. SwsFunc ff_getSwsFunc(SwsContext *c)
  516. {
  517. sws_init_swscale(c);
  518. if (ARCH_PPC)
  519. ff_sws_init_swscale_ppc(c);
  520. if (ARCH_X86)
  521. ff_sws_init_swscale_x86(c);
  522. if (ARCH_AARCH64)
  523. ff_sws_init_swscale_aarch64(c);
  524. if (ARCH_ARM)
  525. ff_sws_init_swscale_arm(c);
  526. return swscale;
  527. }
  528. static void reset_ptr(const uint8_t *src[], enum AVPixelFormat format)
  529. {
  530. if (!isALPHA(format))
  531. src[3] = NULL;
  532. if (!isPlanar(format)) {
  533. src[3] = src[2] = NULL;
  534. if (!usePal(format))
  535. src[1] = NULL;
  536. }
  537. }
  538. static int check_image_pointers(const uint8_t * const data[4], enum AVPixelFormat pix_fmt,
  539. const int linesizes[4])
  540. {
  541. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
  542. int i;
  543. av_assert2(desc);
  544. for (i = 0; i < 4; i++) {
  545. int plane = desc->comp[i].plane;
  546. if (!data[plane] || !linesizes[plane])
  547. return 0;
  548. }
  549. return 1;
  550. }
  551. static void xyz12Torgb48(struct SwsContext *c, uint16_t *dst,
  552. const uint16_t *src, int stride, int h)
  553. {
  554. int xp,yp;
  555. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->srcFormat);
  556. for (yp=0; yp<h; yp++) {
  557. for (xp=0; xp+2<stride; xp+=3) {
  558. int x, y, z, r, g, b;
  559. if (desc->flags & AV_PIX_FMT_FLAG_BE) {
  560. x = AV_RB16(src + xp + 0);
  561. y = AV_RB16(src + xp + 1);
  562. z = AV_RB16(src + xp + 2);
  563. } else {
  564. x = AV_RL16(src + xp + 0);
  565. y = AV_RL16(src + xp + 1);
  566. z = AV_RL16(src + xp + 2);
  567. }
  568. x = c->xyzgamma[x>>4];
  569. y = c->xyzgamma[y>>4];
  570. z = c->xyzgamma[z>>4];
  571. // convert from XYZlinear to sRGBlinear
  572. r = c->xyz2rgb_matrix[0][0] * x +
  573. c->xyz2rgb_matrix[0][1] * y +
  574. c->xyz2rgb_matrix[0][2] * z >> 12;
  575. g = c->xyz2rgb_matrix[1][0] * x +
  576. c->xyz2rgb_matrix[1][1] * y +
  577. c->xyz2rgb_matrix[1][2] * z >> 12;
  578. b = c->xyz2rgb_matrix[2][0] * x +
  579. c->xyz2rgb_matrix[2][1] * y +
  580. c->xyz2rgb_matrix[2][2] * z >> 12;
  581. // limit values to 12-bit depth
  582. r = av_clip_uintp2(r, 12);
  583. g = av_clip_uintp2(g, 12);
  584. b = av_clip_uintp2(b, 12);
  585. // convert from sRGBlinear to RGB and scale from 12bit to 16bit
  586. if (desc->flags & AV_PIX_FMT_FLAG_BE) {
  587. AV_WB16(dst + xp + 0, c->rgbgamma[r] << 4);
  588. AV_WB16(dst + xp + 1, c->rgbgamma[g] << 4);
  589. AV_WB16(dst + xp + 2, c->rgbgamma[b] << 4);
  590. } else {
  591. AV_WL16(dst + xp + 0, c->rgbgamma[r] << 4);
  592. AV_WL16(dst + xp + 1, c->rgbgamma[g] << 4);
  593. AV_WL16(dst + xp + 2, c->rgbgamma[b] << 4);
  594. }
  595. }
  596. src += stride;
  597. dst += stride;
  598. }
  599. }
  600. static void rgb48Toxyz12(struct SwsContext *c, uint16_t *dst,
  601. const uint16_t *src, int stride, int h)
  602. {
  603. int xp,yp;
  604. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->dstFormat);
  605. for (yp=0; yp<h; yp++) {
  606. for (xp=0; xp+2<stride; xp+=3) {
  607. int x, y, z, r, g, b;
  608. if (desc->flags & AV_PIX_FMT_FLAG_BE) {
  609. r = AV_RB16(src + xp + 0);
  610. g = AV_RB16(src + xp + 1);
  611. b = AV_RB16(src + xp + 2);
  612. } else {
  613. r = AV_RL16(src + xp + 0);
  614. g = AV_RL16(src + xp + 1);
  615. b = AV_RL16(src + xp + 2);
  616. }
  617. r = c->rgbgammainv[r>>4];
  618. g = c->rgbgammainv[g>>4];
  619. b = c->rgbgammainv[b>>4];
  620. // convert from sRGBlinear to XYZlinear
  621. x = c->rgb2xyz_matrix[0][0] * r +
  622. c->rgb2xyz_matrix[0][1] * g +
  623. c->rgb2xyz_matrix[0][2] * b >> 12;
  624. y = c->rgb2xyz_matrix[1][0] * r +
  625. c->rgb2xyz_matrix[1][1] * g +
  626. c->rgb2xyz_matrix[1][2] * b >> 12;
  627. z = c->rgb2xyz_matrix[2][0] * r +
  628. c->rgb2xyz_matrix[2][1] * g +
  629. c->rgb2xyz_matrix[2][2] * b >> 12;
  630. // limit values to 12-bit depth
  631. x = av_clip_uintp2(x, 12);
  632. y = av_clip_uintp2(y, 12);
  633. z = av_clip_uintp2(z, 12);
  634. // convert from XYZlinear to X'Y'Z' and scale from 12bit to 16bit
  635. if (desc->flags & AV_PIX_FMT_FLAG_BE) {
  636. AV_WB16(dst + xp + 0, c->xyzgammainv[x] << 4);
  637. AV_WB16(dst + xp + 1, c->xyzgammainv[y] << 4);
  638. AV_WB16(dst + xp + 2, c->xyzgammainv[z] << 4);
  639. } else {
  640. AV_WL16(dst + xp + 0, c->xyzgammainv[x] << 4);
  641. AV_WL16(dst + xp + 1, c->xyzgammainv[y] << 4);
  642. AV_WL16(dst + xp + 2, c->xyzgammainv[z] << 4);
  643. }
  644. }
  645. src += stride;
  646. dst += stride;
  647. }
  648. }
  649. /**
  650. * swscale wrapper, so we don't need to export the SwsContext.
  651. * Assumes planar YUV to be in YUV order instead of YVU.
  652. */
  653. int attribute_align_arg sws_scale(struct SwsContext *c,
  654. const uint8_t * const srcSlice[],
  655. const int srcStride[], int srcSliceY,
  656. int srcSliceH, uint8_t *const dst[],
  657. const int dstStride[])
  658. {
  659. int i, ret;
  660. const uint8_t *src2[4];
  661. uint8_t *dst2[4];
  662. uint8_t *rgb0_tmp = NULL;
  663. int macro_height = isBayer(c->srcFormat) ? 2 : (1 << c->chrSrcVSubSample);
  664. // copy strides, so they can safely be modified
  665. int srcStride2[4];
  666. int dstStride2[4];
  667. int srcSliceY_internal = srcSliceY;
  668. if (!srcStride || !dstStride || !dst || !srcSlice) {
  669. av_log(c, AV_LOG_ERROR, "One of the input parameters to sws_scale() is NULL, please check the calling code\n");
  670. return 0;
  671. }
  672. for (i=0; i<4; i++) {
  673. srcStride2[i] = srcStride[i];
  674. dstStride2[i] = dstStride[i];
  675. }
  676. if ((srcSliceY & (macro_height-1)) ||
  677. ((srcSliceH& (macro_height-1)) && srcSliceY + srcSliceH != c->srcH) ||
  678. srcSliceY + srcSliceH > c->srcH) {
  679. av_log(c, AV_LOG_ERROR, "Slice parameters %d, %d are invalid\n", srcSliceY, srcSliceH);
  680. return AVERROR(EINVAL);
  681. }
  682. if (c->gamma_flag && c->cascaded_context[0]) {
  683. ret = sws_scale(c->cascaded_context[0],
  684. srcSlice, srcStride, srcSliceY, srcSliceH,
  685. c->cascaded_tmp, c->cascaded_tmpStride);
  686. if (ret < 0)
  687. return ret;
  688. if (c->cascaded_context[2])
  689. 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);
  690. else
  691. ret = sws_scale(c->cascaded_context[1], (const uint8_t * const *)c->cascaded_tmp, c->cascaded_tmpStride, srcSliceY, srcSliceH, dst, dstStride);
  692. if (ret < 0)
  693. return ret;
  694. if (c->cascaded_context[2]) {
  695. ret = sws_scale(c->cascaded_context[2],
  696. (const uint8_t * const *)c->cascaded1_tmp, c->cascaded1_tmpStride, c->cascaded_context[1]->dstY - ret, c->cascaded_context[1]->dstY,
  697. dst, dstStride);
  698. }
  699. return ret;
  700. }
  701. if (c->cascaded_context[0] && srcSliceY == 0 && srcSliceH == c->cascaded_context[0]->srcH) {
  702. ret = sws_scale(c->cascaded_context[0],
  703. srcSlice, srcStride, srcSliceY, srcSliceH,
  704. c->cascaded_tmp, c->cascaded_tmpStride);
  705. if (ret < 0)
  706. return ret;
  707. ret = sws_scale(c->cascaded_context[1],
  708. (const uint8_t * const * )c->cascaded_tmp, c->cascaded_tmpStride, 0, c->cascaded_context[0]->dstH,
  709. dst, dstStride);
  710. return ret;
  711. }
  712. memcpy(src2, srcSlice, sizeof(src2));
  713. memcpy(dst2, dst, sizeof(dst2));
  714. // do not mess up sliceDir if we have a "trailing" 0-size slice
  715. if (srcSliceH == 0)
  716. return 0;
  717. if (!check_image_pointers(srcSlice, c->srcFormat, srcStride)) {
  718. av_log(c, AV_LOG_ERROR, "bad src image pointers\n");
  719. return 0;
  720. }
  721. if (!check_image_pointers((const uint8_t* const*)dst, c->dstFormat, dstStride)) {
  722. av_log(c, AV_LOG_ERROR, "bad dst image pointers\n");
  723. return 0;
  724. }
  725. if (c->sliceDir == 0 && srcSliceY != 0 && srcSliceY + srcSliceH != c->srcH) {
  726. av_log(c, AV_LOG_ERROR, "Slices start in the middle!\n");
  727. return 0;
  728. }
  729. if (c->sliceDir == 0) {
  730. if (srcSliceY == 0) c->sliceDir = 1; else c->sliceDir = -1;
  731. }
  732. if (usePal(c->srcFormat)) {
  733. for (i = 0; i < 256; i++) {
  734. int r, g, b, y, u, v, a = 0xff;
  735. if (c->srcFormat == AV_PIX_FMT_PAL8) {
  736. uint32_t p = ((const uint32_t *)(srcSlice[1]))[i];
  737. a = (p >> 24) & 0xFF;
  738. r = (p >> 16) & 0xFF;
  739. g = (p >> 8) & 0xFF;
  740. b = p & 0xFF;
  741. } else if (c->srcFormat == AV_PIX_FMT_RGB8) {
  742. r = ( i >> 5 ) * 36;
  743. g = ((i >> 2) & 7) * 36;
  744. b = ( i & 3) * 85;
  745. } else if (c->srcFormat == AV_PIX_FMT_BGR8) {
  746. b = ( i >> 6 ) * 85;
  747. g = ((i >> 3) & 7) * 36;
  748. r = ( i & 7) * 36;
  749. } else if (c->srcFormat == AV_PIX_FMT_RGB4_BYTE) {
  750. r = ( i >> 3 ) * 255;
  751. g = ((i >> 1) & 3) * 85;
  752. b = ( i & 1) * 255;
  753. } else if (c->srcFormat == AV_PIX_FMT_GRAY8 || c->srcFormat == AV_PIX_FMT_GRAY8A) {
  754. r = g = b = i;
  755. } else {
  756. av_assert1(c->srcFormat == AV_PIX_FMT_BGR4_BYTE);
  757. b = ( i >> 3 ) * 255;
  758. g = ((i >> 1) & 3) * 85;
  759. r = ( i & 1) * 255;
  760. }
  761. #define RGB2YUV_SHIFT 15
  762. #define BY ( (int) (0.114 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
  763. #define BV (-(int) (0.081 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
  764. #define BU ( (int) (0.500 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
  765. #define GY ( (int) (0.587 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
  766. #define GV (-(int) (0.419 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
  767. #define GU (-(int) (0.331 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
  768. #define RY ( (int) (0.299 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
  769. #define RV ( (int) (0.500 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
  770. #define RU (-(int) (0.169 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
  771. y = av_clip_uint8((RY * r + GY * g + BY * b + ( 33 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT);
  772. u = av_clip_uint8((RU * r + GU * g + BU * b + (257 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT);
  773. v = av_clip_uint8((RV * r + GV * g + BV * b + (257 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT);
  774. c->pal_yuv[i]= y + (u<<8) + (v<<16) + ((unsigned)a<<24);
  775. switch (c->dstFormat) {
  776. case AV_PIX_FMT_BGR32:
  777. #if !HAVE_BIGENDIAN
  778. case AV_PIX_FMT_RGB24:
  779. #endif
  780. c->pal_rgb[i]= r + (g<<8) + (b<<16) + ((unsigned)a<<24);
  781. break;
  782. case AV_PIX_FMT_BGR32_1:
  783. #if HAVE_BIGENDIAN
  784. case AV_PIX_FMT_BGR24:
  785. #endif
  786. c->pal_rgb[i]= a + (r<<8) + (g<<16) + ((unsigned)b<<24);
  787. break;
  788. case AV_PIX_FMT_RGB32_1:
  789. #if HAVE_BIGENDIAN
  790. case AV_PIX_FMT_RGB24:
  791. #endif
  792. c->pal_rgb[i]= a + (b<<8) + (g<<16) + ((unsigned)r<<24);
  793. break;
  794. case AV_PIX_FMT_RGB32:
  795. #if !HAVE_BIGENDIAN
  796. case AV_PIX_FMT_BGR24:
  797. #endif
  798. default:
  799. c->pal_rgb[i]= b + (g<<8) + (r<<16) + ((unsigned)a<<24);
  800. }
  801. }
  802. }
  803. if (c->src0Alpha && !c->dst0Alpha && isALPHA(c->dstFormat)) {
  804. uint8_t *base;
  805. int x,y;
  806. rgb0_tmp = av_malloc(FFABS(srcStride[0]) * srcSliceH + 32);
  807. if (!rgb0_tmp)
  808. return AVERROR(ENOMEM);
  809. base = srcStride[0] < 0 ? rgb0_tmp - srcStride[0] * (srcSliceH-1) : rgb0_tmp;
  810. for (y=0; y<srcSliceH; y++){
  811. memcpy(base + srcStride[0]*y, src2[0] + srcStride[0]*y, 4*c->srcW);
  812. for (x=c->src0Alpha-1; x<4*c->srcW; x+=4) {
  813. base[ srcStride[0]*y + x] = 0xFF;
  814. }
  815. }
  816. src2[0] = base;
  817. }
  818. if (c->srcXYZ && !(c->dstXYZ && c->srcW==c->dstW && c->srcH==c->dstH)) {
  819. uint8_t *base;
  820. rgb0_tmp = av_malloc(FFABS(srcStride[0]) * srcSliceH + 32);
  821. if (!rgb0_tmp)
  822. return AVERROR(ENOMEM);
  823. base = srcStride[0] < 0 ? rgb0_tmp - srcStride[0] * (srcSliceH-1) : rgb0_tmp;
  824. xyz12Torgb48(c, (uint16_t*)base, (const uint16_t*)src2[0], srcStride[0]/2, srcSliceH);
  825. src2[0] = base;
  826. }
  827. if (!srcSliceY && (c->flags & SWS_BITEXACT) && c->dither == SWS_DITHER_ED && c->dither_error[0])
  828. for (i = 0; i < 4; i++)
  829. memset(c->dither_error[i], 0, sizeof(c->dither_error[0][0]) * (c->dstW+2));
  830. if (c->sliceDir != 1) {
  831. // slices go from bottom to top => we flip the image internally
  832. for (i=0; i<4; i++) {
  833. srcStride2[i] *= -1;
  834. dstStride2[i] *= -1;
  835. }
  836. src2[0] += (srcSliceH - 1) * srcStride[0];
  837. if (!usePal(c->srcFormat))
  838. src2[1] += ((srcSliceH >> c->chrSrcVSubSample) - 1) * srcStride[1];
  839. src2[2] += ((srcSliceH >> c->chrSrcVSubSample) - 1) * srcStride[2];
  840. src2[3] += (srcSliceH - 1) * srcStride[3];
  841. dst2[0] += ( c->dstH - 1) * dstStride[0];
  842. dst2[1] += ((c->dstH >> c->chrDstVSubSample) - 1) * dstStride[1];
  843. dst2[2] += ((c->dstH >> c->chrDstVSubSample) - 1) * dstStride[2];
  844. dst2[3] += ( c->dstH - 1) * dstStride[3];
  845. srcSliceY_internal = c->srcH-srcSliceY-srcSliceH;
  846. }
  847. reset_ptr(src2, c->srcFormat);
  848. reset_ptr((void*)dst2, c->dstFormat);
  849. /* reset slice direction at end of frame */
  850. if (srcSliceY_internal + srcSliceH == c->srcH)
  851. c->sliceDir = 0;
  852. ret = c->swscale(c, src2, srcStride2, srcSliceY_internal, srcSliceH, dst2, dstStride2);
  853. if (c->dstXYZ && !(c->srcXYZ && c->srcW==c->dstW && c->srcH==c->dstH)) {
  854. int dstY = c->dstY ? c->dstY : srcSliceY + srcSliceH;
  855. uint16_t *dst16 = (uint16_t*)(dst2[0] + (dstY - ret) * dstStride2[0]);
  856. av_assert0(dstY >= ret);
  857. av_assert0(ret >= 0);
  858. av_assert0(c->dstH >= dstY);
  859. /* replace on the same data */
  860. rgb48Toxyz12(c, dst16, dst16, dstStride2[0]/2, ret);
  861. }
  862. av_free(rgb0_tmp);
  863. return ret;
  864. }