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
21 #include <inttypes.h>
22 #include <math.h>
23 #include <stdio.h>
24 #include <string.h>
25
33 #include "config.h"
37
39 { 36, 68, 60, 92, 34, 66, 58, 90, },
40 { 100, 4, 124, 28, 98, 2, 122, 26, },
41 { 52, 84, 44, 76, 50, 82, 42, 74, },
42 { 116, 20, 108, 12, 114, 18, 106, 10, },
43 { 32, 64, 56, 88, 38, 70, 62, 94, },
44 { 96, 0, 120, 24, 102, 6, 126, 30, },
45 { 48, 80, 40, 72, 54, 86, 46, 78, },
46 { 112, 16, 104, 8, 118, 22, 110, 14, },
47 { 36, 68, 60, 92, 34, 66, 58, 90, },
48 };
49
51 64, 64, 64, 64, 64, 64, 64, 64
52 };
53
56 {
57 int i;
59 for (i = 0; i <
height; i++) {
60 memset(ptr, val, width);
62 }
63 }
64
67 const int32_t *filterPos,
int filterSize)
68 {
70 int i;
72 const uint16_t *
src = (
const uint16_t *) _src;
74 int sh = bits - 4;
75
77 sh= 9;
78
79 for (i = 0; i <
dstW; i++) {
80 int j;
81 int srcPos = filterPos[i];
83
84 for (j = 0; j < filterSize; j++) {
85 val += src[srcPos + j] * filter[filterSize * i + j];
86 }
87 // filter=14 bit, input=16 bit, output=30 bit, >> 11 makes 19 bit
88 dst[i] =
FFMIN(val >> sh, (1 << 19) - 1);
89 }
90 }
91
94 const int32_t *filterPos,
int filterSize)
95 {
97 int i;
98 const uint16_t *
src = (
const uint16_t *) _src;
100
101 if(sh<15)
103
104 for (i = 0; i <
dstW; i++) {
105 int j;
106 int srcPos = filterPos[i];
108
109 for (j = 0; j < filterSize; j++) {
110 val += src[srcPos + j] * filter[filterSize * i + j];
111 }
112 // filter=14 bit, input=16 bit, output=30 bit, >> 15 makes 15 bit
113 dst[i] =
FFMIN(val >> sh, (1 << 15) - 1);
114 }
115 }
116
117 // bilinear / bicubic scaling
120 const int32_t *filterPos,
int filterSize)
121 {
122 int i;
123 for (i = 0; i <
dstW; i++) {
124 int j;
125 int srcPos = filterPos[i];
127 for (j = 0; j < filterSize; j++) {
128 val += ((int)src[srcPos + j]) * filter[filterSize * i + j];
129 }
130 dst[i] =
FFMIN(val >> 7, (1 << 15) - 1);
// the cubic equation does overflow ...
131 }
132 }
133
136 const int32_t *filterPos,
int filterSize)
137 {
138 int i;
140 for (i = 0; i <
dstW; i++) {
141 int j;
142 int srcPos = filterPos[i];
144 for (j = 0; j < filterSize; j++) {
145 val += ((int)src[srcPos + j]) * filter[filterSize * i + j];
146 }
147 dst[i] =
FFMIN(val >> 3, (1 << 19) - 1);
// the cubic equation does overflow ...
148 }
149 }
150
151 // FIXME all pal and rgb srcFormats could do this conversion as well
152 // FIXME all scalers more complex than bilinear could do half of this transform
154 {
155 int i;
156 for (i = 0; i <
width; i++) {
157 dstU[i] = (
FFMIN(dstU[i], 30775) * 4663 - 9289992) >> 12;
// -264
158 dstV[i] = (
FFMIN(dstV[i], 30775) * 4663 - 9289992) >> 12;
// -264
159 }
160 }
161
163 {
164 int i;
165 for (i = 0; i <
width; i++) {
166 dstU[i] = (dstU[i] * 1799 + 4081085) >> 11; // 1469
167 dstV[i] = (dstV[i] * 1799 + 4081085) >> 11; // 1469
168 }
169 }
170
172 {
173 int i;
174 for (i = 0; i <
width; i++)
175 dst[i] = (
FFMIN(dst[i], 30189) * 19077 - 39057361) >> 14;
176 }
177
179 {
180 int i;
181 for (i = 0; i <
width; i++)
182 dst[i] = (dst[i] * 14071 + 33561947) >> 14;
183 }
184
186 {
187 int i;
190 for (i = 0; i <
width; i++) {
191 dstU[i] = (
FFMIN(dstU[i], 30775 << 4) * 4663 - (9289992 << 4)) >> 12;
// -264
192 dstV[i] = (
FFMIN(dstV[i], 30775 << 4) * 4663 - (9289992 << 4)) >> 12;
// -264
193 }
194 }
195
197 {
198 int i;
201 for (i = 0; i <
width; i++) {
202 dstU[i] = (dstU[i] * 1799 + (4081085 << 4)) >> 11; // 1469
203 dstV[i] = (dstV[i] * 1799 + (4081085 << 4)) >> 11; // 1469
204 }
205 }
206
208 {
209 int i;
211 for (i = 0; i <
width; i++)
212 dst[i] = (
FFMIN(dst[i], 30189 << 4) * 4769 - (39057361 << 2)) >> 12;
213 }
214
216 {
217 int i;
219 for (i = 0; i <
width; i++)
220 dst[i] = (dst[i]*(14071/4) + (33561947<<4)/4)>>12;
221 }
222
225 {
226 int i;
227 unsigned int xpos = 0;
228 for (i = 0; i < dstWidth; i++) {
229 register unsigned int xx = xpos >> 16;
230 register unsigned int xalpha = (xpos & 0xFFFF) >> 9;
231 dst[i] = (src[xx] << 7) + (src[xx + 1] - src[xx]) * xalpha;
232 xpos += xInc;
233 }
234 for (i=dstWidth-1; (i*xInc)>>16 >=srcW-1; i--)
235 dst[i] = src[srcW-1]*128;
236 }
237
238 // *** horizontal scale Y line to temp buffer
246 uint32_t *pal, int isAlpha)
247 {
248 void (*toYV12)(
uint8_t *,
const uint8_t *,
const uint8_t *,
const uint8_t *, int, uint32_t *) =
251 const uint8_t *
src = src_in[isAlpha ? 3 : 0];
252
254 toYV12(formatConvBuffer,
src, src_in[1], src_in[2], srcW, pal);
262 }
263
266 hLumFilterPos, hLumFilterSize);
267 } else { // fast bilinear upscale / crap downscale
269 }
270
271 if (convertRange)
272 convertRange(dst, dstWidth);
273 }
274
276 int dstWidth,
const uint8_t *src1,
278 {
279 int i;
280 unsigned int xpos = 0;
281 for (i = 0; i < dstWidth; i++) {
282 register unsigned int xx = xpos >> 16;
283 register unsigned int xalpha = (xpos & 0xFFFF) >> 9;
284 dst1[i] = (src1[xx] * (xalpha ^ 127) + src1[xx + 1] * xalpha);
285 dst2[i] = (src2[xx] * (xalpha ^ 127) + src2[xx + 1] * xalpha);
286 xpos += xInc;
287 }
288 for (i=dstWidth-1; (i*xInc)>>16 >=srcW-1; i--) {
289 dst1[i] = src1[srcW-1]*128;
290 dst2[i] = src2[srcW-1]*128;
291 }
292 }
293
295 int16_t *dst2, int dstWidth,
302 {
303 const uint8_t *src1 = src_in[1], *src2 = src_in[2];
305 uint8_t *buf2 = formatConvBuffer +
307 c->
chrToYV12(formatConvBuffer, buf2, src_in[0], src1, src2, srcW, pal);
309 src2= buf2;
311 uint8_t *buf2 = formatConvBuffer +
315 src2 = buf2;
316 }
317
319 c->
hcScale(c, dst1, dstWidth, src1, hChrFilter, hChrFilterPos, hChrFilterSize);
320 c->
hcScale(c, dst2, dstWidth, src2, hChrFilter, hChrFilterPos, hChrFilterSize);
321 } else { // fast bilinear upscale / crap downscale
322 c->
hcscale_fast(c, dst1, dst2, dstWidth, src1, src2, srcW, xInc);
323 }
324
327 }
328
329 #define DEBUG_SWSCALE_BUFFERS 0
330 #define DEBUG_BUFFERS(...) \
331 if (DEBUG_SWSCALE_BUFFERS) \
332 av_log(c, AV_LOG_DEBUG, __VA_ARGS__)
333
335 int srcStride[], int srcSliceY,
336 int srcSliceH,
uint8_t *dst[],
int dstStride[])
337 {
338 /* load a few things into local vars to make the code more readable?
339 * and faster */
380 int lastDstY;
381
382 /* vars which will change and which we need to store back in the context */
388
391 }
392
394 src[0] =
395 src[1] =
396 src[2] =
397 src[3] = src[0];
398 srcStride[0] =
399 srcStride[1] =
400 srcStride[2] =
401 srcStride[3] = srcStride[0];
402 }
405
406 DEBUG_BUFFERS(
"swscale() %p[%d] %p[%d] %p[%d] %p[%d] -> %p[%d] %p[%d] %p[%d] %p[%d]\n",
407 src[0], srcStride[0], src[1], srcStride[1],
408 src[2], srcStride[2], src[3], srcStride[3],
409 dst[0], dstStride[0], dst[1], dstStride[1],
410 dst[2], dstStride[2], dst[3], dstStride[3]);
411 DEBUG_BUFFERS(
"srcSliceY: %d srcSliceH: %d dstY: %d dstH: %d\n",
412 srcSliceY, srcSliceH, dstY, dstH);
413 DEBUG_BUFFERS(
"vLumFilterSize: %d vLumBufSize: %d vChrFilterSize: %d vChrBufSize: %d\n",
414 vLumFilterSize, vLumBufSize, vChrFilterSize, vChrBufSize);
415
416 if (dstStride[0]%16 !=0 || dstStride[1]%16 !=0 ||
417 dstStride[2]%16 !=0 || dstStride[3]%16 != 0) {
418 static int warnedAlready = 0; // FIXME maybe move this into the context
421 "Warning: dstStride is not aligned!\n"
422 " ->cannot do aligned memory accesses anymore\n");
423 warnedAlready = 1;
424 }
425 }
426
427 if ( (uintptr_t)dst[0]%16 || (uintptr_t)dst[1]%16 || (uintptr_t)dst[2]%16
428 || (uintptr_t)src[0]%16 || (uintptr_t)src[1]%16 || (uintptr_t)src[2]%16
429 || dstStride[0]%16 || dstStride[1]%16 || dstStride[2]%16 || dstStride[3]%16
430 || srcStride[0]%16 || srcStride[1]%16 || srcStride[2]%16 || srcStride[3]%16
431 ) {
432 static int warnedAlready=0;
436 warnedAlready=1;
437 }
438 }
439
440 /* Note the user might start scaling the picture in the middle so this
441 * will not get executed. This is not really intended but works
442 * currently, so people might do it. */
443 if (srcSliceY == 0) {
444 lumBufIndex = -1;
445 chrBufIndex = -1;
446 dstY = 0;
447 lastInLumBuf = -1;
448 lastInChrBuf = -1;
449 }
450
451 if (!should_dither) {
453 }
455
456 for (; dstY <
dstH; dstY++) {
459 dst[0] + dstStride[0] *
dstY,
460 dst[1] + dstStride[1] * chrDstY,
461 dst[2] + dstStride[2] * chrDstY,
462 (CONFIG_SWSCALE_ALPHA &&
alpPixBuf) ? dst[3] + dstStride[3] * dstY : NULL,
463 };
465
466 // First line needed as input
467 const int firstLumSrcY =
FFMAX(1 - vLumFilterSize, vLumFilterPos[dstY]);
469 // First line needed as input
470 const int firstChrSrcY =
FFMAX(1 - vChrFilterSize, vChrFilterPos[chrDstY]);
471
472 // Last line needed as input
473 int lastLumSrcY =
FFMIN(c->
srcH, firstLumSrcY + vLumFilterSize) - 1;
474 int lastLumSrcY2 =
FFMIN(c->
srcH, firstLumSrcY2 + vLumFilterSize) - 1;
475 int lastChrSrcY =
FFMIN(c->
chrSrcH, firstChrSrcY + vChrFilterSize) - 1;
476 int enough_lines;
477
478 // handle holes (FAST_BILINEAR & weird filters)
479 if (firstLumSrcY > lastInLumBuf)
480 lastInLumBuf = firstLumSrcY - 1;
481 if (firstChrSrcY > lastInChrBuf)
482 lastInChrBuf = firstChrSrcY - 1;
483 av_assert0(firstLumSrcY >= lastInLumBuf - vLumBufSize + 1);
484 av_assert0(firstChrSrcY >= lastInChrBuf - vChrBufSize + 1);
485
487 DEBUG_BUFFERS(
"\tfirstLumSrcY: %d lastLumSrcY: %d lastInLumBuf: %d\n",
488 firstLumSrcY, lastLumSrcY, lastInLumBuf);
489 DEBUG_BUFFERS(
"\tfirstChrSrcY: %d lastChrSrcY: %d lastInChrBuf: %d\n",
490 firstChrSrcY, lastChrSrcY, lastInChrBuf);
491
492 // Do we have enough lines in this slice to output the dstY line
493 enough_lines = lastLumSrcY2 < srcSliceY + srcSliceH &&
495
496 if (!enough_lines) {
497 lastLumSrcY = srcSliceY + srcSliceH - 1;
498 lastChrSrcY = chrSrcSliceY + chrSrcSliceH - 1;
499 DEBUG_BUFFERS(
"buffering slice: lastLumSrcY %d lastChrSrcY %d\n",
500 lastLumSrcY, lastChrSrcY);
501 }
502
503 // Do horizontal scaling
504 while (lastInLumBuf < lastLumSrcY) {
506 src[0] + (lastInLumBuf + 1 - srcSliceY) * srcStride[0],
507 src[1] + (lastInLumBuf + 1 - srcSliceY) * srcStride[1],
508 src[2] + (lastInLumBuf + 1 - srcSliceY) * srcStride[2],
509 src[3] + (lastInLumBuf + 1 - srcSliceY) * srcStride[3],
510 };
511 lumBufIndex++;
513 av_assert0(lastInLumBuf + 1 - srcSliceY < srcSliceH);
514 av_assert0(lastInLumBuf + 1 - srcSliceY >= 0);
515 hyscale(c, lumPixBuf[lumBufIndex], dstW, src1, srcW, lumXInc,
516 hLumFilter, hLumFilterPos, hLumFilterSize,
517 formatConvBuffer, pal, 0);
518 if (CONFIG_SWSCALE_ALPHA && alpPixBuf)
519 hyscale(c, alpPixBuf[lumBufIndex], dstW, src1, srcW,
520 lumXInc, hLumFilter, hLumFilterPos, hLumFilterSize,
521 formatConvBuffer, pal, 1);
522 lastInLumBuf++;
524 lumBufIndex, lastInLumBuf);
525 }
526 while (lastInChrBuf < lastChrSrcY) {
528 src[0] + (lastInChrBuf + 1 - chrSrcSliceY) * srcStride[0],
529 src[1] + (lastInChrBuf + 1 - chrSrcSliceY) * srcStride[1],
530 src[2] + (lastInChrBuf + 1 - chrSrcSliceY) * srcStride[2],
531 src[3] + (lastInChrBuf + 1 - chrSrcSliceY) * srcStride[3],
532 };
533 chrBufIndex++;
535 av_assert0(lastInChrBuf + 1 - chrSrcSliceY < (chrSrcSliceH));
536 av_assert0(lastInChrBuf + 1 - chrSrcSliceY >= 0);
537 // FIXME replace parameters through context struct (some at least)
538
540 hcscale(c, chrUPixBuf[chrBufIndex], chrVPixBuf[chrBufIndex],
541 chrDstW, src1, chrSrcW, chrXInc,
542 hChrFilter, hChrFilterPos, hChrFilterSize,
543 formatConvBuffer, pal);
544 lastInChrBuf++;
546 chrBufIndex, lastInChrBuf);
547 }
548 // wrap buf index around to stay inside the ring buffer
549 if (lumBufIndex >= vLumBufSize)
551 if (chrBufIndex >= vChrBufSize)
553 if (!enough_lines)
554 break; // we can't output a dstY line so let's try with the next slice
555
556 #if HAVE_MMX_INLINE
558 lastInLumBuf, lastInChrBuf);
559 #endif
560 if (should_dither) {
563 }
564 if (dstY >= dstH - 2) {
565 /* hmm looks like we can't use MMX here without overwriting
566 * this array's tail */
568 &yuv2packed1, &yuv2packed2, &yuv2packedX, &yuv2anyX);
569 use_mmx_vfilter= 0;
570 }
571
572 {
573 const int16_t **lumSrcPtr = (
const int16_t **)(
void*) lumPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf +
vLumBufSize;
574 const int16_t **chrUSrcPtr = (
const int16_t **)(
void*) chrUPixBuf + chrBufIndex + firstChrSrcY - lastInChrBuf +
vChrBufSize;
575 const int16_t **chrVSrcPtr = (
const int16_t **)(
void*) chrVPixBuf + chrBufIndex + firstChrSrcY - lastInChrBuf +
vChrBufSize;
576 const int16_t **alpSrcPtr = (CONFIG_SWSCALE_ALPHA &&
alpPixBuf) ?
577 (const int16_t **)(void*) alpPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize : NULL;
580
584
587
588 // av_assert0(use_mmx_vfilter != (
589 // yuv2planeX == yuv2planeX_10BE_c
590 // || yuv2planeX == yuv2planeX_10LE_c
591 // || yuv2planeX == yuv2planeX_9BE_c
592 // || yuv2planeX == yuv2planeX_9LE_c
593 // || yuv2planeX == yuv2planeX_16BE_c
594 // || yuv2planeX == yuv2planeX_16LE_c
595 // || yuv2planeX == yuv2planeX_8_c) || !ARCH_X86);
596
597 if(use_mmx_vfilter){
600 }
601
602 if (vLumFilterSize == 1) {
604 } else {
606 lumSrcPtr, dest[0],
608 }
609
610 if (!((dstY & chrSkipMask) ||
isGray(dstFormat))) {
611 if (yuv2nv12cX) {
613 vChrFilterSize, chrUSrcPtr, chrVSrcPtr,
614 dest[1], chrDstW);
615 } else if (vChrFilterSize == 1) {
618 } else {
620 vChrFilterSize, chrUSrcPtr, dest[1],
623 vChrFilterSize, chrVSrcPtr, dest[2],
625 }
626 }
627
628 if (CONFIG_SWSCALE_ALPHA && alpPixBuf) {
629 if(use_mmx_vfilter){
631 }
632 if (vLumFilterSize == 1) {
635 } else {
637 vLumFilterSize, alpSrcPtr, dest[3],
639 }
640 }
641 } else if (yuv2packedX) {
642 av_assert1(lumSrcPtr + vLumFilterSize - 1 < (
const int16_t **)lumPixBuf + vLumBufSize * 2);
643 av_assert1(chrUSrcPtr + vChrFilterSize - 1 < (
const int16_t **)chrUPixBuf + vChrBufSize * 2);
645 vChrFilterSize <= 2) { // unscaled RGB
646 int chrAlpha = vChrFilterSize == 1 ? 0 : vChrFilter[2 * dstY + 1];
648 alpPixBuf ? *alpSrcPtr : NULL,
649 dest[0], dstW, chrAlpha, dstY);
650 }
else if (c->
yuv2packed2 && vLumFilterSize == 2 &&
651 vChrFilterSize == 2) { // bilinear upscale RGB
652 int lumAlpha = vLumFilter[2 * dstY + 1];
653 int chrAlpha = vChrFilter[2 * dstY + 1];
654 lumMmxFilter[2] =
655 lumMmxFilter[3] = vLumFilter[2 *
dstY] * 0x10001;
656 chrMmxFilter[2] =
657 chrMmxFilter[3] = vChrFilter[2 * chrDstY] * 0x10001;
659 alpPixBuf ? alpSrcPtr : NULL,
660 dest[0], dstW, lumAlpha, chrAlpha, dstY);
661 } else { // general RGB
663 lumSrcPtr, vLumFilterSize,
664 vChrFilter + dstY * vChrFilterSize,
665 chrUSrcPtr, chrVSrcPtr, vChrFilterSize,
666 alpSrcPtr, dest[0], dstW, dstY);
667 }
668 } else {
670 yuv2anyX(c, vLumFilter + dstY * vLumFilterSize,
671 lumSrcPtr, vLumFilterSize,
672 vChrFilter + dstY * vChrFilterSize,
673 chrUSrcPtr, chrVSrcPtr, vChrFilterSize,
674 alpSrcPtr, dest, dstW, dstY);
675 }
676 }
677 }
680 int height = dstY - lastDstY;
681
684 fillPlane16(dst[3], dstStride[3], length, height, lastDstY,
687 } else
688 fillPlane(dst[3], dstStride[3], length, height, lastDstY, 255);
689 }
690
691 #if HAVE_MMXEXT_INLINE
693 __asm__ volatile ("sfence" ::: "memory");
694 #endif
696
697 /* store changed local vars back in the context */
703
704 return dstY - lastDstY;
705 }
706
708 {
710
714
716
717
724 }
725 } else {
727 }
728 } else {
731 }
732
738 } else {
741 }
742 } else {
746 } else {
749 }
750 }
751 }
752
756 }
757
759 {
761
762 if (ARCH_PPC)
764 if (ARCH_X86)
766
768 }
769
771 {
773 src[3] = NULL;
775 src[3] = src[2] = NULL;
776
778 src[1] = NULL;
779 }
780 }
781
783 const int linesizes[4])
784 {
786 int i;
787
788 for (i = 0; i < 4; i++) {
790 if (!data[plane] || !linesizes[plane])
791 return 0;
792 }
793
794 return 1;
795 }
796
798 const uint16_t *src,
int stride,
int h)
799 {
800 int xp,yp;
802
803 for (yp=0; yp<h; yp++) {
804 for (xp=0; xp+2<
stride; xp+=3) {
805 int x,
y, z,
r,
g,
b;
806
811 } else {
815 }
816
820
821 // convert from XYZlinear to sRGBlinear
831
832 // limit values to 12-bit depth
836
837 // convert from sRGBlinear to RGB and scale from 12bit to 16bit
842 } else {
846 }
847 }
850 }
851 }
852
854 const uint16_t *src,
int stride,
int h)
855 {
856 int xp,yp;
858
859 for (yp=0; yp<h; yp++) {
860 for (xp=0; xp+2<
stride; xp+=3) {
861 int x,
y, z,
r,
g,
b;
862
867 } else {
871 }
872
876
877 // convert from sRGBlinear to XYZlinear
887
888 // limit values to 12-bit depth
892
893 // convert from XYZlinear to X'Y'Z' and scale from 12bit to 16bit
898 } else {
902 }
903 }
906 }
907 }
908
909 /**
910 * swscale wrapper, so we don't need to export the SwsContext.
911 * Assumes planar YUV to be in YUV order instead of YVU.
912 */
914 const uint8_t *
const srcSlice[],
915 const int srcStride[], int srcSliceY,
916 int srcSliceH,
uint8_t *
const dst[],
917 const int dstStride[])
918 {
923
924 if (!srcSlice || !dstStride || !dst || !srcSlice) {
925 av_log(c,
AV_LOG_ERROR,
"One of the input parameters to sws_scale() is NULL, please check the calling code\n");
926 return 0;
927 }
928 memcpy(src2, srcSlice, sizeof(src2));
929 memcpy(dst2, dst, sizeof(dst2));
930
931 // do not mess up sliceDir if we have a "trailing" 0-size slice
932 if (srcSliceH == 0)
933 return 0;
934
937 return 0;
938 }
941 return 0;
942 }
943
944 if (c->
sliceDir == 0 && srcSliceY != 0 && srcSliceY + srcSliceH != c->
srcH) {
946 return 0;
947 }
950 }
951
953 for (i = 0; i < 256; i++) {
954 int p,
r,
g,
b,
y,
u,
v,
a = 0xff;
956 p = ((const uint32_t *)(srcSlice[1]))[i];
957 a = (p >> 24) & 0xFF;
958 r = (p >> 16) & 0xFF;
959 g = (p >> 8) & 0xFF;
960 b = p & 0xFF;
962 r = ( i >> 5 ) * 36;
963 g = ((i >> 2) & 7) * 36;
964 b = ( i & 3) * 85;
966 b = ( i >> 6 ) * 85;
967 g = ((i >> 3) & 7) * 36;
968 r = ( i & 7) * 36;
970 r = ( i >> 3 ) * 255;
971 g = ((i >> 1) & 3) * 85;
972 b = ( i & 1) * 255;
974 r = g = b = i;
975 } else {
977 b = ( i >> 3 ) * 255;
978 g = ((i >> 1) & 3) * 85;
979 r = ( i & 1) * 255;
980 }
981 #define RGB2YUV_SHIFT 15
982 #define BY ( (int) (0.114 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
983 #define BV (-(int) (0.081 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
984 #define BU ( (int) (0.500 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
985 #define GY ( (int) (0.587 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
986 #define GV (-(int) (0.419 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
987 #define GU (-(int) (0.331 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
988 #define RY ( (int) (0.299 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
989 #define RV ( (int) (0.500 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
990 #define RU (-(int) (0.169 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
991
995 c->
pal_yuv[i]= y + (u<<8) + (v<<16) + ((unsigned)a<<24);
996
999 #if !HAVE_BIGENDIAN
1001 #endif
1002 c->
pal_rgb[i]= r + (g<<8) + (b<<16) + ((unsigned)a<<24);
1003 break;
1005 #if HAVE_BIGENDIAN
1007 #endif
1008 c->
pal_rgb[i]= a + (r<<8) + (g<<16) + ((unsigned)b<<24);
1009 break;
1011 #if HAVE_BIGENDIAN
1013 #endif
1014 c->
pal_rgb[i]= a + (b<<8) + (g<<16) + ((unsigned)r<<24);
1015 break;
1017 #if !HAVE_BIGENDIAN
1019 #endif
1020 default:
1021 c->
pal_rgb[i]= b + (g<<8) + (r<<16) + ((unsigned)a<<24);
1022 }
1023 }
1024 }
1025
1030 if (!rgb0_tmp)
1032
1033 base = srcStride[0] < 0 ? rgb0_tmp - srcStride[0] * (srcSliceH-1) : rgb0_tmp;
1034 for (y=0; y<srcSliceH; y++){
1035 memcpy(base + srcStride[0]*y, src2[0] + srcStride[0]*y, 4*c->
srcW);
1036 for (x=c->
src0Alpha-1; x<4*c->srcW; x+=4) {
1037 base[ srcStride[0]*y + x] = 0xFF;
1038 }
1039 }
1040 src2[0] = base;
1041 }
1042
1046 if (!rgb0_tmp)
1048
1049 base = srcStride[0] < 0 ? rgb0_tmp - srcStride[0] * (srcSliceH-1) : rgb0_tmp;
1050
1051 xyz12Torgb48(c, (uint16_t*)base, (
const uint16_t*)src2[0], srcStride[0]/2, srcSliceH);
1052 src2[0] = base;
1053 }
1054
1056 for (i = 0; i < 4; i++)
1058
1059
1060 // copy strides, so they can safely be modified
1062 // slices go from top to bottom
1063 int srcStride2[4] = { srcStride[0], srcStride[1], srcStride[2],
1064 srcStride[3] };
1065 int dstStride2[4] = { dstStride[0], dstStride[1], dstStride[2],
1066 dstStride[3] };
1067
1070
1071 /* reset slice direction at end of frame */
1072 if (srcSliceY + srcSliceH == c->
srcH)
1074
1075 ret = c->
swscale(c, src2, srcStride2, srcSliceY, srcSliceH, dst2,
1076 dstStride2);
1077 } else {
1078 // slices go from bottom to top => we flip the image internally
1079 int srcStride2[4] = { -srcStride[0], -srcStride[1], -srcStride[2],
1080 -srcStride[3] };
1081 int dstStride2[4] = { -dstStride[0], -dstStride[1], -dstStride[2],
1082 -dstStride[3] };
1083
1084 src2[0] += (srcSliceH - 1) * srcStride[0];
1088 src2[3] += (srcSliceH - 1) * srcStride[3];
1089 dst2[0] += ( c->
dstH - 1) * dstStride[0];
1092 dst2[3] += ( c->
dstH - 1) * dstStride[3];
1093
1096
1097 /* reset slice direction at end of frame */
1098 if (!srcSliceY)
1100
1101 ret = c->
swscale(c, src2, srcStride2, c->
srcH-srcSliceY-srcSliceH,
1102 srcSliceH, dst2, dstStride2);
1103 }
1104
1105
1107 /* replace on the same data */
1108 rgb48Toxyz12(c, (uint16_t*)dst2[0], (
const uint16_t*)dst2[0], dstStride[0]/2, ret);
1109 }
1110
1113 }
1114