swscale_unscaled.c 88 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204
  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 <string.h>
  22. #include <math.h>
  23. #include <stdio.h>
  24. #include "config.h"
  25. #include "swscale.h"
  26. #include "swscale_internal.h"
  27. #include "rgb2rgb.h"
  28. #include "libavutil/intreadwrite.h"
  29. #include "libavutil/cpu.h"
  30. #include "libavutil/avutil.h"
  31. #include "libavutil/mathematics.h"
  32. #include "libavutil/bswap.h"
  33. #include "libavutil/pixdesc.h"
  34. #include "libavutil/avassert.h"
  35. #include "libavutil/avconfig.h"
  36. DECLARE_ALIGNED(8, static const uint8_t, dithers)[8][8][8]={
  37. {
  38. { 0, 1, 0, 1, 0, 1, 0, 1,},
  39. { 1, 0, 1, 0, 1, 0, 1, 0,},
  40. { 0, 1, 0, 1, 0, 1, 0, 1,},
  41. { 1, 0, 1, 0, 1, 0, 1, 0,},
  42. { 0, 1, 0, 1, 0, 1, 0, 1,},
  43. { 1, 0, 1, 0, 1, 0, 1, 0,},
  44. { 0, 1, 0, 1, 0, 1, 0, 1,},
  45. { 1, 0, 1, 0, 1, 0, 1, 0,},
  46. },{
  47. { 1, 2, 1, 2, 1, 2, 1, 2,},
  48. { 3, 0, 3, 0, 3, 0, 3, 0,},
  49. { 1, 2, 1, 2, 1, 2, 1, 2,},
  50. { 3, 0, 3, 0, 3, 0, 3, 0,},
  51. { 1, 2, 1, 2, 1, 2, 1, 2,},
  52. { 3, 0, 3, 0, 3, 0, 3, 0,},
  53. { 1, 2, 1, 2, 1, 2, 1, 2,},
  54. { 3, 0, 3, 0, 3, 0, 3, 0,},
  55. },{
  56. { 2, 4, 3, 5, 2, 4, 3, 5,},
  57. { 6, 0, 7, 1, 6, 0, 7, 1,},
  58. { 3, 5, 2, 4, 3, 5, 2, 4,},
  59. { 7, 1, 6, 0, 7, 1, 6, 0,},
  60. { 2, 4, 3, 5, 2, 4, 3, 5,},
  61. { 6, 0, 7, 1, 6, 0, 7, 1,},
  62. { 3, 5, 2, 4, 3, 5, 2, 4,},
  63. { 7, 1, 6, 0, 7, 1, 6, 0,},
  64. },{
  65. { 4, 8, 7, 11, 4, 8, 7, 11,},
  66. { 12, 0, 15, 3, 12, 0, 15, 3,},
  67. { 6, 10, 5, 9, 6, 10, 5, 9,},
  68. { 14, 2, 13, 1, 14, 2, 13, 1,},
  69. { 4, 8, 7, 11, 4, 8, 7, 11,},
  70. { 12, 0, 15, 3, 12, 0, 15, 3,},
  71. { 6, 10, 5, 9, 6, 10, 5, 9,},
  72. { 14, 2, 13, 1, 14, 2, 13, 1,},
  73. },{
  74. { 9, 17, 15, 23, 8, 16, 14, 22,},
  75. { 25, 1, 31, 7, 24, 0, 30, 6,},
  76. { 13, 21, 11, 19, 12, 20, 10, 18,},
  77. { 29, 5, 27, 3, 28, 4, 26, 2,},
  78. { 8, 16, 14, 22, 9, 17, 15, 23,},
  79. { 24, 0, 30, 6, 25, 1, 31, 7,},
  80. { 12, 20, 10, 18, 13, 21, 11, 19,},
  81. { 28, 4, 26, 2, 29, 5, 27, 3,},
  82. },{
  83. { 18, 34, 30, 46, 17, 33, 29, 45,},
  84. { 50, 2, 62, 14, 49, 1, 61, 13,},
  85. { 26, 42, 22, 38, 25, 41, 21, 37,},
  86. { 58, 10, 54, 6, 57, 9, 53, 5,},
  87. { 16, 32, 28, 44, 19, 35, 31, 47,},
  88. { 48, 0, 60, 12, 51, 3, 63, 15,},
  89. { 24, 40, 20, 36, 27, 43, 23, 39,},
  90. { 56, 8, 52, 4, 59, 11, 55, 7,},
  91. },{
  92. { 18, 34, 30, 46, 17, 33, 29, 45,},
  93. { 50, 2, 62, 14, 49, 1, 61, 13,},
  94. { 26, 42, 22, 38, 25, 41, 21, 37,},
  95. { 58, 10, 54, 6, 57, 9, 53, 5,},
  96. { 16, 32, 28, 44, 19, 35, 31, 47,},
  97. { 48, 0, 60, 12, 51, 3, 63, 15,},
  98. { 24, 40, 20, 36, 27, 43, 23, 39,},
  99. { 56, 8, 52, 4, 59, 11, 55, 7,},
  100. },{
  101. { 36, 68, 60, 92, 34, 66, 58, 90,},
  102. { 100, 4,124, 28, 98, 2,122, 26,},
  103. { 52, 84, 44, 76, 50, 82, 42, 74,},
  104. { 116, 20,108, 12,114, 18,106, 10,},
  105. { 32, 64, 56, 88, 38, 70, 62, 94,},
  106. { 96, 0,120, 24,102, 6,126, 30,},
  107. { 48, 80, 40, 72, 54, 86, 46, 78,},
  108. { 112, 16,104, 8,118, 22,110, 14,},
  109. }};
  110. static void fillPlane(uint8_t *plane, int stride, int width, int height, int y,
  111. uint8_t val)
  112. {
  113. int i;
  114. uint8_t *ptr = plane + stride * y;
  115. for (i = 0; i < height; i++) {
  116. memset(ptr, val, width);
  117. ptr += stride;
  118. }
  119. }
  120. static void copyPlane(const uint8_t *src, int srcStride,
  121. int srcSliceY, int srcSliceH, int width,
  122. uint8_t *dst, int dstStride)
  123. {
  124. dst += dstStride * srcSliceY;
  125. if (dstStride == srcStride && srcStride > 0) {
  126. memcpy(dst, src, srcSliceH * dstStride);
  127. } else {
  128. int i;
  129. for (i = 0; i < srcSliceH; i++) {
  130. memcpy(dst, src, width);
  131. src += srcStride;
  132. dst += dstStride;
  133. }
  134. }
  135. }
  136. static int planarToNv12Wrapper(SwsContext *c, const uint8_t *src[],
  137. int srcStride[], int srcSliceY,
  138. int srcSliceH, uint8_t *dstParam[],
  139. int dstStride[])
  140. {
  141. uint8_t *dst = dstParam[1] + dstStride[1] * srcSliceY / 2;
  142. copyPlane(src[0], srcStride[0], srcSliceY, srcSliceH, c->srcW,
  143. dstParam[0], dstStride[0]);
  144. if (c->dstFormat == AV_PIX_FMT_NV12)
  145. interleaveBytes(src[1], src[2], dst, c->chrSrcW, (srcSliceH + 1) / 2,
  146. srcStride[1], srcStride[2], dstStride[1]);
  147. else
  148. interleaveBytes(src[2], src[1], dst, c->chrSrcW, (srcSliceH + 1) / 2,
  149. srcStride[2], srcStride[1], dstStride[1]);
  150. return srcSliceH;
  151. }
  152. static int nv12ToPlanarWrapper(SwsContext *c, const uint8_t *src[],
  153. int srcStride[], int srcSliceY,
  154. int srcSliceH, uint8_t *dstParam[],
  155. int dstStride[])
  156. {
  157. uint8_t *dst1 = dstParam[1] + dstStride[1] * srcSliceY / 2;
  158. uint8_t *dst2 = dstParam[2] + dstStride[2] * srcSliceY / 2;
  159. copyPlane(src[0], srcStride[0], srcSliceY, srcSliceH, c->srcW,
  160. dstParam[0], dstStride[0]);
  161. if (c->srcFormat == AV_PIX_FMT_NV12)
  162. deinterleaveBytes(src[1], dst1, dst2, c->chrSrcW, (srcSliceH + 1) / 2,
  163. srcStride[1], dstStride[1], dstStride[2]);
  164. else
  165. deinterleaveBytes(src[1], dst2, dst1, c->chrSrcW, (srcSliceH + 1) / 2,
  166. srcStride[1], dstStride[2], dstStride[1]);
  167. return srcSliceH;
  168. }
  169. static int planarToNv24Wrapper(SwsContext *c, const uint8_t *src[],
  170. int srcStride[], int srcSliceY,
  171. int srcSliceH, uint8_t *dstParam[],
  172. int dstStride[])
  173. {
  174. uint8_t *dst = dstParam[1] + dstStride[1] * srcSliceY;
  175. copyPlane(src[0], srcStride[0], srcSliceY, srcSliceH, c->srcW,
  176. dstParam[0], dstStride[0]);
  177. if (c->dstFormat == AV_PIX_FMT_NV24)
  178. interleaveBytes(src[1], src[2], dst, c->chrSrcW, srcSliceH,
  179. srcStride[1], srcStride[2], dstStride[1]);
  180. else
  181. interleaveBytes(src[2], src[1], dst, c->chrSrcW, srcSliceH,
  182. srcStride[2], srcStride[1], dstStride[1]);
  183. return srcSliceH;
  184. }
  185. static int nv24ToPlanarWrapper(SwsContext *c, const uint8_t *src[],
  186. int srcStride[], int srcSliceY,
  187. int srcSliceH, uint8_t *dstParam[],
  188. int dstStride[])
  189. {
  190. uint8_t *dst1 = dstParam[1] + dstStride[1] * srcSliceY;
  191. uint8_t *dst2 = dstParam[2] + dstStride[2] * srcSliceY;
  192. copyPlane(src[0], srcStride[0], srcSliceY, srcSliceH, c->srcW,
  193. dstParam[0], dstStride[0]);
  194. if (c->srcFormat == AV_PIX_FMT_NV24)
  195. deinterleaveBytes(src[1], dst1, dst2, c->chrSrcW, srcSliceH,
  196. srcStride[1], dstStride[1], dstStride[2]);
  197. else
  198. deinterleaveBytes(src[1], dst2, dst1, c->chrSrcW, srcSliceH,
  199. srcStride[1], dstStride[2], dstStride[1]);
  200. return srcSliceH;
  201. }
  202. static int planarToP01xWrapper(SwsContext *c, const uint8_t *src8[],
  203. int srcStride[], int srcSliceY,
  204. int srcSliceH, uint8_t *dstParam8[],
  205. int dstStride[])
  206. {
  207. const AVPixFmtDescriptor *src_format = av_pix_fmt_desc_get(c->srcFormat);
  208. const AVPixFmtDescriptor *dst_format = av_pix_fmt_desc_get(c->dstFormat);
  209. const uint16_t **src = (const uint16_t**)src8;
  210. uint16_t *dstY = (uint16_t*)(dstParam8[0] + dstStride[0] * srcSliceY);
  211. uint16_t *dstUV = (uint16_t*)(dstParam8[1] + dstStride[1] * srcSliceY / 2);
  212. int x, y;
  213. /* Calculate net shift required for values. */
  214. const int shift[3] = {
  215. dst_format->comp[0].depth + dst_format->comp[0].shift -
  216. src_format->comp[0].depth - src_format->comp[0].shift,
  217. dst_format->comp[1].depth + dst_format->comp[1].shift -
  218. src_format->comp[1].depth - src_format->comp[1].shift,
  219. dst_format->comp[2].depth + dst_format->comp[2].shift -
  220. src_format->comp[2].depth - src_format->comp[2].shift,
  221. };
  222. av_assert0(!(srcStride[0] % 2 || srcStride[1] % 2 || srcStride[2] % 2 ||
  223. dstStride[0] % 2 || dstStride[1] % 2));
  224. for (y = 0; y < srcSliceH; y++) {
  225. uint16_t *tdstY = dstY;
  226. const uint16_t *tsrc0 = src[0];
  227. for (x = c->srcW; x > 0; x--) {
  228. *tdstY++ = *tsrc0++ << shift[0];
  229. }
  230. src[0] += srcStride[0] / 2;
  231. dstY += dstStride[0] / 2;
  232. if (!(y & 1)) {
  233. uint16_t *tdstUV = dstUV;
  234. const uint16_t *tsrc1 = src[1];
  235. const uint16_t *tsrc2 = src[2];
  236. for (x = c->srcW / 2; x > 0; x--) {
  237. *tdstUV++ = *tsrc1++ << shift[1];
  238. *tdstUV++ = *tsrc2++ << shift[2];
  239. }
  240. src[1] += srcStride[1] / 2;
  241. src[2] += srcStride[2] / 2;
  242. dstUV += dstStride[1] / 2;
  243. }
  244. }
  245. return srcSliceH;
  246. }
  247. #if AV_HAVE_BIGENDIAN
  248. #define output_pixel(p, v) do { \
  249. uint16_t *pp = (p); \
  250. AV_WL16(pp, (v)); \
  251. } while(0)
  252. #else
  253. #define output_pixel(p, v) (*p) = (v)
  254. #endif
  255. static int planar8ToP01xleWrapper(SwsContext *c, const uint8_t *src[],
  256. int srcStride[], int srcSliceY,
  257. int srcSliceH, uint8_t *dstParam8[],
  258. int dstStride[])
  259. {
  260. uint16_t *dstY = (uint16_t*)(dstParam8[0] + dstStride[0] * srcSliceY);
  261. uint16_t *dstUV = (uint16_t*)(dstParam8[1] + dstStride[1] * srcSliceY / 2);
  262. int x, y, t;
  263. av_assert0(!(dstStride[0] % 2 || dstStride[1] % 2));
  264. for (y = 0; y < srcSliceH; y++) {
  265. uint16_t *tdstY = dstY;
  266. const uint8_t *tsrc0 = src[0];
  267. for (x = c->srcW; x > 0; x--) {
  268. t = *tsrc0++;
  269. output_pixel(tdstY++, t | (t << 8));
  270. }
  271. src[0] += srcStride[0];
  272. dstY += dstStride[0] / 2;
  273. if (!(y & 1)) {
  274. uint16_t *tdstUV = dstUV;
  275. const uint8_t *tsrc1 = src[1];
  276. const uint8_t *tsrc2 = src[2];
  277. for (x = c->srcW / 2; x > 0; x--) {
  278. t = *tsrc1++;
  279. output_pixel(tdstUV++, t | (t << 8));
  280. t = *tsrc2++;
  281. output_pixel(tdstUV++, t | (t << 8));
  282. }
  283. src[1] += srcStride[1];
  284. src[2] += srcStride[2];
  285. dstUV += dstStride[1] / 2;
  286. }
  287. }
  288. return srcSliceH;
  289. }
  290. #undef output_pixel
  291. static int planarToYuy2Wrapper(SwsContext *c, const uint8_t *src[],
  292. int srcStride[], int srcSliceY, int srcSliceH,
  293. uint8_t *dstParam[], int dstStride[])
  294. {
  295. uint8_t *dst = dstParam[0] + dstStride[0] * srcSliceY;
  296. yv12toyuy2(src[0], src[1], src[2], dst, c->srcW, srcSliceH, srcStride[0],
  297. srcStride[1], dstStride[0]);
  298. return srcSliceH;
  299. }
  300. static int planarToUyvyWrapper(SwsContext *c, const uint8_t *src[],
  301. int srcStride[], int srcSliceY, int srcSliceH,
  302. uint8_t *dstParam[], int dstStride[])
  303. {
  304. uint8_t *dst = dstParam[0] + dstStride[0] * srcSliceY;
  305. yv12touyvy(src[0], src[1], src[2], dst, c->srcW, srcSliceH, srcStride[0],
  306. srcStride[1], dstStride[0]);
  307. return srcSliceH;
  308. }
  309. static int yuv422pToYuy2Wrapper(SwsContext *c, const uint8_t *src[],
  310. int srcStride[], int srcSliceY, int srcSliceH,
  311. uint8_t *dstParam[], int dstStride[])
  312. {
  313. uint8_t *dst = dstParam[0] + dstStride[0] * srcSliceY;
  314. yuv422ptoyuy2(src[0], src[1], src[2], dst, c->srcW, srcSliceH, srcStride[0],
  315. srcStride[1], dstStride[0]);
  316. return srcSliceH;
  317. }
  318. static int yuv422pToUyvyWrapper(SwsContext *c, const uint8_t *src[],
  319. int srcStride[], int srcSliceY, int srcSliceH,
  320. uint8_t *dstParam[], int dstStride[])
  321. {
  322. uint8_t *dst = dstParam[0] + dstStride[0] * srcSliceY;
  323. yuv422ptouyvy(src[0], src[1], src[2], dst, c->srcW, srcSliceH, srcStride[0],
  324. srcStride[1], dstStride[0]);
  325. return srcSliceH;
  326. }
  327. static int yuyvToYuv420Wrapper(SwsContext *c, const uint8_t *src[],
  328. int srcStride[], int srcSliceY, int srcSliceH,
  329. uint8_t *dstParam[], int dstStride[])
  330. {
  331. uint8_t *ydst = dstParam[0] + dstStride[0] * srcSliceY;
  332. uint8_t *udst = dstParam[1] + dstStride[1] * srcSliceY / 2;
  333. uint8_t *vdst = dstParam[2] + dstStride[2] * srcSliceY / 2;
  334. yuyvtoyuv420(ydst, udst, vdst, src[0], c->srcW, srcSliceH, dstStride[0],
  335. dstStride[1], srcStride[0]);
  336. if (dstParam[3])
  337. fillPlane(dstParam[3], dstStride[3], c->srcW, srcSliceH, srcSliceY, 255);
  338. return srcSliceH;
  339. }
  340. static int yuyvToYuv422Wrapper(SwsContext *c, const uint8_t *src[],
  341. int srcStride[], int srcSliceY, int srcSliceH,
  342. uint8_t *dstParam[], int dstStride[])
  343. {
  344. uint8_t *ydst = dstParam[0] + dstStride[0] * srcSliceY;
  345. uint8_t *udst = dstParam[1] + dstStride[1] * srcSliceY;
  346. uint8_t *vdst = dstParam[2] + dstStride[2] * srcSliceY;
  347. yuyvtoyuv422(ydst, udst, vdst, src[0], c->srcW, srcSliceH, dstStride[0],
  348. dstStride[1], srcStride[0]);
  349. return srcSliceH;
  350. }
  351. static int uyvyToYuv420Wrapper(SwsContext *c, const uint8_t *src[],
  352. int srcStride[], int srcSliceY, int srcSliceH,
  353. uint8_t *dstParam[], int dstStride[])
  354. {
  355. uint8_t *ydst = dstParam[0] + dstStride[0] * srcSliceY;
  356. uint8_t *udst = dstParam[1] + dstStride[1] * srcSliceY / 2;
  357. uint8_t *vdst = dstParam[2] + dstStride[2] * srcSliceY / 2;
  358. uyvytoyuv420(ydst, udst, vdst, src[0], c->srcW, srcSliceH, dstStride[0],
  359. dstStride[1], srcStride[0]);
  360. if (dstParam[3])
  361. fillPlane(dstParam[3], dstStride[3], c->srcW, srcSliceH, srcSliceY, 255);
  362. return srcSliceH;
  363. }
  364. static int uyvyToYuv422Wrapper(SwsContext *c, const uint8_t *src[],
  365. int srcStride[], int srcSliceY, int srcSliceH,
  366. uint8_t *dstParam[], int dstStride[])
  367. {
  368. uint8_t *ydst = dstParam[0] + dstStride[0] * srcSliceY;
  369. uint8_t *udst = dstParam[1] + dstStride[1] * srcSliceY;
  370. uint8_t *vdst = dstParam[2] + dstStride[2] * srcSliceY;
  371. uyvytoyuv422(ydst, udst, vdst, src[0], c->srcW, srcSliceH, dstStride[0],
  372. dstStride[1], srcStride[0]);
  373. return srcSliceH;
  374. }
  375. static void gray8aToPacked32(const uint8_t *src, uint8_t *dst, int num_pixels,
  376. const uint8_t *palette)
  377. {
  378. int i;
  379. for (i = 0; i < num_pixels; i++)
  380. ((uint32_t *) dst)[i] = ((const uint32_t *) palette)[src[i << 1]] | (src[(i << 1) + 1] << 24);
  381. }
  382. static void gray8aToPacked32_1(const uint8_t *src, uint8_t *dst, int num_pixels,
  383. const uint8_t *palette)
  384. {
  385. int i;
  386. for (i = 0; i < num_pixels; i++)
  387. ((uint32_t *) dst)[i] = ((const uint32_t *) palette)[src[i << 1]] | src[(i << 1) + 1];
  388. }
  389. static void gray8aToPacked24(const uint8_t *src, uint8_t *dst, int num_pixels,
  390. const uint8_t *palette)
  391. {
  392. int i;
  393. for (i = 0; i < num_pixels; i++) {
  394. //FIXME slow?
  395. dst[0] = palette[src[i << 1] * 4 + 0];
  396. dst[1] = palette[src[i << 1] * 4 + 1];
  397. dst[2] = palette[src[i << 1] * 4 + 2];
  398. dst += 3;
  399. }
  400. }
  401. static int bswap_16bpc(SwsContext *c, const uint8_t *src[],
  402. int srcStride[], int srcSliceY, int srcSliceH,
  403. uint8_t *dst[], int dstStride[])
  404. {
  405. int i, j, p;
  406. for (p = 0; p < 4; p++) {
  407. int srcstr = srcStride[p] / 2;
  408. int dststr = dstStride[p] / 2;
  409. uint16_t *dstPtr = (uint16_t *) dst[p];
  410. const uint16_t *srcPtr = (const uint16_t *) src[p];
  411. int min_stride = FFMIN(FFABS(srcstr), FFABS(dststr));
  412. if(!dstPtr || !srcPtr)
  413. continue;
  414. dstPtr += (srcSliceY >> c->chrDstVSubSample) * dststr;
  415. for (i = 0; i < (srcSliceH >> c->chrDstVSubSample); i++) {
  416. for (j = 0; j < min_stride; j++) {
  417. dstPtr[j] = av_bswap16(srcPtr[j]);
  418. }
  419. srcPtr += srcstr;
  420. dstPtr += dststr;
  421. }
  422. }
  423. return srcSliceH;
  424. }
  425. static int bswap_32bpc(SwsContext *c, const uint8_t *src[],
  426. int srcStride[], int srcSliceY, int srcSliceH,
  427. uint8_t *dst[], int dstStride[])
  428. {
  429. int i, j, p;
  430. for (p = 0; p < 4; p++) {
  431. int srcstr = srcStride[p] / 4;
  432. int dststr = dstStride[p] / 4;
  433. uint32_t *dstPtr = (uint32_t *) dst[p];
  434. const uint32_t *srcPtr = (const uint32_t *) src[p];
  435. int min_stride = FFMIN(FFABS(srcstr), FFABS(dststr));
  436. if(!dstPtr || !srcPtr)
  437. continue;
  438. dstPtr += (srcSliceY >> c->chrDstVSubSample) * dststr;
  439. for (i = 0; i < (srcSliceH >> c->chrDstVSubSample); i++) {
  440. for (j = 0; j < min_stride; j++) {
  441. dstPtr[j] = av_bswap32(srcPtr[j]);
  442. }
  443. srcPtr += srcstr;
  444. dstPtr += dststr;
  445. }
  446. }
  447. return srcSliceH;
  448. }
  449. static int palToRgbWrapper(SwsContext *c, const uint8_t *src[], int srcStride[],
  450. int srcSliceY, int srcSliceH, uint8_t *dst[],
  451. int dstStride[])
  452. {
  453. const enum AVPixelFormat srcFormat = c->srcFormat;
  454. const enum AVPixelFormat dstFormat = c->dstFormat;
  455. void (*conv)(const uint8_t *src, uint8_t *dst, int num_pixels,
  456. const uint8_t *palette) = NULL;
  457. int i;
  458. uint8_t *dstPtr = dst[0] + dstStride[0] * srcSliceY;
  459. const uint8_t *srcPtr = src[0];
  460. if (srcFormat == AV_PIX_FMT_YA8) {
  461. switch (dstFormat) {
  462. case AV_PIX_FMT_RGB32 : conv = gray8aToPacked32; break;
  463. case AV_PIX_FMT_BGR32 : conv = gray8aToPacked32; break;
  464. case AV_PIX_FMT_BGR32_1: conv = gray8aToPacked32_1; break;
  465. case AV_PIX_FMT_RGB32_1: conv = gray8aToPacked32_1; break;
  466. case AV_PIX_FMT_RGB24 : conv = gray8aToPacked24; break;
  467. case AV_PIX_FMT_BGR24 : conv = gray8aToPacked24; break;
  468. }
  469. } else if (usePal(srcFormat)) {
  470. switch (dstFormat) {
  471. case AV_PIX_FMT_RGB32 : conv = sws_convertPalette8ToPacked32; break;
  472. case AV_PIX_FMT_BGR32 : conv = sws_convertPalette8ToPacked32; break;
  473. case AV_PIX_FMT_BGR32_1: conv = sws_convertPalette8ToPacked32; break;
  474. case AV_PIX_FMT_RGB32_1: conv = sws_convertPalette8ToPacked32; break;
  475. case AV_PIX_FMT_RGB24 : conv = sws_convertPalette8ToPacked24; break;
  476. case AV_PIX_FMT_BGR24 : conv = sws_convertPalette8ToPacked24; break;
  477. }
  478. }
  479. if (!conv)
  480. av_log(c, AV_LOG_ERROR, "internal error %s -> %s converter\n",
  481. av_get_pix_fmt_name(srcFormat), av_get_pix_fmt_name(dstFormat));
  482. else {
  483. for (i = 0; i < srcSliceH; i++) {
  484. conv(srcPtr, dstPtr, c->srcW, (uint8_t *) c->pal_rgb);
  485. srcPtr += srcStride[0];
  486. dstPtr += dstStride[0];
  487. }
  488. }
  489. return srcSliceH;
  490. }
  491. static void packed16togbra16(const uint8_t *src, int srcStride,
  492. uint16_t *dst[], int dstStride[], int srcSliceH,
  493. int src_alpha, int swap, int shift, int width)
  494. {
  495. int x, h, i;
  496. int dst_alpha = dst[3] != NULL;
  497. for (h = 0; h < srcSliceH; h++) {
  498. uint16_t *src_line = (uint16_t *)(src + srcStride * h);
  499. switch (swap) {
  500. case 3:
  501. if (src_alpha && dst_alpha) {
  502. for (x = 0; x < width; x++) {
  503. dst[0][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
  504. dst[1][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
  505. dst[2][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
  506. dst[3][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
  507. }
  508. } else if (dst_alpha) {
  509. for (x = 0; x < width; x++) {
  510. dst[0][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
  511. dst[1][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
  512. dst[2][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
  513. dst[3][x] = 0xFFFF;
  514. }
  515. } else if (src_alpha) {
  516. for (x = 0; x < width; x++) {
  517. dst[0][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
  518. dst[1][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
  519. dst[2][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
  520. src_line++;
  521. }
  522. } else {
  523. for (x = 0; x < width; x++) {
  524. dst[0][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
  525. dst[1][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
  526. dst[2][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
  527. }
  528. }
  529. break;
  530. case 2:
  531. if (src_alpha && dst_alpha) {
  532. for (x = 0; x < width; x++) {
  533. dst[0][x] = av_bswap16(*src_line++ >> shift);
  534. dst[1][x] = av_bswap16(*src_line++ >> shift);
  535. dst[2][x] = av_bswap16(*src_line++ >> shift);
  536. dst[3][x] = av_bswap16(*src_line++ >> shift);
  537. }
  538. } else if (dst_alpha) {
  539. for (x = 0; x < width; x++) {
  540. dst[0][x] = av_bswap16(*src_line++ >> shift);
  541. dst[1][x] = av_bswap16(*src_line++ >> shift);
  542. dst[2][x] = av_bswap16(*src_line++ >> shift);
  543. dst[3][x] = 0xFFFF;
  544. }
  545. } else if (src_alpha) {
  546. for (x = 0; x < width; x++) {
  547. dst[0][x] = av_bswap16(*src_line++ >> shift);
  548. dst[1][x] = av_bswap16(*src_line++ >> shift);
  549. dst[2][x] = av_bswap16(*src_line++ >> shift);
  550. src_line++;
  551. }
  552. } else {
  553. for (x = 0; x < width; x++) {
  554. dst[0][x] = av_bswap16(*src_line++ >> shift);
  555. dst[1][x] = av_bswap16(*src_line++ >> shift);
  556. dst[2][x] = av_bswap16(*src_line++ >> shift);
  557. }
  558. }
  559. break;
  560. case 1:
  561. if (src_alpha && dst_alpha) {
  562. for (x = 0; x < width; x++) {
  563. dst[0][x] = av_bswap16(*src_line++) >> shift;
  564. dst[1][x] = av_bswap16(*src_line++) >> shift;
  565. dst[2][x] = av_bswap16(*src_line++) >> shift;
  566. dst[3][x] = av_bswap16(*src_line++) >> shift;
  567. }
  568. } else if (dst_alpha) {
  569. for (x = 0; x < width; x++) {
  570. dst[0][x] = av_bswap16(*src_line++) >> shift;
  571. dst[1][x] = av_bswap16(*src_line++) >> shift;
  572. dst[2][x] = av_bswap16(*src_line++) >> shift;
  573. dst[3][x] = 0xFFFF;
  574. }
  575. } else if (src_alpha) {
  576. for (x = 0; x < width; x++) {
  577. dst[0][x] = av_bswap16(*src_line++) >> shift;
  578. dst[1][x] = av_bswap16(*src_line++) >> shift;
  579. dst[2][x] = av_bswap16(*src_line++) >> shift;
  580. src_line++;
  581. }
  582. } else {
  583. for (x = 0; x < width; x++) {
  584. dst[0][x] = av_bswap16(*src_line++) >> shift;
  585. dst[1][x] = av_bswap16(*src_line++) >> shift;
  586. dst[2][x] = av_bswap16(*src_line++) >> shift;
  587. }
  588. }
  589. break;
  590. default:
  591. if (src_alpha && dst_alpha) {
  592. for (x = 0; x < width; x++) {
  593. dst[0][x] = *src_line++ >> shift;
  594. dst[1][x] = *src_line++ >> shift;
  595. dst[2][x] = *src_line++ >> shift;
  596. dst[3][x] = *src_line++ >> shift;
  597. }
  598. } else if (dst_alpha) {
  599. for (x = 0; x < width; x++) {
  600. dst[0][x] = *src_line++ >> shift;
  601. dst[1][x] = *src_line++ >> shift;
  602. dst[2][x] = *src_line++ >> shift;
  603. dst[3][x] = 0xFFFF;
  604. }
  605. } else if (src_alpha) {
  606. for (x = 0; x < width; x++) {
  607. dst[0][x] = *src_line++ >> shift;
  608. dst[1][x] = *src_line++ >> shift;
  609. dst[2][x] = *src_line++ >> shift;
  610. src_line++;
  611. }
  612. } else {
  613. for (x = 0; x < width; x++) {
  614. dst[0][x] = *src_line++ >> shift;
  615. dst[1][x] = *src_line++ >> shift;
  616. dst[2][x] = *src_line++ >> shift;
  617. }
  618. }
  619. }
  620. for (i = 0; i < 4; i++)
  621. dst[i] += dstStride[i] >> 1;
  622. }
  623. }
  624. static int Rgb16ToPlanarRgb16Wrapper(SwsContext *c, const uint8_t *src[],
  625. int srcStride[], int srcSliceY, int srcSliceH,
  626. uint8_t *dst[], int dstStride[])
  627. {
  628. uint16_t *dst2013[] = { (uint16_t *)dst[2], (uint16_t *)dst[0], (uint16_t *)dst[1], (uint16_t *)dst[3] };
  629. uint16_t *dst1023[] = { (uint16_t *)dst[1], (uint16_t *)dst[0], (uint16_t *)dst[2], (uint16_t *)dst[3] };
  630. int stride2013[] = { dstStride[2], dstStride[0], dstStride[1], dstStride[3] };
  631. int stride1023[] = { dstStride[1], dstStride[0], dstStride[2], dstStride[3] };
  632. const AVPixFmtDescriptor *src_format = av_pix_fmt_desc_get(c->srcFormat);
  633. const AVPixFmtDescriptor *dst_format = av_pix_fmt_desc_get(c->dstFormat);
  634. int bpc = dst_format->comp[0].depth;
  635. int alpha = src_format->flags & AV_PIX_FMT_FLAG_ALPHA;
  636. int swap = 0;
  637. int i;
  638. if ( HAVE_BIGENDIAN && !(src_format->flags & AV_PIX_FMT_FLAG_BE) ||
  639. !HAVE_BIGENDIAN && src_format->flags & AV_PIX_FMT_FLAG_BE)
  640. swap++;
  641. if ( HAVE_BIGENDIAN && !(dst_format->flags & AV_PIX_FMT_FLAG_BE) ||
  642. !HAVE_BIGENDIAN && dst_format->flags & AV_PIX_FMT_FLAG_BE)
  643. swap += 2;
  644. if ((dst_format->flags & (AV_PIX_FMT_FLAG_PLANAR | AV_PIX_FMT_FLAG_RGB)) !=
  645. (AV_PIX_FMT_FLAG_PLANAR | AV_PIX_FMT_FLAG_RGB) || bpc < 9) {
  646. av_log(c, AV_LOG_ERROR, "unsupported conversion to planar RGB %s -> %s\n",
  647. src_format->name, dst_format->name);
  648. return srcSliceH;
  649. }
  650. for(i=0; i<4; i++) {
  651. dst2013[i] += stride2013[i] * srcSliceY / 2;
  652. dst1023[i] += stride1023[i] * srcSliceY / 2;
  653. }
  654. switch (c->srcFormat) {
  655. case AV_PIX_FMT_RGB48LE:
  656. case AV_PIX_FMT_RGB48BE:
  657. case AV_PIX_FMT_RGBA64LE:
  658. case AV_PIX_FMT_RGBA64BE:
  659. packed16togbra16(src[0], srcStride[0],
  660. dst2013, stride2013, srcSliceH, alpha, swap,
  661. 16 - bpc, c->srcW);
  662. break;
  663. case AV_PIX_FMT_BGR48LE:
  664. case AV_PIX_FMT_BGR48BE:
  665. case AV_PIX_FMT_BGRA64LE:
  666. case AV_PIX_FMT_BGRA64BE:
  667. packed16togbra16(src[0], srcStride[0],
  668. dst1023, stride1023, srcSliceH, alpha, swap,
  669. 16 - bpc, c->srcW);
  670. break;
  671. default:
  672. av_log(c, AV_LOG_ERROR,
  673. "unsupported conversion to planar RGB %s -> %s\n",
  674. src_format->name, dst_format->name);
  675. }
  676. return srcSliceH;
  677. }
  678. static void gbr16ptopacked16(const uint16_t *src[], int srcStride[],
  679. uint8_t *dst, int dstStride, int srcSliceH,
  680. int alpha, int swap, int bpp, int width)
  681. {
  682. int x, h, i;
  683. int src_alpha = src[3] != NULL;
  684. int scale_high = 16 - bpp, scale_low = (bpp - 8) * 2;
  685. for (h = 0; h < srcSliceH; h++) {
  686. uint16_t *dest = (uint16_t *)(dst + dstStride * h);
  687. uint16_t component;
  688. switch(swap) {
  689. case 3:
  690. if (alpha && !src_alpha) {
  691. for (x = 0; x < width; x++) {
  692. component = av_bswap16(src[0][x]);
  693. *dest++ = av_bswap16(component << scale_high | component >> scale_low);
  694. component = av_bswap16(src[1][x]);
  695. *dest++ = av_bswap16(component << scale_high | component >> scale_low);
  696. component = av_bswap16(src[2][x]);
  697. *dest++ = av_bswap16(component << scale_high | component >> scale_low);
  698. *dest++ = 0xffff;
  699. }
  700. } else if (alpha && src_alpha) {
  701. for (x = 0; x < width; x++) {
  702. component = av_bswap16(src[0][x]);
  703. *dest++ = av_bswap16(component << scale_high | component >> scale_low);
  704. component = av_bswap16(src[1][x]);
  705. *dest++ = av_bswap16(component << scale_high | component >> scale_low);
  706. component = av_bswap16(src[2][x]);
  707. *dest++ = av_bswap16(component << scale_high | component >> scale_low);
  708. component = av_bswap16(src[3][x]);
  709. *dest++ = av_bswap16(component << scale_high | component >> scale_low);
  710. }
  711. } else {
  712. for (x = 0; x < width; x++) {
  713. component = av_bswap16(src[0][x]);
  714. *dest++ = av_bswap16(component << scale_high | component >> scale_low);
  715. component = av_bswap16(src[1][x]);
  716. *dest++ = av_bswap16(component << scale_high | component >> scale_low);
  717. component = av_bswap16(src[2][x]);
  718. *dest++ = av_bswap16(component << scale_high | component >> scale_low);
  719. }
  720. }
  721. break;
  722. case 2:
  723. if (alpha && !src_alpha) {
  724. for (x = 0; x < width; x++) {
  725. *dest++ = av_bswap16(src[0][x] << scale_high | src[0][x] >> scale_low);
  726. *dest++ = av_bswap16(src[1][x] << scale_high | src[1][x] >> scale_low);
  727. *dest++ = av_bswap16(src[2][x] << scale_high | src[2][x] >> scale_low);
  728. *dest++ = 0xffff;
  729. }
  730. } else if (alpha && src_alpha) {
  731. for (x = 0; x < width; x++) {
  732. *dest++ = av_bswap16(src[0][x] << scale_high | src[0][x] >> scale_low);
  733. *dest++ = av_bswap16(src[1][x] << scale_high | src[1][x] >> scale_low);
  734. *dest++ = av_bswap16(src[2][x] << scale_high | src[2][x] >> scale_low);
  735. *dest++ = av_bswap16(src[3][x] << scale_high | src[3][x] >> scale_low);
  736. }
  737. } else {
  738. for (x = 0; x < width; x++) {
  739. *dest++ = av_bswap16(src[0][x] << scale_high | src[0][x] >> scale_low);
  740. *dest++ = av_bswap16(src[1][x] << scale_high | src[1][x] >> scale_low);
  741. *dest++ = av_bswap16(src[2][x] << scale_high | src[2][x] >> scale_low);
  742. }
  743. }
  744. break;
  745. case 1:
  746. if (alpha && !src_alpha) {
  747. for (x = 0; x < width; x++) {
  748. *dest++ = av_bswap16(src[0][x]) << scale_high | av_bswap16(src[0][x]) >> scale_low;
  749. *dest++ = av_bswap16(src[1][x]) << scale_high | av_bswap16(src[1][x]) >> scale_low;
  750. *dest++ = av_bswap16(src[2][x]) << scale_high | av_bswap16(src[2][x]) >> scale_low;
  751. *dest++ = 0xffff;
  752. }
  753. } else if (alpha && src_alpha) {
  754. for (x = 0; x < width; x++) {
  755. *dest++ = av_bswap16(src[0][x]) << scale_high | av_bswap16(src[0][x]) >> scale_low;
  756. *dest++ = av_bswap16(src[1][x]) << scale_high | av_bswap16(src[1][x]) >> scale_low;
  757. *dest++ = av_bswap16(src[2][x]) << scale_high | av_bswap16(src[2][x]) >> scale_low;
  758. *dest++ = av_bswap16(src[3][x]) << scale_high | av_bswap16(src[3][x]) >> scale_low;
  759. }
  760. } else {
  761. for (x = 0; x < width; x++) {
  762. *dest++ = av_bswap16(src[0][x]) << scale_high | av_bswap16(src[0][x]) >> scale_low;
  763. *dest++ = av_bswap16(src[1][x]) << scale_high | av_bswap16(src[1][x]) >> scale_low;
  764. *dest++ = av_bswap16(src[2][x]) << scale_high | av_bswap16(src[2][x]) >> scale_low;
  765. }
  766. }
  767. break;
  768. default:
  769. if (alpha && !src_alpha) {
  770. for (x = 0; x < width; x++) {
  771. *dest++ = src[0][x] << scale_high | src[0][x] >> scale_low;
  772. *dest++ = src[1][x] << scale_high | src[1][x] >> scale_low;
  773. *dest++ = src[2][x] << scale_high | src[2][x] >> scale_low;
  774. *dest++ = 0xffff;
  775. }
  776. } else if (alpha && src_alpha) {
  777. for (x = 0; x < width; x++) {
  778. *dest++ = src[0][x] << scale_high | src[0][x] >> scale_low;
  779. *dest++ = src[1][x] << scale_high | src[1][x] >> scale_low;
  780. *dest++ = src[2][x] << scale_high | src[2][x] >> scale_low;
  781. *dest++ = src[3][x] << scale_high | src[3][x] >> scale_low;
  782. }
  783. } else {
  784. for (x = 0; x < width; x++) {
  785. *dest++ = src[0][x] << scale_high | src[0][x] >> scale_low;
  786. *dest++ = src[1][x] << scale_high | src[1][x] >> scale_low;
  787. *dest++ = src[2][x] << scale_high | src[2][x] >> scale_low;
  788. }
  789. }
  790. }
  791. for (i = 0; i < 3 + src_alpha; i++)
  792. src[i] += srcStride[i] >> 1;
  793. }
  794. }
  795. static int planarRgb16ToRgb16Wrapper(SwsContext *c, const uint8_t *src[],
  796. int srcStride[], int srcSliceY, int srcSliceH,
  797. uint8_t *dst[], int dstStride[])
  798. {
  799. const uint16_t *src102[] = { (uint16_t *)src[1], (uint16_t *)src[0], (uint16_t *)src[2], (uint16_t *)src[3] };
  800. const uint16_t *src201[] = { (uint16_t *)src[2], (uint16_t *)src[0], (uint16_t *)src[1], (uint16_t *)src[3] };
  801. int stride102[] = { srcStride[1], srcStride[0], srcStride[2], srcStride[3] };
  802. int stride201[] = { srcStride[2], srcStride[0], srcStride[1], srcStride[3] };
  803. const AVPixFmtDescriptor *src_format = av_pix_fmt_desc_get(c->srcFormat);
  804. const AVPixFmtDescriptor *dst_format = av_pix_fmt_desc_get(c->dstFormat);
  805. int bits_per_sample = src_format->comp[0].depth;
  806. int swap = 0;
  807. if ( HAVE_BIGENDIAN && !(src_format->flags & AV_PIX_FMT_FLAG_BE) ||
  808. !HAVE_BIGENDIAN && src_format->flags & AV_PIX_FMT_FLAG_BE)
  809. swap++;
  810. if ( HAVE_BIGENDIAN && !(dst_format->flags & AV_PIX_FMT_FLAG_BE) ||
  811. !HAVE_BIGENDIAN && dst_format->flags & AV_PIX_FMT_FLAG_BE)
  812. swap += 2;
  813. if ((src_format->flags & (AV_PIX_FMT_FLAG_PLANAR | AV_PIX_FMT_FLAG_RGB)) !=
  814. (AV_PIX_FMT_FLAG_PLANAR | AV_PIX_FMT_FLAG_RGB) ||
  815. bits_per_sample <= 8) {
  816. av_log(c, AV_LOG_ERROR, "unsupported planar RGB conversion %s -> %s\n",
  817. src_format->name, dst_format->name);
  818. return srcSliceH;
  819. }
  820. switch (c->dstFormat) {
  821. case AV_PIX_FMT_BGR48LE:
  822. case AV_PIX_FMT_BGR48BE:
  823. gbr16ptopacked16(src102, stride102,
  824. dst[0] + srcSliceY * dstStride[0], dstStride[0],
  825. srcSliceH, 0, swap, bits_per_sample, c->srcW);
  826. break;
  827. case AV_PIX_FMT_RGB48LE:
  828. case AV_PIX_FMT_RGB48BE:
  829. gbr16ptopacked16(src201, stride201,
  830. dst[0] + srcSliceY * dstStride[0], dstStride[0],
  831. srcSliceH, 0, swap, bits_per_sample, c->srcW);
  832. break;
  833. case AV_PIX_FMT_RGBA64LE:
  834. case AV_PIX_FMT_RGBA64BE:
  835. gbr16ptopacked16(src201, stride201,
  836. dst[0] + srcSliceY * dstStride[0], dstStride[0],
  837. srcSliceH, 1, swap, bits_per_sample, c->srcW);
  838. break;
  839. case AV_PIX_FMT_BGRA64LE:
  840. case AV_PIX_FMT_BGRA64BE:
  841. gbr16ptopacked16(src102, stride102,
  842. dst[0] + srcSliceY * dstStride[0], dstStride[0],
  843. srcSliceH, 1, swap, bits_per_sample, c->srcW);
  844. break;
  845. default:
  846. av_log(c, AV_LOG_ERROR,
  847. "unsupported planar RGB conversion %s -> %s\n",
  848. src_format->name, dst_format->name);
  849. }
  850. return srcSliceH;
  851. }
  852. static void gbr24ptopacked24(const uint8_t *src[], int srcStride[],
  853. uint8_t *dst, int dstStride, int srcSliceH,
  854. int width)
  855. {
  856. int x, h, i;
  857. for (h = 0; h < srcSliceH; h++) {
  858. uint8_t *dest = dst + dstStride * h;
  859. for (x = 0; x < width; x++) {
  860. *dest++ = src[0][x];
  861. *dest++ = src[1][x];
  862. *dest++ = src[2][x];
  863. }
  864. for (i = 0; i < 3; i++)
  865. src[i] += srcStride[i];
  866. }
  867. }
  868. static void gbr24ptopacked32(const uint8_t *src[], int srcStride[],
  869. uint8_t *dst, int dstStride, int srcSliceH,
  870. int alpha_first, int width)
  871. {
  872. int x, h, i;
  873. for (h = 0; h < srcSliceH; h++) {
  874. uint8_t *dest = dst + dstStride * h;
  875. if (alpha_first) {
  876. for (x = 0; x < width; x++) {
  877. *dest++ = 0xff;
  878. *dest++ = src[0][x];
  879. *dest++ = src[1][x];
  880. *dest++ = src[2][x];
  881. }
  882. } else {
  883. for (x = 0; x < width; x++) {
  884. *dest++ = src[0][x];
  885. *dest++ = src[1][x];
  886. *dest++ = src[2][x];
  887. *dest++ = 0xff;
  888. }
  889. }
  890. for (i = 0; i < 3; i++)
  891. src[i] += srcStride[i];
  892. }
  893. }
  894. static void gbraptopacked32(const uint8_t *src[], int srcStride[],
  895. uint8_t *dst, int dstStride, int srcSliceH,
  896. int alpha_first, int width)
  897. {
  898. int x, h, i;
  899. for (h = 0; h < srcSliceH; h++) {
  900. uint8_t *dest = dst + dstStride * h;
  901. if (alpha_first) {
  902. for (x = 0; x < width; x++) {
  903. *dest++ = src[3][x];
  904. *dest++ = src[0][x];
  905. *dest++ = src[1][x];
  906. *dest++ = src[2][x];
  907. }
  908. } else {
  909. for (x = 0; x < width; x++) {
  910. *dest++ = src[0][x];
  911. *dest++ = src[1][x];
  912. *dest++ = src[2][x];
  913. *dest++ = src[3][x];
  914. }
  915. }
  916. for (i = 0; i < 4; i++)
  917. src[i] += srcStride[i];
  918. }
  919. }
  920. static int planarRgbaToRgbWrapper(SwsContext *c, const uint8_t *src[],
  921. int srcStride[], int srcSliceY, int srcSliceH,
  922. uint8_t *dst[], int dstStride[])
  923. {
  924. int alpha_first = 0;
  925. const uint8_t *src102[] = { src[1], src[0], src[2], src[3] };
  926. const uint8_t *src201[] = { src[2], src[0], src[1], src[3] };
  927. int stride102[] = { srcStride[1], srcStride[0], srcStride[2], srcStride[3] };
  928. int stride201[] = { srcStride[2], srcStride[0], srcStride[1], srcStride[3] };
  929. if (c->srcFormat != AV_PIX_FMT_GBRAP) {
  930. av_log(c, AV_LOG_ERROR, "unsupported planar RGB conversion %s -> %s\n",
  931. av_get_pix_fmt_name(c->srcFormat),
  932. av_get_pix_fmt_name(c->dstFormat));
  933. return srcSliceH;
  934. }
  935. switch (c->dstFormat) {
  936. case AV_PIX_FMT_BGR24:
  937. gbr24ptopacked24(src102, stride102,
  938. dst[0] + srcSliceY * dstStride[0], dstStride[0],
  939. srcSliceH, c->srcW);
  940. break;
  941. case AV_PIX_FMT_RGB24:
  942. gbr24ptopacked24(src201, stride201,
  943. dst[0] + srcSliceY * dstStride[0], dstStride[0],
  944. srcSliceH, c->srcW);
  945. break;
  946. case AV_PIX_FMT_ARGB:
  947. alpha_first = 1;
  948. case AV_PIX_FMT_RGBA:
  949. gbraptopacked32(src201, stride201,
  950. dst[0] + srcSliceY * dstStride[0], dstStride[0],
  951. srcSliceH, alpha_first, c->srcW);
  952. break;
  953. case AV_PIX_FMT_ABGR:
  954. alpha_first = 1;
  955. case AV_PIX_FMT_BGRA:
  956. gbraptopacked32(src102, stride102,
  957. dst[0] + srcSliceY * dstStride[0], dstStride[0],
  958. srcSliceH, alpha_first, c->srcW);
  959. break;
  960. default:
  961. av_log(c, AV_LOG_ERROR,
  962. "unsupported planar RGB conversion %s -> %s\n",
  963. av_get_pix_fmt_name(c->srcFormat),
  964. av_get_pix_fmt_name(c->dstFormat));
  965. }
  966. return srcSliceH;
  967. }
  968. static int planarRgbToRgbWrapper(SwsContext *c, const uint8_t *src[],
  969. int srcStride[], int srcSliceY, int srcSliceH,
  970. uint8_t *dst[], int dstStride[])
  971. {
  972. int alpha_first = 0;
  973. const uint8_t *src102[] = { src[1], src[0], src[2] };
  974. const uint8_t *src201[] = { src[2], src[0], src[1] };
  975. int stride102[] = { srcStride[1], srcStride[0], srcStride[2] };
  976. int stride201[] = { srcStride[2], srcStride[0], srcStride[1] };
  977. if (c->srcFormat != AV_PIX_FMT_GBRP) {
  978. av_log(c, AV_LOG_ERROR, "unsupported planar RGB conversion %s -> %s\n",
  979. av_get_pix_fmt_name(c->srcFormat),
  980. av_get_pix_fmt_name(c->dstFormat));
  981. return srcSliceH;
  982. }
  983. switch (c->dstFormat) {
  984. case AV_PIX_FMT_BGR24:
  985. gbr24ptopacked24(src102, stride102,
  986. dst[0] + srcSliceY * dstStride[0], dstStride[0],
  987. srcSliceH, c->srcW);
  988. break;
  989. case AV_PIX_FMT_RGB24:
  990. gbr24ptopacked24(src201, stride201,
  991. dst[0] + srcSliceY * dstStride[0], dstStride[0],
  992. srcSliceH, c->srcW);
  993. break;
  994. case AV_PIX_FMT_ARGB:
  995. alpha_first = 1;
  996. case AV_PIX_FMT_RGBA:
  997. gbr24ptopacked32(src201, stride201,
  998. dst[0] + srcSliceY * dstStride[0], dstStride[0],
  999. srcSliceH, alpha_first, c->srcW);
  1000. break;
  1001. case AV_PIX_FMT_ABGR:
  1002. alpha_first = 1;
  1003. case AV_PIX_FMT_BGRA:
  1004. gbr24ptopacked32(src102, stride102,
  1005. dst[0] + srcSliceY * dstStride[0], dstStride[0],
  1006. srcSliceH, alpha_first, c->srcW);
  1007. break;
  1008. default:
  1009. av_log(c, AV_LOG_ERROR,
  1010. "unsupported planar RGB conversion %s -> %s\n",
  1011. av_get_pix_fmt_name(c->srcFormat),
  1012. av_get_pix_fmt_name(c->dstFormat));
  1013. }
  1014. return srcSliceH;
  1015. }
  1016. static int planarRgbToplanarRgbWrapper(SwsContext *c,
  1017. const uint8_t *src[], int srcStride[],
  1018. int srcSliceY, int srcSliceH,
  1019. uint8_t *dst[], int dstStride[])
  1020. {
  1021. copyPlane(src[0], srcStride[0], srcSliceY, srcSliceH, c->srcW,
  1022. dst[0], dstStride[0]);
  1023. copyPlane(src[1], srcStride[1], srcSliceY, srcSliceH, c->srcW,
  1024. dst[1], dstStride[1]);
  1025. copyPlane(src[2], srcStride[2], srcSliceY, srcSliceH, c->srcW,
  1026. dst[2], dstStride[2]);
  1027. if (dst[3])
  1028. fillPlane(dst[3], dstStride[3], c->srcW, srcSliceH, srcSliceY, 255);
  1029. return srcSliceH;
  1030. }
  1031. static void packedtogbr24p(const uint8_t *src, int srcStride,
  1032. uint8_t *dst[], int dstStride[], int srcSliceH,
  1033. int alpha_first, int inc_size, int width)
  1034. {
  1035. uint8_t *dest[3];
  1036. int x, h;
  1037. dest[0] = dst[0];
  1038. dest[1] = dst[1];
  1039. dest[2] = dst[2];
  1040. if (alpha_first)
  1041. src++;
  1042. for (h = 0; h < srcSliceH; h++) {
  1043. for (x = 0; x < width; x++) {
  1044. dest[0][x] = src[0];
  1045. dest[1][x] = src[1];
  1046. dest[2][x] = src[2];
  1047. src += inc_size;
  1048. }
  1049. src += srcStride - width * inc_size;
  1050. dest[0] += dstStride[0];
  1051. dest[1] += dstStride[1];
  1052. dest[2] += dstStride[2];
  1053. }
  1054. }
  1055. static int rgbToPlanarRgbWrapper(SwsContext *c, const uint8_t *src[],
  1056. int srcStride[], int srcSliceY, int srcSliceH,
  1057. uint8_t *dst[], int dstStride[])
  1058. {
  1059. int alpha_first = 0;
  1060. int stride102[] = { dstStride[1], dstStride[0], dstStride[2] };
  1061. int stride201[] = { dstStride[2], dstStride[0], dstStride[1] };
  1062. uint8_t *dst102[] = { dst[1] + srcSliceY * dstStride[1],
  1063. dst[0] + srcSliceY * dstStride[0],
  1064. dst[2] + srcSliceY * dstStride[2] };
  1065. uint8_t *dst201[] = { dst[2] + srcSliceY * dstStride[2],
  1066. dst[0] + srcSliceY * dstStride[0],
  1067. dst[1] + srcSliceY * dstStride[1] };
  1068. switch (c->srcFormat) {
  1069. case AV_PIX_FMT_RGB24:
  1070. packedtogbr24p((const uint8_t *) src[0], srcStride[0], dst201,
  1071. stride201, srcSliceH, alpha_first, 3, c->srcW);
  1072. break;
  1073. case AV_PIX_FMT_BGR24:
  1074. packedtogbr24p((const uint8_t *) src[0], srcStride[0], dst102,
  1075. stride102, srcSliceH, alpha_first, 3, c->srcW);
  1076. break;
  1077. case AV_PIX_FMT_ARGB:
  1078. alpha_first = 1;
  1079. case AV_PIX_FMT_RGBA:
  1080. packedtogbr24p((const uint8_t *) src[0], srcStride[0], dst201,
  1081. stride201, srcSliceH, alpha_first, 4, c->srcW);
  1082. break;
  1083. case AV_PIX_FMT_ABGR:
  1084. alpha_first = 1;
  1085. case AV_PIX_FMT_BGRA:
  1086. packedtogbr24p((const uint8_t *) src[0], srcStride[0], dst102,
  1087. stride102, srcSliceH, alpha_first, 4, c->srcW);
  1088. break;
  1089. default:
  1090. av_log(c, AV_LOG_ERROR,
  1091. "unsupported planar RGB conversion %s -> %s\n",
  1092. av_get_pix_fmt_name(c->srcFormat),
  1093. av_get_pix_fmt_name(c->dstFormat));
  1094. }
  1095. return srcSliceH;
  1096. }
  1097. #define BAYER_GBRG
  1098. #define BAYER_8
  1099. #define BAYER_RENAME(x) bayer_gbrg8_to_##x
  1100. #include "bayer_template.c"
  1101. #define BAYER_GBRG
  1102. #define BAYER_16LE
  1103. #define BAYER_RENAME(x) bayer_gbrg16le_to_##x
  1104. #include "bayer_template.c"
  1105. #define BAYER_GBRG
  1106. #define BAYER_16BE
  1107. #define BAYER_RENAME(x) bayer_gbrg16be_to_##x
  1108. #include "bayer_template.c"
  1109. #define BAYER_GRBG
  1110. #define BAYER_8
  1111. #define BAYER_RENAME(x) bayer_grbg8_to_##x
  1112. #include "bayer_template.c"
  1113. #define BAYER_GRBG
  1114. #define BAYER_16LE
  1115. #define BAYER_RENAME(x) bayer_grbg16le_to_##x
  1116. #include "bayer_template.c"
  1117. #define BAYER_GRBG
  1118. #define BAYER_16BE
  1119. #define BAYER_RENAME(x) bayer_grbg16be_to_##x
  1120. #include "bayer_template.c"
  1121. #define BAYER_BGGR
  1122. #define BAYER_8
  1123. #define BAYER_RENAME(x) bayer_bggr8_to_##x
  1124. #include "bayer_template.c"
  1125. #define BAYER_BGGR
  1126. #define BAYER_16LE
  1127. #define BAYER_RENAME(x) bayer_bggr16le_to_##x
  1128. #include "bayer_template.c"
  1129. #define BAYER_BGGR
  1130. #define BAYER_16BE
  1131. #define BAYER_RENAME(x) bayer_bggr16be_to_##x
  1132. #include "bayer_template.c"
  1133. #define BAYER_RGGB
  1134. #define BAYER_8
  1135. #define BAYER_RENAME(x) bayer_rggb8_to_##x
  1136. #include "bayer_template.c"
  1137. #define BAYER_RGGB
  1138. #define BAYER_16LE
  1139. #define BAYER_RENAME(x) bayer_rggb16le_to_##x
  1140. #include "bayer_template.c"
  1141. #define BAYER_RGGB
  1142. #define BAYER_16BE
  1143. #define BAYER_RENAME(x) bayer_rggb16be_to_##x
  1144. #include "bayer_template.c"
  1145. static int bayer_to_rgb24_wrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY,
  1146. int srcSliceH, uint8_t* dst[], int dstStride[])
  1147. {
  1148. uint8_t *dstPtr= dst[0] + srcSliceY * dstStride[0];
  1149. const uint8_t *srcPtr= src[0];
  1150. int i;
  1151. void (*copy) (const uint8_t *src, int src_stride, uint8_t *dst, int dst_stride, int width);
  1152. void (*interpolate)(const uint8_t *src, int src_stride, uint8_t *dst, int dst_stride, int width);
  1153. switch(c->srcFormat) {
  1154. #define CASE(pixfmt, prefix) \
  1155. case pixfmt: copy = bayer_##prefix##_to_rgb24_copy; \
  1156. interpolate = bayer_##prefix##_to_rgb24_interpolate; \
  1157. break;
  1158. CASE(AV_PIX_FMT_BAYER_BGGR8, bggr8)
  1159. CASE(AV_PIX_FMT_BAYER_BGGR16LE, bggr16le)
  1160. CASE(AV_PIX_FMT_BAYER_BGGR16BE, bggr16be)
  1161. CASE(AV_PIX_FMT_BAYER_RGGB8, rggb8)
  1162. CASE(AV_PIX_FMT_BAYER_RGGB16LE, rggb16le)
  1163. CASE(AV_PIX_FMT_BAYER_RGGB16BE, rggb16be)
  1164. CASE(AV_PIX_FMT_BAYER_GBRG8, gbrg8)
  1165. CASE(AV_PIX_FMT_BAYER_GBRG16LE, gbrg16le)
  1166. CASE(AV_PIX_FMT_BAYER_GBRG16BE, gbrg16be)
  1167. CASE(AV_PIX_FMT_BAYER_GRBG8, grbg8)
  1168. CASE(AV_PIX_FMT_BAYER_GRBG16LE, grbg16le)
  1169. CASE(AV_PIX_FMT_BAYER_GRBG16BE, grbg16be)
  1170. #undef CASE
  1171. default: return 0;
  1172. }
  1173. av_assert0(srcSliceH > 1);
  1174. copy(srcPtr, srcStride[0], dstPtr, dstStride[0], c->srcW);
  1175. srcPtr += 2 * srcStride[0];
  1176. dstPtr += 2 * dstStride[0];
  1177. for (i = 2; i < srcSliceH - 2; i += 2) {
  1178. interpolate(srcPtr, srcStride[0], dstPtr, dstStride[0], c->srcW);
  1179. srcPtr += 2 * srcStride[0];
  1180. dstPtr += 2 * dstStride[0];
  1181. }
  1182. if (i + 1 == srcSliceH) {
  1183. copy(srcPtr, -srcStride[0], dstPtr, -dstStride[0], c->srcW);
  1184. } else if (i < srcSliceH)
  1185. copy(srcPtr, srcStride[0], dstPtr, dstStride[0], c->srcW);
  1186. return srcSliceH;
  1187. }
  1188. static int bayer_to_yv12_wrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY,
  1189. int srcSliceH, uint8_t* dst[], int dstStride[])
  1190. {
  1191. const uint8_t *srcPtr= src[0];
  1192. uint8_t *dstY= dst[0] + srcSliceY * dstStride[0];
  1193. uint8_t *dstU= dst[1] + srcSliceY * dstStride[1] / 2;
  1194. uint8_t *dstV= dst[2] + srcSliceY * dstStride[2] / 2;
  1195. int i;
  1196. void (*copy) (const uint8_t *src, int src_stride, uint8_t *dstY, uint8_t *dstU, uint8_t *dstV, int luma_stride, int width, int32_t *rgb2yuv);
  1197. void (*interpolate)(const uint8_t *src, int src_stride, uint8_t *dstY, uint8_t *dstU, uint8_t *dstV, int luma_stride, int width, int32_t *rgb2yuv);
  1198. switch(c->srcFormat) {
  1199. #define CASE(pixfmt, prefix) \
  1200. case pixfmt: copy = bayer_##prefix##_to_yv12_copy; \
  1201. interpolate = bayer_##prefix##_to_yv12_interpolate; \
  1202. break;
  1203. CASE(AV_PIX_FMT_BAYER_BGGR8, bggr8)
  1204. CASE(AV_PIX_FMT_BAYER_BGGR16LE, bggr16le)
  1205. CASE(AV_PIX_FMT_BAYER_BGGR16BE, bggr16be)
  1206. CASE(AV_PIX_FMT_BAYER_RGGB8, rggb8)
  1207. CASE(AV_PIX_FMT_BAYER_RGGB16LE, rggb16le)
  1208. CASE(AV_PIX_FMT_BAYER_RGGB16BE, rggb16be)
  1209. CASE(AV_PIX_FMT_BAYER_GBRG8, gbrg8)
  1210. CASE(AV_PIX_FMT_BAYER_GBRG16LE, gbrg16le)
  1211. CASE(AV_PIX_FMT_BAYER_GBRG16BE, gbrg16be)
  1212. CASE(AV_PIX_FMT_BAYER_GRBG8, grbg8)
  1213. CASE(AV_PIX_FMT_BAYER_GRBG16LE, grbg16le)
  1214. CASE(AV_PIX_FMT_BAYER_GRBG16BE, grbg16be)
  1215. #undef CASE
  1216. default: return 0;
  1217. }
  1218. av_assert0(srcSliceH > 1);
  1219. copy(srcPtr, srcStride[0], dstY, dstU, dstV, dstStride[0], c->srcW, c->input_rgb2yuv_table);
  1220. srcPtr += 2 * srcStride[0];
  1221. dstY += 2 * dstStride[0];
  1222. dstU += dstStride[1];
  1223. dstV += dstStride[1];
  1224. for (i = 2; i < srcSliceH - 2; i += 2) {
  1225. interpolate(srcPtr, srcStride[0], dstY, dstU, dstV, dstStride[0], c->srcW, c->input_rgb2yuv_table);
  1226. srcPtr += 2 * srcStride[0];
  1227. dstY += 2 * dstStride[0];
  1228. dstU += dstStride[1];
  1229. dstV += dstStride[1];
  1230. }
  1231. if (i + 1 == srcSliceH) {
  1232. copy(srcPtr, -srcStride[0], dstY, dstU, dstV, -dstStride[0], c->srcW, c->input_rgb2yuv_table);
  1233. } else if (i < srcSliceH)
  1234. copy(srcPtr, srcStride[0], dstY, dstU, dstV, dstStride[0], c->srcW, c->input_rgb2yuv_table);
  1235. return srcSliceH;
  1236. }
  1237. #define isRGBA32(x) ( \
  1238. (x) == AV_PIX_FMT_ARGB \
  1239. || (x) == AV_PIX_FMT_RGBA \
  1240. || (x) == AV_PIX_FMT_BGRA \
  1241. || (x) == AV_PIX_FMT_ABGR \
  1242. )
  1243. #define isRGBA64(x) ( \
  1244. (x) == AV_PIX_FMT_RGBA64LE \
  1245. || (x) == AV_PIX_FMT_RGBA64BE \
  1246. || (x) == AV_PIX_FMT_BGRA64LE \
  1247. || (x) == AV_PIX_FMT_BGRA64BE \
  1248. )
  1249. #define isRGB48(x) ( \
  1250. (x) == AV_PIX_FMT_RGB48LE \
  1251. || (x) == AV_PIX_FMT_RGB48BE \
  1252. || (x) == AV_PIX_FMT_BGR48LE \
  1253. || (x) == AV_PIX_FMT_BGR48BE \
  1254. )
  1255. /* {RGB,BGR}{15,16,24,32,32_1} -> {RGB,BGR}{15,16,24,32} */
  1256. typedef void (* rgbConvFn) (const uint8_t *, uint8_t *, int);
  1257. static rgbConvFn findRgbConvFn(SwsContext *c)
  1258. {
  1259. const enum AVPixelFormat srcFormat = c->srcFormat;
  1260. const enum AVPixelFormat dstFormat = c->dstFormat;
  1261. const int srcId = c->srcFormatBpp;
  1262. const int dstId = c->dstFormatBpp;
  1263. rgbConvFn conv = NULL;
  1264. #define IS_NOT_NE(bpp, desc) \
  1265. (((bpp + 7) >> 3) == 2 && \
  1266. (!(desc->flags & AV_PIX_FMT_FLAG_BE) != !HAVE_BIGENDIAN))
  1267. #define CONV_IS(src, dst) (srcFormat == AV_PIX_FMT_##src && dstFormat == AV_PIX_FMT_##dst)
  1268. if (isRGBA32(srcFormat) && isRGBA32(dstFormat)) {
  1269. if ( CONV_IS(ABGR, RGBA)
  1270. || CONV_IS(ARGB, BGRA)
  1271. || CONV_IS(BGRA, ARGB)
  1272. || CONV_IS(RGBA, ABGR)) conv = shuffle_bytes_3210;
  1273. else if (CONV_IS(ABGR, ARGB)
  1274. || CONV_IS(ARGB, ABGR)) conv = shuffle_bytes_0321;
  1275. else if (CONV_IS(ABGR, BGRA)
  1276. || CONV_IS(ARGB, RGBA)) conv = shuffle_bytes_1230;
  1277. else if (CONV_IS(BGRA, RGBA)
  1278. || CONV_IS(RGBA, BGRA)) conv = shuffle_bytes_2103;
  1279. else if (CONV_IS(BGRA, ABGR)
  1280. || CONV_IS(RGBA, ARGB)) conv = shuffle_bytes_3012;
  1281. } else if (isRGB48(srcFormat) && isRGB48(dstFormat)) {
  1282. if (CONV_IS(RGB48LE, BGR48LE)
  1283. || CONV_IS(BGR48LE, RGB48LE)
  1284. || CONV_IS(RGB48BE, BGR48BE)
  1285. || CONV_IS(BGR48BE, RGB48BE)) conv = rgb48tobgr48_nobswap;
  1286. else if (CONV_IS(RGB48LE, BGR48BE)
  1287. || CONV_IS(BGR48LE, RGB48BE)
  1288. || CONV_IS(RGB48BE, BGR48LE)
  1289. || CONV_IS(BGR48BE, RGB48LE)) conv = rgb48tobgr48_bswap;
  1290. } else if (isRGB48(srcFormat) && isRGBA64(dstFormat)) {
  1291. if (CONV_IS(RGB48LE, BGRA64LE)
  1292. || CONV_IS(BGR48LE, RGBA64LE)
  1293. || CONV_IS(RGB48BE, BGRA64BE)
  1294. || CONV_IS(BGR48BE, RGBA64BE)) conv = rgb48tobgr64_nobswap;
  1295. else if (CONV_IS(RGB48LE, BGRA64BE)
  1296. || CONV_IS(BGR48LE, RGBA64BE)
  1297. || CONV_IS(RGB48BE, BGRA64LE)
  1298. || CONV_IS(BGR48BE, RGBA64LE)) conv = rgb48tobgr64_bswap;
  1299. if (CONV_IS(RGB48LE, RGBA64LE)
  1300. || CONV_IS(BGR48LE, BGRA64LE)
  1301. || CONV_IS(RGB48BE, RGBA64BE)
  1302. || CONV_IS(BGR48BE, BGRA64BE)) conv = rgb48to64_nobswap;
  1303. else if (CONV_IS(RGB48LE, RGBA64BE)
  1304. || CONV_IS(BGR48LE, BGRA64BE)
  1305. || CONV_IS(RGB48BE, RGBA64LE)
  1306. || CONV_IS(BGR48BE, BGRA64LE)) conv = rgb48to64_bswap;
  1307. } else if (isRGBA64(srcFormat) && isRGB48(dstFormat)) {
  1308. if (CONV_IS(RGBA64LE, BGR48LE)
  1309. || CONV_IS(BGRA64LE, RGB48LE)
  1310. || CONV_IS(RGBA64BE, BGR48BE)
  1311. || CONV_IS(BGRA64BE, RGB48BE)) conv = rgb64tobgr48_nobswap;
  1312. else if (CONV_IS(RGBA64LE, BGR48BE)
  1313. || CONV_IS(BGRA64LE, RGB48BE)
  1314. || CONV_IS(RGBA64BE, BGR48LE)
  1315. || CONV_IS(BGRA64BE, RGB48LE)) conv = rgb64tobgr48_bswap;
  1316. else if (CONV_IS(RGBA64LE, RGB48LE)
  1317. || CONV_IS(BGRA64LE, BGR48LE)
  1318. || CONV_IS(RGBA64BE, RGB48BE)
  1319. || CONV_IS(BGRA64BE, BGR48BE)) conv = rgb64to48_nobswap;
  1320. else if (CONV_IS(RGBA64LE, RGB48BE)
  1321. || CONV_IS(BGRA64LE, BGR48BE)
  1322. || CONV_IS(RGBA64BE, RGB48LE)
  1323. || CONV_IS(BGRA64BE, BGR48LE)) conv = rgb64to48_bswap;
  1324. } else
  1325. /* BGR -> BGR */
  1326. if ((isBGRinInt(srcFormat) && isBGRinInt(dstFormat)) ||
  1327. (isRGBinInt(srcFormat) && isRGBinInt(dstFormat))) {
  1328. switch (srcId | (dstId << 16)) {
  1329. case 0x000F000C: conv = rgb12to15; break;
  1330. case 0x000F0010: conv = rgb16to15; break;
  1331. case 0x000F0018: conv = rgb24to15; break;
  1332. case 0x000F0020: conv = rgb32to15; break;
  1333. case 0x0010000F: conv = rgb15to16; break;
  1334. case 0x00100018: conv = rgb24to16; break;
  1335. case 0x00100020: conv = rgb32to16; break;
  1336. case 0x0018000F: conv = rgb15to24; break;
  1337. case 0x00180010: conv = rgb16to24; break;
  1338. case 0x00180020: conv = rgb32to24; break;
  1339. case 0x0020000F: conv = rgb15to32; break;
  1340. case 0x00200010: conv = rgb16to32; break;
  1341. case 0x00200018: conv = rgb24to32; break;
  1342. }
  1343. } else if ((isBGRinInt(srcFormat) && isRGBinInt(dstFormat)) ||
  1344. (isRGBinInt(srcFormat) && isBGRinInt(dstFormat))) {
  1345. switch (srcId | (dstId << 16)) {
  1346. case 0x000C000C: conv = rgb12tobgr12; break;
  1347. case 0x000F000F: conv = rgb15tobgr15; break;
  1348. case 0x000F0010: conv = rgb16tobgr15; break;
  1349. case 0x000F0018: conv = rgb24tobgr15; break;
  1350. case 0x000F0020: conv = rgb32tobgr15; break;
  1351. case 0x0010000F: conv = rgb15tobgr16; break;
  1352. case 0x00100010: conv = rgb16tobgr16; break;
  1353. case 0x00100018: conv = rgb24tobgr16; break;
  1354. case 0x00100020: conv = rgb32tobgr16; break;
  1355. case 0x0018000F: conv = rgb15tobgr24; break;
  1356. case 0x00180010: conv = rgb16tobgr24; break;
  1357. case 0x00180018: conv = rgb24tobgr24; break;
  1358. case 0x00180020: conv = rgb32tobgr24; break;
  1359. case 0x0020000F: conv = rgb15tobgr32; break;
  1360. case 0x00200010: conv = rgb16tobgr32; break;
  1361. case 0x00200018: conv = rgb24tobgr32; break;
  1362. }
  1363. }
  1364. if ((dstFormat == AV_PIX_FMT_RGB32_1 || dstFormat == AV_PIX_FMT_BGR32_1) && !isRGBA32(srcFormat) && ALT32_CORR<0)
  1365. return NULL;
  1366. // Maintain symmetry between endianness
  1367. if (c->flags & SWS_BITEXACT)
  1368. if ((dstFormat == AV_PIX_FMT_RGB32 || dstFormat == AV_PIX_FMT_BGR32 ) && !isRGBA32(srcFormat) && ALT32_CORR>0)
  1369. return NULL;
  1370. return conv;
  1371. }
  1372. /* {RGB,BGR}{15,16,24,32,32_1} -> {RGB,BGR}{15,16,24,32} */
  1373. static int rgbToRgbWrapper(SwsContext *c, const uint8_t *src[], int srcStride[],
  1374. int srcSliceY, int srcSliceH, uint8_t *dst[],
  1375. int dstStride[])
  1376. {
  1377. const enum AVPixelFormat srcFormat = c->srcFormat;
  1378. const enum AVPixelFormat dstFormat = c->dstFormat;
  1379. const AVPixFmtDescriptor *desc_src = av_pix_fmt_desc_get(c->srcFormat);
  1380. const AVPixFmtDescriptor *desc_dst = av_pix_fmt_desc_get(c->dstFormat);
  1381. const int srcBpp = (c->srcFormatBpp + 7) >> 3;
  1382. const int dstBpp = (c->dstFormatBpp + 7) >> 3;
  1383. rgbConvFn conv = findRgbConvFn(c);
  1384. if (!conv) {
  1385. av_log(c, AV_LOG_ERROR, "internal error %s -> %s converter\n",
  1386. av_get_pix_fmt_name(srcFormat), av_get_pix_fmt_name(dstFormat));
  1387. } else {
  1388. const uint8_t *srcPtr = src[0];
  1389. uint8_t *dstPtr = dst[0];
  1390. int src_bswap = IS_NOT_NE(c->srcFormatBpp, desc_src);
  1391. int dst_bswap = IS_NOT_NE(c->dstFormatBpp, desc_dst);
  1392. if ((srcFormat == AV_PIX_FMT_RGB32_1 || srcFormat == AV_PIX_FMT_BGR32_1) &&
  1393. !isRGBA32(dstFormat))
  1394. srcPtr += ALT32_CORR;
  1395. if ((dstFormat == AV_PIX_FMT_RGB32_1 || dstFormat == AV_PIX_FMT_BGR32_1) &&
  1396. !isRGBA32(srcFormat)) {
  1397. int i;
  1398. av_assert0(ALT32_CORR == 1);
  1399. for (i = 0; i < srcSliceH; i++)
  1400. dstPtr[dstStride[0] * (srcSliceY + i)] = 255;
  1401. dstPtr += ALT32_CORR;
  1402. }
  1403. if (dstStride[0] * srcBpp == srcStride[0] * dstBpp && srcStride[0] > 0 &&
  1404. !(srcStride[0] % srcBpp) && !dst_bswap && !src_bswap)
  1405. conv(srcPtr, dstPtr + dstStride[0] * srcSliceY,
  1406. (srcSliceH - 1) * srcStride[0] + c->srcW * srcBpp);
  1407. else {
  1408. int i, j;
  1409. dstPtr += dstStride[0] * srcSliceY;
  1410. for (i = 0; i < srcSliceH; i++) {
  1411. if(src_bswap) {
  1412. for(j=0; j<c->srcW; j++)
  1413. ((uint16_t*)c->formatConvBuffer)[j] = av_bswap16(((uint16_t*)srcPtr)[j]);
  1414. conv(c->formatConvBuffer, dstPtr, c->srcW * srcBpp);
  1415. }else
  1416. conv(srcPtr, dstPtr, c->srcW * srcBpp);
  1417. if(dst_bswap)
  1418. for(j=0; j<c->srcW; j++)
  1419. ((uint16_t*)dstPtr)[j] = av_bswap16(((uint16_t*)dstPtr)[j]);
  1420. srcPtr += srcStride[0];
  1421. dstPtr += dstStride[0];
  1422. }
  1423. }
  1424. }
  1425. return srcSliceH;
  1426. }
  1427. static int bgr24ToYv12Wrapper(SwsContext *c, const uint8_t *src[],
  1428. int srcStride[], int srcSliceY, int srcSliceH,
  1429. uint8_t *dst[], int dstStride[])
  1430. {
  1431. ff_rgb24toyv12(
  1432. src[0],
  1433. dst[0] + srcSliceY * dstStride[0],
  1434. dst[1] + (srcSliceY >> 1) * dstStride[1],
  1435. dst[2] + (srcSliceY >> 1) * dstStride[2],
  1436. c->srcW, srcSliceH,
  1437. dstStride[0], dstStride[1], srcStride[0],
  1438. c->input_rgb2yuv_table);
  1439. if (dst[3])
  1440. fillPlane(dst[3], dstStride[3], c->srcW, srcSliceH, srcSliceY, 255);
  1441. return srcSliceH;
  1442. }
  1443. static int yvu9ToYv12Wrapper(SwsContext *c, const uint8_t *src[],
  1444. int srcStride[], int srcSliceY, int srcSliceH,
  1445. uint8_t *dst[], int dstStride[])
  1446. {
  1447. copyPlane(src[0], srcStride[0], srcSliceY, srcSliceH, c->srcW,
  1448. dst[0], dstStride[0]);
  1449. planar2x(src[1], dst[1] + dstStride[1] * (srcSliceY >> 1), c->chrSrcW,
  1450. srcSliceH >> 2, srcStride[1], dstStride[1]);
  1451. planar2x(src[2], dst[2] + dstStride[2] * (srcSliceY >> 1), c->chrSrcW,
  1452. srcSliceH >> 2, srcStride[2], dstStride[2]);
  1453. if (dst[3])
  1454. fillPlane(dst[3], dstStride[3], c->srcW, srcSliceH, srcSliceY, 255);
  1455. return srcSliceH;
  1456. }
  1457. static int uint_y_to_float_y_wrapper(SwsContext *c, const uint8_t *src[],
  1458. int srcStride[], int srcSliceY,
  1459. int srcSliceH, uint8_t *dst[], int dstStride[])
  1460. {
  1461. int y, x;
  1462. ptrdiff_t dstStrideFloat = dstStride[0] >> 2;
  1463. const uint8_t *srcPtr = src[0];
  1464. float *dstPtr = (float *)(dst[0] + dstStride[0] * srcSliceY);
  1465. for (y = 0; y < srcSliceH; ++y){
  1466. for (x = 0; x < c->srcW; ++x){
  1467. dstPtr[x] = c->uint2float_lut[srcPtr[x]];
  1468. }
  1469. srcPtr += srcStride[0];
  1470. dstPtr += dstStrideFloat;
  1471. }
  1472. return srcSliceH;
  1473. }
  1474. static int float_y_to_uint_y_wrapper(SwsContext *c, const uint8_t* src[],
  1475. int srcStride[], int srcSliceY,
  1476. int srcSliceH, uint8_t* dst[], int dstStride[])
  1477. {
  1478. int y, x;
  1479. ptrdiff_t srcStrideFloat = srcStride[0] >> 2;
  1480. const float *srcPtr = (const float *)src[0];
  1481. uint8_t *dstPtr = dst[0] + dstStride[0] * srcSliceY;
  1482. for (y = 0; y < srcSliceH; ++y){
  1483. for (x = 0; x < c->srcW; ++x){
  1484. dstPtr[x] = av_clip_uint8(lrintf(255.0f * srcPtr[x]));
  1485. }
  1486. srcPtr += srcStrideFloat;
  1487. dstPtr += dstStride[0];
  1488. }
  1489. return srcSliceH;
  1490. }
  1491. /* unscaled copy like stuff (assumes nearly identical formats) */
  1492. static int packedCopyWrapper(SwsContext *c, const uint8_t *src[],
  1493. int srcStride[], int srcSliceY, int srcSliceH,
  1494. uint8_t *dst[], int dstStride[])
  1495. {
  1496. if (dstStride[0] == srcStride[0] && srcStride[0] > 0)
  1497. memcpy(dst[0] + dstStride[0] * srcSliceY, src[0], srcSliceH * dstStride[0]);
  1498. else {
  1499. int i;
  1500. const uint8_t *srcPtr = src[0];
  1501. uint8_t *dstPtr = dst[0] + dstStride[0] * srcSliceY;
  1502. int length = 0;
  1503. /* universal length finder */
  1504. while (length + c->srcW <= FFABS(dstStride[0]) &&
  1505. length + c->srcW <= FFABS(srcStride[0]))
  1506. length += c->srcW;
  1507. av_assert1(length != 0);
  1508. for (i = 0; i < srcSliceH; i++) {
  1509. memcpy(dstPtr, srcPtr, length);
  1510. srcPtr += srcStride[0];
  1511. dstPtr += dstStride[0];
  1512. }
  1513. }
  1514. return srcSliceH;
  1515. }
  1516. #define DITHER_COPY(dst, dstStride, src, srcStride, bswap, dbswap)\
  1517. unsigned shift= src_depth-dst_depth, tmp;\
  1518. if (c->dither == SWS_DITHER_NONE) {\
  1519. for (i = 0; i < height; i++) {\
  1520. for (j = 0; j < length-7; j+=8) {\
  1521. dst[j+0] = dbswap(bswap(src[j+0])>>shift);\
  1522. dst[j+1] = dbswap(bswap(src[j+1])>>shift);\
  1523. dst[j+2] = dbswap(bswap(src[j+2])>>shift);\
  1524. dst[j+3] = dbswap(bswap(src[j+3])>>shift);\
  1525. dst[j+4] = dbswap(bswap(src[j+4])>>shift);\
  1526. dst[j+5] = dbswap(bswap(src[j+5])>>shift);\
  1527. dst[j+6] = dbswap(bswap(src[j+6])>>shift);\
  1528. dst[j+7] = dbswap(bswap(src[j+7])>>shift);\
  1529. }\
  1530. for (; j < length; j++) {\
  1531. dst[j] = dbswap(bswap(src[j])>>shift);\
  1532. }\
  1533. dst += dstStride;\
  1534. src += srcStride;\
  1535. }\
  1536. } else if (shiftonly) {\
  1537. for (i = 0; i < height; i++) {\
  1538. const uint8_t *dither= dithers[shift-1][i&7];\
  1539. for (j = 0; j < length-7; j+=8) {\
  1540. tmp = (bswap(src[j+0]) + dither[0])>>shift; dst[j+0] = dbswap(tmp - (tmp>>dst_depth));\
  1541. tmp = (bswap(src[j+1]) + dither[1])>>shift; dst[j+1] = dbswap(tmp - (tmp>>dst_depth));\
  1542. tmp = (bswap(src[j+2]) + dither[2])>>shift; dst[j+2] = dbswap(tmp - (tmp>>dst_depth));\
  1543. tmp = (bswap(src[j+3]) + dither[3])>>shift; dst[j+3] = dbswap(tmp - (tmp>>dst_depth));\
  1544. tmp = (bswap(src[j+4]) + dither[4])>>shift; dst[j+4] = dbswap(tmp - (tmp>>dst_depth));\
  1545. tmp = (bswap(src[j+5]) + dither[5])>>shift; dst[j+5] = dbswap(tmp - (tmp>>dst_depth));\
  1546. tmp = (bswap(src[j+6]) + dither[6])>>shift; dst[j+6] = dbswap(tmp - (tmp>>dst_depth));\
  1547. tmp = (bswap(src[j+7]) + dither[7])>>shift; dst[j+7] = dbswap(tmp - (tmp>>dst_depth));\
  1548. }\
  1549. for (; j < length; j++) {\
  1550. tmp = (bswap(src[j]) + dither[j&7])>>shift; dst[j] = dbswap(tmp - (tmp>>dst_depth));\
  1551. }\
  1552. dst += dstStride;\
  1553. src += srcStride;\
  1554. }\
  1555. } else {\
  1556. for (i = 0; i < height; i++) {\
  1557. const uint8_t *dither= dithers[shift-1][i&7];\
  1558. for (j = 0; j < length-7; j+=8) {\
  1559. tmp = bswap(src[j+0]); dst[j+0] = dbswap((tmp - (tmp>>dst_depth) + dither[0])>>shift);\
  1560. tmp = bswap(src[j+1]); dst[j+1] = dbswap((tmp - (tmp>>dst_depth) + dither[1])>>shift);\
  1561. tmp = bswap(src[j+2]); dst[j+2] = dbswap((tmp - (tmp>>dst_depth) + dither[2])>>shift);\
  1562. tmp = bswap(src[j+3]); dst[j+3] = dbswap((tmp - (tmp>>dst_depth) + dither[3])>>shift);\
  1563. tmp = bswap(src[j+4]); dst[j+4] = dbswap((tmp - (tmp>>dst_depth) + dither[4])>>shift);\
  1564. tmp = bswap(src[j+5]); dst[j+5] = dbswap((tmp - (tmp>>dst_depth) + dither[5])>>shift);\
  1565. tmp = bswap(src[j+6]); dst[j+6] = dbswap((tmp - (tmp>>dst_depth) + dither[6])>>shift);\
  1566. tmp = bswap(src[j+7]); dst[j+7] = dbswap((tmp - (tmp>>dst_depth) + dither[7])>>shift);\
  1567. }\
  1568. for (; j < length; j++) {\
  1569. tmp = bswap(src[j]); dst[j] = dbswap((tmp - (tmp>>dst_depth) + dither[j&7])>>shift);\
  1570. }\
  1571. dst += dstStride;\
  1572. src += srcStride;\
  1573. }\
  1574. }
  1575. static int planarCopyWrapper(SwsContext *c, const uint8_t *src[],
  1576. int srcStride[], int srcSliceY, int srcSliceH,
  1577. uint8_t *dst[], int dstStride[])
  1578. {
  1579. const AVPixFmtDescriptor *desc_src = av_pix_fmt_desc_get(c->srcFormat);
  1580. const AVPixFmtDescriptor *desc_dst = av_pix_fmt_desc_get(c->dstFormat);
  1581. int plane, i, j;
  1582. for (plane = 0; plane < 4; plane++) {
  1583. int length = (plane == 0 || plane == 3) ? c->srcW : AV_CEIL_RSHIFT(c->srcW, c->chrDstHSubSample);
  1584. int y = (plane == 0 || plane == 3) ? srcSliceY: AV_CEIL_RSHIFT(srcSliceY, c->chrDstVSubSample);
  1585. int height = (plane == 0 || plane == 3) ? srcSliceH: AV_CEIL_RSHIFT(srcSliceH, c->chrDstVSubSample);
  1586. const uint8_t *srcPtr = src[plane];
  1587. uint8_t *dstPtr = dst[plane] + dstStride[plane] * y;
  1588. int shiftonly = plane == 1 || plane == 2 || (!c->srcRange && plane == 0);
  1589. if (!dst[plane])
  1590. continue;
  1591. // ignore palette for GRAY8
  1592. if (plane == 1 && !dst[2]) continue;
  1593. if (!src[plane] || (plane == 1 && !src[2])) {
  1594. if (is16BPS(c->dstFormat) || isNBPS(c->dstFormat)) {
  1595. fillPlane16(dst[plane], dstStride[plane], length, height, y,
  1596. plane == 3, desc_dst->comp[plane].depth,
  1597. isBE(c->dstFormat));
  1598. } else {
  1599. fillPlane(dst[plane], dstStride[plane], length, height, y,
  1600. (plane == 3) ? 255 : 128);
  1601. }
  1602. } else {
  1603. if(isNBPS(c->srcFormat) || isNBPS(c->dstFormat)
  1604. || (is16BPS(c->srcFormat) != is16BPS(c->dstFormat))
  1605. ) {
  1606. const int src_depth = desc_src->comp[plane].depth;
  1607. const int dst_depth = desc_dst->comp[plane].depth;
  1608. const uint16_t *srcPtr2 = (const uint16_t *) srcPtr;
  1609. uint16_t *dstPtr2 = (uint16_t*)dstPtr;
  1610. if (dst_depth == 8) {
  1611. if(isBE(c->srcFormat) == HAVE_BIGENDIAN){
  1612. DITHER_COPY(dstPtr, dstStride[plane], srcPtr2, srcStride[plane]/2, , )
  1613. } else {
  1614. DITHER_COPY(dstPtr, dstStride[plane], srcPtr2, srcStride[plane]/2, av_bswap16, )
  1615. }
  1616. } else if (src_depth == 8) {
  1617. for (i = 0; i < height; i++) {
  1618. #define COPY816(w)\
  1619. if (shiftonly) {\
  1620. for (j = 0; j < length; j++)\
  1621. w(&dstPtr2[j], srcPtr[j]<<(dst_depth-8));\
  1622. } else {\
  1623. for (j = 0; j < length; j++)\
  1624. w(&dstPtr2[j], (srcPtr[j]<<(dst_depth-8)) |\
  1625. (srcPtr[j]>>(2*8-dst_depth)));\
  1626. }
  1627. if(isBE(c->dstFormat)){
  1628. COPY816(AV_WB16)
  1629. } else {
  1630. COPY816(AV_WL16)
  1631. }
  1632. dstPtr2 += dstStride[plane]/2;
  1633. srcPtr += srcStride[plane];
  1634. }
  1635. } else if (src_depth <= dst_depth) {
  1636. for (i = 0; i < height; i++) {
  1637. j = 0;
  1638. if(isBE(c->srcFormat) == HAVE_BIGENDIAN &&
  1639. isBE(c->dstFormat) == HAVE_BIGENDIAN &&
  1640. shiftonly) {
  1641. unsigned shift = dst_depth - src_depth;
  1642. #if HAVE_FAST_64BIT
  1643. #define FAST_COPY_UP(shift) \
  1644. for (; j < length - 3; j += 4) { \
  1645. uint64_t v = AV_RN64A(srcPtr2 + j); \
  1646. AV_WN64A(dstPtr2 + j, v << shift); \
  1647. }
  1648. #else
  1649. #define FAST_COPY_UP(shift) \
  1650. for (; j < length - 1; j += 2) { \
  1651. uint32_t v = AV_RN32A(srcPtr2 + j); \
  1652. AV_WN32A(dstPtr2 + j, v << shift); \
  1653. }
  1654. #endif
  1655. switch (shift)
  1656. {
  1657. case 6: FAST_COPY_UP(6); break;
  1658. case 7: FAST_COPY_UP(7); break;
  1659. }
  1660. }
  1661. #define COPY_UP(r,w) \
  1662. if(shiftonly){\
  1663. for (; j < length; j++){ \
  1664. unsigned int v= r(&srcPtr2[j]);\
  1665. w(&dstPtr2[j], v<<(dst_depth-src_depth));\
  1666. }\
  1667. }else{\
  1668. for (; j < length; j++){ \
  1669. unsigned int v= r(&srcPtr2[j]);\
  1670. w(&dstPtr2[j], (v<<(dst_depth-src_depth)) | \
  1671. (v>>(2*src_depth-dst_depth)));\
  1672. }\
  1673. }
  1674. if(isBE(c->srcFormat)){
  1675. if(isBE(c->dstFormat)){
  1676. COPY_UP(AV_RB16, AV_WB16)
  1677. } else {
  1678. COPY_UP(AV_RB16, AV_WL16)
  1679. }
  1680. } else {
  1681. if(isBE(c->dstFormat)){
  1682. COPY_UP(AV_RL16, AV_WB16)
  1683. } else {
  1684. COPY_UP(AV_RL16, AV_WL16)
  1685. }
  1686. }
  1687. dstPtr2 += dstStride[plane]/2;
  1688. srcPtr2 += srcStride[plane]/2;
  1689. }
  1690. } else {
  1691. if(isBE(c->srcFormat) == HAVE_BIGENDIAN){
  1692. if(isBE(c->dstFormat) == HAVE_BIGENDIAN){
  1693. DITHER_COPY(dstPtr2, dstStride[plane]/2, srcPtr2, srcStride[plane]/2, , )
  1694. } else {
  1695. DITHER_COPY(dstPtr2, dstStride[plane]/2, srcPtr2, srcStride[plane]/2, , av_bswap16)
  1696. }
  1697. }else{
  1698. if(isBE(c->dstFormat) == HAVE_BIGENDIAN){
  1699. DITHER_COPY(dstPtr2, dstStride[plane]/2, srcPtr2, srcStride[plane]/2, av_bswap16, )
  1700. } else {
  1701. DITHER_COPY(dstPtr2, dstStride[plane]/2, srcPtr2, srcStride[plane]/2, av_bswap16, av_bswap16)
  1702. }
  1703. }
  1704. }
  1705. } else if (is16BPS(c->srcFormat) && is16BPS(c->dstFormat) &&
  1706. isBE(c->srcFormat) != isBE(c->dstFormat)) {
  1707. for (i = 0; i < height; i++) {
  1708. for (j = 0; j < length; j++)
  1709. ((uint16_t *) dstPtr)[j] = av_bswap16(((const uint16_t *) srcPtr)[j]);
  1710. srcPtr += srcStride[plane];
  1711. dstPtr += dstStride[plane];
  1712. }
  1713. } else if (isFloat(c->srcFormat) && isFloat(c->dstFormat) &&
  1714. isBE(c->srcFormat) != isBE(c->dstFormat)) { /* swap float plane */
  1715. for (i = 0; i < height; i++) {
  1716. for (j = 0; j < length; j++)
  1717. ((uint32_t *) dstPtr)[j] = av_bswap32(((const uint32_t *) srcPtr)[j]);
  1718. srcPtr += srcStride[plane];
  1719. dstPtr += dstStride[plane];
  1720. }
  1721. } else if (dstStride[plane] == srcStride[plane] &&
  1722. srcStride[plane] > 0 && srcStride[plane] == length) {
  1723. memcpy(dst[plane] + dstStride[plane] * y, src[plane],
  1724. height * dstStride[plane]);
  1725. } else {
  1726. if (is16BPS(c->srcFormat) && is16BPS(c->dstFormat))
  1727. length *= 2;
  1728. else if (desc_src->comp[0].depth == 1)
  1729. length >>= 3; // monowhite/black
  1730. for (i = 0; i < height; i++) {
  1731. memcpy(dstPtr, srcPtr, length);
  1732. srcPtr += srcStride[plane];
  1733. dstPtr += dstStride[plane];
  1734. }
  1735. }
  1736. }
  1737. }
  1738. return srcSliceH;
  1739. }
  1740. #define IS_DIFFERENT_ENDIANESS(src_fmt, dst_fmt, pix_fmt) \
  1741. ((src_fmt == pix_fmt ## BE && dst_fmt == pix_fmt ## LE) || \
  1742. (src_fmt == pix_fmt ## LE && dst_fmt == pix_fmt ## BE))
  1743. void ff_get_unscaled_swscale(SwsContext *c)
  1744. {
  1745. const enum AVPixelFormat srcFormat = c->srcFormat;
  1746. const enum AVPixelFormat dstFormat = c->dstFormat;
  1747. const int flags = c->flags;
  1748. const int dstH = c->dstH;
  1749. int needsDither;
  1750. needsDither = isAnyRGB(dstFormat) &&
  1751. c->dstFormatBpp < 24 &&
  1752. (c->dstFormatBpp < c->srcFormatBpp || (!isAnyRGB(srcFormat)));
  1753. /* yv12_to_nv12 */
  1754. if ((srcFormat == AV_PIX_FMT_YUV420P || srcFormat == AV_PIX_FMT_YUVA420P) &&
  1755. (dstFormat == AV_PIX_FMT_NV12 || dstFormat == AV_PIX_FMT_NV21)) {
  1756. c->swscale = planarToNv12Wrapper;
  1757. }
  1758. /* yv24_to_nv24 */
  1759. if ((srcFormat == AV_PIX_FMT_YUV444P || srcFormat == AV_PIX_FMT_YUVA444P) &&
  1760. (dstFormat == AV_PIX_FMT_NV24 || dstFormat == AV_PIX_FMT_NV42)) {
  1761. c->swscale = planarToNv24Wrapper;
  1762. }
  1763. /* nv12_to_yv12 */
  1764. if (dstFormat == AV_PIX_FMT_YUV420P &&
  1765. (srcFormat == AV_PIX_FMT_NV12 || srcFormat == AV_PIX_FMT_NV21)) {
  1766. c->swscale = nv12ToPlanarWrapper;
  1767. }
  1768. /* nv24_to_yv24 */
  1769. if (dstFormat == AV_PIX_FMT_YUV444P &&
  1770. (srcFormat == AV_PIX_FMT_NV24 || srcFormat == AV_PIX_FMT_NV42)) {
  1771. c->swscale = nv24ToPlanarWrapper;
  1772. }
  1773. /* yuv2bgr */
  1774. if ((srcFormat == AV_PIX_FMT_YUV420P || srcFormat == AV_PIX_FMT_YUV422P ||
  1775. srcFormat == AV_PIX_FMT_YUVA420P) && isAnyRGB(dstFormat) &&
  1776. !(flags & SWS_ACCURATE_RND) && (c->dither == SWS_DITHER_BAYER || c->dither == SWS_DITHER_AUTO) && !(dstH & 1)) {
  1777. c->swscale = ff_yuv2rgb_get_func_ptr(c);
  1778. }
  1779. /* yuv420p1x_to_p01x */
  1780. if ((srcFormat == AV_PIX_FMT_YUV420P10 || srcFormat == AV_PIX_FMT_YUVA420P10 ||
  1781. srcFormat == AV_PIX_FMT_YUV420P12 ||
  1782. srcFormat == AV_PIX_FMT_YUV420P14 ||
  1783. srcFormat == AV_PIX_FMT_YUV420P16 || srcFormat == AV_PIX_FMT_YUVA420P16) &&
  1784. (dstFormat == AV_PIX_FMT_P010 || dstFormat == AV_PIX_FMT_P016)) {
  1785. c->swscale = planarToP01xWrapper;
  1786. }
  1787. /* yuv420p_to_p01xle */
  1788. if ((srcFormat == AV_PIX_FMT_YUV420P || srcFormat == AV_PIX_FMT_YUVA420P) &&
  1789. (dstFormat == AV_PIX_FMT_P010LE || dstFormat == AV_PIX_FMT_P016LE)) {
  1790. c->swscale = planar8ToP01xleWrapper;
  1791. }
  1792. if (srcFormat == AV_PIX_FMT_YUV410P && !(dstH & 3) &&
  1793. (dstFormat == AV_PIX_FMT_YUV420P || dstFormat == AV_PIX_FMT_YUVA420P) &&
  1794. !(flags & SWS_BITEXACT)) {
  1795. c->swscale = yvu9ToYv12Wrapper;
  1796. }
  1797. /* bgr24toYV12 */
  1798. if (srcFormat == AV_PIX_FMT_BGR24 &&
  1799. (dstFormat == AV_PIX_FMT_YUV420P || dstFormat == AV_PIX_FMT_YUVA420P) &&
  1800. !(flags & SWS_ACCURATE_RND))
  1801. c->swscale = bgr24ToYv12Wrapper;
  1802. /* RGB/BGR -> RGB/BGR (no dither needed forms) */
  1803. if (isAnyRGB(srcFormat) && isAnyRGB(dstFormat) && findRgbConvFn(c)
  1804. && (!needsDither || (c->flags&(SWS_FAST_BILINEAR|SWS_POINT))))
  1805. c->swscale = rgbToRgbWrapper;
  1806. /* RGB to planar RGB */
  1807. if ((srcFormat == AV_PIX_FMT_GBRP && dstFormat == AV_PIX_FMT_GBRAP) ||
  1808. (srcFormat == AV_PIX_FMT_GBRAP && dstFormat == AV_PIX_FMT_GBRP))
  1809. c->swscale = planarRgbToplanarRgbWrapper;
  1810. #define isByteRGB(f) ( \
  1811. f == AV_PIX_FMT_RGB32 || \
  1812. f == AV_PIX_FMT_RGB32_1 || \
  1813. f == AV_PIX_FMT_RGB24 || \
  1814. f == AV_PIX_FMT_BGR32 || \
  1815. f == AV_PIX_FMT_BGR32_1 || \
  1816. f == AV_PIX_FMT_BGR24)
  1817. if (srcFormat == AV_PIX_FMT_GBRP && isPlanar(srcFormat) && isByteRGB(dstFormat))
  1818. c->swscale = planarRgbToRgbWrapper;
  1819. if (srcFormat == AV_PIX_FMT_GBRAP && isByteRGB(dstFormat))
  1820. c->swscale = planarRgbaToRgbWrapper;
  1821. if ((srcFormat == AV_PIX_FMT_RGB48LE || srcFormat == AV_PIX_FMT_RGB48BE ||
  1822. srcFormat == AV_PIX_FMT_BGR48LE || srcFormat == AV_PIX_FMT_BGR48BE ||
  1823. srcFormat == AV_PIX_FMT_RGBA64LE || srcFormat == AV_PIX_FMT_RGBA64BE ||
  1824. srcFormat == AV_PIX_FMT_BGRA64LE || srcFormat == AV_PIX_FMT_BGRA64BE) &&
  1825. (dstFormat == AV_PIX_FMT_GBRP9LE || dstFormat == AV_PIX_FMT_GBRP9BE ||
  1826. dstFormat == AV_PIX_FMT_GBRP10LE || dstFormat == AV_PIX_FMT_GBRP10BE ||
  1827. dstFormat == AV_PIX_FMT_GBRP12LE || dstFormat == AV_PIX_FMT_GBRP12BE ||
  1828. dstFormat == AV_PIX_FMT_GBRP14LE || dstFormat == AV_PIX_FMT_GBRP14BE ||
  1829. dstFormat == AV_PIX_FMT_GBRP16LE || dstFormat == AV_PIX_FMT_GBRP16BE ||
  1830. dstFormat == AV_PIX_FMT_GBRAP10LE || dstFormat == AV_PIX_FMT_GBRAP10BE ||
  1831. dstFormat == AV_PIX_FMT_GBRAP12LE || dstFormat == AV_PIX_FMT_GBRAP12BE ||
  1832. dstFormat == AV_PIX_FMT_GBRAP16LE || dstFormat == AV_PIX_FMT_GBRAP16BE ))
  1833. c->swscale = Rgb16ToPlanarRgb16Wrapper;
  1834. if ((srcFormat == AV_PIX_FMT_GBRP9LE || srcFormat == AV_PIX_FMT_GBRP9BE ||
  1835. srcFormat == AV_PIX_FMT_GBRP16LE || srcFormat == AV_PIX_FMT_GBRP16BE ||
  1836. srcFormat == AV_PIX_FMT_GBRP10LE || srcFormat == AV_PIX_FMT_GBRP10BE ||
  1837. srcFormat == AV_PIX_FMT_GBRP12LE || srcFormat == AV_PIX_FMT_GBRP12BE ||
  1838. srcFormat == AV_PIX_FMT_GBRP14LE || srcFormat == AV_PIX_FMT_GBRP14BE ||
  1839. srcFormat == AV_PIX_FMT_GBRAP10LE || srcFormat == AV_PIX_FMT_GBRAP10BE ||
  1840. srcFormat == AV_PIX_FMT_GBRAP12LE || srcFormat == AV_PIX_FMT_GBRAP12BE ||
  1841. srcFormat == AV_PIX_FMT_GBRAP16LE || srcFormat == AV_PIX_FMT_GBRAP16BE) &&
  1842. (dstFormat == AV_PIX_FMT_RGB48LE || dstFormat == AV_PIX_FMT_RGB48BE ||
  1843. dstFormat == AV_PIX_FMT_BGR48LE || dstFormat == AV_PIX_FMT_BGR48BE ||
  1844. dstFormat == AV_PIX_FMT_RGBA64LE || dstFormat == AV_PIX_FMT_RGBA64BE ||
  1845. dstFormat == AV_PIX_FMT_BGRA64LE || dstFormat == AV_PIX_FMT_BGRA64BE))
  1846. c->swscale = planarRgb16ToRgb16Wrapper;
  1847. if (av_pix_fmt_desc_get(srcFormat)->comp[0].depth == 8 &&
  1848. isPackedRGB(srcFormat) && dstFormat == AV_PIX_FMT_GBRP)
  1849. c->swscale = rgbToPlanarRgbWrapper;
  1850. if (isBayer(srcFormat)) {
  1851. if (dstFormat == AV_PIX_FMT_RGB24)
  1852. c->swscale = bayer_to_rgb24_wrapper;
  1853. else if (dstFormat == AV_PIX_FMT_YUV420P)
  1854. c->swscale = bayer_to_yv12_wrapper;
  1855. else if (!isBayer(dstFormat)) {
  1856. av_log(c, AV_LOG_ERROR, "unsupported bayer conversion\n");
  1857. av_assert0(0);
  1858. }
  1859. }
  1860. /* bswap 16 bits per pixel/component packed formats */
  1861. if (IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BAYER_BGGR16) ||
  1862. IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BAYER_RGGB16) ||
  1863. IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BAYER_GBRG16) ||
  1864. IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BAYER_GRBG16) ||
  1865. IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BGR444) ||
  1866. IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BGR48) ||
  1867. IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BGR555) ||
  1868. IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BGR565) ||
  1869. IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BGRA64) ||
  1870. IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GRAY9) ||
  1871. IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GRAY10) ||
  1872. IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GRAY12) ||
  1873. IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GRAY14) ||
  1874. IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GRAY16) ||
  1875. IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YA16) ||
  1876. IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_AYUV64) ||
  1877. IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GBRP9) ||
  1878. IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GBRP10) ||
  1879. IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GBRP12) ||
  1880. IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GBRP14) ||
  1881. IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GBRP16) ||
  1882. IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GBRAP10) ||
  1883. IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GBRAP12) ||
  1884. IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GBRAP16) ||
  1885. IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_RGB444) ||
  1886. IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_RGB48) ||
  1887. IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_RGB555) ||
  1888. IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_RGB565) ||
  1889. IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_RGBA64) ||
  1890. IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_XYZ12) ||
  1891. IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV420P9) ||
  1892. IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV420P10) ||
  1893. IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV420P12) ||
  1894. IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV420P14) ||
  1895. IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV420P16) ||
  1896. IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV422P9) ||
  1897. IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV422P10) ||
  1898. IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV422P12) ||
  1899. IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV422P14) ||
  1900. IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV422P16) ||
  1901. IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV440P10) ||
  1902. IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV440P12) ||
  1903. IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV444P9) ||
  1904. IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV444P10) ||
  1905. IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV444P12) ||
  1906. IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV444P14) ||
  1907. IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV444P16))
  1908. c->swscale = bswap_16bpc;
  1909. /* bswap 32 bits per pixel/component formats */
  1910. if (IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GBRPF32) ||
  1911. IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GBRAPF32))
  1912. c->swscale = bswap_32bpc;
  1913. if (usePal(srcFormat) && isByteRGB(dstFormat))
  1914. c->swscale = palToRgbWrapper;
  1915. if (srcFormat == AV_PIX_FMT_YUV422P) {
  1916. if (dstFormat == AV_PIX_FMT_YUYV422)
  1917. c->swscale = yuv422pToYuy2Wrapper;
  1918. else if (dstFormat == AV_PIX_FMT_UYVY422)
  1919. c->swscale = yuv422pToUyvyWrapper;
  1920. }
  1921. /* uint Y to float Y */
  1922. if (srcFormat == AV_PIX_FMT_GRAY8 && dstFormat == AV_PIX_FMT_GRAYF32){
  1923. c->swscale = uint_y_to_float_y_wrapper;
  1924. }
  1925. /* float Y to uint Y */
  1926. if (srcFormat == AV_PIX_FMT_GRAYF32 && dstFormat == AV_PIX_FMT_GRAY8){
  1927. c->swscale = float_y_to_uint_y_wrapper;
  1928. }
  1929. /* LQ converters if -sws 0 or -sws 4*/
  1930. if (c->flags&(SWS_FAST_BILINEAR|SWS_POINT)) {
  1931. /* yv12_to_yuy2 */
  1932. if (srcFormat == AV_PIX_FMT_YUV420P || srcFormat == AV_PIX_FMT_YUVA420P) {
  1933. if (dstFormat == AV_PIX_FMT_YUYV422)
  1934. c->swscale = planarToYuy2Wrapper;
  1935. else if (dstFormat == AV_PIX_FMT_UYVY422)
  1936. c->swscale = planarToUyvyWrapper;
  1937. }
  1938. }
  1939. if (srcFormat == AV_PIX_FMT_YUYV422 &&
  1940. (dstFormat == AV_PIX_FMT_YUV420P || dstFormat == AV_PIX_FMT_YUVA420P))
  1941. c->swscale = yuyvToYuv420Wrapper;
  1942. if (srcFormat == AV_PIX_FMT_UYVY422 &&
  1943. (dstFormat == AV_PIX_FMT_YUV420P || dstFormat == AV_PIX_FMT_YUVA420P))
  1944. c->swscale = uyvyToYuv420Wrapper;
  1945. if (srcFormat == AV_PIX_FMT_YUYV422 && dstFormat == AV_PIX_FMT_YUV422P)
  1946. c->swscale = yuyvToYuv422Wrapper;
  1947. if (srcFormat == AV_PIX_FMT_UYVY422 && dstFormat == AV_PIX_FMT_YUV422P)
  1948. c->swscale = uyvyToYuv422Wrapper;
  1949. #define isPlanarGray(x) (isGray(x) && (x) != AV_PIX_FMT_YA8 && (x) != AV_PIX_FMT_YA16LE && (x) != AV_PIX_FMT_YA16BE)
  1950. /* simple copy */
  1951. if ( srcFormat == dstFormat ||
  1952. (srcFormat == AV_PIX_FMT_YUVA420P && dstFormat == AV_PIX_FMT_YUV420P) ||
  1953. (srcFormat == AV_PIX_FMT_YUV420P && dstFormat == AV_PIX_FMT_YUVA420P) ||
  1954. (isFloat(srcFormat) == isFloat(dstFormat)) && ((isPlanarYUV(srcFormat) && isPlanarGray(dstFormat)) ||
  1955. (isPlanarYUV(dstFormat) && isPlanarGray(srcFormat)) ||
  1956. (isPlanarGray(dstFormat) && isPlanarGray(srcFormat)) ||
  1957. (isPlanarYUV(srcFormat) && isPlanarYUV(dstFormat) &&
  1958. c->chrDstHSubSample == c->chrSrcHSubSample &&
  1959. c->chrDstVSubSample == c->chrSrcVSubSample &&
  1960. !isSemiPlanarYUV(srcFormat) && !isSemiPlanarYUV(dstFormat))))
  1961. {
  1962. if (isPacked(c->srcFormat))
  1963. c->swscale = packedCopyWrapper;
  1964. else /* Planar YUV or gray */
  1965. c->swscale = planarCopyWrapper;
  1966. }
  1967. if (ARCH_PPC)
  1968. ff_get_unscaled_swscale_ppc(c);
  1969. if (ARCH_ARM)
  1970. ff_get_unscaled_swscale_arm(c);
  1971. if (ARCH_AARCH64)
  1972. ff_get_unscaled_swscale_aarch64(c);
  1973. }
  1974. /* Convert the palette to the same packed 32-bit format as the palette */
  1975. void sws_convertPalette8ToPacked32(const uint8_t *src, uint8_t *dst,
  1976. int num_pixels, const uint8_t *palette)
  1977. {
  1978. int i;
  1979. for (i = 0; i < num_pixels; i++)
  1980. ((uint32_t *) dst)[i] = ((const uint32_t *) palette)[src[i]];
  1981. }
  1982. /* Palette format: ABCD -> dst format: ABC */
  1983. void sws_convertPalette8ToPacked24(const uint8_t *src, uint8_t *dst,
  1984. int num_pixels, const uint8_t *palette)
  1985. {
  1986. int i;
  1987. for (i = 0; i < num_pixels; i++) {
  1988. //FIXME slow?
  1989. dst[0] = palette[src[i] * 4 + 0];
  1990. dst[1] = palette[src[i] * 4 + 1];
  1991. dst[2] = palette[src[i] * 4 + 2];
  1992. dst += 3;
  1993. }
  1994. }