SDL_stretch.c 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. #include "../SDL_internal.h"
  19. /* This a stretch blit implementation based on ideas given to me by
  20. Tomasz Cejner - thanks! :)
  21. April 27, 2000 - Sam Lantinga
  22. */
  23. #include "SDL_video.h"
  24. #include "SDL_blit.h"
  25. #include "SDL_render.h"
  26. /* This isn't ready for general consumption yet - it should be folded
  27. into the general blitting mechanism.
  28. */
  29. #if ((defined(_MSC_VER) && defined(_M_IX86)) || \
  30. (defined(__WATCOMC__) && defined(__386__)) || \
  31. (defined(__GNUC__) && defined(__i386__))) && SDL_ASSEMBLY_ROUTINES
  32. /* There's a bug with gcc 4.4.1 and -O2 where srcp doesn't get the correct
  33. * value after the first scanline. FIXME? */
  34. /* #define USE_ASM_STRETCH */
  35. #endif
  36. #ifdef USE_ASM_STRETCH
  37. #ifdef HAVE_MPROTECT
  38. #include <sys/types.h>
  39. #include <sys/mman.h>
  40. #endif
  41. #ifdef __GNUC__
  42. #define PAGE_ALIGNED __attribute__((__aligned__(4096)))
  43. #else
  44. #define PAGE_ALIGNED
  45. #endif
  46. #if defined(_M_IX86) || defined(__i386__) || defined(__386__)
  47. #define PREFIX16 0x66
  48. #define STORE_BYTE 0xAA
  49. #define STORE_WORD 0xAB
  50. #define LOAD_BYTE 0xAC
  51. #define LOAD_WORD 0xAD
  52. #define RETURN 0xC3
  53. #else
  54. #error Need assembly opcodes for this architecture
  55. #endif
  56. static unsigned char copy_row[4096] PAGE_ALIGNED;
  57. static int
  58. generate_rowbytes(int src_w, int dst_w, int bpp)
  59. {
  60. static struct
  61. {
  62. int bpp;
  63. int src_w;
  64. int dst_w;
  65. int status;
  66. } last;
  67. int i;
  68. int pos, inc;
  69. unsigned char *eip, *fence;
  70. unsigned char load, store;
  71. /* See if we need to regenerate the copy buffer */
  72. if ((src_w == last.src_w) && (dst_w == last.dst_w) && (bpp == last.bpp)) {
  73. return (last.status);
  74. }
  75. last.bpp = bpp;
  76. last.src_w = src_w;
  77. last.dst_w = dst_w;
  78. last.status = -1;
  79. switch (bpp) {
  80. case 1:
  81. load = LOAD_BYTE;
  82. store = STORE_BYTE;
  83. break;
  84. case 2:
  85. case 4:
  86. load = LOAD_WORD;
  87. store = STORE_WORD;
  88. break;
  89. default:
  90. return SDL_SetError("ASM stretch of %d bytes isn't supported", bpp);
  91. }
  92. #ifdef HAVE_MPROTECT
  93. /* Make the code writeable */
  94. if (mprotect(copy_row, sizeof(copy_row), PROT_READ | PROT_WRITE) < 0) {
  95. return SDL_SetError("Couldn't make copy buffer writeable");
  96. }
  97. #endif
  98. pos = 0x10000;
  99. inc = (src_w << 16) / dst_w;
  100. eip = copy_row;
  101. fence = copy_row + sizeof(copy_row)-2;
  102. for (i = 0; i < dst_w; ++i) {
  103. while (pos >= 0x10000L) {
  104. if (eip == fence) {
  105. return -1;
  106. }
  107. if (bpp == 2) {
  108. *eip++ = PREFIX16;
  109. }
  110. *eip++ = load;
  111. pos -= 0x10000L;
  112. }
  113. if (eip == fence) {
  114. return -1;
  115. }
  116. if (bpp == 2) {
  117. *eip++ = PREFIX16;
  118. }
  119. *eip++ = store;
  120. pos += inc;
  121. }
  122. *eip++ = RETURN;
  123. #ifdef HAVE_MPROTECT
  124. /* Make the code executable but not writeable */
  125. if (mprotect(copy_row, sizeof(copy_row), PROT_READ | PROT_EXEC) < 0) {
  126. return SDL_SetError("Couldn't make copy buffer executable");
  127. }
  128. #endif
  129. last.status = 0;
  130. return (0);
  131. }
  132. #endif /* USE_ASM_STRETCH */
  133. #define DEFINE_COPY_ROW(name, type) \
  134. static void name(type *src, int src_w, type *dst, int dst_w) \
  135. { \
  136. int i; \
  137. int pos, inc; \
  138. type pixel = 0; \
  139. \
  140. pos = 0x10000; \
  141. inc = (src_w << 16) / dst_w; \
  142. for ( i=dst_w; i>0; --i ) { \
  143. while ( pos >= 0x10000L ) { \
  144. pixel = *src++; \
  145. pos -= 0x10000L; \
  146. } \
  147. *dst++ = pixel; \
  148. pos += inc; \
  149. } \
  150. }
  151. /* *INDENT-OFF* */
  152. DEFINE_COPY_ROW(copy_row1, Uint8)
  153. DEFINE_COPY_ROW(copy_row2, Uint16)
  154. DEFINE_COPY_ROW(copy_row4, Uint32)
  155. /* *INDENT-ON* */
  156. /* The ASM code doesn't handle 24-bpp stretch blits */
  157. static void
  158. copy_row3(Uint8 * src, int src_w, Uint8 * dst, int dst_w)
  159. {
  160. int i;
  161. int pos, inc;
  162. Uint8 pixel[3] = { 0, 0, 0 };
  163. pos = 0x10000;
  164. inc = (src_w << 16) / dst_w;
  165. for (i = dst_w; i > 0; --i) {
  166. while (pos >= 0x10000L) {
  167. pixel[0] = *src++;
  168. pixel[1] = *src++;
  169. pixel[2] = *src++;
  170. pos -= 0x10000L;
  171. }
  172. *dst++ = pixel[0];
  173. *dst++ = pixel[1];
  174. *dst++ = pixel[2];
  175. pos += inc;
  176. }
  177. }
  178. static int SDL_LowerSoftStretchNearest(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect);
  179. static int SDL_LowerSoftStretchLinear(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect);
  180. static int SDL_UpperSoftStretch(SDL_Surface * src, const SDL_Rect * srcrect, SDL_Surface * dst, const SDL_Rect * dstrect, SDL_ScaleMode scaleMode);
  181. /* Perform a stretch blit between two surfaces of the same format.
  182. NOTE: This function is not safe to call from multiple threads!
  183. */
  184. int
  185. SDL_SoftStretch(SDL_Surface *src, const SDL_Rect *srcrect,
  186. SDL_Surface *dst, const SDL_Rect *dstrect)
  187. {
  188. return SDL_UpperSoftStretch(src, srcrect, dst, dstrect, SDL_ScaleModeNearest);
  189. }
  190. int
  191. SDL_SoftStretchLinear(SDL_Surface *src, const SDL_Rect *srcrect,
  192. SDL_Surface *dst, const SDL_Rect *dstrect)
  193. {
  194. return SDL_UpperSoftStretch(src, srcrect, dst, dstrect, SDL_ScaleModeLinear);
  195. }
  196. static int
  197. SDL_UpperSoftStretch(SDL_Surface * src, const SDL_Rect * srcrect,
  198. SDL_Surface * dst, const SDL_Rect * dstrect, SDL_ScaleMode scaleMode)
  199. {
  200. int ret;
  201. int src_locked;
  202. int dst_locked;
  203. SDL_Rect full_src;
  204. SDL_Rect full_dst;
  205. if (src->format->format != dst->format->format) {
  206. return SDL_SetError("Only works with same format surfaces");
  207. }
  208. if (scaleMode != SDL_ScaleModeNearest) {
  209. if (src->format->BytesPerPixel != 4 || src->format->format == SDL_PIXELFORMAT_ARGB2101010) {
  210. return SDL_SetError("Wrong format");
  211. }
  212. }
  213. /* Verify the blit rectangles */
  214. if (srcrect) {
  215. if ((srcrect->x < 0) || (srcrect->y < 0) ||
  216. ((srcrect->x + srcrect->w) > src->w) ||
  217. ((srcrect->y + srcrect->h) > src->h)) {
  218. return SDL_SetError("Invalid source blit rectangle");
  219. }
  220. } else {
  221. full_src.x = 0;
  222. full_src.y = 0;
  223. full_src.w = src->w;
  224. full_src.h = src->h;
  225. srcrect = &full_src;
  226. }
  227. if (dstrect) {
  228. if ((dstrect->x < 0) || (dstrect->y < 0) ||
  229. ((dstrect->x + dstrect->w) > dst->w) ||
  230. ((dstrect->y + dstrect->h) > dst->h)) {
  231. return SDL_SetError("Invalid destination blit rectangle");
  232. }
  233. } else {
  234. full_dst.x = 0;
  235. full_dst.y = 0;
  236. full_dst.w = dst->w;
  237. full_dst.h = dst->h;
  238. dstrect = &full_dst;
  239. }
  240. if (dstrect->w <= 0 || dstrect->h <= 0) {
  241. return 0;
  242. }
  243. /* Lock the destination if it's in hardware */
  244. dst_locked = 0;
  245. if (SDL_MUSTLOCK(dst)) {
  246. if (SDL_LockSurface(dst) < 0) {
  247. return SDL_SetError("Unable to lock destination surface");
  248. }
  249. dst_locked = 1;
  250. }
  251. /* Lock the source if it's in hardware */
  252. src_locked = 0;
  253. if (SDL_MUSTLOCK(src)) {
  254. if (SDL_LockSurface(src) < 0) {
  255. if (dst_locked) {
  256. SDL_UnlockSurface(dst);
  257. }
  258. return SDL_SetError("Unable to lock source surface");
  259. }
  260. src_locked = 1;
  261. }
  262. if (scaleMode == SDL_ScaleModeNearest) {
  263. ret = SDL_LowerSoftStretchNearest(src, srcrect, dst, dstrect);
  264. } else {
  265. ret = SDL_LowerSoftStretchLinear(src, srcrect, dst, dstrect);
  266. }
  267. /* We need to unlock the surfaces if they're locked */
  268. if (dst_locked) {
  269. SDL_UnlockSurface(dst);
  270. }
  271. if (src_locked) {
  272. SDL_UnlockSurface(src);
  273. }
  274. return ret;
  275. }
  276. int
  277. SDL_LowerSoftStretchNearest(SDL_Surface *src, const SDL_Rect *srcrect,
  278. SDL_Surface *dst, const SDL_Rect *dstrect)
  279. {
  280. int pos, inc;
  281. int dst_maxrow;
  282. int src_row, dst_row;
  283. Uint8 *srcp = NULL;
  284. Uint8 *dstp;
  285. #ifdef USE_ASM_STRETCH
  286. SDL_bool use_asm = SDL_TRUE;
  287. #ifdef __GNUC__
  288. int u1, u2;
  289. #endif
  290. #endif /* USE_ASM_STRETCH */
  291. const int bpp = dst->format->BytesPerPixel;
  292. /* Set up the data... */
  293. pos = 0x10000;
  294. inc = (srcrect->h << 16) / dstrect->h;
  295. src_row = srcrect->y;
  296. dst_row = dstrect->y;
  297. #ifdef USE_ASM_STRETCH
  298. /* Write the opcodes for this stretch */
  299. if ((bpp == 3) || (generate_rowbytes(srcrect->w, dstrect->w, bpp) < 0)) {
  300. use_asm = SDL_FALSE;
  301. }
  302. #endif
  303. /* Perform the stretch blit */
  304. for (dst_maxrow = dst_row + dstrect->h; dst_row < dst_maxrow; ++dst_row) {
  305. dstp = (Uint8 *) dst->pixels + (dst_row * dst->pitch)
  306. + (dstrect->x * bpp);
  307. while (pos >= 0x10000L) {
  308. srcp = (Uint8 *) src->pixels + (src_row * src->pitch)
  309. + (srcrect->x * bpp);
  310. ++src_row;
  311. pos -= 0x10000L;
  312. }
  313. #ifdef USE_ASM_STRETCH
  314. if (use_asm) {
  315. #ifdef __GNUC__
  316. __asm__ __volatile__("call *%4":"=&D"(u1), "=&S"(u2)
  317. :"0"(dstp), "1"(srcp), "r"(copy_row)
  318. :"memory");
  319. #elif defined(_MSC_VER) || defined(__WATCOMC__)
  320. /* *INDENT-OFF* */
  321. {
  322. void *code = copy_row;
  323. __asm {
  324. push edi
  325. push esi
  326. mov edi, dstp
  327. mov esi, srcp
  328. call dword ptr code
  329. pop esi
  330. pop edi
  331. }
  332. }
  333. /* *INDENT-ON* */
  334. #else
  335. #error Need inline assembly for this compiler
  336. #endif
  337. } else
  338. #endif
  339. switch (bpp) {
  340. case 1:
  341. copy_row1(srcp, srcrect->w, dstp, dstrect->w);
  342. break;
  343. case 2:
  344. copy_row2((Uint16 *) srcp, srcrect->w,
  345. (Uint16 *) dstp, dstrect->w);
  346. break;
  347. case 3:
  348. copy_row3(srcp, srcrect->w, dstp, dstrect->w);
  349. break;
  350. case 4:
  351. copy_row4((Uint32 *) srcp, srcrect->w,
  352. (Uint32 *) dstp, dstrect->w);
  353. break;
  354. }
  355. pos += inc;
  356. }
  357. return 0;
  358. }
  359. /* bilinear interpolation precision must be < 8
  360. Because with SSE: add-multiply: _mm_madd_epi16 works with signed int
  361. so pixels 0xb1...... are negatives and false the result
  362. same in NEON probably */
  363. #define PRECISION 7
  364. #define FIXED_POINT(i) ((uint32_t)(i) << 16)
  365. #define SRC_INDEX(fp) ((uint32_t)(fp) >> 16)
  366. #define INTEGER(fp) ((uint32_t)(fp) >> PRECISION)
  367. #define FRAC(fp) ((uint32_t)(fp >> (16 - PRECISION)) & ((1<<PRECISION) - 1))
  368. #define FRAC_ZERO 0
  369. #define FRAC_ONE (1 << PRECISION)
  370. #define FP_ONE FIXED_POINT(1)
  371. #define BILINEAR___START \
  372. int i; \
  373. int fp_sum_h, fp_step_h, left_pad_h, right_pad_h; \
  374. int fp_sum_w, fp_step_w, left_pad_w, right_pad_w; \
  375. int fp_sum_w_init, left_pad_w_init, right_pad_w_init, dst_gap, middle_init; \
  376. get_scaler_datas(src_h, dst_h, &fp_sum_h, &fp_step_h, &left_pad_h, &right_pad_h); \
  377. get_scaler_datas(src_w, dst_w, &fp_sum_w, &fp_step_w, &left_pad_w, &right_pad_w); \
  378. fp_sum_w_init = fp_sum_w + left_pad_w * fp_step_w; \
  379. left_pad_w_init = left_pad_w; \
  380. right_pad_w_init = right_pad_w; \
  381. dst_gap = dst_pitch - 4 * dst_w; \
  382. middle_init = dst_w - left_pad_w - right_pad_w; \
  383. #define BILINEAR___HEIGHT \
  384. int index_h, frac_h0, frac_h1, middle; \
  385. const Uint32 *src_h0, *src_h1; \
  386. int no_padding, incr_h0, incr_h1; \
  387. \
  388. no_padding = !(i < left_pad_h || i > dst_h - 1 - right_pad_h); \
  389. index_h = SRC_INDEX(fp_sum_h); \
  390. frac_h0 = FRAC(fp_sum_h); \
  391. \
  392. index_h = no_padding ? index_h : (i < left_pad_h ? 0 : src_h - 1); \
  393. frac_h0 = no_padding ? frac_h0 : 0; \
  394. incr_h1 = no_padding ? src_pitch : 0; \
  395. incr_h0 = index_h * src_pitch; \
  396. \
  397. src_h0 = (const Uint32 *)((const Uint8 *)src + incr_h0); \
  398. src_h1 = (const Uint32 *)((const Uint8 *)src_h0 + incr_h1); \
  399. \
  400. fp_sum_h += fp_step_h; \
  401. \
  402. frac_h1 = FRAC_ONE - frac_h0; \
  403. fp_sum_w = fp_sum_w_init; \
  404. right_pad_w = right_pad_w_init; \
  405. left_pad_w = left_pad_w_init; \
  406. middle = middle_init; \
  407. #if defined(__clang__)
  408. // Remove inlining of this function
  409. // Compiler crash with clang 9.0.8 / android-ndk-r21d
  410. // Compiler crash with clang 11.0.3 / Xcode
  411. // OK with clang 11.0.5 / android-ndk-22
  412. // OK with clang 12.0.0 / Xcode
  413. __attribute__((noinline))
  414. #endif
  415. static void
  416. get_scaler_datas(int src_nb, int dst_nb, int *fp_start, int *fp_step, int *left_pad, int *right_pad)
  417. {
  418. int step = FIXED_POINT(src_nb) / (dst_nb); /* source step in fixed point */
  419. int x0 = FP_ONE / 2; /* dst first pixel center at 0.5 in fixed point */
  420. int fp_sum;
  421. int i;
  422. #if 0
  423. /* scale to source coordinates */
  424. x0 *= src_nb;
  425. x0 /= dst_nb; /* x0 == step / 2 */
  426. #else
  427. /* Use this code for perfect match with pixman */
  428. Sint64 tmp[2];
  429. tmp[0] = (Sint64)step * (x0 >> 16);
  430. tmp[1] = (Sint64)step * (x0 & 0xFFFF);
  431. x0 = (int) (tmp[0] + ((tmp[1] + 0x8000) >> 16)); /* x0 == (step + 1) / 2 */
  432. #endif
  433. /* -= 0.5, get back the pixel origin, in source coordinates */
  434. x0 -= FP_ONE / 2;
  435. *fp_start = x0;
  436. *fp_step = step;
  437. *left_pad = 0;
  438. *right_pad = 0;
  439. fp_sum = x0;
  440. for (i = 0; i < dst_nb; i++) {
  441. if (fp_sum < 0) {
  442. *left_pad += 1;
  443. } else {
  444. int index = SRC_INDEX(fp_sum);
  445. if (index > src_nb - 2) {
  446. *right_pad += 1;
  447. }
  448. }
  449. fp_sum += step;
  450. }
  451. // SDL_Log("%d -> %d x0=%d step=%d left_pad=%d right_pad=%d", src_nb, dst_nb, *fp_start, *fp_step, *left_pad, *right_pad);
  452. }
  453. typedef struct color_t {
  454. Uint8 a;
  455. Uint8 b;
  456. Uint8 c;
  457. Uint8 d;
  458. } color_t;
  459. #if 0
  460. static void
  461. printf_64(const char *str, void *var)
  462. {
  463. uint8_t *val = (uint8_t*) var;
  464. printf(" * %s: %02x %02x %02x %02x _ %02x %02x %02x %02x\n",
  465. str, val[0], val[1], val[2], val[3], val[4], val[5], val[6], val[7]);
  466. }
  467. #endif
  468. /* Interpolated == x0 + frac * (x1 - x0) == x0 * (1 - frac) + x1 * frac */
  469. static SDL_INLINE void
  470. INTERPOL(const Uint32 *src_x0, const Uint32 *src_x1, int frac0, int frac1, Uint32 *dst)
  471. {
  472. const color_t *c0 = (const color_t *)src_x0;
  473. const color_t *c1 = (const color_t *)src_x1;
  474. color_t *cx = (color_t *)dst;
  475. #if 0
  476. cx->a = c0->a + INTEGER(frac0 * (c1->a - c0->a));
  477. cx->b = c0->b + INTEGER(frac0 * (c1->b - c0->b));
  478. cx->c = c0->c + INTEGER(frac0 * (c1->c - c0->c));
  479. cx->d = c0->d + INTEGER(frac0 * (c1->d - c0->d));
  480. #else
  481. cx->a = INTEGER(frac1 * c0->a + frac0 * c1->a);
  482. cx->b = INTEGER(frac1 * c0->b + frac0 * c1->b);
  483. cx->c = INTEGER(frac1 * c0->c + frac0 * c1->c);
  484. cx->d = INTEGER(frac1 * c0->d + frac0 * c1->d);
  485. #endif
  486. }
  487. static SDL_INLINE void
  488. INTERPOL_BILINEAR(const Uint32 *s0, const Uint32 *s1, int frac_w0, int frac_h0, int frac_h1, Uint32 *dst)
  489. {
  490. Uint32 tmp[2];
  491. unsigned int frac_w1 = FRAC_ONE - frac_w0;
  492. /* Vertical first, store to 'tmp' */
  493. INTERPOL(s0, s1, frac_h0, frac_h1, tmp);
  494. INTERPOL(s0 + 1, s1 + 1, frac_h0, frac_h1, tmp + 1);
  495. /* Horizontal, store to 'dst' */
  496. INTERPOL(tmp, tmp + 1, frac_w0, frac_w1, dst);
  497. }
  498. static int
  499. scale_mat(const Uint32 *src, int src_w, int src_h, int src_pitch,
  500. Uint32 *dst, int dst_w, int dst_h, int dst_pitch)
  501. {
  502. BILINEAR___START
  503. for (i = 0; i < dst_h; i++) {
  504. BILINEAR___HEIGHT
  505. while (left_pad_w--) {
  506. INTERPOL_BILINEAR(src_h0, src_h1, FRAC_ZERO, frac_h0, frac_h1, dst);
  507. dst += 1;
  508. }
  509. while (middle--) {
  510. const Uint32 *s_00_01;
  511. const Uint32 *s_10_11;
  512. int index_w = 4 * SRC_INDEX(fp_sum_w);
  513. int frac_w = FRAC(fp_sum_w);
  514. fp_sum_w += fp_step_w;
  515. /*
  516. x00 ... x0_ ..... x01
  517. . . .
  518. . x .
  519. . . .
  520. . . .
  521. x10 ... x1_ ..... x11
  522. */
  523. s_00_01 = (const Uint32 *)((const Uint8 *)src_h0 + index_w);
  524. s_10_11 = (const Uint32 *)((const Uint8 *)src_h1 + index_w);
  525. INTERPOL_BILINEAR(s_00_01, s_10_11, frac_w, frac_h0, frac_h1, dst);
  526. dst += 1;
  527. }
  528. while (right_pad_w--) {
  529. int index_w = 4 * (src_w - 2);
  530. const Uint32 *s_00_01 = (const Uint32 *)((const Uint8 *)src_h0 + index_w);
  531. const Uint32 *s_10_11 = (const Uint32 *)((const Uint8 *)src_h1 + index_w);
  532. INTERPOL_BILINEAR(s_00_01, s_10_11, FRAC_ONE, frac_h0, frac_h1, dst);
  533. dst += 1;
  534. }
  535. dst = (Uint32 *)((Uint8 *)dst + dst_gap);
  536. }
  537. return 0;
  538. }
  539. #if defined(__SSE2__)
  540. # define HAVE_SSE2_INTRINSICS 1
  541. #endif
  542. #if defined(__ARM_NEON)
  543. # define HAVE_NEON_INTRINSICS 1
  544. # define CAST_uint8x8_t (uint8x8_t)
  545. # define CAST_uint32x2_t (uint32x2_t)
  546. #endif
  547. #if defined(__WINRT__) || defined(_MSC_VER)
  548. # if defined(HAVE_NEON_INTRINSICS)
  549. # undef CAST_uint8x8_t
  550. # undef CAST_uint32x2_t
  551. # define CAST_uint8x8_t
  552. # define CAST_uint32x2_t
  553. # endif
  554. #endif
  555. #if defined(HAVE_SSE2_INTRINSICS)
  556. #if 0
  557. static void
  558. printf_128(const char *str, __m128i var)
  559. {
  560. uint16_t *val = (uint16_t*) &var;
  561. printf(" * %s: %04x %04x %04x %04x _ %04x %04x %04x %04x\n",
  562. str, val[0], val[1], val[2], val[3], val[4], val[5], val[6], val[7]);
  563. }
  564. #endif
  565. static SDL_INLINE int
  566. hasSSE2()
  567. {
  568. static int val = -1;
  569. if (val != -1) {
  570. return val;
  571. }
  572. val = SDL_HasSSE2();
  573. return val;
  574. }
  575. static SDL_INLINE void
  576. INTERPOL_BILINEAR_SSE(const Uint32 *s0, const Uint32 *s1, int frac_w, __m128i v_frac_h0, __m128i v_frac_h1, Uint32 *dst, __m128i zero)
  577. {
  578. __m128i x_00_01, x_10_11; /* Pixels in 4*uint8 in row */
  579. __m128i v_frac_w0, k0, l0, d0, e0;
  580. int f, f2;
  581. f = frac_w;
  582. f2 = FRAC_ONE - frac_w;
  583. v_frac_w0 = _mm_set_epi16(f, f2, f, f2, f, f2, f, f2);
  584. x_00_01 = _mm_loadl_epi64((const __m128i *)s0); /* Load x00 and x01 */
  585. x_10_11 = _mm_loadl_epi64((const __m128i *)s1);
  586. /* Interpolated == x0 + frac * (x1 - x0) == x0 * (1 - frac) + x1 * frac */
  587. /* Interpolation vertical */
  588. k0 = _mm_mullo_epi16(_mm_unpacklo_epi8(x_00_01, zero), v_frac_h1);
  589. l0 = _mm_mullo_epi16(_mm_unpacklo_epi8(x_10_11, zero), v_frac_h0);
  590. k0 = _mm_add_epi16(k0, l0);
  591. /* For perfect match, clear the factionnal part eventually. */
  592. /*
  593. k0 = _mm_srli_epi16(k0, PRECISION);
  594. k0 = _mm_slli_epi16(k0, PRECISION);
  595. */
  596. /* Interpolation horizontal */
  597. l0 = _mm_unpacklo_epi64(/* unused */ l0, k0);
  598. k0 = _mm_madd_epi16(_mm_unpackhi_epi16(l0, k0), v_frac_w0);
  599. /* Store 1 pixel */
  600. d0 = _mm_srli_epi32(k0, PRECISION * 2);
  601. e0 = _mm_packs_epi32(d0, d0);
  602. e0 = _mm_packus_epi16(e0, e0);
  603. *dst = _mm_cvtsi128_si32(e0);
  604. }
  605. static int
  606. scale_mat_SSE(const Uint32 *src, int src_w, int src_h, int src_pitch, Uint32 *dst, int dst_w, int dst_h, int dst_pitch)
  607. {
  608. BILINEAR___START
  609. for (i = 0; i < dst_h; i++) {
  610. int nb_block2;
  611. __m128i v_frac_h0;
  612. __m128i v_frac_h1;
  613. __m128i zero;
  614. BILINEAR___HEIGHT
  615. nb_block2 = middle / 2;
  616. v_frac_h0 = _mm_set_epi16(frac_h0, frac_h0, frac_h0, frac_h0, frac_h0, frac_h0, frac_h0, frac_h0);
  617. v_frac_h1 = _mm_set_epi16(frac_h1, frac_h1, frac_h1, frac_h1, frac_h1, frac_h1, frac_h1, frac_h1);
  618. zero = _mm_setzero_si128();
  619. while (left_pad_w--) {
  620. INTERPOL_BILINEAR_SSE(src_h0, src_h1, FRAC_ZERO, v_frac_h0, v_frac_h1, dst, zero);
  621. dst += 1;
  622. }
  623. while (nb_block2--) {
  624. int index_w_0, frac_w_0;
  625. int index_w_1, frac_w_1;
  626. const Uint32 *s_00_01, *s_02_03, *s_10_11, *s_12_13;
  627. __m128i x_00_01, x_10_11, x_02_03, x_12_13;/* Pixels in 4*uint8 in row */
  628. __m128i v_frac_w0, k0, l0, d0, e0;
  629. __m128i v_frac_w1, k1, l1, d1, e1;
  630. int f, f2;
  631. index_w_0 = 4 * SRC_INDEX(fp_sum_w);
  632. frac_w_0 = FRAC(fp_sum_w);
  633. fp_sum_w += fp_step_w;
  634. index_w_1 = 4 * SRC_INDEX(fp_sum_w);
  635. frac_w_1 = FRAC(fp_sum_w);
  636. fp_sum_w += fp_step_w;
  637. /*
  638. x00............ x01 x02...........x03
  639. . . . . . .
  640. j0 f0 j1 j2 f1 j3
  641. . . . . . .
  642. . . . . . .
  643. . . . . . .
  644. x10............ x11 x12...........x13
  645. */
  646. s_00_01 = (const Uint32 *)((const Uint8 *)src_h0 + index_w_0);
  647. s_02_03 = (const Uint32 *)((const Uint8 *)src_h0 + index_w_1);
  648. s_10_11 = (const Uint32 *)((const Uint8 *)src_h1 + index_w_0);
  649. s_12_13 = (const Uint32 *)((const Uint8 *)src_h1 + index_w_1);
  650. f = frac_w_0;
  651. f2 = FRAC_ONE - frac_w_0;
  652. v_frac_w0 = _mm_set_epi16(f, f2, f, f2, f, f2, f, f2);
  653. f = frac_w_1;
  654. f2 = FRAC_ONE - frac_w_1;
  655. v_frac_w1 = _mm_set_epi16(f, f2, f, f2, f, f2, f, f2);
  656. x_00_01 = _mm_loadl_epi64((const __m128i *)s_00_01); /* Load x00 and x01 */
  657. x_02_03 = _mm_loadl_epi64((const __m128i *)s_02_03);
  658. x_10_11 = _mm_loadl_epi64((const __m128i *)s_10_11);
  659. x_12_13 = _mm_loadl_epi64((const __m128i *)s_12_13);
  660. /* Interpolation vertical */
  661. k0 = _mm_mullo_epi16(_mm_unpacklo_epi8(x_00_01, zero), v_frac_h1);
  662. l0 = _mm_mullo_epi16(_mm_unpacklo_epi8(x_10_11, zero), v_frac_h0);
  663. k0 = _mm_add_epi16(k0, l0);
  664. k1 = _mm_mullo_epi16(_mm_unpacklo_epi8(x_02_03, zero), v_frac_h1);
  665. l1 = _mm_mullo_epi16(_mm_unpacklo_epi8(x_12_13, zero), v_frac_h0);
  666. k1 = _mm_add_epi16(k1, l1);
  667. /* Interpolation horizontal */
  668. l0 = _mm_unpacklo_epi64(/* unused */ l0, k0);
  669. k0 = _mm_madd_epi16(_mm_unpackhi_epi16(l0, k0), v_frac_w0);
  670. l1 = _mm_unpacklo_epi64(/* unused */ l1, k1);
  671. k1 = _mm_madd_epi16(_mm_unpackhi_epi16(l1, k1), v_frac_w1);
  672. /* Store 1 pixel */
  673. d0 = _mm_srli_epi32(k0, PRECISION * 2);
  674. e0 = _mm_packs_epi32(d0, d0);
  675. e0 = _mm_packus_epi16(e0, e0);
  676. *dst++ = _mm_cvtsi128_si32(e0);
  677. /* Store 1 pixel */
  678. d1 = _mm_srli_epi32(k1, PRECISION * 2);
  679. e1 = _mm_packs_epi32(d1, d1);
  680. e1 = _mm_packus_epi16(e1, e1);
  681. *dst++ = _mm_cvtsi128_si32(e1);
  682. }
  683. /* Last point */
  684. if (middle & 0x1) {
  685. const Uint32 *s_00_01;
  686. const Uint32 *s_10_11;
  687. int index_w = 4 * SRC_INDEX(fp_sum_w);
  688. int frac_w = FRAC(fp_sum_w);
  689. fp_sum_w += fp_step_w;
  690. s_00_01 = (const Uint32 *)((const Uint8 *)src_h0 + index_w);
  691. s_10_11 = (const Uint32 *)((const Uint8 *)src_h1 + index_w);
  692. INTERPOL_BILINEAR_SSE(s_00_01, s_10_11, frac_w, v_frac_h0, v_frac_h1, dst, zero);
  693. dst += 1;
  694. }
  695. while (right_pad_w--) {
  696. int index_w = 4 * (src_w - 2);
  697. const Uint32 *s_00_01 = (const Uint32 *)((const Uint8 *)src_h0 + index_w);
  698. const Uint32 *s_10_11 = (const Uint32 *)((const Uint8 *)src_h1 + index_w);
  699. INTERPOL_BILINEAR_SSE(s_00_01, s_10_11, FRAC_ONE, v_frac_h0, v_frac_h1, dst, zero);
  700. dst += 1;
  701. }
  702. dst = (Uint32 *)((Uint8 *)dst + dst_gap);
  703. }
  704. return 0;
  705. }
  706. #endif
  707. #if defined(HAVE_NEON_INTRINSICS)
  708. static SDL_INLINE int
  709. hasNEON()
  710. {
  711. static int val = -1;
  712. if (val != -1) {
  713. return val;
  714. }
  715. val = SDL_HasNEON();
  716. return val;
  717. }
  718. static SDL_INLINE void
  719. INTERPOL_BILINEAR_NEON(const Uint32 *s0, const Uint32 *s1, int frac_w, uint8x8_t v_frac_h0, uint8x8_t v_frac_h1, Uint32 *dst)
  720. {
  721. uint8x8_t x_00_01, x_10_11; /* Pixels in 4*uint8 in row */
  722. uint16x8_t k0;
  723. uint32x4_t l0;
  724. uint16x8_t d0;
  725. uint8x8_t e0;
  726. x_00_01 = CAST_uint8x8_t vld1_u32(s0); /* Load 2 pixels */
  727. x_10_11 = CAST_uint8x8_t vld1_u32(s1);
  728. /* Interpolated == x0 + frac * (x1 - x0) == x0 * (1 - frac) + x1 * frac */
  729. k0 = vmull_u8(x_00_01, v_frac_h1); /* k0 := x0 * (1 - frac) */
  730. k0 = vmlal_u8(k0, x_10_11, v_frac_h0); /* k0 += x1 * frac */
  731. /* k0 now contains 2 interpolated pixels { j0, j1 } */
  732. l0 = vshll_n_u16(vget_low_u16(k0), PRECISION);
  733. l0 = vmlsl_n_u16(l0, vget_low_u16(k0), frac_w);
  734. l0 = vmlal_n_u16(l0, vget_high_u16(k0), frac_w);
  735. /* Shift and narrow */
  736. d0 = vcombine_u16(
  737. /* uint16x4_t */ vshrn_n_u32(l0, 2 * PRECISION),
  738. /* uint16x4_t */ vshrn_n_u32(l0, 2 * PRECISION)
  739. );
  740. /* Narrow again */
  741. e0 = vmovn_u16(d0);
  742. /* Store 1 pixel */
  743. *dst = vget_lane_u32(CAST_uint32x2_t e0, 0);
  744. }
  745. static int
  746. scale_mat_NEON(const Uint32 *src, int src_w, int src_h, int src_pitch, Uint32 *dst, int dst_w, int dst_h, int dst_pitch)
  747. {
  748. BILINEAR___START
  749. for (i = 0; i < dst_h; i++) {
  750. int nb_block4;
  751. uint8x8_t v_frac_h0, v_frac_h1;
  752. BILINEAR___HEIGHT
  753. nb_block4 = middle / 4;
  754. v_frac_h0 = vmov_n_u8(frac_h0);
  755. v_frac_h1 = vmov_n_u8(frac_h1);
  756. while (left_pad_w--) {
  757. INTERPOL_BILINEAR_NEON(src_h0, src_h1, FRAC_ZERO, v_frac_h0, v_frac_h1, dst);
  758. dst += 1;
  759. }
  760. while (nb_block4--) {
  761. int index_w_0, frac_w_0;
  762. int index_w_1, frac_w_1;
  763. int index_w_2, frac_w_2;
  764. int index_w_3, frac_w_3;
  765. const Uint32 *s_00_01, *s_02_03, *s_04_05, *s_06_07;
  766. const Uint32 *s_10_11, *s_12_13, *s_14_15, *s_16_17;
  767. uint8x8_t x_00_01, x_10_11, x_02_03, x_12_13;/* Pixels in 4*uint8 in row */
  768. uint8x8_t x_04_05, x_14_15, x_06_07, x_16_17;
  769. uint16x8_t k0, k1, k2, k3;
  770. uint32x4_t l0, l1, l2, l3;
  771. uint16x8_t d0, d1;
  772. uint8x8_t e0, e1;
  773. uint32x4_t f0;
  774. index_w_0 = 4 * SRC_INDEX(fp_sum_w);
  775. frac_w_0 = FRAC(fp_sum_w);
  776. fp_sum_w += fp_step_w;
  777. index_w_1 = 4 * SRC_INDEX(fp_sum_w);
  778. frac_w_1 = FRAC(fp_sum_w);
  779. fp_sum_w += fp_step_w;
  780. index_w_2 = 4 * SRC_INDEX(fp_sum_w);
  781. frac_w_2 = FRAC(fp_sum_w);
  782. fp_sum_w += fp_step_w;
  783. index_w_3 = 4 * SRC_INDEX(fp_sum_w);
  784. frac_w_3 = FRAC(fp_sum_w);
  785. fp_sum_w += fp_step_w;
  786. s_00_01 = (const Uint32 *)((const Uint8 *)src_h0 + index_w_0);
  787. s_02_03 = (const Uint32 *)((const Uint8 *)src_h0 + index_w_1);
  788. s_04_05 = (const Uint32 *)((const Uint8 *)src_h0 + index_w_2);
  789. s_06_07 = (const Uint32 *)((const Uint8 *)src_h0 + index_w_3);
  790. s_10_11 = (const Uint32 *)((const Uint8 *)src_h1 + index_w_0);
  791. s_12_13 = (const Uint32 *)((const Uint8 *)src_h1 + index_w_1);
  792. s_14_15 = (const Uint32 *)((const Uint8 *)src_h1 + index_w_2);
  793. s_16_17 = (const Uint32 *)((const Uint8 *)src_h1 + index_w_3);
  794. /* Interpolation vertical */
  795. x_00_01 = CAST_uint8x8_t vld1_u32(s_00_01); /* Load 2 pixels */
  796. x_02_03 = CAST_uint8x8_t vld1_u32(s_02_03);
  797. x_04_05 = CAST_uint8x8_t vld1_u32(s_04_05);
  798. x_06_07 = CAST_uint8x8_t vld1_u32(s_06_07);
  799. x_10_11 = CAST_uint8x8_t vld1_u32(s_10_11);
  800. x_12_13 = CAST_uint8x8_t vld1_u32(s_12_13);
  801. x_14_15 = CAST_uint8x8_t vld1_u32(s_14_15);
  802. x_16_17 = CAST_uint8x8_t vld1_u32(s_16_17);
  803. /* Interpolated == x0 + frac * (x1 - x0) == x0 * (1 - frac) + x1 * frac */
  804. k0 = vmull_u8(x_00_01, v_frac_h1); /* k0 := x0 * (1 - frac) */
  805. k0 = vmlal_u8(k0, x_10_11, v_frac_h0); /* k0 += x1 * frac */
  806. k1 = vmull_u8(x_02_03, v_frac_h1);
  807. k1 = vmlal_u8(k1, x_12_13, v_frac_h0);
  808. k2 = vmull_u8(x_04_05, v_frac_h1);
  809. k2 = vmlal_u8(k2, x_14_15, v_frac_h0);
  810. k3 = vmull_u8(x_06_07, v_frac_h1);
  811. k3 = vmlal_u8(k3, x_16_17, v_frac_h0);
  812. /* k0 now contains 2 interpolated pixels { j0, j1 } */
  813. /* k1 now contains 2 interpolated pixels { j2, j3 } */
  814. /* k2 now contains 2 interpolated pixels { j4, j5 } */
  815. /* k3 now contains 2 interpolated pixels { j6, j7 } */
  816. l0 = vshll_n_u16(vget_low_u16(k0), PRECISION);
  817. l0 = vmlsl_n_u16(l0, vget_low_u16(k0), frac_w_0);
  818. l0 = vmlal_n_u16(l0, vget_high_u16(k0), frac_w_0);
  819. l1 = vshll_n_u16(vget_low_u16(k1), PRECISION);
  820. l1 = vmlsl_n_u16(l1, vget_low_u16(k1), frac_w_1);
  821. l1 = vmlal_n_u16(l1, vget_high_u16(k1), frac_w_1);
  822. l2 = vshll_n_u16(vget_low_u16(k2), PRECISION);
  823. l2 = vmlsl_n_u16(l2, vget_low_u16(k2), frac_w_2);
  824. l2 = vmlal_n_u16(l2, vget_high_u16(k2), frac_w_2);
  825. l3 = vshll_n_u16(vget_low_u16(k3), PRECISION);
  826. l3 = vmlsl_n_u16(l3, vget_low_u16(k3), frac_w_3);
  827. l3 = vmlal_n_u16(l3, vget_high_u16(k3), frac_w_3);
  828. /* shift and narrow */
  829. d0 = vcombine_u16(
  830. /* uint16x4_t */ vshrn_n_u32(l0, 2 * PRECISION),
  831. /* uint16x4_t */ vshrn_n_u32(l1, 2 * PRECISION)
  832. );
  833. /* narrow again */
  834. e0 = vmovn_u16(d0);
  835. /* Shift and narrow */
  836. d1 = vcombine_u16(
  837. /* uint16x4_t */ vshrn_n_u32(l2, 2 * PRECISION),
  838. /* uint16x4_t */ vshrn_n_u32(l3, 2 * PRECISION)
  839. );
  840. /* Narrow again */
  841. e1 = vmovn_u16(d1);
  842. f0 = vcombine_u32(CAST_uint32x2_t e0, CAST_uint32x2_t e1);
  843. /* Store 4 pixels */
  844. vst1q_u32(dst, f0);
  845. dst += 4;
  846. }
  847. if (middle & 0x2) {
  848. int index_w_0, frac_w_0;
  849. int index_w_1, frac_w_1;
  850. const Uint32 *s_00_01, *s_02_03;
  851. const Uint32 *s_10_11, *s_12_13;
  852. uint8x8_t x_00_01, x_10_11, x_02_03, x_12_13;/* Pixels in 4*uint8 in row */
  853. uint16x8_t k0, k1;
  854. uint32x4_t l0, l1;
  855. uint16x8_t d0;
  856. uint8x8_t e0;
  857. index_w_0 = 4 * SRC_INDEX(fp_sum_w);
  858. frac_w_0 = FRAC(fp_sum_w);
  859. fp_sum_w += fp_step_w;
  860. index_w_1 = 4 * SRC_INDEX(fp_sum_w);
  861. frac_w_1 = FRAC(fp_sum_w);
  862. fp_sum_w += fp_step_w;
  863. /*
  864. x00............ x01 x02...........x03
  865. . . . . . .
  866. j0 dest0 j1 j2 dest1 j3
  867. . . . . . .
  868. . . . . . .
  869. . . . . . .
  870. x10............ x11 x12...........x13
  871. */
  872. s_00_01 = (const Uint32 *)((const Uint8 *)src_h0 + index_w_0);
  873. s_02_03 = (const Uint32 *)((const Uint8 *)src_h0 + index_w_1);
  874. s_10_11 = (const Uint32 *)((const Uint8 *)src_h1 + index_w_0);
  875. s_12_13 = (const Uint32 *)((const Uint8 *)src_h1 + index_w_1);
  876. /* Interpolation vertical */
  877. x_00_01 = CAST_uint8x8_t vld1_u32(s_00_01);/* Load 2 pixels */
  878. x_02_03 = CAST_uint8x8_t vld1_u32(s_02_03);
  879. x_10_11 = CAST_uint8x8_t vld1_u32(s_10_11);
  880. x_12_13 = CAST_uint8x8_t vld1_u32(s_12_13);
  881. /* Interpolated == x0 + frac * (x1 - x0) == x0 * (1 - frac) + x1 * frac */
  882. k0 = vmull_u8(x_00_01, v_frac_h1); /* k0 := x0 * (1 - frac) */
  883. k0 = vmlal_u8(k0, x_10_11, v_frac_h0); /* k0 += x1 * frac */
  884. k1 = vmull_u8(x_02_03, v_frac_h1);
  885. k1 = vmlal_u8(k1, x_12_13, v_frac_h0);
  886. /* k0 now contains 2 interpolated pixels { j0, j1 } */
  887. /* k1 now contains 2 interpolated pixels { j2, j3 } */
  888. l0 = vshll_n_u16(vget_low_u16(k0), PRECISION);
  889. l0 = vmlsl_n_u16(l0, vget_low_u16(k0), frac_w_0);
  890. l0 = vmlal_n_u16(l0, vget_high_u16(k0), frac_w_0);
  891. l1 = vshll_n_u16(vget_low_u16(k1), PRECISION);
  892. l1 = vmlsl_n_u16(l1, vget_low_u16(k1), frac_w_1);
  893. l1 = vmlal_n_u16(l1, vget_high_u16(k1), frac_w_1);
  894. /* Shift and narrow */
  895. d0 = vcombine_u16(
  896. /* uint16x4_t */ vshrn_n_u32(l0, 2 * PRECISION),
  897. /* uint16x4_t */ vshrn_n_u32(l1, 2 * PRECISION)
  898. );
  899. /* Narrow again */
  900. e0 = vmovn_u16(d0);
  901. /* Store 2 pixels */
  902. vst1_u32(dst, CAST_uint32x2_t e0);
  903. dst += 2;
  904. }
  905. /* Last point */
  906. if (middle & 0x1) {
  907. int index_w = 4 * SRC_INDEX(fp_sum_w);
  908. int frac_w = FRAC(fp_sum_w);
  909. const Uint32 *s_00_01 = (const Uint32 *)((const Uint8 *)src_h0 + index_w);
  910. const Uint32 *s_10_11 = (const Uint32 *)((const Uint8 *)src_h1 + index_w);
  911. INTERPOL_BILINEAR_NEON(s_00_01, s_10_11, frac_w, v_frac_h0, v_frac_h1, dst);
  912. dst += 1;
  913. }
  914. while (right_pad_w--) {
  915. int index_w = 4 * (src_w - 2);
  916. const Uint32 *s_00_01 = (const Uint32 *)((const Uint8 *)src_h0 + index_w);
  917. const Uint32 *s_10_11 = (const Uint32 *)((const Uint8 *)src_h1 + index_w);
  918. INTERPOL_BILINEAR_NEON(s_00_01, s_10_11, FRAC_ONE, v_frac_h0, v_frac_h1, dst);
  919. dst += 1;
  920. }
  921. dst = (Uint32 *)((Uint8 *)dst + dst_gap);
  922. }
  923. return 0;
  924. }
  925. #endif
  926. int
  927. SDL_LowerSoftStretchLinear(SDL_Surface *s, const SDL_Rect *srcrect,
  928. SDL_Surface *d, const SDL_Rect *dstrect)
  929. {
  930. int ret = -1;
  931. int src_w = srcrect->w;
  932. int src_h = srcrect->h;
  933. int dst_w = dstrect->w;
  934. int dst_h = dstrect->h;
  935. int src_pitch = s->pitch;
  936. int dst_pitch = d->pitch;
  937. Uint32 *src = (Uint32 *) ((Uint8 *)s->pixels + srcrect->x * 4 + srcrect->y * src_pitch);
  938. Uint32 *dst = (Uint32 *) ((Uint8 *)d->pixels + dstrect->x * 4 + dstrect->y * dst_pitch);
  939. #if defined(HAVE_NEON_INTRINSICS)
  940. if (ret == -1 && hasNEON()) {
  941. ret = scale_mat_NEON(src, src_w, src_h, src_pitch, dst, dst_w, dst_h, dst_pitch);
  942. }
  943. #endif
  944. #if defined(HAVE_SSE2_INTRINSICS)
  945. if (ret == -1 && hasSSE2()) {
  946. ret = scale_mat_SSE(src, src_w, src_h, src_pitch, dst, dst_w, dst_h, dst_pitch);
  947. }
  948. #endif
  949. if (ret == -1) {
  950. scale_mat(src, src_w, src_h, src_pitch, dst, dst_w, dst_h, dst_pitch);
  951. }
  952. return ret;
  953. }
  954. /* vi: set ts=4 sw=4 expandtab: */