32 #ifdef SWITCH_HAVE_VPX 33 #include "vpx/vpx_image.h" 34 #if VPX_IMAGE_ABI_VERSION != (4) 35 #error VPX_IMAGE_ABI_VERSION is not (4) 42 #ifdef SWITCH_HAVE_YUV 51 #define STB_IMAGE_IMPLEMENTATION 52 #include "../libs/stb/stb_image.h" 54 #define STB_IMAGE_WRITE_IMPLEMENTATION 55 #include "../libs/stb/stb_image_write.h" 57 #ifdef SWITCH_HAVE_YUV 69 #ifdef SWITCH_HAVE_YUV 78 #ifdef SWITCH_HAVE_YUV 136 for(i = 0; POS_TABLE[i].
name; i++) {
137 if (!strcasecmp(POS_TABLE[i].name, name)) {
138 r = POS_TABLE[i].
pos;
169 for(i = 0; IMG_FIT_TABLE[i].
name; i++) {
170 if (!strcasecmp(IMG_FIT_TABLE[i].name, name)) {
171 r = IMG_FIT_TABLE[i].
fit;
181 #ifdef SWITCH_HAVE_VPX 182 #ifdef SWITCH_HAVE_YUV 198 #ifdef SWITCH_HAVE_VPX 202 gdImagePtr gd = gdImageCreateTrueColor(d_w, d_h);
204 if (!gd)
return NULL;
240 unsigned char *img_data)
242 #ifdef SWITCH_HAVE_VPX 255 #ifdef SWITCH_HAVE_VPX 264 #ifdef SWITCH_HAVE_YUV 286 (*img)->d_w, (*img)->d_h, (
int)mode);
297 #ifdef SWITCH_HAVE_VPX 301 gdImageDestroy((gdImagePtr)(*img)->user_priv);
304 if ((
int)(intptr_t)(*img)->user_priv != 1) {
318 #define MIN(a,b) ((a) < (b) ? (a) : (b)) 322 #define MAX(a,b) ((a) > (b) ? (a) : (b)) 325 #ifdef SWITCH_HAVE_YUV 331 int max_w =
MIN(img->
d_w, IMG->
d_w - abs(x));
332 int max_h =
MIN(img->
d_h, IMG->
d_h - abs(y));
337 for (i = 0; i < max_h; i++) {
338 for (j = 0; j < max_w; j++) {
355 uint8_t delta1, delta2, delta;
357 delta1 = 255 - RGB->
a;
358 delta2 = 255 - rgb->
a;
359 delta = (delta1 * delta2) >> 8;
360 RGB->
r = ((RGB->
r * RGB->
a) + (rgb->
r * rgb->
a)) / (RGB->
a + rgb->
a);
361 RGB->
g = ((RGB->
g * RGB->
a) + (rgb->
g * rgb->
a)) / (RGB->
a + rgb->
a);
362 RGB->
b = ((RGB->
b * RGB->
a) + (rgb->
b * rgb->
a)) / (RGB->
a + rgb->
a);
363 RGB->
a = 255 - delta;
373 #ifdef SWITCH_HAVE_YUV 392 #ifdef SWITCH_HAVE_YUV 396 switch_img_patch_rgb_noalpha(IMG, img, x, y);
407 int width =
MIN(img->
d_w, IMG->
d_w - abs(x));
408 int height =
MIN(img->
d_h, IMG->
d_h - abs(y));
409 void (*ARGBBlendRow)(
const uint8_t* src_argb,
const uint8_t* src_argb1, uint8_t* dst_argb,
int width) = GetARGBBlend();
414 if (src_stride_argb0 == width * 4 &&
415 src_stride_argb1 == width * 4 &&
419 src_stride_argb0 = src_stride_argb1 = dst_stride_argb = 0;
423 src_argb1 += (y * IMG->
d_w * 4);
424 dst_argb += (y * IMG->
d_w * 4);
427 src_argb1 += (x * 4);
431 for (i = 0; i < height; ++i) {
432 ARGBBlendRow(src_argb0, src_argb1, dst_argb, width);
433 src_argb0 += src_stride_argb0;
434 src_argb1 += src_stride_argb1;
435 dst_argb += dst_stride_argb;
444 int xoff = 0, yoff = 0;
454 int max_w =
MIN(img->
d_w, IMG->
d_w - abs(x));
455 int max_h =
MIN(img->
d_h, IMG->
d_h - abs(y));
460 for (i = 0; i < max_h; i++) {
461 for (j = 0; j < max_w; j++) {
467 }
else if (alpha != 0) {
472 RGB.
r = ((RGB.
r * (255 - alpha)) >> 8) + ((rgb->
r * alpha) >> 8);
473 RGB.
g = ((RGB.
g * (255 - alpha)) >> 8) + ((rgb->
g * alpha) >> 8);
474 RGB.
b = ((RGB.
b * (255 - alpha)) >> 8) + ((rgb->
b * alpha) >> 8);
485 gdImagePtr gd = (gdImagePtr)img->
user_priv;
492 if (!gd->trueColor) {
498 for(i = 0; i < img->
d_h; i++) {
499 for(j = 0; j < img->
d_w; j++) {
500 pixel = gd->tpixels[i][j];
502 rgb_color.r = gdTrueColorGetRed(pixel);
503 rgb_color.g = gdTrueColorGetGreen(pixel);
504 rgb_color.b = gdTrueColorGetBlue(pixel);
524 max_h =
MIN(y + img->
d_h - yoff, IMG->
d_h);
525 len =
MIN(img->
d_w - xoff, IMG->
d_w - x);
528 if (x & 0x1) { x++; len--; }
530 if (len <= 0)
return;
532 for (i = y; i < max_h; i++) {
536 if ((len & 1) && (x + len) < img->
d_w - 1) len++;
540 for (i = y; i < max_h; i += 2) {
548 #ifdef SWITCH_HAVE_VPX 552 if (x >= img->
d_w || y >= img->
d_h)
return;
554 if (w == img->
d_w && h == img->
d_h) {
586 #ifdef SWITCH_HAVE_YUV 595 new_fmt = (*new_img)->fmt;
597 if (img->
d_w != (*new_img)->d_w || img->
d_h != (*new_img)->d_h ) {
598 new_fmt = (*new_img)->fmt;
603 if (*new_img == NULL) {
655 #ifdef SWITCH_HAVE_YUV 658 if (*new_img != NULL) {
659 if (img->
fmt != (*new_img)->fmt || img->
d_w != (*new_img)->d_w || img->
d_h != (*new_img)->d_h) {
664 if (*new_img == NULL) {
681 img->
d_w, img->
d_h, (
int)mode);
689 #ifdef SWITCH_HAVE_VPX 695 if (x >= img->
d_w || y >= img->
d_h)
return NULL;
704 if (!tmp)
return NULL;
726 r = (double)rgb->
r / 255;
727 g = (
double)rgb->
g / 255;
728 b = (double)rgb->
b / 255;
731 r = ( ( r + 0.055 ) / 1.055 );
738 g = ( ( g + 0.055 ) / 1.055 );
745 b = ( ( b + 0.055 ) / 1.055 );
756 xyz->
x = r * 0.4124 + g * 0.3576 + b * 0.1805;
757 xyz->
y = r * 0.2126 + g * 0.7152 + b * 0.0722;
758 xyz->
z = r * 0.0193 + g * 0.1192 + b * 0.9505;
762 #define SVMAX(a,b) ((a) > (b) ? (a) : (b)) 763 #define SVMAX3(a,b,c) (SVMAX((a), SVMAX((b),(c)))) 764 #define SVMIN(a,b) ((a) < (b) ? (a) : (b)) 765 #define SVMIN3(a,b,c) (SVMIN((a), SVMIN((b),(c)))) 770 double r, g,
b, max, min;
772 r = (double)rgb->
r / 255;
773 g = (
double)rgb->
g / 255;
774 b = (double)rgb->
b / 255;
776 max = SVMAX3(r, g, b);
777 min = SVMIN3(r, g, b);
779 hsl->
l = (max + min) / 2;
782 double d = max - min;
784 hsl->
s = hsl->
l > 0.5f ? d / (2 - max - min) : d / (max + min);
787 hsl->
h = (g -
b) / (max - min);
788 }
else if(max == g) {
789 hsl->
h = 2.0 + ((b - r) / (max - min));
791 hsl->
h = 4.0 + ((r - g) / (max - min));
797 hsl->
h = round(hsl->
h * 60);
798 if (hsl->
h < 0) hsl->
h += 360;
812 r=r>10.31475 ? 1.474000611989649e-6 * pow(r+14.025 , 2.4) : r * 0.0003035269835488375;
813 g=g>10.31475 ? 1.474000611989649e-6 * pow(g+14.025 , 2.4) : g * 0.0003035269835488375;
814 b=b>10.31475 ? 1.474000611989649e-6 * pow(b+14.025 , 2.4) : b * 0.0003035269835488375;
815 x=r * 0.43394994055572506 + g * 0.3762097699033109 + b * 0.18984028954096394;
816 y=r * 0.2126729 + g * 0.7151522 + b * 0.0721750;
817 z=r * 0.017756582753965265 + g * 0.10946796102238182 + b * 0.8727754562236529;
820 x = x > 0.008856452 ? pow(x , 0.3333333333333333) : 7.787037037037037 * x + 0.13793103448275862;
821 y = y > 0.008856452 ? pow(y , 0.3333333333333333) : 7.787037037037037 * y + 0.13793103448275862;
822 z = z > 0.008856452 ? pow(z , 0.3333333333333333) : 7.787037037037037 * z + 0.13793103448275862;
824 lab->
l = 116 * y - 16;
825 lab->
a = 500 * (x - y);
826 lab->
b = 200 * (y - z);
842 double Lstd = lab1->
l;
843 double astd = lab1->
a;
844 double bstd = lab1->
b;
847 double Lsample = lab2->
l;
848 double asample = lab2->
a;
849 double bsample = lab2->
b;
855 double Cabstd= sqrt(astd*astd+bstd*bstd);
856 double Cabsample= sqrt(asample*asample+bsample*bsample);
858 double Cabarithmean= (Cabstd + Cabsample)/2.0;
860 double G= 0.5*( 1.0 - sqrt( pow(Cabarithmean,7.0)/(pow(Cabarithmean,7.0) + pow(25.0,7.0))));
862 double apstd= (1.0+G)*astd;
863 double apsample= (1.0+G)*asample;
864 double Cpsample= sqrt(apsample*apsample+bsample*bsample);
866 double Cpstd= sqrt(apstd*apstd+bstd*bstd);
868 double Cpprod= (Cpsample*Cpstd);
871 double hpsample, dL, dC, dhp, dH, Lp, Cp;
872 double hp, Lpm502, Sl, Sc, T, Sh, delthetarad, Rc, RT;
875 double hpstd= atan2(bstd,apstd);
876 if (hpstd<0) hpstd+= 2.0*pi;
878 hpsample= atan2(bsample,apsample);
879 if (hpsample<0) hpsample+= 2.0*pi;
880 if ( (fabs(apsample)+fabs(bsample))==0.0) hpsample= 0.0;
883 dC= (Cpsample-Cpstd);
886 dhp= (hpsample-hpstd);
887 if (dhp>pi) dhp-= 2.0*pi;
888 if (dhp<-pi) dhp+= 2.0*pi;
890 if (Cpprod == 0.0) dhp= 0.0;
896 dH= 2.0*sqrt(Cpprod)*sin(dhp/2.0);
900 Lp= (Lsample+Lstd)/2.0;
901 Cp= (Cpstd+Cpsample)/2.0;
907 hp= (hpstd+hpsample)/2.0;
909 if ( fabs(hpstd-hpsample) > pi ) hp-= pi;
911 if (hp<0) hp+= 2.0*pi;
915 if (Cpprod==0.0) hp= hpsample+hpstd;
917 Lpm502= (Lp-50.0)*(Lp-50.0);;
918 Sl= 1.0+0.015*Lpm502/sqrt(20.0+Lpm502);
920 T= 1.0 - 0.17*cos(hp - pi/6.0) + 0.24*cos(2.0*hp) + 0.32*cos(3.0*hp+pi/30.0) - 0.20*cos(4.0*hp-63.0*pi/180.0);
921 Sh= 1.0 + 0.015*Cp*T;
922 delthetarad= (30.0*pi/180.0)*exp(- pow(( (180.0/pi*hp-275.0)/25.0),2.0));
923 Rc= 2.0*sqrt(pow(Cp,7.0)/(pow(Cp,7.0) + pow(25.0,7.0)));
924 RT= -sin(2.0*delthetarad)*Rc;
927 return sqrt( pow((dL/Sl),2.0) + pow((dC/Sc),2.0) + pow((dH/Sh),2.0) + RT*(dC/Sc)*(dH/Sh) );
943 if (!cr && !cg && !cb)
return 0;
945 cr2 = c1->
r/2 - c2->
r/2;
946 cg2 = c1->
g/2 - c2->
g/2;
947 cb2 = c1->
b/2 - c2->
b/2;
949 a = ((2*cr*cr) + (4*cg*cg) + (3*cb*cb));
950 b = ((2*cr2*cr2) + (4*cg2*cg2) + (3*cb2*cb2));
955 r = (((bb*4)+(aa))/9)/100;
965 for (x = 0; x <
count; x++) {
968 if (distance <= thresholds[x]) {
1001 if (!strcasecmp(shade_name,
"red")) {
1003 }
else if (!strcasecmp(shade_name,
"green")) {
1005 }
else if (!strcasecmp(shade_name,
"blue")) {
1007 }
else if (!strcasecmp(shade_name,
"auto")) {
1021 for (i = 0; i < ck->
mask_len; i++) {
1112 if (c1->
r > c1->
g && c1->
r > c1->
b) {
1116 if (c1->
g > c1->
r && c1->
g > c1->
b) {
1120 if (c1->
b > c1->
r && c1->
b > c1->
g) {
1133 if (c1_max && c1_max == c2_max)
return 1;
1141 int r = abs(c1->
r - c2->
r);
1142 int g = abs(c1->
g - c2->
g);
1143 int b = abs(c1->
b - c2->
b);
1145 if (r < distance && g < distance && b < distance)
return 1;
1152 int r = abs(c1->
r - c2->
r);
1153 int g = abs(c1->
g - c2->
g);
1154 int b = abs(c1->
b - c2->
b);
1156 if (r < 5 && g < 5 && b < 5)
return 0;
1158 return (3*r) + (4*g) + (3*b);
1196 uint8_t *pixel, *last_pixel = NULL, *cache_pixel = NULL, *end_pixel = NULL;
1203 int other_img_cached = 0, color_cached = 0, checked = 0, hit_total = 0, total_pixel = 0, delta_hits = 0;
1222 if (cache_img && (cache_img->
d_w != img->
d_w || cache_img->
d_h != img->
d_h)) {
1234 ck->
rr = ck->
gg = ck->
bb = 0;
1237 for (; pixel < end_pixel; pixel += 4) {
1248 if (!ck->
no_cache && cache_img && cache_pixel) {
1255 color->
a = cache_color->
a;
1289 if (dom > a && dom > b && dom > tol) {
1290 if (dom - a > a_tol && dom - b > b_tol) {
1349 for (i = 0; i < ck->
mask_len; i++) {
1350 last_color = &ck->
mask[i];
1373 printf(
"total %d: other img cache %d color cache %d Checked %d Hit Total %d Delta hits: %d\n", total_pixel, other_img_cached, color_cached, checked, hit_total, delta_hits);
1388 int last_threshold = 0;
1398 if (last_pixel && (*(uint32_t *)pixel & 0xFFFFFF) == (*(uint32_t *)last_pixel & 0xFFFFFF)) {
1399 threshold = last_threshold;
1404 last_threshold = threshold;
1417 #ifdef SWITCH_HAVE_YUV 1420 if (x < 0 || y < 0 || x >= img->
d_w || y >= img->
d_h)
return;
1423 switch_color_rgb2yuv(color, &yuv);
1427 if (((x & 0x1) == 0) && ((y & 0x1) == 0)) {
1439 #ifdef SWITCH_HAVE_YUV 1443 int max_w = img->
d_w;
1444 int max_h = img->
d_h;
1448 for (i = 0; i < max_h; i++) {
1449 for (j = 0; j < max_w; j++) {
1466 #ifdef SWITCH_HAVE_YUV 1470 int max_w = img->
d_w;
1471 int max_h = img->
d_h;
1476 for (i = 0; i < max_h; i++) {
1477 for (j = 0; j < max_w; j++) {
1482 if (!rgb->
a)
continue;;
1485 bytes = (uint32_t *) rgb;
1487 #if SWITCH_BYTE_ORDER == __BIG_ENDIAN 1488 *bytes = *bytes & 0xE0E0C0FF;
1490 *bytes = *bytes & 0xFFC0E0E0;
1510 tmp_img->
d_w, tmp_img->
d_h);
1519 #ifdef SWITCH_HAVE_YUV 1520 if (x < 0 || y < 0 || x >= img->
d_w || y >= img->
d_h)
return;
1527 max_h =
MIN(y + h, img->
d_h);
1528 len =
MIN(w, img->
d_w - x);
1530 if (x & 1) { x++; len--; }
1532 if (len <= 0)
return;
1534 if ((len & 1) && (x + len) < img->
d_w - 1) len++;
1538 for (i = y; i < max_h; i += 2) {
1548 #ifdef SWITCH_HAVE_YUV 1550 if (x < 0 || y < 0 || x >= img->
d_w || y >= img->
d_h)
return;
1557 max_h =
MIN(y + h, img->
d_h);
1558 len =
MIN(w, img->
d_w - x);
1560 if (x & 1) { x++; len--; }
1562 if (len <= 0)
return;
1564 if ((len & 1) && (x + len) < img->
d_w - 1) len++;
1568 for (i = y; i < max_h; i += 2) {
1578 #ifdef SWITCH_HAVE_YUV 1582 if (x < 0 || y < 0 || x >= img->
d_w || y >= img->
d_h)
return;
1585 switch_color_rgb2yuv(color, &yuv_color);
1587 max_h =
MIN(y + h, img->
d_h);
1588 len =
MIN(w, img->
d_w - x);
1590 if (x & 1) { x++; len--; }
1592 if (len <= 0)
return;
1594 for (i = y; i < max_h; i++) {
1598 if ((len & 1) && (x + len) < img->
d_w - 1) len++;
1602 for (i = y; i < max_h; i += 2) {
1607 for (i = 0; i < img->
d_w; i++) {
1611 for (i = 1; i < img->
d_h; i++) {
1619 #ifdef SWITCH_HAVE_YUV 1623 if (x < 0 || y < 0 || x >= img->
d_w || y >= img->
d_h)
return;
1633 #ifdef SWITCH_HAVE_YUV 1634 if (x < 0 || y < 0 || x >= img->
d_w || y >= img->
d_h)
return;
1639 switch_img_get_yuv_pixel(img, &yuv, x, y);
1640 switch_color_yuv2rgb(&yuv, rgb);
1649 int i, j, len, max_h;
1651 int xoff = 0, yoff = 0;
1652 uint8_t alpha = (int8_t)((255 * percent) / 100);
1667 max_h =
MIN(y + img->
d_h - yoff, IMG->
d_h);
1668 len =
MIN(img->
d_w - xoff, IMG->
d_w - x);
1670 if (x & 1) { x++; len--; }
1672 if (len <= 0)
return;
1674 for (i = y; i < max_h; i++) {
1675 for (j = 0; j < len; j++) {
1680 c.r = ((RGB.
r * (255 - alpha)) >> 8) + ((rgb.
r * alpha) >> 8);
1681 c.g = ((RGB.
g * (255 - alpha)) >> 8) + ((rgb.
g * alpha) >> 8);
1682 c.b = ((RGB.
b * (255 - alpha)) >> 8) + ((rgb.
b * alpha) >> 8);
1695 {0x00, 0x7E, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x7E, 0x00},
1696 {0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x00},
1697 {0x00, 0x7E, 0x02, 0x02, 0x02, 0x02, 0x02, 0x7E, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x7E, 0x00},
1698 {0x00, 0x7E, 0x02, 0x02, 0x02, 0x02, 0x02, 0x7E, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x7E, 0x00},
1699 {0x00, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x7E, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x00},
1700 {0x00, 0x7E, 0x40, 0x40, 0x40, 0x40, 0x40, 0x7E, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x7E, 0x00},
1701 {0x00, 0x7E, 0x40, 0x40, 0x40, 0x40, 0x40, 0x7E, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x7E, 0x00},
1702 {0x00, 0x7E, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x00},
1703 {0x00, 0x7E, 0x42, 0x42, 0x42, 0x42, 0x42, 0x7E, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x7E, 0x00},
1704 {0x00, 0x7E, 0x42, 0x42, 0x42, 0x42, 0x42, 0x7E, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x7E, 0x00},
1705 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00},
1706 {0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
1707 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
1708 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
1718 for(i=0; i<8; i++) {
1719 for (j=0; j<16; j++) {
1720 *( p + (y + j) * w + (x + i)) = (
scv_art[n][j] & 0x80 >> i) ? 0xFF : 0x00;
1730 if (x > w - 8)
break;
1733 case '.': index = 10;
break;
1734 case ':': index = 11;
break;
1735 case '-': index = 12;
break;
1736 case ' ': index = 13;
break;
1741 scv_tag(buffer, w, x, y, index);
1749 if (
zstr(str))
return;
1751 if ((*str) ==
'#' && strlen(str) == 7) {
1752 unsigned int r, g,
b;
1753 sscanf(str,
"#%02x%02x%02x", &r, &g, &b);
1758 if (!strcmp(str,
"red")) {
1762 }
else if (!strcmp(str,
"green")) {
1766 }
else if (!strcmp(str,
"blue")) {
1776 #ifdef SWITCH_HAVE_YUV 1780 yuv->
y = ( ( 66 * rgb->
r + 129 * rgb->
g + 25 * rgb->
b + 128) >> 8) + 16;
1781 yuv->
u = ( ( -38 * rgb->
r - 74 * rgb->
g + 112 * rgb->
b + 128) >> 8) + 128;
1782 yuv->
v = ( ( 112 * rgb->
r - 94 * rgb->
g - 18 * rgb->
b + 128) >> 8) + 128;
1790 #define CLAMP(val) MAX(0, MIN(val, 255)) 1792 #ifdef SWITCH_HAVE_YUV 1796 int C = yuv->
y - 16;
1797 int D = yuv->
u - 128;
1798 int E = yuv->
v - 128;
1800 rgb->
r =
CLAMP((298 * C + 409 * E + 128) >> 8);
1801 rgb->
g =
CLAMP((298 * C - 100 * D - 208 * E + 128) >> 8);
1802 rgb->
b =
CLAMP((298 * C + 516 * D + 128) >> 8);
1806 rgb->
r =
CLAMP( yuv->
y + ((22457 * (yuv->
v-128)) >> 14));
1807 rgb->
g =
CLAMP((yuv->
y - ((715 * (yuv->
v-128)) >> 10) - ((5532 * (yuv->
u-128)) >> 14)));
1808 rgb->
b =
CLAMP((yuv->
y + ((28384 * (yuv->
u-128)) >> 14)));
1814 #ifdef SWITCH_HAVE_YUV 1818 switch_color_rgb2yuv(&rgb, color);
1822 #if SWITCH_HAVE_FREETYPE 1823 #include <ft2build.h> 1824 #include FT_FREETYPE_H 1828 #define MAX_GRADIENT 8 1831 #if SWITCH_HAVE_FREETYPE 1857 color->
r = c1->
r + (c2->
r - c1->
r) * i / MAX_GRADIENT;
1858 color->
g = c1->
g + (c2->
g - c1->
g) * i / MAX_GRADIENT;
1859 color->
b = c1->
b + (c2->
b - c1->
b) * i / MAX_GRADIENT;
1877 #if SWITCH_HAVE_FREETYPE 1878 if (FT_Init_FreeType(&new_handle->library)) {
1888 if (
zstr(font_family)) {
1900 #if SWITCH_HAVE_FREETYPE 1901 if (new_handle->library) {
1902 FT_Done_FreeType(new_handle->library);
1903 new_handle->library = NULL;
1914 new_handle->
angle = angle;
1921 *handleP = new_handle;
1934 old_handle = *handleP;
1936 if (!old_handle)
return;
1939 #if SWITCH_HAVE_FREETYPE 1940 if (old_handle->library) {
1941 FT_Done_FreeType(old_handle->library);
1942 old_handle->library = NULL;
1945 pool = old_handle->
pool;
1955 #if SWITCH_HAVE_FREETYPE 1959 FT_Int x_max = x + bitmap->width;
1960 FT_Int y_max = y + bitmap->rows;
1962 if (bitmap->width == 0)
return;
1964 switch (bitmap->pixel_mode) {
1965 case FT_PIXEL_MODE_GRAY:
1967 case FT_PIXEL_MODE_NONE:
1968 case FT_PIXEL_MODE_MONO:
1970 for ( j = y, q = 0; j < y_max; j++, q++ ) {
1971 for ( i = x, p = 0; i < x_max; i++, p++ ) {
1973 int linesize = ((bitmap->width - 1) / 8 + 1) * 8;
1975 if ( i < 0 || j < 0 || i >= img->
d_w || j >= img->
d_h)
continue;
1977 byte = bitmap->buffer[(q * linesize + p) / 8];
1978 if ((byte >> (7 - (p % 8))) & 0x1) {
1985 case FT_PIXEL_MODE_GRAY2:
1986 case FT_PIXEL_MODE_GRAY4:
1987 case FT_PIXEL_MODE_LCD:
1988 case FT_PIXEL_MODE_LCD_V:
1993 for ( i = x, p = 0; i < x_max; i++, p++ ) {
1994 for ( j = y, q = 0; j < y_max; j++, q++ ) {
1995 int gradient = bitmap->buffer[q * bitmap->width + p];
1996 if ( i < 0 || j < 0 || i >= img->
d_w || j >= img->
d_h)
continue;
2005 if (rgb_color.
a > 0) {
2006 c.
a = rgb_color.
a * gradient / 255;
2007 c.
r = ((rgb_color.
r * (255 - gradient)) >> 8) + ((handle->
color.
r * gradient) >> 8);
2008 c.
g = ((rgb_color.
g * (255 - gradient)) >> 8) + ((handle->
color.
g * gradient) >> 8);
2009 c.
b = ((rgb_color.
b * (255 - gradient)) >> 8) + ((handle->
color.
b * gradient) >> 8);
2026 int x,
int y,
const char *text,
2027 const char *font_family,
const char *font_color,
2028 const char *bgcolor, uint16_t font_size,
double angle)
2030 #if SWITCH_HAVE_FREETYPE 2040 int this_x = 0, last_x = 0, space = 0;
2043 if (
zstr(text))
return 0;
2045 if (!handle)
return 0;
2072 handle->
angle = angle;
2078 error = FT_New_Face(handle->library, font_family, 0, &face);
2084 error = FT_Set_Char_Size(face, 64 * font_size, 0, 96, 0);
2085 if (error)
return 0;
2089 if (handle->
use_bgcolor && slot->bitmap.pixel_mode != FT_PIXEL_MODE_MONO) {
2094 matrix.xx = (FT_Fixed)( cos( angle ) * 0x10000L );
2095 matrix.xy = (FT_Fixed)(-sin( angle ) * 0x10000L );
2096 matrix.yx = (FT_Fixed)( sin( angle ) * 0x10000L );
2097 matrix.yy = (FT_Fixed)( cos( angle ) * 0x10000L );
2102 while(*(text + index)) {
2107 pen.y += (font_size + font_size / 4);
2112 FT_Set_Transform(face, &matrix, &pen);
2115 error = FT_Load_Char(face, ch, FT_LOAD_RENDER);
2117 if (error)
continue;
2119 this_x = pen.x + slot->bitmap_left;
2123 draw_bitmap(handle, img, &slot->bitmap, this_x, pen.y - slot->bitmap_top + font_size);
2127 space = this_x - last_x;
2137 pen.x += slot->advance.x >> 6;
2138 pen.y += slot->advance.y >> 6;
2141 ret = width + slot->bitmap.width * 5;
2153 const char *fg =
"#cccccc";
2154 const char *bg =
"#142e55";
2156 const char *font_face = NULL;
2157 const char *fontsz =
"4%";
2158 char *txt =
"Value Optimized Out!";
2160 char *argv[6] = { 0 };
2162 int pre_width = 0, width = 0, font_size = 0, height = 0;
2163 char *duptxt = strdup(text);
2172 if (strchr(text,
':')) {
2175 if (argc > 0 && !
zstr(argv[0])) {
2179 if (argc > 1 && !
zstr(argv[1])) {
2181 if (!strcasecmp(bg,
"transparent")) {
2186 if (argc > 2 && !
zstr(argv[2])) {
2187 font_face = argv[2];
2190 if (argc > 3 && !
zstr(argv[3])) {
2197 }
else txt = duptxt;
2199 if (!txt) txt = duptxt;
2201 if (strrchr(fontsz,
'%')) {
2202 font_size = 1 + ((int) (
float)h * (atof(fontsz) / 100.0f));
2204 font_size = atoi(fontsz);
2209 while (*txt ==
' ') txt++;
2216 font_size / 2, font_size / 2,
2217 txt, NULL, fg, bg, 0, 0);
2219 height = font_size * 2;
2221 if (full && w > width) {
2227 if (width == 0 || height == 0) {
2252 x = (txtimg->
d_w / 2) - (pre_width / 2);
2258 txt, NULL, fg, bg, 0, 0);
2282 if (len <= 0)
return;
2284 for (i = y; i < (y + img->
d_h) && i < IMG->d_h; i++) {
2285 if (rect && i >= rect->
y && i < (rect->
y + rect->
h)) {
2286 int size = rect->
x > x ? rect->
x - x : 0;
2288 size =
MIN(img->
d_w - rect->
w - size, IMG->
d_w - (rect->
x + rect->
w));
2297 for (i = y; i < (y + img->
d_h) && i < IMG->d_h; i += 2) {
2298 if (rect && i > rect->
y && i < (rect->
y + rect->
h)) {
2299 int size = rect->
x > x ? rect->
x - x : 0;
2304 size =
MIN(img->
d_w - rect->
w - size, IMG->
d_w - (rect->
x + rect->
w)) / 2;
2314 #define SWITCH_IMG_MAX_WIDTH 1920 * 4 2315 #define SWITCH_IMG_MAX_HEIGHT 1080 * 4 2317 #if !defined(SWITCH_HAVE_YUV) 2318 #undef SWITCH_HAVE_PNG 2321 #ifdef SWITCH_HAVE_PNG 2324 #define PNG_SKIP_SETJMP_CHECK 2328 #ifdef PNG_SIMPLIFIED_READ_SUPPORTED 2330 struct switch_png_opaque_s {
2344 use_png->
pvt->png.version = PNG_IMAGE_VERSION;
2346 if (!png_image_begin_read_from_file(&use_png->
pvt->png, file_name)) {
2351 use_png->
pvt->png.format = PNG_FORMAT_ARGB;
2353 use_png->
pvt->buffer = malloc(PNG_IMAGE_SIZE(use_png->
pvt->png));
2356 if (!png_image_finish_read(&use_png->
pvt->png, NULL, use_png->
pvt->buffer, 0, NULL)) {
2362 use_png->
w = use_png->
pvt->png.width;
2363 use_png->
h = use_png->
pvt->png.height;
2384 png_image_free(&use_png->
pvt->png);
2400 for (i = 0; i < use_png->
pvt->png.height; i++) {
2401 for (j = 0; j < use_png->
pvt->png.width; j++) {
2435 #ifdef PNG_SIMPLIFIED_READ_SUPPORTED 2442 png->version = PNG_IMAGE_VERSION;
2445 png->format = PNG_FORMAT_RGB;
2447 #if SWITCH_BYTE_ORDER == __BIG_ENDIAN 2448 png->format = PNG_FORMAT_ARGB;
2450 png->format = PNG_FORMAT_BGRA;
2457 buffer = malloc(PNG_IMAGE_SIZE(*png));
2460 if (!png_image_finish_read(png, NULL, buffer, 0, NULL)) {
2474 RAWToI420(buffer, png->width * 3,
2478 png->width, png->height);
2480 ARGBCopy(buffer, png->width * 4,
2482 png->width, png->height);
2486 png_image_free(png);
2493 png_image png = { 0 };
2495 png.version = PNG_IMAGE_VERSION;
2497 if (!png_image_begin_read_from_file(&png, file_name)) {
2502 return png2img(&png, img_fmt);
2507 png_image png = { 0 };
2509 png.version = PNG_IMAGE_VERSION;
2511 if (!png_image_begin_read_from_memory(&png, mem, size)) {
2516 return png2img(&png, img_fmt);
2531 png_bytep *row_pointers = NULL;
2535 png_byte color_type;
2538 png_structp png_ptr = NULL;
2539 png_infop info_ptr = NULL;
2542 png_color_8p sig_bit;
2555 fp = fopen(file_name,
"rb");
2561 fread(header, 1, 8, fp);
2562 if (png_sig_cmp(header, 0, 8)) {
2567 png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
2573 info_ptr = png_create_info_struct(png_ptr);
2579 if (setjmp(png_jmpbuf(png_ptr))) {
2584 png_init_io(png_ptr, fp);
2585 png_set_sig_bytes(png_ptr, 8);
2586 png_read_info(png_ptr, info_ptr);
2588 width = png_get_image_width(png_ptr, info_ptr);
2589 height = png_get_image_height(png_ptr, info_ptr);
2590 color_type = png_get_color_type(png_ptr, info_ptr);
2591 bit_depth = png_get_bit_depth(png_ptr, info_ptr);
2598 if (color_type == PNG_COLOR_TYPE_PALETTE) {
2599 png_set_expand(png_ptr);
2603 if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) {
2604 png_set_expand(png_ptr);
2608 if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
2609 png_set_expand(png_ptr);
2613 if (png_get_valid(png_ptr, info_ptr, PNG_INFO_bKGD)) {
2623 if (png_get_valid(png_ptr, info_ptr, PNG_INFO_gAMA)) {
2630 if (bit_depth == 16) {
2631 png_set_strip_16(png_ptr);
2637 if (0 && color_type & PNG_COLOR_MASK_COLOR) {
2638 if (png_get_valid(png_ptr, info_ptr, & PNG_INFO_PLTE)) {
2639 png_set_dither(png_ptr, info_ptr->palette,
2640 info_ptr->num_palette, max_screen_colors,
2641 info_ptr->histogram);
2643 png_color std_color_cube[MAX_SCREEN_COLORS] =
2646 png_set_dither(png_ptr, std_color_cube, MAX_SCREEN_COLORS,
2647 MAX_SCREEN_COLORS, NULL);
2653 if (bit_depth == 1 && color_type == PNG_COLOR_TYPE_GRAY) {
2657 png_get_sBIT(png_ptr, info_ptr, &sig_bit);
2665 if (bit_depth < 8) {
2666 png_set_packing(png_ptr);
2670 if (color_type == PNG_COLOR_TYPE_RGB || color_type == PNG_COLOR_TYPE_RGB_ALPHA) {
2675 if (bit_depth == 16) {
2676 png_set_swap(png_ptr);
2679 if (0 && color_type & PNG_COLOR_MASK_ALPHA) {
2680 if (setjmp(png_jmpbuf(png_ptr))) {
2685 png_set_strip_alpha(png_ptr);
2688 if (setjmp(png_jmpbuf(png_ptr))) {
2693 if (color_type == PNG_COLOR_TYPE_PALETTE) {
2694 png_set_palette_to_rgb(png_ptr);
2697 png_read_update_info(png_ptr, info_ptr);
2699 color_type = png_get_color_type(png_ptr, info_ptr);
2706 row_bytes = png_get_rowbytes(png_ptr, info_ptr);
2709 row_pointers = (png_bytep*)malloc(
sizeof(png_bytep) * height);
2712 buffer = (png_byte *)malloc(row_bytes * height);
2715 for (y = 0; y < height; y++) {
2716 row_pointers[y] = buffer + row_bytes * y;
2720 if (setjmp(png_jmpbuf(png_ptr))) {
2725 png_read_image(png_ptr, row_pointers);
2727 if (color_type == PNG_COLOR_TYPE_RGBA) {
2728 if (row_bytes > width * 4) {
2729 for(y = 1; y < height; y++) {
2730 memcpy(buffer + y * width * 4, row_pointers[y], width * 4);
2738 ABGRToI420(buffer, width * 4,
2744 BGRAToARGB(buffer, width * 4,
2748 }
else if (color_type == PNG_COLOR_TYPE_RGB) {
2749 if (row_bytes > width * 3) {
2750 for(y = 1; y < height; y++) {
2751 memcpy(buffer + y * width * 3, row_pointers[y], width * 3);
2763 RAWToI420(buffer, width * 3,
2776 if (info_ptr) png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
2788 static void my_png_write_data(png_structp png_ptr, png_bytep data, png_size_t
length)
2794 static void my_png_flush(png_structp png_ptr)
2801 png_byte color_type;
2803 png_structp png_ptr;
2805 png_bytep *row_pointers = NULL;
2811 unsigned char *head;
2816 color_type = PNG_COLOR_TYPE_RGB;
2819 color_type = PNG_COLOR_TYPE_RGBA;
2823 png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
2830 info_ptr = png_create_info_struct(png_ptr);
2836 if (setjmp(png_jmpbuf(png_ptr))) {
2842 png_set_write_fn(png_ptr, data_buffer, my_png_write_data, my_png_flush);
2845 if (setjmp(png_jmpbuf(png_ptr))) {
2850 png_set_IHDR(png_ptr, info_ptr, width, height,
2851 bit_depth, color_type, PNG_INTERLACE_NONE,
2852 PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
2854 png_write_info(png_ptr, info_ptr);
2856 row_bytes = png_get_rowbytes(png_ptr, info_ptr);
2859 buffer = (png_byte *)malloc(row_bytes * height);
2862 row_pointers = (png_bytep*)malloc(
sizeof(png_bytep) * height);
2865 for (y = 0; y < height; y++) {
2866 row_pointers[y] = buffer + row_bytes * y;
2877 buffer, row_bytes, width, height);
2880 if (setjmp(png_jmpbuf(png_ptr))) {
2887 png_write_image(png_ptr, row_pointers);
2889 if (setjmp(png_jmpbuf(png_ptr))) {
2894 png_write_end(png_ptr, info_ptr);
2898 unsigned char *out = NULL;
2899 const char *header =
"data:image/png;base64,";
2904 if (olen > strlen(header) + 1) {
2909 *urlP = (
char *)out;
2927 png_destroy_write_struct(&png_ptr, &info_ptr);
2932 #ifdef PNG_SIMPLIFIED_WRITE_SUPPORTED 2936 png_image png = { 0 };
2941 png.format = PNG_FORMAT_RGB;
2942 buffer = malloc(img->
d_w * img->
d_h * 3);
2948 buffer, img->
d_w * 3,
2951 #if SWITCH_BYTE_ORDER == __BIG_ENDIAN 2952 png.format = PNG_FORMAT_ARGB;
2954 png.format = PNG_FORMAT_BGRA;
2959 png.version = PNG_IMAGE_VERSION;
2960 png.width = img->
d_w;
2961 png.height = img->
d_h;
2963 if (!png_image_write_to_file(&png, file_name, 0, buffer, 0, NULL)) {
2981 png_byte color_type;
2983 png_structp png_ptr;
2985 png_bytep *row_pointers = NULL;
2995 color_type = PNG_COLOR_TYPE_RGB;
2998 color_type = PNG_COLOR_TYPE_RGBA;
3001 fp = fopen(file_name,
"wb");
3007 png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
3013 info_ptr = png_create_info_struct(png_ptr);
3019 if (setjmp(png_jmpbuf(png_ptr))) {
3024 png_init_io(png_ptr, fp);
3026 if (setjmp(png_jmpbuf(png_ptr))) {
3031 png_set_IHDR(png_ptr, info_ptr, width, height,
3032 bit_depth, color_type, PNG_INTERLACE_NONE,
3033 PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
3035 png_write_info(png_ptr, info_ptr);
3037 row_bytes = png_get_rowbytes(png_ptr, info_ptr);
3040 row_pointers = (png_bytep*)malloc(
sizeof(png_bytep) * height);
3043 buffer = (png_byte *)malloc(row_bytes * height);
3046 for (y = 0; y < height; y++) {
3047 row_pointers[y] = buffer + row_bytes * y;
3058 buffer, row_bytes, width, height);
3061 if (setjmp(png_jmpbuf(png_ptr))) {
3066 png_write_image(png_ptr, row_pointers);
3068 if (setjmp(png_jmpbuf(png_ptr))) {
3073 png_write_end(png_ptr, NULL);
3082 png_destroy_write_struct(&png_ptr, &info_ptr);
3119 #ifdef SWITCH_HAVE_YUV 3120 int width = 0, height = 0, channels = 0;
3121 int comp = STBI_rgb;
3122 unsigned char *data = NULL;
3127 comp = STBI_rgb_alpha;
3132 data = stbi_load(file_name, &width, &height, &channels, comp);
3135 if (data && width > 0 && height > 0) {
3140 RAWToI420(data, width * 3,
3146 #if SWITCH_BYTE_ORDER == __BIG_ENDIAN 3153 stbi_image_free(data);
3157 stbi_image_free(data);
3166 #ifndef SWITCH_HAVE_YUV 3169 int comp = STBI_rgb;
3170 unsigned char *data = NULL;
3171 const char *ext = strrchr(file_name,
'.');
3172 int stride_in_bytes = 0;
3181 stride_in_bytes = img->
d_w * 3;
3183 data = malloc(stride_in_bytes * img->
d_h);
3189 data, stride_in_bytes,
3192 comp = STBI_rgb_alpha;
3193 stride_in_bytes = img->
d_w * 4;
3195 data = malloc(stride_in_bytes * img->
d_h);
3198 #if SWITCH_BYTE_ORDER == __BIG_ENDIAN 3207 if (!strcasecmp(ext,
"png")) {
3208 ret = stbi_write_png(file_name, img->
d_w, img->
d_h, comp, (
const void *)data, stride_in_bytes);
3209 }
else if (!strcasecmp(ext,
"jpg") || !strcasecmp(ext,
"jpeg")) {
3210 ret = stbi_write_jpg(file_name, img->
d_w, img->
d_h, comp, (
const void *)data, quality);
3211 }
else if (!strcasecmp(ext,
"bmp")) {
3212 ret = stbi_write_bmp(file_name, img->
d_w, img->
d_h, comp, (
const void *)data);
3213 }
else if (!strcasecmp(ext,
"tga")) {
3214 ret = stbi_write_tga(file_name, img->
d_w, img->
d_h, comp, (
const void *)data);
3215 }
else if (!strcasecmp(ext,
"hdr")) {
3216 ret = stbi_write_hdr(file_name, img->
d_w, img->
d_h, comp, (
const float *)data);
3233 #ifdef SWITCH_HAVE_YUV 3234 static void data_url_write_func(
void *context,
void *data,
int size)
3243 #ifndef SWITCH_HAVE_YUV 3246 int comp = STBI_rgb;
3247 unsigned char *data = NULL;
3248 int stride_in_bytes = 0;
3251 const char *header = NULL;
3258 stride_in_bytes = img->
d_w * 3;
3260 data = malloc(stride_in_bytes * img->
d_h);
3266 data, stride_in_bytes,
3269 comp = STBI_rgb_alpha;
3270 stride_in_bytes = img->
d_w * 4;
3272 data = malloc(stride_in_bytes * img->
d_h);
3275 #if SWITCH_BYTE_ORDER == __BIG_ENDIAN 3286 if (!strcmp(type,
"png")) {
3287 header =
"data:image/png;base64,";
3288 ret = stbi_write_png_to_func(data_url_write_func, (
void *)buffer, img->
d_w, img->
d_h, comp, (
const void *)data, stride_in_bytes);
3289 }
else if (!strcmp(type,
"jpeg") || !strcmp(type,
"jpeg")) {
3290 header =
"data:image/jpeg;base64,";
3291 ret = stbi_write_jpg_to_func(data_url_write_func, (
void *)buffer, img->
d_w, img->
d_h, comp, (
const void *)data, quality);
3301 unsigned char *out = NULL;
3304 header_len = strlen(header);
3305 memcpy(out, header, header_len);
3307 *urlP = (
char *)out;
3320 int img_w = 0, img_h = 0;
3321 double screen_aspect = 0, img_aspect = 0;
3330 if (img->
d_w == width && img->
d_h == height) {
3342 screen_aspect = (double) IMG->
d_w / IMG->
d_h;
3343 img_aspect = (
double) img->
d_w / img->
d_h;
3346 if (screen_aspect > img_aspect) {
3347 img_w = img_aspect * IMG->
d_h;
3348 x_pos = (IMG->
d_w - img_w) / 2;
3349 }
else if (screen_aspect < img_aspect) {
3350 img_h = IMG->
d_w / img_aspect;
3351 y_pos = (IMG->
d_h - img_h) / 2;
3372 if (src->
d_w < width && src->
d_h < height) {
3373 float rw = (float)new_w / width;
3374 float rh = (float)new_h / height;
3377 new_h = (int)((
float)new_h / rw);
3380 new_w = (int)((
float)new_w / rh);
3384 while(new_w > width || new_h > height) {
3385 if (new_w > width) {
3386 double m = (double) width / new_w;
3388 new_h = (int) (new_h * m);
3390 double m = (double) height / new_h;
3392 new_w = (int) (new_w * m);
3404 int new_w = 0, new_h = 0;
3411 if (!src || (src->
d_w == width && src->
d_h == height)) {
3428 if (new_w && new_h) {
3448 #ifdef SWITCH_HAVE_YUV 3480 default: fourcc = (uint32_t)FOURCC_ANY;
3489 #ifdef SWITCH_HAVE_YUV 3495 fourcc = switch_img_fmt2fourcc(fmt);
3497 if (fourcc == FOURCC_ANY) {
3526 #ifdef SWITCH_HAVE_YUV 3537 fourcc = switch_img_fmt2fourcc(fmt);
3539 if (fourcc == FOURCC_ANY) {
3547 if (width == 0 || height == 0) {
3567 ret = ConvertToI420(src, 0,
3576 ConvertToARGB(src, 0,
3577 dest->
planes[0], width * 4,
3594 #ifdef SWITCH_HAVE_YUV 3645 #ifdef SWITCH_HAVE_YUV 3697 *yP = (sh - ih) / 2;
3704 *xP = (sw - iw) / 2;
3708 *xP = (sw - iw) / 2;
3709 *yP = (sh - ih) / 2;
3712 *xP = (sw - iw) / 2;
3721 *yP = (sh - ih) / 2;
3735 gdImagePtr gd = NULL;
3739 if (!img)
return NULL;
3743 ext = strrchr(file_name,
'.');
3746 fp = fopen(file_name,
"rb");
3749 if (!strcmp(ext,
".png")) {
3750 gd = gdImageCreateFromPng(fp);
3751 }
else if (!strcmp(ext,
".gif")) {
3752 gd = gdImageCreateFromGif(fp);
3753 }
else if (!strcmp(ext,
".jpg") || !strcmp(ext,
".jpeg")) {
3754 gd = gdImageCreateFromJpeg(fp);
3780 const uint8_t *src_u,
int src_stride_u,
3781 const uint8_t *src_v,
int src_stride_v,
3782 uint8_t *dst_y,
int dst_stride_y,
3783 uint8_t *dst_u,
int dst_stride_u,
3784 uint8_t *dst_v,
int dst_stride_v,
3785 int width,
int height)
3787 #ifdef SWITCH_HAVE_YUV 3788 int ret = I420Copy(src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v,
3789 dst_y, dst_stride_y, dst_u, dst_stride_u, dst_v, dst_stride_v,
3798 uint8_t *dst_planes[],
int dst_stride[],
3799 int width,
int height)
3801 #ifdef SWITCH_HAVE_YUV 3802 int ret = I420Copy(src_planes[
SWITCH_PLANE_Y], src_stride[SWITCH_PLANE_Y],
3805 dst_planes[SWITCH_PLANE_Y], dst_stride[SWITCH_PLANE_Y],
3806 dst_planes[SWITCH_PLANE_U], dst_stride[SWITCH_PLANE_U],
3807 dst_planes[SWITCH_PLANE_V], dst_stride[SWITCH_PLANE_V],
3816 const uint8_t *src_u,
int src_stride_u,
3817 const uint8_t *src_v,
int src_stride_v,
3818 uint8_t *dst_argb,
int dst_stride_argb,
3819 int width,
int height)
3822 #ifdef SWITCH_HAVE_YUV 3823 int ret = I420ToARGB(src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v,
3824 dst_argb, dst_stride_argb, width, height);
3834 uint8_t* dst_argb,
int dst_stride_argb,
3835 int width,
int height)
3837 #ifdef SWITCH_HAVE_YUV 3838 int ret = RGBAToARGB(src_frame, src_stride_frame, dst_argb, dst_stride_argb, width, height);
3848 uint8_t* dst_argb,
int dst_stride_argb,
3849 int width,
int height)
3851 #ifdef SWITCH_HAVE_YUV 3852 int ret = ABGRToARGB(src_frame, src_stride_frame, dst_argb, dst_stride_argb, width, height);
3861 uint8_t* dst_argb,
int dst_stride_argb,
3862 int width,
int height)
3864 #ifdef SWITCH_HAVE_YUV 3865 int ret = ARGBToARGB(src_frame, src_stride_frame, dst_argb, dst_stride_argb, width, height);
3878 if (!filter_str)
return;
#define switch_core_new_memory_pool(p)
Create a new sub memory pool from the core's master pool.
switch_status_t switch_chromakey_create(switch_chromakey_t **ckP)
void vpx_img_free(vpx_image_t *img)
Close an image descriptor.
switch_image_t * cache_img
switch_bool_t use_bgcolor
switch_size_t switch_buffer_len(_In_ switch_buffer_t *buffer)
Get the length of a switch_buffer_t.
switch_status_t switch_chromakey_autocolor(switch_chromakey_t *ck, switch_shade_t autocolor, uint32_t threshold)
#define SWITCH_CHANNEL_LOG
vpx_image_t * vpx_img_alloc(vpx_image_t *img, vpx_img_fmt_t fmt, unsigned int d_w, unsigned int d_h, unsigned int align)
Open a descriptor, allocating storage for the underlying image.
switch_image_t * switch_img_read_from_file(const char *file_name, switch_img_fmt_t img_fmt)
Read an image file to switch_image_t.
static struct pos_el POS_TABLE[]
switch_image_t * switch_img_read_file(const char *file_name)
switch_img_position_t pos
#define SWITCH_IMG_FMT_I444
switch_rgb_color_t auto_color
switch_image_t * switch_chromakey_cache_image(switch_chromakey_t *ck)
switch_status_t switch_chromakey_add_color(switch_chromakey_t *ck, switch_rgb_color_t *color, uint32_t threshold)
switch_status_t switch_buffer_create_dynamic(_Out_ switch_buffer_t **buffer, _In_ switch_size_t blocksize, _In_ switch_size_t start_len, _In_ switch_size_t max_len)
Allocate a new dynamic switch_buffer.
#define SWITCH_IMG_FMT_RGB24
struct data_url_context_s data_url_context_t
switch_image_t * switch_img_write_text_img(int w, int h, switch_bool_t full, const char *text)
switch_rgb_color_t mask[CHROMAKEY_MAX_MASK]
int vpx_img_set_rect(vpx_image_t *img, unsigned int x, unsigned int y, unsigned int w, unsigned int h)
Set the rectangle identifying the displayed portion of the image.
#define SWITCH_IMG_MAX_HEIGHT
switch_status_t switch_chromakey_clear_colors(switch_chromakey_t *ck)
void switch_img_patch_rgb(switch_image_t *IMG, switch_image_t *img, int x, int y, switch_bool_t noalpha)
patch a small img to a big IMG at position x,y
void switch_img_8bit(switch_image_t *img)
switch_status_t switch_chromakey_destroy(switch_chromakey_t **ckP)
#define SWITCH_IMG_FMT_VPXYV12
#define switch_core_strdup(_pool, _todup)
Copy a string using memory allocation from a given pool.
#define switch_split(_data, _delim, _array)
#define SWITCH_IMG_FMT_I440
#define SWITCH_IMG_FMT_RGB555
#define switch_core_destroy_memory_pool(p)
Returns a subpool back to the main pool.
switch_memory_pool_t * pool
void switch_img_rotate_copy(switch_image_t *img, switch_image_t **new_img, switch_image_rotation_mode_t mode)
Representation of a rectangle on a surface.
#define SWITCH_IMG_FMT_YVYU
switch_status_t switch_img_data_url_png(switch_image_t *img, char **urlP)
switch_status_t switch_img_from_raw(switch_image_t **destP, void *src, switch_img_fmt_t fmt, int width, int height)
convert raw memory to switch_img_t
switch_status_t switch_img_write_png(switch_image_t *img, char *file_name)
void switch_img_gray(switch_image_t *img, int x, int y, int w, int h)
#define SWITCH_PLANE_PACKED
void switch_img_copy(switch_image_t *img, switch_image_t **new_img)
Copy image to a new image.
#define SWITCH_IMG_FMT_ARGB
switch_status_t switch_img_fit(switch_image_t **srcP, int width, int height, switch_img_fit_t fit)
#define SWITCH_IMG_FMT_RGB32
void switch_core_video_parse_filter_string(switch_core_video_filter_t *filters, const char *filter_str)
switch_status_t switch_img_data_url(switch_image_t *img, char **urlP, const char *type, int quality)
int switch_snprintf(_Out_z_cap_(len) char *buf, _In_ switch_size_t len, _In_z_ _Printf_format_string_ const char *format,...)
switch_size_t switch_buffer_write(_In_ switch_buffer_t *buffer, _In_bytecount_(datalen) const void *data, _In_ switch_size_t datalen)
Write data into a switch_buffer_t up to the length of datalen.
switch_status_t switch_RGBAToARGB(const uint8_t *src_frame, int src_stride_frame, uint8_t *dst_argb, int dst_stride_argb, int width, int height)
switch_image_t * switch_img_read_png(const char *file_name, switch_img_fmt_t img_fmt)
static void scv_tag(void *buffer, int w, int x, int y, uint8_t n)
#define SWITCH_IMG_FMT_I44416
void switch_img_patch_rect(switch_image_t *IMG, int X, int Y, switch_image_t *img, uint32_t x, uint32_t y, uint32_t w, uint32_t h)
patch part of a small img (x,y,w,h) to a big IMG at position X,Y
switch_img_position_t parse_img_position(const char *name)
void switch_img_free(switch_image_t **img)
Close an image descriptor.
#define SWITCH_IMG_FMT_NONE
switch_shade_t switch_chromakey_str2shade(switch_chromakey_t *ck, const char *shade_name)
void switch_img_txt_handle_destroy(switch_img_txt_handle_t **handleP)
Free a text handle.
void switch_png_free(switch_png_t **pngP)
#define SWITCH_IMG_FMT_YV12
switch_status_t switch_img_letterbox(switch_image_t *img, switch_image_t **imgP, int width, int height, const char *color)
#define SWITCH_IMG_FMT_VPXI420
void switch_img_attenuate(switch_image_t *img)
switch_png_opaque_t * pvt
switch_status_t switch_ARGBToARGB(const uint8_t *src_frame, int src_stride_frame, uint8_t *dst_argb, int dst_stride_argb, int width, int height)
#define SWITCH_IMG_FMT_RGB565_LE
#define SWITCH_IMG_FMT_GD
switch_status_t switch_ABGRToARGB(const uint8_t *src_frame, int src_stride_frame, uint8_t *dst_argb, int dst_stride_argb, int width, int height)
switch_memory_pool_t * pool
#define SWITCH_PATH_SEPARATOR
static int switch_color_dom_cmp(switch_rgb_color_t *c1, switch_rgb_color_t *c2)
if((uint32_t)(unpack->cur - unpack->buf) > unpack->buflen)
switch_status_t switch_img_patch_png(switch_image_t *img, int x, int y, const char *file_name)
#define CHROMAKEY_MAX_MASK
uint32_t thresholds[CHROMAKEY_MAX_MASK]
switch_status_t switch_b64_encode(unsigned char *in, switch_size_t ilen, unsigned char *out, switch_size_t olen)
#define switch_core_alloc(_pool, _mem)
Allocate memory directly from a memory pool.
static void get_dom(switch_shade_t autocolor, switch_rgb_color_t *color, int *domP, int *aP, int *bP)
#define switch_zmalloc(ptr, len)
unsigned char * planes[4]
static int switch_color_distance_multi(switch_rgb_color_t *c1, switch_rgb_color_t *clist, int count, uint32_t *thresholds)
compute distance between a color and a list of colors
void switch_img_rotate(switch_image_t **img, switch_image_rotation_mode_t mode)
Flip the image vertically (top for bottom)
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
switch_byte_t switch_byte_t uint32_t switch_bitpack_mode_t mode
#define SWITCH_IMG_FMT_RGB32_LE
switch_image_t * switch_img_wrap(switch_image_t *img, switch_img_fmt_t fmt, unsigned int d_w, unsigned int d_h, unsigned int align, unsigned char *img_data)
Open a descriptor, using existing storage for the underlying image.
#define SWITCH_IMG_FMT_PLANAR
switch_bool_t switch_core_has_video(void)
static struct fit_el IMG_FIT_TABLE[]
static void switch_img_draw_pixel(switch_image_t *img, int x, int y, switch_rgb_color_t *color)
Draw a pixel on an image.
switch_status_t switch_png_patch_img(switch_png_t *use_png, switch_image_t *img, int x, int y)
uint32_t switch_img_txt_handle_render(switch_img_txt_handle_t *handle, switch_image_t *img, int x, int y, const char *text, const char *font_family, const char *font_color, const char *bgcolor, uint16_t font_size, double angle)
Render text to an img.
switch_status_t switch_img_write_to_file(switch_image_t *img, const char *file_name, int quality)
Write an image file, supported formats png,jpg,bmp,tga,hdr.
int switch_img_set_rect(switch_image_t *img, unsigned int x, unsigned int y, unsigned int w, unsigned int h)
Set the rectangle identifying the displayed portion of the image.
char * switch_url_decode(char *s)
vpx_img_fmt_t switch_img_fmt_t
#define SWITCH_IMG_FMT_I42216
static void switch_img_get_rgb_pixel(switch_image_t *img, switch_rgb_color_t *rgb, int x, int y)
switch_directories SWITCH_GLOBAL_dirs
void switch_img_overlay(switch_image_t *IMG, switch_image_t *img, int x, int y, uint8_t percent)
put a small img over a big IMG at position x,y, with alpha transparency
switch_status_t switch_I420_copy2(uint8_t *src_planes[], int src_stride[], uint8_t *dst_planes[], int dst_stride[], int width, int height)
void switch_img_chromakey(switch_image_t *img, switch_rgb_color_t *mask, int threshold)
chromakey an img, img must be RGBA and return modified img
switch_status_t switch_img_mirror(switch_image_t *src, switch_image_t **destP)
switch_status_t switch_img_txt_handle_create(switch_img_txt_handle_t **handleP, const char *font_family, const char *font_color, const char *bgcolor, uint16_t font_size, double angle, switch_memory_pool_t *pool)
Created a text handle.
static int switch_color_distance_literal(switch_rgb_color_t *c1, switch_rgb_color_t *c2, int distance)
switch_status_t switch_file_exists(const char *filename, switch_memory_pool_t *pool)
void switch_img_add_text(void *buffer, int w, int x, int y, char *s)
void switch_img_fill_noalpha(switch_image_t *img, int x, int y, int w, int h, switch_rgb_color_t *color)
switch_status_t
Common return values.
#define switch_goto_status(_status, _label)
static void init_gradient_table(switch_img_txt_handle_t *handle)
vpx_image_t * vpx_img_wrap(vpx_image_t *img, vpx_img_fmt_t fmt, unsigned int d_w, unsigned int d_h, unsigned int stride_align, unsigned char *img_data)
Open a descriptor, using existing storage for the underlying image.
#define SWITCH_IMG_FMT_ARGB_LE
static uint8_t scv_art[14][16]
switch_status_t switch_png_open(switch_png_t **pngP, const char *file_name)
void switch_chromakey_set_default_threshold(switch_chromakey_t *ck, uint32_t threshold)
switch_image_t * switch_img_alloc(switch_image_t *img, switch_img_fmt_t fmt, unsigned int d_w, unsigned int d_h, unsigned int align)
Open a descriptor, allocating storage for the underlying image.
switch_status_t switch_img_to_raw(switch_image_t *src, void *dest, int stride, switch_img_fmt_t fmt)
convert img to raw format
static switch_bool_t switch_is_file_path(const char *file)
static int get_max(switch_rgb_color_t *c1)
#define SWITCH_IMG_FMT_UYVY
#define SWITCH_IMG_FMT_I420
#define SWITCH_IMG_FMT_I44016
switch_img_fit_t parse_img_fit(const char *name)
#define SWITCH_IMG_FMT_BGR24
uint32_t dft_thresh_squared
switch_status_t switch_img_scale(switch_image_t *src, switch_image_t **destP, int width, int height)
void switch_img_patch_hole(switch_image_t *IMG, switch_image_t *img, int x, int y, switch_image_rect_t *rect)
#define SWITCH_IMG_FMT_RGB555_LE
void switch_img_patch(switch_image_t *IMG, switch_image_t *img, int x, int y)
patch a small img to a big IMG at position x,y
uint32_t switch_u8_get_char(char *s, int *i)
#define SWITCH_IMG_FMT_444A
switch_status_t switch_I420_copy(const uint8_t *src_y, int src_stride_y, const uint8_t *src_u, int src_stride_u, const uint8_t *src_v, int src_stride_v, uint8_t *dst_y, int dst_stride_y, uint8_t *dst_u, int dst_stride_u, uint8_t *dst_v, int dst_stride_v, int width, int height)
I420 to I420 Copy.
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
const char * switch_stristr(const char *instr, const char *str)
#define SWITCH_IMG_FMT_I42016
void switch_color_set_yuv(switch_yuv_color_t *color, const char *str)
Set YUV color with a string.
switch_image_rotation_mode_t
struct fspr_pool_t switch_memory_pool_t
void switch_chromakey_process(switch_chromakey_t *ck, switch_image_t *img)
void * user_priv
The following member may be set by the application to associate data with this image.
void switch_img_sepia(switch_image_t *img, int x, int y, int w, int h)
char * switch_core_sprintf(_In_ switch_memory_pool_t *pool, _In_z_ _Printf_format_string_ const char *fmt,...)
printf-style style printing routine. The data is output to a string allocated from the pool ...
static int switch_color_distance(switch_rgb_color_t *c1, switch_rgb_color_t *c2)
Convert RGB color to YUV.
#define SWITCH_IMG_FMT_RGB565
void switch_img_find_position(switch_img_position_t pos, int sw, int sh, int iw, int ih, int *xP, int *yP)
switch_status_t switch_I420ToARGB(const uint8_t *src_y, int src_stride_y, const uint8_t *src_u, int src_stride_u, const uint8_t *src_v, int src_stride_v, uint8_t *dst_argb, int dst_stride_argb, int width, int height)
I420 to ARGB Convertion.
static int switch_color_distance_cheap(switch_rgb_color_t *c1, switch_rgb_color_t *c2)
void switch_color_set_rgb(switch_rgb_color_t *color, const char *str)
Set RGB color with a string.
switch_size_t switch_buffer_inuse(_In_ switch_buffer_t *buffer)
Get the in use amount of a switch_buffer_t.
enum vpx_img_fmt vpx_img_fmt_t
List of supported image formats.
void switch_buffer_destroy(switch_buffer_t **buffer)
Destroy the buffer.
void * switch_buffer_get_head_pointer(switch_buffer_t *buffer)
#define SWITCH_IMG_FMT_I422
switch_image_t * switch_img_read_png_from_memory(void *mem, size_t size, switch_img_fmt_t img_fmt)
void switch_img_fill(switch_image_t *img, int x, int y, int w, int h, switch_rgb_color_t *color)
Fill image with color.
#define SWITCH_IMG_MAX_WIDTH
switch_rgb_color_t bgcolor
switch_image_t * switch_img_copy_rect(switch_image_t *img, uint32_t x, uint32_t y, uint32_t w, uint32_t h)
Copy part of an image to a new image.
#define SWITCH_IMG_FMT_YUY2
void switch_img_calc_fit(switch_image_t *src, int width, int height, int *new_wP, int *new_hP)
switch_rgb_color_t gradient_table[MAX_GRADIENT]
switch_core_video_filter_t