swscale_unscaled.c 87 KB

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