43 typedef U32BIT HD4Color;
54 static const S_COLOUR trans_col = {0,0,0,0};
60 U32BIT alpha, a_alpha, b_alpha;
62 a_alpha = cola.alfa * weighta;
65 b_alpha = colb.alfa * weightb;
73 colr.alfa = (U8BIT)(b_alpha / (weighta + weightb));
78 b_alpha = colb.alfa * weightb;
82 colr.alfa = (U8BIT)(a_alpha / (weighta + weightb));
86 alpha = a_alpha + b_alpha;
87 colr.red = (U8BIT)((cola.red * a_alpha + colb.red * b_alpha) / alpha);
88 colr.green = (U8BIT)((cola.green * a_alpha + colb.green * b_alpha) / alpha);
89 colr.blue = (U8BIT)((cola.blue * a_alpha + colb.blue * b_alpha) / alpha);
90 colr.alfa = (U8BIT)(alpha / (weighta + weightb));
98 static void copyRgb16Bit( U8BIT *s_buff, U16BIT s_width, U16BIT s_height, HD2Color *d_buff, U16BIT stride )
101 U8BIT red, green, blue;
103 TRACE(TGRAPHICS, (
"(0x%x,%d,%d,0x%x, %d)", s_buff, s_width, s_height, d_buff, stride))
107 for (s_y = 0; s_y != s_height; s_y++)
109 for (s_x = 0; s_x != s_width; s_x++)
113 green = *s_buff >> 4;
117 *d_buff = 0xf000 | (red << 8) | (green << 4) | blue;
124 static void copyArgb16Bit( U8BIT *s_buff, U16BIT s_width, U16BIT s_height, HD2Color *d_buff, U16BIT stride )
127 U8BIT red, green, blue, alpha;
129 TRACE(TGRAPHICS, (
"(0x%x,%d,%d,0x%x)", s_buff, s_width, s_height, d_buff))
133 for (s_y = 0; s_y != s_height; s_y++)
135 for (s_x = 0; s_x != s_width; s_x++)
137 alpha = *s_buff >> 4;
141 green = *s_buff >> 4;
145 *d_buff = (alpha << 12) | (red << 8) | (green << 4) | blue;
152 static void expandRgb16Bit( U8BIT *src_buff, U16BIT src_width, U16BIT src_height,
153 HD2Color *dst_buff, U16BIT dst_width, U16BIT dst_height, U16BIT stride )
156 U32BIT avl_width, avl_height, nxt_height, nxt_width, src_area, tmp_area;
157 U32BIT x_red, x_green, x_blue;
160 TRACE(TGRAPHICS, (
"(0x%x,%d,%d,0x%x,%d,%d)", src_buff, src_width, src_height,
161 dst_buff, dst_width, dst_height))
165 avl_height = dst_height;
166 avl_width = dst_width;
167 src_area = src_width * src_height;
168 for (d_y = 0; d_y != dst_height; d_y++)
170 assert( avl_width == dst_width );
171 if (avl_height < src_height)
173 nxt_height = src_height - avl_height;
174 nxt_row = src_buff + (src_width * 3);
176 for (d_x = 0; d_x != dst_width; d_x++, dst_buff++)
178 if (avl_width < src_width)
180 nxt_width = src_width - avl_width;
182 tmp_area = avl_width * avl_height;
183 x_red = *src_buff * tmp_area;
185 x_green = *src_buff * tmp_area;
187 x_blue = *src_buff * tmp_area;
190 tmp_area = avl_width * nxt_height;
191 x_red += *nxt_row * tmp_area;
193 x_green += *nxt_row * tmp_area;
195 x_blue += *nxt_row * tmp_area;
198 tmp_area = nxt_width * avl_height;
199 x_red += src_buff[0] * tmp_area;
200 x_green += src_buff[1] * tmp_area;
201 x_blue += src_buff[2] * tmp_area;
203 tmp_area = nxt_width * nxt_height;
204 x_red += nxt_row[0] * tmp_area;
205 x_green += nxt_row[1] * tmp_area;
206 x_blue += nxt_row[2] * tmp_area;
212 avl_width = dst_width - nxt_width;
216 x_red = (src_buff[0] * avl_height) + (nxt_row[0] * nxt_height);
217 x_green = (src_buff[1] * avl_height) + (nxt_row[1] * nxt_height);
218 x_blue = (src_buff[2] * avl_height) + (nxt_row[2] * nxt_height);
220 x_green /= src_height;
221 x_blue /= src_height;
222 if (avl_width == src_width)
224 avl_width = dst_width;
230 avl_width -= src_width;
236 *dst_buff = 0xf000 | (x_red << 8) | (x_green << 4) | x_blue;
238 avl_height = dst_height - nxt_height;
244 for (d_x = 0; d_x != dst_width; d_x++, dst_buff++)
246 if (avl_width < src_width)
248 nxt_width = src_width - avl_width;
249 x_red = *nxt_row * avl_width;
251 x_green = *nxt_row * avl_width;
253 x_blue = *nxt_row * avl_width;
256 x_red += nxt_row[0] * nxt_width;
257 x_green += nxt_row[1] * nxt_width;
258 x_blue += nxt_row[2] * nxt_width;
261 x_green /= src_width;
267 avl_width = dst_width - nxt_width;
272 x_red = nxt_row[0] >> 4;
273 x_green = nxt_row[1] >> 4;
274 x_blue = nxt_row[2] >> 4;
275 if (avl_width == src_width)
277 avl_width = dst_width;
282 avl_width -= src_width;
285 *dst_buff = 0xf000 | (x_red << 8) | (x_green << 4) | x_blue;
287 if (avl_height == src_height)
290 avl_height = dst_height;
294 avl_height -= src_height;
301 static void ExpOneRowArgb16(
S_COLOUR *scola, U16BIT src_width, U16BIT dst_width, HD2Color *dst_ptr )
303 S_COLOUR *colend = scola + src_width;
304 HD2Color *end_ptr = dst_ptr + dst_width;
306 U32BIT *pcol0 = (U32BIT*)&color0;
307 U32BIT *pcol1 = (U32BIT*)&color1;
310 weight =(dst_width>>1) - (src_width>>1);
312 colour.alfa = color0.alfa >> 4;
313 colour.red = color0.red >> 4;
314 colour.green = color0.green >> 4;
315 colour.blue = color0.blue >> 4;
318 *dst_ptr = (CalcAlpha(colour.alfa) << 12) | (colour.red << 8) | (colour.green << 4) | colour.blue;
327 while (dst_ptr != end_ptr)
329 if (*pcol0 == *pcol1)
335 colour = MeanArgbCol(color0,weight,color1,dst_width-weight);
341 *dst_ptr = (CalcAlpha(colour.alfa) << 12) | (colour.red << 8) | (colour.green << 4) | colour.blue;
356 colour.alfa = color0.alfa >> 4;
357 colour.red = color0.red >> 4;
358 colour.green = color0.green >> 4;
359 colour.blue = color0.blue >> 4;
360 while (dst_ptr != end_ptr)
362 *dst_ptr = (CalcAlpha(color0.alfa) << 24) | (color0.red << 16) | (color0.green << 8) | color0.blue;
369 static void ExpTwoRowsArgb16(
S_COLOUR *scola, U32BIT weighta,
S_COLOUR *scolb, U32BIT weightb,
370 U16BIT src_width, U16BIT dst_width, HD2Color *dst_ptr )
372 S_COLOUR *colend = scola + src_width;
373 HD2Color *end_ptr = dst_ptr + dst_width;
375 U32BIT *pcol0 = (U32BIT*)&color0;
376 U32BIT *pcol1 = (U32BIT*)&color1;
379 weight =(dst_width>>1) - (src_width>>1);
380 if (*((U32BIT*)scola) == *((U32BIT*)scolb))
386 color0 = MeanArgbCol(*scola,weighta,*scolb,weightb);
388 colour.alfa = color0.alfa >> 4;
389 colour.red = color0.red >> 4;
390 colour.green = color0.green >> 4;
391 colour.blue = color0.blue >> 4;
394 *dst_ptr = (CalcAlpha(colour.alfa) << 12) | (colour.red << 8) | (colour.green << 4) | colour.blue;
402 if (*((U32BIT*)scola) == *((U32BIT*)scolb))
408 color1 = MeanArgbCol(*scola,weighta,*scolb,weightb);
411 while (dst_ptr != end_ptr)
413 if (*pcol0 == *pcol1)
419 colour = MeanArgbCol(color0,weight,color1,dst_width-weight);
425 *dst_ptr = (CalcAlpha(colour.alfa) << 12) | (colour.red << 8) | (colour.green << 4) | colour.blue;
438 if (*((U32BIT*)scola) == *((U32BIT*)scolb))
444 color1 = MeanArgbCol(*scola,weighta,*scolb,weightb);
448 colour.alfa = color0.alfa >> 4;
449 colour.red = color0.red >> 4;
450 colour.green = color0.green >> 4;
451 colour.blue = color0.blue >> 4;
452 while (dst_ptr != end_ptr)
454 *dst_ptr = (CalcAlpha(color0.alfa) << 24) | (color0.red << 16) | (color0.green << 8) | color0.blue;
461 static void expandArgb16Bit( U8BIT *src_buff, U16BIT src_width, U16BIT src_height,
462 HD2Color *dst_buff, U16BIT dst_width, U16BIT dst_height, U16BIT stride )
468 TRACE(TGRAPHICS, (
"(0x%x,%d,%d,0x%x,%d,%d, %d)", src_buff, src_width, src_height,
469 dst_buff, dst_width, dst_height, stride))
471 end_buff = dst_buff + (dst_height*stride);
473 row_b = row_a + src_width;
474 row_end = row_a + (src_height*src_width);
475 weight = (dst_height>>1) - (src_height>>1);
478 ExpOneRowArgb16( row_a, src_width, dst_width, dst_buff );
480 weight -= src_height;
482 while (row_b != row_end)
484 ExpTwoRowsArgb16( row_a, weight, row_b, dst_height - weight, src_width, dst_width, dst_buff );
486 weight -= src_height;
489 weight += dst_height;
494 while (dst_buff != end_buff)
496 ExpOneRowArgb16( row_a, src_width, dst_width, dst_buff );
501 static void shrinkRgb16Bit(
const U8BIT *src_buff, U16BIT src_width, U16BIT src_height,
502 HD2Color *dst_buff, U16BIT dst_width, U16BIT dst_height, U16BIT stride )
504 U32BIT avl_width, avl_height, nxt_height;
505 U32BIT tmp, n_tmp, src_area;
507 U32BIT *tmp_row, *tmp_pix;
508 U16BIT stride_diff = stride - dst_width;
510 TRACE(TGRAPHICS, (
"(0x%x,%d,%d,0x%x,%d,%d)", src_buff, src_width, src_height,
511 dst_buff, dst_width, dst_height))
513 tmp_row = (U32BIT *)OSD_MemAlloc( dst_width *
sizeof(U32BIT) * 3 );
516 avl_height = src_height;
517 avl_width = src_width;
518 src_area = src_width * src_height;
521 for (s_x = 0; s_x != tmp; s_x++)
525 for (s_y = 0; s_y != src_height; s_y++)
528 if (avl_height <= dst_height)
530 U32BIT d_red = 0, d_grn = 0, d_blu = 0;
531 nxt_height = dst_height - avl_height;
533 for (s_x = 0; s_x != src_width; s_x++, src_buff += 3)
535 if (avl_width <= dst_width)
537 tmp = avl_width * avl_height;
538 n_tmp = avl_width * nxt_height;
542 tmp = dst_width * avl_height;
543 n_tmp = dst_width * nxt_height;
545 tmp_pix[0] += src_buff[0] * tmp;
546 tmp_pix[1] += src_buff[1] * tmp;
547 tmp_pix[2] += src_buff[2] * tmp;
548 d_red += src_buff[0] * n_tmp;
549 d_grn += src_buff[1] * n_tmp;
550 d_blu += src_buff[2] * n_tmp;
551 if (avl_width <= dst_width)
553 *dst_buff = 0xf0 | ((*tmp_pix / src_area) >> 4);
557 *dst_buff |= (*tmp_pix / src_area) >> 4;
561 *dst_buff |= (*tmp_pix / src_area) >> 4;
565 if (s_x != src_width - 1)
567 tmp = (dst_width - avl_width) * avl_height;
568 n_tmp = (dst_width - avl_width) * nxt_height;
569 tmp_pix[0] += src_buff[0] * tmp;
570 tmp_pix[1] += src_buff[1] * tmp;
571 tmp_pix[2] += src_buff[2] * tmp;
572 d_red = src_buff[0] * n_tmp;
573 d_grn = src_buff[1] * n_tmp;
574 d_blu = src_buff[2] * n_tmp;
576 avl_width += src_width;
578 avl_width -= dst_width;
580 dst_buff += stride_diff;
581 avl_height += src_height;
586 for (s_x = 0; s_x != src_width; s_x++, src_buff += 3)
588 if (avl_width <= dst_width)
591 tmp = avl_width * dst_height;
592 tmp_pix[0] += src_buff[0] * tmp;
593 tmp_pix[1] += src_buff[1] * tmp;
594 tmp_pix[2] += src_buff[2] * tmp;
596 tmp = (dst_width - avl_width) * dst_height;
597 avl_width += src_width;
602 tmp = dst_width * dst_height;
604 tmp_pix[0] += src_buff[0] * tmp;
605 tmp_pix[1] += src_buff[1] * tmp;
606 tmp_pix[2] += src_buff[2] * tmp;
607 avl_width -= dst_width;
610 avl_height -= dst_height;
612 OSD_MemFree( tmp_row );
616 static void shrinkArgb16Bit(
const U8BIT *src_buff, U16BIT src_width, U16BIT src_height,
617 HD2Color *dst_buff, U16BIT dst_width, U16BIT dst_height, U16BIT stride )
619 U32BIT avl_width, avl_height, nxt_height;
620 U32BIT tmp, n_tmp, src_area;
622 U32BIT *tmp_row, *tmp_pix;
623 U16BIT stride_diff = stride - dst_width;
625 TRACE(TGRAPHICS, (
"(0x%x,%d,%d,0x%x,%d,%d)", src_buff, src_width, src_height,
626 dst_buff, dst_width, dst_height))
628 tmp_row = (U32BIT *)OSD_MemAlloc( dst_width *
sizeof(U32BIT) * 4 );
631 avl_height = src_height;
632 avl_width = src_width;
633 src_area = src_width * src_height;
636 for (s_x = 0; s_x != tmp; s_x++)
640 for (s_y = 0; s_y != src_height; s_y++)
643 if (avl_height <= dst_height)
645 U32BIT d_alf = 0, d_red = 0, d_grn = 0, d_blu = 0;
647 nxt_height = dst_height - avl_height;
648 for (s_x = 0; s_x != src_width; s_x++, src_buff += 4)
650 if (avl_width <= dst_width)
652 tmp = avl_width * avl_height;
653 n_tmp = avl_width * nxt_height;
657 tmp = dst_width * avl_height;
658 n_tmp = dst_width * nxt_height;
660 tmp_pix[0] += src_buff[0] * tmp;
661 tmp_pix[1] += src_buff[1] * tmp;
662 tmp_pix[2] += src_buff[2] * tmp;
663 tmp_pix[3] += src_buff[3] * tmp;
664 d_alf += src_buff[0] * n_tmp;
665 d_red += src_buff[1] * n_tmp;
666 d_grn += src_buff[2] * n_tmp;
667 d_blu += src_buff[3] * n_tmp;
668 if (avl_width <= dst_width)
670 *dst_buff = (*tmp_pix / src_area) >> 4;
674 *dst_buff |= (*tmp_pix / src_area) >> 4;
678 *dst_buff |= (*tmp_pix / src_area) >> 4;
682 *dst_buff |= (*tmp_pix / src_area) >> 4;
686 if (s_x != src_width - 1)
688 tmp = (dst_width - avl_width) * avl_height;
689 n_tmp = (dst_width - avl_width) * nxt_height;
690 tmp_pix[0] += src_buff[0] * tmp;
691 tmp_pix[1] += src_buff[1] * tmp;
692 tmp_pix[2] += src_buff[2] * tmp;
693 tmp_pix[3] += src_buff[3] * tmp;
694 d_alf = src_buff[0] * n_tmp;
695 d_red = src_buff[1] * n_tmp;
696 d_grn = src_buff[2] * n_tmp;
697 d_blu = src_buff[3] * n_tmp;
699 avl_width += src_width;
701 avl_width -= dst_width;
703 dst_buff += stride_diff;
704 avl_height += src_height;
709 for (s_x = 0; s_x != src_width; s_x++, src_buff += 4)
711 if (avl_width <= dst_width)
714 tmp = avl_width * dst_height;
715 tmp_pix[0] += src_buff[0] * tmp;
716 tmp_pix[1] += src_buff[1] * tmp;
717 tmp_pix[2] += src_buff[2] * tmp;
718 tmp_pix[3] += src_buff[3] * tmp;
720 tmp = (dst_width - avl_width) * dst_height;
721 avl_width += src_width;
726 tmp = dst_width * dst_height;
728 tmp_pix[0] += src_buff[0] * tmp;
729 tmp_pix[1] += src_buff[1] * tmp;
730 tmp_pix[2] += src_buff[2] * tmp;
731 tmp_pix[3] += src_buff[3] * tmp;
732 avl_width -= dst_width;
735 avl_height -= dst_height;
737 OSD_MemFree( tmp_row );
744 #if defined(OSD_31_BIT) || defined(OSD_32_BIT) 747 static void copyRgb32Bit( U8BIT *s_buff, U16BIT s_width, U16BIT s_height, HD4Color *d_buff, U16BIT stride )
750 U8BIT red, green, blue;
752 TRACE(TGRAPHICS, (
"(0x%x,%d,%d,0x%x, %d)", s_buff, s_width, s_height, d_buff, stride))
756 for (s_y = 0; s_y != s_height; s_y++)
758 for (s_x = 0; s_x != s_width; s_x++)
766 *d_buff = RGBA( red, green, blue, MAX_ALPHA );
773 static void copyArgb32Bit( U8BIT *s_buff, U16BIT s_width, U16BIT s_height, HD4Color *d_buff, U16BIT stride )
775 U16BIT s_x, s_y, alpha;
776 U8BIT red, green, blue;
778 TRACE(TGRAPHICS, (
"(0x%x,%d,%d,0x%x,%d)", s_buff, s_width, s_height, d_buff, stride))
782 for (s_y = 0; s_y != s_height; s_y++)
784 for (s_x = 0; s_x != s_width; s_x++)
794 *d_buff = RGBA( red, green, blue, CalcAlpha(alpha));
801 static void expandRgb32Bit( U8BIT *src_buff, U16BIT src_width, U16BIT src_height,
802 HD4Color *d_buff, U16BIT dst_width, U16BIT dst_height, U16BIT stride )
804 HD4Color *dst_buff = d_buff;
806 U32BIT avl_width, avl_height, nxt_height, nxt_width, src_area, tmp_area;
807 U32BIT x_red, x_green, x_blue;
810 TRACE(TGRAPHICS, (
"(0x%x,%d,%d,0x%x,%d,%d, %d)", src_buff, src_width, src_height,
811 dst_buff, dst_width, dst_height, stride))
815 avl_height = dst_height;
816 avl_width = dst_width;
817 src_area = src_width * src_height;
818 for (d_y = 0; d_y != dst_height; d_y++)
820 assert( avl_width == dst_width );
821 if (avl_height < src_height)
823 nxt_height = src_height - avl_height;
824 nxt_row = src_buff + (src_width * 3);
826 for (d_x = 0; d_x != dst_width; d_x++, dst_buff++)
828 if (avl_width < src_width)
830 nxt_width = src_width - avl_width;
832 tmp_area = avl_width * avl_height;
833 x_red = *src_buff * tmp_area;
835 x_green = *src_buff * tmp_area;
837 x_blue = *src_buff * tmp_area;
840 tmp_area = avl_width * nxt_height;
841 x_red += *nxt_row * tmp_area;
843 x_green += *nxt_row * tmp_area;
845 x_blue += *nxt_row * tmp_area;
848 tmp_area = nxt_width * avl_height;
849 x_red += src_buff[0] * tmp_area;
850 x_green += src_buff[1] * tmp_area;
851 x_blue += src_buff[2] * tmp_area;
853 tmp_area = nxt_width * nxt_height;
854 x_red += nxt_row[0] * tmp_area;
855 x_green += nxt_row[1] * tmp_area;
856 x_blue += nxt_row[2] * tmp_area;
862 avl_width = dst_width - nxt_width;
866 x_red = (src_buff[0] * avl_height + nxt_row[0] * nxt_height) / src_height;
867 x_green = (src_buff[1] * avl_height + nxt_row[1] * nxt_height) / src_height;
868 x_blue = (src_buff[2] * avl_height + nxt_row[2] * nxt_height) / src_height;
870 if (avl_width == src_width)
872 avl_width = dst_width;
878 avl_width -= src_width;
881 *dst_buff = (MAX_ALPHA << 24) | (x_red << 16) | (x_green << 8) | x_blue;
883 avl_height = dst_height - nxt_height;
889 for (d_x = 0; d_x != dst_width; d_x++, dst_buff++)
891 if (avl_width < src_width)
893 nxt_width = src_width - avl_width;
894 x_red = *nxt_row * avl_width;
896 x_green = *nxt_row * avl_width;
898 x_blue = *nxt_row * avl_width;
901 x_red += nxt_row[0] * nxt_width;
902 x_green += nxt_row[1] * nxt_width;
903 x_blue += nxt_row[2] * nxt_width;
906 x_green /= src_width;
909 *dst_buff = (MAX_ALPHA << 24) | (x_red << 16) | (x_green << 8) | x_blue;
910 avl_width = dst_width - nxt_width;
915 *dst_buff = (MAX_ALPHA << 24) | (nxt_row[0] << 16) | (nxt_row[1] << 8) | nxt_row[2];
916 if (avl_width == src_width)
918 avl_width = dst_width;
923 avl_width -= src_width;
927 if (avl_height == src_height)
930 avl_height = dst_height;
934 avl_height -= src_height;
939 TRACE(TGRAPHICS, (
"dst_buff=0x%x stride=%d", dst_buff, stride))
942 TRACE_UINT(TGRAPHICS, (U32BIT *)d_buff, dst_width * dst_height, dst_width)
946 static void ExpOneRowArgb32(
S_COLOUR *scola, U16BIT src_width, U16BIT dst_width, HD4Color *dst_ptr )
948 S_COLOUR *colend = scola + src_width;
949 HD4Color *end_ptr = dst_ptr + dst_width;
951 U32BIT *pcol0 = (U32BIT*)&color0;
952 U32BIT *pcol1 = (U32BIT*)&color1;
955 weight =(dst_width>>1) - (src_width>>1);
959 *dst_ptr = (CalcAlpha(color0.alfa) << 24) | (color0.red << 16) | (color0.green << 8) | color0.blue;
968 while (dst_ptr != end_ptr)
970 if (*pcol0 == *pcol1)
972 *dst_ptr = (CalcAlpha(color0.alfa) << 24) | (color0.red << 16) | (color0.green << 8) | color0.blue;
976 colour = MeanArgbCol(color0,weight,color1,dst_width-weight);
977 *dst_ptr = (CalcAlpha(colour.alfa) << 24) | (colour.red << 16) | (colour.green << 8) | colour.blue;
993 while (dst_ptr != end_ptr)
995 *dst_ptr = (CalcAlpha(color0.alfa) << 24) | (color0.red << 16) | (color0.green << 8) | color0.blue;
1002 static void ExpTwoRowsArgb32(
S_COLOUR *scola, U32BIT weighta,
S_COLOUR *scolb, U32BIT weightb,
1003 U16BIT src_width, U16BIT dst_width, HD4Color *dst_ptr )
1005 S_COLOUR *colend = scola + src_width;
1006 HD4Color *end_ptr = dst_ptr + dst_width;
1008 U32BIT *pcol0 = (U32BIT*)&color0;
1009 U32BIT *pcol1 = (U32BIT*)&color1;
1012 weight =(dst_width>>1) - (src_width>>1);
1013 if (*((U32BIT*)scola) == *((U32BIT*)scolb))
1019 color0 = MeanArgbCol(*scola,weighta,*scolb,weightb);
1023 *dst_ptr = (CalcAlpha(color0.alfa) << 24) | (color0.red << 16) | (color0.green << 8) | color0.blue;
1025 weight -= src_width;
1029 if (scola != colend)
1031 if (*((U32BIT*)scola) == *((U32BIT*)scolb))
1037 color1 = MeanArgbCol(*scola,weighta,*scolb,weightb);
1039 weight += dst_width;
1040 while (dst_ptr != end_ptr)
1042 if (*pcol0 == *pcol1)
1044 *dst_ptr = (CalcAlpha(color0.alfa) << 24) | (color0.red << 16) | (color0.green << 8) | color0.blue;
1048 colour = MeanArgbCol(color0,weight,color1,dst_width-weight);
1049 *dst_ptr = (CalcAlpha(colour.alfa) << 24) | (colour.red << 16) | (colour.green << 8) | colour.blue;
1052 weight -= src_width;
1055 weight += dst_width;
1059 if (scola == colend)
1063 if (*((U32BIT*)scola) == *((U32BIT*)scolb))
1069 color1 = MeanArgbCol(*scola,weighta,*scolb,weightb);
1073 while (dst_ptr != end_ptr)
1075 *dst_ptr = (CalcAlpha(color0.alfa) << 24) | (color0.red << 16) | (color0.green << 8) | color0.blue;
1077 weight -= src_width;
1082 static void expandArgb32Bit( U8BIT *src_buff, U16BIT src_width, U16BIT src_height,
1083 HD4Color *dst_buff, U16BIT dst_width, U16BIT dst_height, U16BIT stride )
1089 TRACE(TGRAPHICS, (
"(0x%x,%d,%d,0x%x,%d,%d, %d)", src_buff, src_width, src_height,
1090 dst_buff, dst_width, dst_height, stride))
1092 end_buff = dst_buff + (dst_height*stride);
1094 row_b = row_a + src_width;
1095 row_end = row_a + (src_height*src_width);
1096 weight = (dst_height>>1) - (src_height>>1);
1099 ExpOneRowArgb32( row_a, src_width, dst_width, dst_buff );
1101 weight -= src_height;
1106 weight += dst_height;
1108 while (row_b != row_end)
1110 ExpTwoRowsArgb32( row_a, weight, row_b, dst_height - weight, src_width, dst_width, dst_buff );
1112 weight -= src_height;
1115 weight += dst_height;
1121 while (dst_buff != end_buff)
1123 ExpOneRowArgb32( row_a, src_width, dst_width, dst_buff );
1128 static void shrinkRgb32Bit(
const U8BIT *src_buff, U16BIT src_width, U16BIT src_height,
1129 HD4Color *dst_buff, U16BIT dst_width, U16BIT dst_height, U16BIT stride )
1131 U32BIT avl_width, avl_height, nxt_height;
1132 U32BIT tmp, n_tmp, src_area;
1134 U32BIT *tmp_row, *tmp_pix;
1135 U16BIT stride_diff = stride - dst_width;
1137 TRACE(TGRAPHICS, (
"(0x%x,%d,%d,0x%x,%d,%d, %d)", src_buff, src_width, src_height,
1138 dst_buff, dst_width, dst_height, stride))
1140 tmp_row = (U32BIT *)OSD_MemAlloc( dst_width *
sizeof(U32BIT) * 3 );
1143 avl_height = src_height;
1144 avl_width = src_width;
1145 src_area = src_width * src_height;
1147 tmp = dst_width * 3;
1148 for (s_x = 0; s_x != tmp; s_x++)
1152 for (s_y = 0; s_y != src_height; s_y++)
1155 if (avl_height <= dst_height)
1157 U32BIT d_red = 0, d_grn = 0, d_blu = 0;
1158 nxt_height = dst_height - avl_height;
1160 for (s_x = 0; s_x != src_width; s_x++, src_buff += 3)
1162 if (avl_width <= dst_width)
1164 tmp = avl_width * avl_height;
1165 n_tmp = avl_width * nxt_height;
1169 tmp = dst_width * avl_height;
1170 n_tmp = dst_width * nxt_height;
1172 tmp_pix[0] += src_buff[0] * tmp;
1173 tmp_pix[1] += src_buff[1] * tmp;
1174 tmp_pix[2] += src_buff[2] * tmp;
1175 d_red += src_buff[0] * n_tmp;
1176 d_grn += src_buff[1] * n_tmp;
1177 d_blu += src_buff[2] * n_tmp;
1178 if (avl_width <= dst_width)
1180 *dst_buff = (MAX_ALPHA << 8) | (*tmp_pix / src_area);
1184 *dst_buff |= *tmp_pix / src_area;
1188 *dst_buff |= *tmp_pix / src_area;
1192 if (s_x != src_width - 1)
1194 tmp = (dst_width - avl_width) * avl_height;
1195 n_tmp = (dst_width - avl_width) * nxt_height;
1196 tmp_pix[0] += src_buff[0] * tmp;
1197 tmp_pix[1] += src_buff[1] * tmp;
1198 tmp_pix[2] += src_buff[2] * tmp;
1199 d_red = src_buff[0] * n_tmp;
1200 d_grn = src_buff[1] * n_tmp;
1201 d_blu = src_buff[2] * n_tmp;
1203 avl_width += src_width;
1205 avl_width -= dst_width;
1207 dst_buff += stride_diff;
1208 avl_height += src_height;
1213 for (s_x = 0; s_x != src_width; s_x++, src_buff += 3)
1215 if (avl_width <= dst_width)
1218 tmp = avl_width * dst_height;
1219 tmp_pix[0] += src_buff[0] * tmp;
1220 tmp_pix[1] += src_buff[1] * tmp;
1221 tmp_pix[2] += src_buff[2] * tmp;
1223 tmp = (dst_width - avl_width) * dst_height;
1224 avl_width += src_width;
1229 tmp = dst_width * dst_height;
1231 tmp_pix[0] += src_buff[0] * tmp;
1232 tmp_pix[1] += src_buff[1] * tmp;
1233 tmp_pix[2] += src_buff[2] * tmp;
1234 avl_width -= dst_width;
1237 avl_height -= dst_height;
1239 OSD_MemFree( tmp_row );
1243 static void shrinkArgb32Bit(
const U8BIT *src_buff, U16BIT src_width, U16BIT src_height,
1244 HD4Color *dst_buff, U16BIT dst_width, U16BIT dst_height, U16BIT stride )
1246 U32BIT avl_width, avl_height, nxt_height;
1247 U32BIT tmp, n_tmp, src_area;
1249 U32BIT *tmp_row, *tmp_pix;
1250 U16BIT stride_diff = stride - dst_width;
1252 TRACE(TGRAPHICS, (
"(0x%x,%d,%d,0x%x,%d,%d, %d)", src_buff, src_width, src_height,
1253 dst_buff, dst_width, dst_height, stride))
1255 tmp_row = (U32BIT *)OSD_MemAlloc( dst_width *
sizeof(U32BIT) * 4 );
1258 avl_height = src_height;
1259 avl_width = src_width;
1260 src_area = src_width * src_height;
1262 tmp = dst_width * 4;
1263 for (s_x = 0; s_x != tmp; s_x++)
1267 for (s_y = 0; s_y != src_height; s_y++)
1270 if (avl_height <= dst_height)
1272 U32BIT d_alf = 0, d_red = 0, d_grn = 0, d_blu = 0;
1274 nxt_height = dst_height - avl_height;
1275 for (s_x = 0; s_x != src_width; s_x++, src_buff += 4)
1277 if (avl_width <= dst_width)
1279 tmp = avl_width * avl_height;
1280 n_tmp = avl_width * nxt_height;
1284 tmp = dst_width * avl_height;
1285 n_tmp = dst_width * nxt_height;
1287 tmp_pix[0] += src_buff[0] * tmp;
1288 tmp_pix[1] += src_buff[1] * tmp;
1289 tmp_pix[2] += src_buff[2] * tmp;
1290 tmp_pix[3] += src_buff[3] * tmp;
1291 d_alf += src_buff[0] * n_tmp;
1292 d_red += src_buff[1] * n_tmp;
1293 d_grn += src_buff[2] * n_tmp;
1294 d_blu += src_buff[3] * n_tmp;
1295 if (avl_width <= dst_width)
1297 *dst_buff = *tmp_pix / src_area;
1299 *dst_buff = CalcAlpha(*dst_buff);
1304 *dst_buff |= *tmp_pix / src_area;
1308 *dst_buff |= *tmp_pix / src_area;
1312 *dst_buff |= *tmp_pix / src_area;
1316 if (s_x != src_width - 1)
1318 tmp = (dst_width - avl_width) * avl_height;
1319 n_tmp = (dst_width - avl_width) * nxt_height;
1320 tmp_pix[0] += src_buff[0] * tmp;
1321 tmp_pix[1] += src_buff[1] * tmp;
1322 tmp_pix[2] += src_buff[2] * tmp;
1323 tmp_pix[3] += src_buff[3] * tmp;
1324 d_alf = src_buff[0] * n_tmp;
1325 d_red = src_buff[1] * n_tmp;
1326 d_grn = src_buff[2] * n_tmp;
1327 d_blu = src_buff[3] * n_tmp;
1329 avl_width += src_width;
1331 avl_width -= dst_width;
1333 dst_buff += stride_diff;
1334 avl_height += src_height;
1339 for (s_x = 0; s_x != src_width; s_x++, src_buff += 4)
1341 if (avl_width <= dst_width)
1344 tmp = avl_width * dst_height;
1345 tmp_pix[0] += src_buff[0] * tmp;
1346 tmp_pix[1] += src_buff[1] * tmp;
1347 tmp_pix[2] += src_buff[2] * tmp;
1348 tmp_pix[3] += src_buff[3] * tmp;
1350 tmp = (dst_width - avl_width) * dst_height;
1351 avl_width += src_width;
1356 tmp = dst_width * dst_height;
1358 tmp_pix[0] += src_buff[0] * tmp;
1359 tmp_pix[1] += src_buff[1] * tmp;
1360 tmp_pix[2] += src_buff[2] * tmp;
1361 tmp_pix[3] += src_buff[3] * tmp;
1362 avl_width -= dst_width;
1365 avl_height -= dst_height;
1367 OSD_MemFree( tmp_row );
1398 U32BIT i_width, U32BIT i_height,
1399 S_IMAGE *image, U32BIT *pStride )
1405 TRACE(TGRAPHICS, (
"(%d,%d, image=%d,%d s=%d)", s_width, s_height, image->width, image->height, *pStride));
1406 if (!s_width || !s_height)
1408 DBGTRACE(TGRAPHICS,
"ERR: width=%d height=%d", s_width, s_height);
1415 if (hw_handle != NULL)
1419 IF_COL_DEPTH( COLOUR_FORMAT_ARGB4444 )
1422 stride = *pStride >> 1;
1427 #if defined(OSD_31_BIT) || defined(OSD_32_BIT) 1428 stride = *pStride >> 2;
1433 if (i_height == image->height)
1435 if (image->pix_bytes == 3)
1437 IF_COL_DEPTH( COLOUR_FORMAT_ARGB4444 )
1440 copyRgb16Bit( image->col_buff, image->width, image->height,
1441 (HD2Color *)col_buff, stride );
1446 #if defined(OSD_31_BIT) || defined(OSD_32_BIT) 1447 copyRgb32Bit( image->col_buff, image->width, image->height,
1448 (HD4Color *)col_buff, stride );
1455 IF_COL_DEPTH( COLOUR_FORMAT_ARGB4444 )
1458 copyArgb16Bit( image->col_buff, image->width, image->height,
1459 (HD2Color *)col_buff, stride );
1464 #if defined(OSD_31_BIT) || defined(OSD_32_BIT) 1465 copyArgb32Bit( image->col_buff, image->width, image->height,
1466 (HD4Color *)col_buff, stride );
1471 else if (i_height > image->height)
1473 if (image->pix_bytes == 3)
1476 IF_COL_DEPTH( COLOUR_FORMAT_ARGB4444 )
1479 expandRgb16Bit( image->col_buff, image->width, image->height,
1480 (HD2Color *)col_buff, (U16BIT)i_width, (U16BIT)i_height, stride );
1485 #if defined(OSD_31_BIT) || defined(OSD_32_BIT) 1486 expandRgb32Bit( image->col_buff, image->width, image->height,
1487 (HD4Color *)col_buff, (U16BIT)i_width, (U16BIT)i_height, stride );
1493 IF_COL_DEPTH( COLOUR_FORMAT_ARGB4444 )
1496 expandArgb16Bit( image->col_buff, image->width, image->height,
1497 (HD2Color *)col_buff, (U16BIT)i_width, (U16BIT)i_height, stride );
1502 #if defined(OSD_31_BIT) || defined(OSD_32_BIT) 1503 expandArgb32Bit( image->col_buff, image->width, image->height,
1504 (HD4Color *)col_buff, (U16BIT)i_width, (U16BIT)i_height, stride );
1514 if (image->pix_bytes == 3)
1516 IF_COL_DEPTH( COLOUR_FORMAT_ARGB4444 )
1519 shrinkRgb16Bit( image->col_buff, image->width, image->height,
1520 (HD2Color *)col_buff, (U16BIT)i_width, (U16BIT)i_height, stride );
1525 #if defined(OSD_31_BIT) || defined(OSD_32_BIT) 1526 shrinkRgb32Bit( image->col_buff, image->width, image->height,
1527 (HD4Color *)col_buff, (U16BIT)i_width, (U16BIT)i_height, stride );
1533 IF_COL_DEPTH( COLOUR_FORMAT_ARGB4444 )
1536 shrinkArgb16Bit( image->col_buff, image->width, image->height,
1537 (HD2Color *)col_buff, (U16BIT)i_width, (U16BIT)i_height, stride );
1542 #if defined(OSD_31_BIT) || defined(OSD_32_BIT) 1543 shrinkArgb32Bit( image->col_buff, image->width, image->height,
1544 (HD4Color *)col_buff, (U16BIT)i_width, (U16BIT)i_height, stride );
1550 IF_COL_DEPTH( COLOUR_FORMAT_ARGB4444 )
1554 HD2Color *d_buff, *s_buff;
1557 if (s_width > i_width)
1560 s_buff = (HD2Color *)col_buff;
1563 d_buff = s_buff + i_width;
1564 width = s_width - i_width;
1567 if (width > i_width)
1569 memcpy( d_buff, s_buff, i_width << 1 );
1575 memcpy( d_buff, s_buff, width << 1 );
1583 if (s_height > i_height)
1585 s_buff = (HD2Color *)col_buff;
1586 d_buff = s_buff + (i_height * stride);
1587 height = s_height - i_height;
1590 memcpy( d_buff, s_buff, s_width << 1 );
1600 #if defined(OSD_31_BIT) || defined(OSD_32_BIT) 1602 HD4Color *d_buff, *s_buff;
1605 if (s_width > i_width)
1608 s_buff = (HD4Color *)col_buff;
1611 d_buff = s_buff + i_width;
1612 width = s_width - i_width;
1615 if (width > i_width)
1617 memcpy( d_buff, s_buff, i_width << 2 );
1623 memcpy( d_buff, s_buff, width << 2 );
1631 if (s_height > i_height)
1633 s_buff = (HD4Color *)col_buff;
1634 d_buff = s_buff + (i_height * stride);
1635 height = s_height - i_height;
1638 memcpy( d_buff, s_buff, s_width << 2 );
1650 TRACE(TGRAPHICS, (
"rtn=0x%x", hw_handle))
void * STB_OSDMhegCreateSurface(U16BIT width, U16BIT height, BOOLEAN init, U32BIT colour)
Creates a hardware surface on which MHEG5 engine will draw an individual MHEG object. At its basic the function can just allocate the buffer to be returned by STB_OSDMhegLockBuffer(). It's size being: (width * height * bytes_per_pixel) Also, when 'init' is TRUE, function initialises surface buffer to the specified colour. For pixel colour format of less than four bytes, use least significant bits of 'colour'.
The functions in this file are OPTIONALLY provided by Receiver Platform *.
void * STB_OSDMhegLockBuffer(void *surface, U32BIT *pPitch)
Converts hardware surface handle returned by STB_OSDMhegCreateSurface() to buffer address that the en...
void * DEC_OSDCreateBmpSurf(U32BIT s_width, U32BIT s_height, U32BIT i_width, U32BIT i_height, S_IMAGE *image, U32BIT *pStride)
This creates a hardware surface of size using STB_OSDMhegCreateSurface() with s_width and s_height...
Graphics functions required by the HD MHEG5 engine. All references to colour used in these functions ...
void STB_OSDMhegUnlockBuffer(void *surface)
This function informs HW that MHEG5 is finished writing to the buffer.