MHEG5  18.9.0
MHEG5 Documentation
mg_bitmap.c
Go to the documentation of this file.
1 /*******************************************************************************
2  * Copyright © 2014 The DTVKit Open Software Foundation Ltd (www.dtvkit.org)
3  * Copyright © 2009 Ocean Blue Software Ltd
4  *
5  * This file is part of a DTVKit Software Component
6  * You are permitted to copy, modify or distribute this file subject to the terms
7  * of the DTVKit 1.0 Licence which can be found in licence.txt or at www.dtvkit.org
8  *
9  * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
10  * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES
11  * OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
12  *
13  * If you or your organisation is not a member of DTVKit then you have access
14  * to this source code outside of the terms of the licence agreement
15  * and you are expected to delete this and any associated files immediately.
16  * Further information on DTVKit, membership and terms can be found at www.dtvkit.org
17  *******************************************************************************/
25 /*---includes for this file--------------------------------------------------*/
26 #include <stdlib.h>
27 #include <string.h> /* memset */
28 #include <stdio.h>
29 
30 /* OBS header files */
31 #include "glue_memory.h"
32 #include "glue_debug.h"
33 #include "osd_utils.h"
34 #include "mg_ctxt.h"
35 #include "stb_osd.h"
36 #include "decoder.h"
37 
38 /*---constant definitions for this file--------------------------------------*/
39 
40 
41 /*---local typedef structs for this file-------------------------------------*/
42 
43 typedef U32BIT HD4Color;
44 
45 typedef struct {
50 } S_COLOUR;
51 
52 /*---local (static) variable declarations for this file----------------------*/
53 
54 static const S_COLOUR trans_col = {0,0,0,0};
55 
56 /*--- local function definitions---------------------------------------------*/
57 
58 S_COLOUR MeanArgbCol(S_COLOUR cola, U32BIT weighta, S_COLOUR colb, U32BIT weightb)
59 {
60  U32BIT alpha, a_alpha, b_alpha;
61  S_COLOUR colr;
62  a_alpha = cola.alfa * weighta;
63  if (a_alpha == 0)
64  {
65  b_alpha = colb.alfa * weightb;
66  if (b_alpha == 0)
67  {
68  colr = trans_col;
69  }
70  else
71  {
72  colr = colb;
73  colr.alfa = (U8BIT)(b_alpha / (weighta + weightb));
74  }
75  }
76  else
77  {
78  b_alpha = colb.alfa * weightb;
79  if (b_alpha == 0)
80  {
81  colr = cola;
82  colr.alfa = (U8BIT)(a_alpha / (weighta + weightb));
83  }
84  else
85  {
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));
91  }
92  }
93  return colr;
94 }
95 
96 #ifdef OSD_16_BIT
97 
98 static void copyRgb16Bit( U8BIT *s_buff, U16BIT s_width, U16BIT s_height, HD2Color *d_buff, U16BIT stride )
99 {
100  U16BIT s_x, s_y;
101  U8BIT red, green, blue;
102 
103  TRACE(TGRAPHICS, ("(0x%x,%d,%d,0x%x, %d)", s_buff, s_width, s_height, d_buff, stride))
104 
105  stride -= s_width; /* reduce 'stride' by the width */
106 
107  for (s_y = 0; s_y != s_height; s_y++)
108  {
109  for (s_x = 0; s_x != s_width; s_x++)
110  {
111  red = *s_buff >> 4;
112  s_buff++;
113  green = *s_buff >> 4;
114  s_buff++;
115  blue = *s_buff >> 4;
116  s_buff++;
117  *d_buff = 0xf000 | (red << 8) | (green << 4) | blue;
118  d_buff++;
119  }
120  d_buff += stride;
121  }
122 }
123 
124 static void copyArgb16Bit( U8BIT *s_buff, U16BIT s_width, U16BIT s_height, HD2Color *d_buff, U16BIT stride )
125 {
126  U16BIT s_x, s_y;
127  U8BIT red, green, blue, alpha;
128 
129  TRACE(TGRAPHICS, ("(0x%x,%d,%d,0x%x)", s_buff, s_width, s_height, d_buff))
130 
131  stride -= s_width; /* reduce 'stride' by the width */
132 
133  for (s_y = 0; s_y != s_height; s_y++)
134  {
135  for (s_x = 0; s_x != s_width; s_x++)
136  {
137  alpha = *s_buff >> 4;
138  s_buff++;
139  red = *s_buff >> 4;
140  s_buff++;
141  green = *s_buff >> 4;
142  s_buff++;
143  blue = *s_buff >> 4;
144  s_buff++;
145  *d_buff = (alpha << 12) | (red << 8) | (green << 4) | blue;
146  d_buff++;
147  }
148  d_buff += stride;
149  }
150 }
151 
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 )
154 {
155  U8BIT *nxt_row;
156  U32BIT avl_width, avl_height, nxt_height, nxt_width, src_area, tmp_area;
157  U32BIT x_red, x_green, x_blue;
158  U16BIT d_x, d_y;
159 
160  TRACE(TGRAPHICS, ("(0x%x,%d,%d,0x%x,%d,%d)", src_buff, src_width, src_height,
161  dst_buff, dst_width, dst_height))
162 
163  stride -= dst_width; /* reduce 'stride' by the width */
164 
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++)
169  {
170  assert( avl_width == dst_width );
171  if (avl_height < src_height)
172  {
173  nxt_height = src_height - avl_height;
174  nxt_row = src_buff + (src_width * 3);
175  /* dst row has contrib from 2 src rows */
176  for (d_x = 0; d_x != dst_width; d_x++, dst_buff++)
177  {
178  if (avl_width < src_width)
179  {
180  nxt_width = src_width - avl_width;
181 
182  tmp_area = avl_width * avl_height;
183  x_red = *src_buff * tmp_area;
184  src_buff++;
185  x_green = *src_buff * tmp_area;
186  src_buff++;
187  x_blue = *src_buff * tmp_area;
188  src_buff++;
189 
190  tmp_area = avl_width * nxt_height;
191  x_red += *nxt_row * tmp_area;
192  nxt_row++;
193  x_green += *nxt_row * tmp_area;
194  nxt_row++;
195  x_blue += *nxt_row * tmp_area;
196  nxt_row++;
197 
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;
202 
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;
207 
208  x_red /= src_area;
209  x_green /= src_area;
210  x_blue /= src_area;
211 
212  avl_width = dst_width - nxt_width;
213  }
214  else
215  {
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);
219  x_red /= src_height;
220  x_green /= src_height;
221  x_blue /= src_height;
222  if (avl_width == src_width)
223  {
224  avl_width = dst_width;
225  src_buff += 3;
226  nxt_row += 3;
227  }
228  else
229  {
230  avl_width -= src_width;
231  }
232  }
233  x_red >>= 4;
234  x_green >>= 4;
235  x_blue >>= 4;
236  *dst_buff = 0xf000 | (x_red << 8) | (x_green << 4) | x_blue;
237  }
238  avl_height = dst_height - nxt_height;
239  }
240  else
241  {
242  /* dst row has one src row */
243  nxt_row = src_buff;
244  for (d_x = 0; d_x != dst_width; d_x++, dst_buff++)
245  {
246  if (avl_width < src_width)
247  {
248  nxt_width = src_width - avl_width;
249  x_red = *nxt_row * avl_width;
250  nxt_row++;
251  x_green = *nxt_row * avl_width;
252  nxt_row++;
253  x_blue = *nxt_row * avl_width;
254  nxt_row++;
255 
256  x_red += nxt_row[0] * nxt_width;
257  x_green += nxt_row[1] * nxt_width;
258  x_blue += nxt_row[2] * nxt_width;
259 
260  x_red /= src_width;
261  x_green /= src_width;
262  x_blue /= src_width;
263 
264  x_red >>= 4;
265  x_green >>= 4;
266  x_blue >>= 4;
267  avl_width = dst_width - nxt_width;
268  }
269  else
270  {
271  /* straight copy */
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)
276  {
277  avl_width = dst_width;
278  nxt_row += 3;
279  }
280  else
281  {
282  avl_width -= src_width;
283  }
284  }
285  *dst_buff = 0xf000 | (x_red << 8) | (x_green << 4) | x_blue;
286  }
287  if (avl_height == src_height)
288  {
289  src_buff = nxt_row;
290  avl_height = dst_height;
291  }
292  else
293  {
294  avl_height -= src_height;
295  }
296  }
297  dst_buff += stride; /* move on by diff in width and stride */
298  }
299 }
300 
301 static void ExpOneRowArgb16( S_COLOUR *scola, U16BIT src_width, U16BIT dst_width, HD2Color *dst_ptr )
302 {
303  S_COLOUR *colend = scola + src_width;
304  HD2Color *end_ptr = dst_ptr + dst_width;
305  S_COLOUR colour, color0, color1;
306  U32BIT *pcol0 = (U32BIT*)&color0;
307  U32BIT *pcol1 = (U32BIT*)&color1;
308  S32BIT weight;
309 
310  weight =(dst_width>>1) - (src_width>>1);
311  color0 = *scola;
312  colour.alfa = color0.alfa >> 4;
313  colour.red = color0.red >> 4;
314  colour.green = color0.green >> 4;
315  colour.blue = color0.blue >> 4;
316  while (weight > 0)
317  {
318  *dst_ptr = (CalcAlpha(colour.alfa) << 12) | (colour.red << 8) | (colour.green << 4) | colour.blue;
319  dst_ptr++;
320  weight -= src_width;
321  }
322  scola++;
323  if (scola != colend)
324  {
325  color1 = *scola;
326  weight += dst_width;
327  while (dst_ptr != end_ptr)
328  {
329  if (*pcol0 == *pcol1)
330  {
331  colour = color0;
332  }
333  else
334  {
335  colour = MeanArgbCol(color0,weight,color1,dst_width-weight);
336  }
337  colour.alfa >>= 4;
338  colour.red >>= 4;
339  colour.green >>= 4;
340  colour.blue >>= 4;
341  *dst_ptr = (CalcAlpha(colour.alfa) << 12) | (colour.red << 8) | (colour.green << 4) | colour.blue;
342  dst_ptr++;
343  weight -= src_width;
344  if (weight < 0)
345  {
346  weight += dst_width;
347  color0 = color1;
348  scola++;
349  if (scola == colend)
350  {
351  break;
352  }
353  color1 = *scola;
354  }
355  }
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)
361  {
362  *dst_ptr = (CalcAlpha(color0.alfa) << 24) | (color0.red << 16) | (color0.green << 8) | color0.blue;
363  dst_ptr++;
364  weight -= src_width;
365  }
366  }
367 }
368 
369 static void ExpTwoRowsArgb16( S_COLOUR *scola, U32BIT weighta, S_COLOUR *scolb, U32BIT weightb,
370  U16BIT src_width, U16BIT dst_width, HD2Color *dst_ptr )
371 {
372  S_COLOUR *colend = scola + src_width;
373  HD2Color *end_ptr = dst_ptr + dst_width;
374  S_COLOUR colour, color0, color1;
375  U32BIT *pcol0 = (U32BIT*)&color0;
376  U32BIT *pcol1 = (U32BIT*)&color1;
377  S32BIT weight;
378 
379  weight =(dst_width>>1) - (src_width>>1);
380  if (*((U32BIT*)scola) == *((U32BIT*)scolb))
381  {
382  color0 = *scola;
383  }
384  else
385  {
386  color0 = MeanArgbCol(*scola,weighta,*scolb,weightb);
387  }
388  colour.alfa = color0.alfa >> 4;
389  colour.red = color0.red >> 4;
390  colour.green = color0.green >> 4;
391  colour.blue = color0.blue >> 4;
392  while (weight > 0)
393  {
394  *dst_ptr = (CalcAlpha(colour.alfa) << 12) | (colour.red << 8) | (colour.green << 4) | colour.blue;
395  dst_ptr++;
396  weight -= src_width;
397  }
398  scola++;
399  scolb++;
400  if (scola != colend)
401  {
402  if (*((U32BIT*)scola) == *((U32BIT*)scolb))
403  {
404  color1 = *scola;
405  }
406  else
407  {
408  color1 = MeanArgbCol(*scola,weighta,*scolb,weightb);
409  }
410  weight += dst_width;
411  while (dst_ptr != end_ptr)
412  {
413  if (*pcol0 == *pcol1)
414  {
415  colour = color0;
416  }
417  else
418  {
419  colour = MeanArgbCol(color0,weight,color1,dst_width-weight);
420  }
421  colour.alfa >>= 4;
422  colour.red >>= 4;
423  colour.green >>= 4;
424  colour.blue >>= 4;
425  *dst_ptr = (CalcAlpha(colour.alfa) << 12) | (colour.red << 8) | (colour.green << 4) | colour.blue;
426  dst_ptr++;
427  weight -= src_width;
428  if (weight < 0)
429  {
430  weight += dst_width;
431  color0 = color1;
432  scola++;
433  scolb++;
434  if (scola == colend)
435  {
436  break;
437  }
438  if (*((U32BIT*)scola) == *((U32BIT*)scolb))
439  {
440  color1 = *scola;
441  }
442  else
443  {
444  color1 = MeanArgbCol(*scola,weighta,*scolb,weightb);
445  }
446  }
447  }
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)
453  {
454  *dst_ptr = (CalcAlpha(color0.alfa) << 24) | (color0.red << 16) | (color0.green << 8) | color0.blue;
455  dst_ptr++;
456  weight -= src_width;
457  }
458  }
459 }
460 
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 )
463 {
464  S_COLOUR *row_a, *row_b, *row_end;
465  HD2Color *end_buff;
466  S32BIT weight;
467 
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))
470 
471  end_buff = dst_buff + (dst_height*stride);
472  row_a = (S_COLOUR*)src_buff;
473  row_b = row_a + src_width;
474  row_end = row_a + (src_height*src_width);
475  weight = (dst_height>>1) - (src_height>>1);
476  while (weight > 0)
477  {
478  ExpOneRowArgb16( row_a, src_width, dst_width, dst_buff );
479  dst_buff += stride;
480  weight -= src_height;
481  }
482  while (row_b != row_end)
483  {
484  ExpTwoRowsArgb16( row_a, weight, row_b, dst_height - weight, src_width, dst_width, dst_buff );
485  dst_buff += stride;
486  weight -= src_height;
487  if (weight < 0)
488  {
489  weight += dst_height;
490  row_a = row_b;
491  row_b += src_width;
492  }
493  }
494  while (dst_buff != end_buff)
495  {
496  ExpOneRowArgb16( row_a, src_width, dst_width, dst_buff );
497  dst_buff += stride;
498  }
499 }
500 
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 )
503 {
504  U32BIT avl_width, avl_height, nxt_height;
505  U32BIT tmp, n_tmp, src_area;
506  U16BIT s_x, s_y;
507  U32BIT *tmp_row, *tmp_pix;
508  U16BIT stride_diff = stride - dst_width;
509 
510  TRACE(TGRAPHICS, ("(0x%x,%d,%d,0x%x,%d,%d)", src_buff, src_width, src_height,
511  dst_buff, dst_width, dst_height))
512 
513  tmp_row = (U32BIT *)OSD_MemAlloc( dst_width * sizeof(U32BIT) * 3 );
514  if (tmp_row)
515  {
516  avl_height = src_height;
517  avl_width = src_width;
518  src_area = src_width * src_height;
519  nxt_height = 0;
520  tmp = dst_width * 3;
521  for (s_x = 0; s_x != tmp; s_x++)
522  {
523  tmp_row[s_x] = 0;
524  }
525  for (s_y = 0; s_y != src_height; s_y++)
526  {
527  tmp_pix = tmp_row;
528  if (avl_height <= dst_height)
529  {
530  U32BIT d_red = 0, d_grn = 0, d_blu = 0;
531  nxt_height = dst_height - avl_height;
532  /* src row contribs to 2 dst rows */
533  for (s_x = 0; s_x != src_width; s_x++, src_buff += 3)
534  {
535  if (avl_width <= dst_width)
536  {
537  tmp = avl_width * avl_height;
538  n_tmp = avl_width * nxt_height;
539  }
540  else
541  {
542  tmp = dst_width * avl_height;
543  n_tmp = dst_width * nxt_height;
544  }
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)
552  {
553  *dst_buff = 0xf0 | ((*tmp_pix / src_area) >> 4);
554  *tmp_pix = d_red;
555  *dst_buff <<= 4;
556  tmp_pix++;
557  *dst_buff |= (*tmp_pix / src_area) >> 4;
558  *tmp_pix = d_grn;
559  *dst_buff <<= 4;
560  tmp_pix++;
561  *dst_buff |= (*tmp_pix / src_area) >> 4;
562  *tmp_pix = d_blu;
563  dst_buff++;
564  tmp_pix++;
565  if (s_x != src_width - 1)
566  {
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;
575  }
576  avl_width += src_width;
577  }
578  avl_width -= dst_width;
579  }
580  dst_buff += stride_diff;
581  avl_height += src_height;
582  }
583  else
584  {
585  /* src row contributes to one dst row */
586  for (s_x = 0; s_x != src_width; s_x++, src_buff += 3)
587  {
588  if (avl_width <= dst_width)
589  {
590  /* src pixel contributes to two dst pixels */
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;
595  tmp_pix += 3;
596  tmp = (dst_width - avl_width) * dst_height;
597  avl_width += src_width;
598  }
599  else
600  {
601  /* src pixel contributes to one dst pixel */
602  tmp = dst_width * dst_height;
603  }
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;
608  }
609  }
610  avl_height -= dst_height;
611  }
612  OSD_MemFree( tmp_row );
613  }
614 }
615 
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 )
618 {
619  U32BIT avl_width, avl_height, nxt_height;
620  U32BIT tmp, n_tmp, src_area;
621  U16BIT s_x, s_y;
622  U32BIT *tmp_row, *tmp_pix;
623  U16BIT stride_diff = stride - dst_width;
624 
625  TRACE(TGRAPHICS, ("(0x%x,%d,%d,0x%x,%d,%d)", src_buff, src_width, src_height,
626  dst_buff, dst_width, dst_height))
627 
628  tmp_row = (U32BIT *)OSD_MemAlloc( dst_width * sizeof(U32BIT) * 4 );
629  if (tmp_row)
630  {
631  avl_height = src_height;
632  avl_width = src_width;
633  src_area = src_width * src_height;
634  nxt_height = 0;
635  tmp = dst_width * 4;
636  for (s_x = 0; s_x != tmp; s_x++)
637  {
638  tmp_row[s_x] = 0;
639  }
640  for (s_y = 0; s_y != src_height; s_y++)
641  {
642  tmp_pix = tmp_row;
643  if (avl_height <= dst_height)
644  {
645  U32BIT d_alf = 0, d_red = 0, d_grn = 0, d_blu = 0;
646  /* src row contribs to 2 dst rows */
647  nxt_height = dst_height - avl_height;
648  for (s_x = 0; s_x != src_width; s_x++, src_buff += 4)
649  {
650  if (avl_width <= dst_width)
651  {
652  tmp = avl_width * avl_height;
653  n_tmp = avl_width * nxt_height;
654  }
655  else
656  {
657  tmp = dst_width * avl_height;
658  n_tmp = dst_width * nxt_height;
659  }
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)
669  {
670  *dst_buff = (*tmp_pix / src_area) >> 4;
671  *tmp_pix = d_alf;
672  *dst_buff <<= 4;
673  tmp_pix++;
674  *dst_buff |= (*tmp_pix / src_area) >> 4;
675  *tmp_pix = d_red;
676  *dst_buff <<= 4;
677  tmp_pix++;
678  *dst_buff |= (*tmp_pix / src_area) >> 4;
679  *tmp_pix = d_grn;
680  *dst_buff <<= 4;
681  tmp_pix++;
682  *dst_buff |= (*tmp_pix / src_area) >> 4;
683  *tmp_pix = d_blu;
684  dst_buff++;
685  tmp_pix++;
686  if (s_x != src_width - 1)
687  {
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;
698  }
699  avl_width += src_width;
700  }
701  avl_width -= dst_width;
702  }
703  dst_buff += stride_diff;
704  avl_height += src_height;
705  }
706  else
707  {
708  /* src row contributes to one dst row */
709  for (s_x = 0; s_x != src_width; s_x++, src_buff += 4)
710  {
711  if (avl_width <= dst_width)
712  {
713  /* src pixel contributes to two dst pixels */
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;
719  tmp_pix += 4;
720  tmp = (dst_width - avl_width) * dst_height;
721  avl_width += src_width;
722  }
723  else
724  {
725  /* src pixel contributes to one dst pixel */
726  tmp = dst_width * dst_height;
727  }
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;
733  }
734  }
735  avl_height -= dst_height;
736  }
737  OSD_MemFree( tmp_row );
738  }
739 }
740 
741 #endif /*OSD_16_BIT*/
742 
743 
744 #if defined(OSD_31_BIT) || defined(OSD_32_BIT)
745 /* '31' bit == ST based platforms */
746 
747 static void copyRgb32Bit( U8BIT *s_buff, U16BIT s_width, U16BIT s_height, HD4Color *d_buff, U16BIT stride )
748 {
749  U16BIT s_x, s_y;
750  U8BIT red, green, blue;
751 
752  TRACE(TGRAPHICS, ("(0x%x,%d,%d,0x%x, %d)", s_buff, s_width, s_height, d_buff, stride))
753 
754  stride -= s_width; /* reduce 'stride' by the width */
755 
756  for (s_y = 0; s_y != s_height; s_y++)
757  {
758  for (s_x = 0; s_x != s_width; s_x++)
759  {
760  red = *s_buff;
761  s_buff++;
762  green = *s_buff;
763  s_buff++;
764  blue = *s_buff;
765  s_buff++;
766  *d_buff = RGBA( red, green, blue, MAX_ALPHA );
767  d_buff++;
768  }
769  d_buff += stride; /* move on by diff in width and stride */
770  }
771 }
772 
773 static void copyArgb32Bit( U8BIT *s_buff, U16BIT s_width, U16BIT s_height, HD4Color *d_buff, U16BIT stride )
774 {
775  U16BIT s_x, s_y, alpha;
776  U8BIT red, green, blue;
777 
778  TRACE(TGRAPHICS, ("(0x%x,%d,%d,0x%x,%d)", s_buff, s_width, s_height, d_buff, stride))
779 
780  stride -= s_width; /* reduce 'stride' by the width */
781 
782  for (s_y = 0; s_y != s_height; s_y++)
783  {
784  for (s_x = 0; s_x != s_width; s_x++)
785  {
786  alpha = *s_buff;
787  s_buff++;
788  red = *s_buff;
789  s_buff++;
790  green = *s_buff;
791  s_buff++;
792  blue = *s_buff;
793  s_buff++;
794  *d_buff = RGBA( red, green, blue, CalcAlpha(alpha));
795  d_buff++;
796  }
797  d_buff += stride; /* move on by diff in width and stride */
798  }
799 }
800 
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 )
803 {
804  HD4Color *dst_buff = d_buff;
805  U8BIT *nxt_row;
806  U32BIT avl_width, avl_height, nxt_height, nxt_width, src_area, tmp_area;
807  U32BIT x_red, x_green, x_blue;
808  U16BIT d_x, d_y;
809 
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))
812 
813  stride -= dst_width; /* reduce 'stride' by the width */
814 
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++)
819  {
820  assert( avl_width == dst_width );
821  if (avl_height < src_height)
822  {
823  nxt_height = src_height - avl_height;
824  nxt_row = src_buff + (src_width * 3);
825  /* dst row has contrib from 2 src rows */
826  for (d_x = 0; d_x != dst_width; d_x++, dst_buff++)
827  {
828  if (avl_width < src_width)
829  {
830  nxt_width = src_width - avl_width;
831 
832  tmp_area = avl_width * avl_height;
833  x_red = *src_buff * tmp_area;
834  src_buff++;
835  x_green = *src_buff * tmp_area;
836  src_buff++;
837  x_blue = *src_buff * tmp_area;
838  src_buff++;
839 
840  tmp_area = avl_width * nxt_height;
841  x_red += *nxt_row * tmp_area;
842  nxt_row++;
843  x_green += *nxt_row * tmp_area;
844  nxt_row++;
845  x_blue += *nxt_row * tmp_area;
846  nxt_row++;
847 
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;
852 
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;
857 
858  x_red /= src_area;
859  x_green /= src_area;
860  x_blue /= src_area;
861 
862  avl_width = dst_width - nxt_width;
863  }
864  else
865  {
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;
869 
870  if (avl_width == src_width)
871  {
872  avl_width = dst_width;
873  src_buff += 3;
874  nxt_row += 3;
875  }
876  else
877  {
878  avl_width -= src_width;
879  }
880  }
881  *dst_buff = (MAX_ALPHA << 24) | (x_red << 16) | (x_green << 8) | x_blue;
882  }
883  avl_height = dst_height - nxt_height;
884  }
885  else
886  {
887  /* dst row has one src row */
888  nxt_row = src_buff;
889  for (d_x = 0; d_x != dst_width; d_x++, dst_buff++)
890  {
891  if (avl_width < src_width)
892  {
893  nxt_width = src_width - avl_width;
894  x_red = *nxt_row * avl_width;
895  nxt_row++;
896  x_green = *nxt_row * avl_width;
897  nxt_row++;
898  x_blue = *nxt_row * avl_width;
899  nxt_row++;
900 
901  x_red += nxt_row[0] * nxt_width;
902  x_green += nxt_row[1] * nxt_width;
903  x_blue += nxt_row[2] * nxt_width;
904 
905  x_red /= src_width;
906  x_green /= src_width;
907  x_blue /= src_width;
908 
909  *dst_buff = (MAX_ALPHA << 24) | (x_red << 16) | (x_green << 8) | x_blue;
910  avl_width = dst_width - nxt_width;
911  }
912  else
913  {
914  /* straight copy */
915  *dst_buff = (MAX_ALPHA << 24) | (nxt_row[0] << 16) | (nxt_row[1] << 8) | nxt_row[2];
916  if (avl_width == src_width)
917  {
918  avl_width = dst_width;
919  nxt_row += 3;
920  }
921  else
922  {
923  avl_width -= src_width;
924  }
925  }
926  }
927  if (avl_height == src_height)
928  {
929  src_buff = nxt_row;
930  avl_height = dst_height;
931  }
932  else
933  {
934  avl_height -= src_height;
935  }
936  }
937  dst_buff += stride; /* move on by diff in width and stride */
938  }
939  TRACE(TGRAPHICS, ("dst_buff=0x%x stride=%d", dst_buff, stride))
940  if (dst_width <= 16)
941  {
942  TRACE_UINT(TGRAPHICS, (U32BIT *)d_buff, dst_width * dst_height, dst_width)
943  }
944 }
945 
946 static void ExpOneRowArgb32( S_COLOUR *scola, U16BIT src_width, U16BIT dst_width, HD4Color *dst_ptr )
947 {
948  S_COLOUR *colend = scola + src_width;
949  HD4Color *end_ptr = dst_ptr + dst_width;
950  S_COLOUR colour, color0, color1;
951  U32BIT *pcol0 = (U32BIT*)&color0;
952  U32BIT *pcol1 = (U32BIT*)&color1;
953  S32BIT weight;
954 
955  weight =(dst_width>>1) - (src_width>>1);
956  color0 = *scola;
957  while (weight > 0)
958  {
959  *dst_ptr = (CalcAlpha(color0.alfa) << 24) | (color0.red << 16) | (color0.green << 8) | color0.blue;
960  dst_ptr++;
961  weight -= src_width;
962  }
963  scola++;
964  if (scola != colend)
965  {
966  color1 = *scola;
967  weight += dst_width;
968  while (dst_ptr != end_ptr)
969  {
970  if (*pcol0 == *pcol1)
971  {
972  *dst_ptr = (CalcAlpha(color0.alfa) << 24) | (color0.red << 16) | (color0.green << 8) | color0.blue;
973  }
974  else
975  {
976  colour = MeanArgbCol(color0,weight,color1,dst_width-weight);
977  *dst_ptr = (CalcAlpha(colour.alfa) << 24) | (colour.red << 16) | (colour.green << 8) | colour.blue;
978  }
979  dst_ptr++;
980  weight -= src_width;
981  if (weight < 0)
982  {
983  weight += dst_width;
984  color0 = color1;
985  scola++;
986  if (scola == colend)
987  {
988  break;
989  }
990  color1 = *scola;
991  }
992  }
993  while (dst_ptr != end_ptr)
994  {
995  *dst_ptr = (CalcAlpha(color0.alfa) << 24) | (color0.red << 16) | (color0.green << 8) | color0.blue;
996  dst_ptr++;
997  weight -= src_width;
998  }
999  }
1000 }
1001 
1002 static void ExpTwoRowsArgb32( S_COLOUR *scola, U32BIT weighta, S_COLOUR *scolb, U32BIT weightb,
1003  U16BIT src_width, U16BIT dst_width, HD4Color *dst_ptr )
1004 {
1005  S_COLOUR *colend = scola + src_width;
1006  HD4Color *end_ptr = dst_ptr + dst_width;
1007  S_COLOUR colour, color0, color1;
1008  U32BIT *pcol0 = (U32BIT*)&color0;
1009  U32BIT *pcol1 = (U32BIT*)&color1;
1010  S32BIT weight;
1011 
1012  weight =(dst_width>>1) - (src_width>>1);
1013  if (*((U32BIT*)scola) == *((U32BIT*)scolb))
1014  {
1015  color0 = *scola;
1016  }
1017  else
1018  {
1019  color0 = MeanArgbCol(*scola,weighta,*scolb,weightb);
1020  }
1021  while (weight > 0)
1022  {
1023  *dst_ptr = (CalcAlpha(color0.alfa) << 24) | (color0.red << 16) | (color0.green << 8) | color0.blue;
1024  dst_ptr++;
1025  weight -= src_width;
1026  }
1027  scola++;
1028  scolb++;
1029  if (scola != colend)
1030  {
1031  if (*((U32BIT*)scola) == *((U32BIT*)scolb))
1032  {
1033  color1 = *scola;
1034  }
1035  else
1036  {
1037  color1 = MeanArgbCol(*scola,weighta,*scolb,weightb);
1038  }
1039  weight += dst_width;
1040  while (dst_ptr != end_ptr)
1041  {
1042  if (*pcol0 == *pcol1)
1043  {
1044  *dst_ptr = (CalcAlpha(color0.alfa) << 24) | (color0.red << 16) | (color0.green << 8) | color0.blue;
1045  }
1046  else
1047  {
1048  colour = MeanArgbCol(color0,weight,color1,dst_width-weight);
1049  *dst_ptr = (CalcAlpha(colour.alfa) << 24) | (colour.red << 16) | (colour.green << 8) | colour.blue;
1050  }
1051  dst_ptr++;
1052  weight -= src_width;
1053  if (weight < 0)
1054  {
1055  weight += dst_width;
1056  color0 = color1;
1057  scola++;
1058  scolb++;
1059  if (scola == colend)
1060  {
1061  break;
1062  }
1063  if (*((U32BIT*)scola) == *((U32BIT*)scolb))
1064  {
1065  color1 = *scola;
1066  }
1067  else
1068  {
1069  color1 = MeanArgbCol(*scola,weighta,*scolb,weightb);
1070  }
1071  }
1072  }
1073  while (dst_ptr != end_ptr)
1074  {
1075  *dst_ptr = (CalcAlpha(color0.alfa) << 24) | (color0.red << 16) | (color0.green << 8) | color0.blue;
1076  dst_ptr++;
1077  weight -= src_width;
1078  }
1079  }
1080 }
1081 
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 )
1084 {
1085  S_COLOUR *row_a, *row_b, *row_end;
1086  HD4Color *end_buff;
1087  S32BIT weight;
1088 
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))
1091 
1092  end_buff = dst_buff + (dst_height*stride);
1093  row_a = (S_COLOUR*)src_buff;
1094  row_b = row_a + src_width;
1095  row_end = row_a + (src_height*src_width);
1096  weight = (dst_height>>1) - (src_height>>1);
1097  while (weight > 0)
1098  {
1099  ExpOneRowArgb32( row_a, src_width, dst_width, dst_buff );
1100  dst_buff += stride;
1101  weight -= src_height;
1102  }
1103  row_a = row_b;
1104  if (src_height > 2)
1105  {
1106  weight += dst_height;
1107  row_b += src_width;
1108  while (row_b != row_end)
1109  {
1110  ExpTwoRowsArgb32( row_a, weight, row_b, dst_height - weight, src_width, dst_width, dst_buff );
1111  dst_buff += stride;
1112  weight -= src_height;
1113  if (weight < 0)
1114  {
1115  weight += dst_height;
1116  row_a = row_b;
1117  row_b += src_width;
1118  }
1119  }
1120  }
1121  while (dst_buff != end_buff)
1122  {
1123  ExpOneRowArgb32( row_a, src_width, dst_width, dst_buff );
1124  dst_buff += stride;
1125  }
1126 }
1127 
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 )
1130 {
1131  U32BIT avl_width, avl_height, nxt_height;
1132  U32BIT tmp, n_tmp, src_area;
1133  U16BIT s_x, s_y;
1134  U32BIT *tmp_row, *tmp_pix;
1135  U16BIT stride_diff = stride - dst_width;
1136 
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))
1139 
1140  tmp_row = (U32BIT *)OSD_MemAlloc( dst_width * sizeof(U32BIT) * 3 );
1141  if (tmp_row)
1142  {
1143  avl_height = src_height;
1144  avl_width = src_width;
1145  src_area = src_width * src_height;
1146  nxt_height = 0;
1147  tmp = dst_width * 3;
1148  for (s_x = 0; s_x != tmp; s_x++)
1149  {
1150  tmp_row[s_x] = 0;
1151  }
1152  for (s_y = 0; s_y != src_height; s_y++)
1153  {
1154  tmp_pix = tmp_row;
1155  if (avl_height <= dst_height)
1156  {
1157  U32BIT d_red = 0, d_grn = 0, d_blu = 0;
1158  nxt_height = dst_height - avl_height;
1159  /* src row contribs to 2 dst rows */
1160  for (s_x = 0; s_x != src_width; s_x++, src_buff += 3)
1161  {
1162  if (avl_width <= dst_width)
1163  {
1164  tmp = avl_width * avl_height;
1165  n_tmp = avl_width * nxt_height;
1166  }
1167  else
1168  {
1169  tmp = dst_width * avl_height;
1170  n_tmp = dst_width * nxt_height;
1171  }
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)
1179  {
1180  *dst_buff = (MAX_ALPHA << 8) | (*tmp_pix / src_area);
1181  *tmp_pix = d_red;
1182  *dst_buff <<= 8;
1183  tmp_pix++;
1184  *dst_buff |= *tmp_pix / src_area;
1185  *tmp_pix = d_grn;
1186  *dst_buff <<= 8;
1187  tmp_pix++;
1188  *dst_buff |= *tmp_pix / src_area;
1189  *tmp_pix = d_blu;
1190  dst_buff++;
1191  tmp_pix++;
1192  if (s_x != src_width - 1)
1193  {
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;
1202  }
1203  avl_width += src_width;
1204  }
1205  avl_width -= dst_width;
1206  }
1207  dst_buff += stride_diff;
1208  avl_height += src_height;
1209  }
1210  else
1211  {
1212  /* src row contributes to one dst row */
1213  for (s_x = 0; s_x != src_width; s_x++, src_buff += 3)
1214  {
1215  if (avl_width <= dst_width)
1216  {
1217  /* src pixel contributes to two dst pixels */
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;
1222  tmp_pix += 3;
1223  tmp = (dst_width - avl_width) * dst_height;
1224  avl_width += src_width;
1225  }
1226  else
1227  {
1228  /* src pixel contributes to one dst pixel */
1229  tmp = dst_width * dst_height;
1230  }
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;
1235  }
1236  }
1237  avl_height -= dst_height;
1238  }
1239  OSD_MemFree( tmp_row );
1240  }
1241 }
1242 
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 )
1245 {
1246  U32BIT avl_width, avl_height, nxt_height;
1247  U32BIT tmp, n_tmp, src_area;
1248  U16BIT s_x, s_y;
1249  U32BIT *tmp_row, *tmp_pix;
1250  U16BIT stride_diff = stride - dst_width;
1251 
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))
1254 
1255  tmp_row = (U32BIT *)OSD_MemAlloc( dst_width * sizeof(U32BIT) * 4 );
1256  if (tmp_row)
1257  {
1258  avl_height = src_height;
1259  avl_width = src_width;
1260  src_area = src_width * src_height;
1261  nxt_height = 0;
1262  tmp = dst_width * 4;
1263  for (s_x = 0; s_x != tmp; s_x++)
1264  {
1265  tmp_row[s_x] = 0;
1266  }
1267  for (s_y = 0; s_y != src_height; s_y++)
1268  {
1269  tmp_pix = tmp_row;
1270  if (avl_height <= dst_height)
1271  {
1272  U32BIT d_alf = 0, d_red = 0, d_grn = 0, d_blu = 0;
1273  /* src row contribs to 2 dst rows */
1274  nxt_height = dst_height - avl_height;
1275  for (s_x = 0; s_x != src_width; s_x++, src_buff += 4)
1276  {
1277  if (avl_width <= dst_width)
1278  {
1279  tmp = avl_width * avl_height;
1280  n_tmp = avl_width * nxt_height;
1281  }
1282  else
1283  {
1284  tmp = dst_width * avl_height;
1285  n_tmp = dst_width * nxt_height;
1286  }
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)
1296  {
1297  *dst_buff = *tmp_pix / src_area;
1298  #ifdef OSD_31_BIT
1299  *dst_buff = CalcAlpha(*dst_buff);
1300  #endif
1301  *tmp_pix = d_alf;
1302  *dst_buff <<= 8;
1303  tmp_pix++;
1304  *dst_buff |= *tmp_pix / src_area;
1305  *tmp_pix = d_red;
1306  *dst_buff <<= 8;
1307  tmp_pix++;
1308  *dst_buff |= *tmp_pix / src_area;
1309  *tmp_pix = d_grn;
1310  *dst_buff <<= 8;
1311  tmp_pix++;
1312  *dst_buff |= *tmp_pix / src_area;
1313  *tmp_pix = d_blu;
1314  dst_buff++;
1315  tmp_pix++;
1316  if (s_x != src_width - 1)
1317  {
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;
1328  }
1329  avl_width += src_width;
1330  }
1331  avl_width -= dst_width;
1332  }
1333  dst_buff += stride_diff;
1334  avl_height += src_height;
1335  }
1336  else
1337  {
1338  /* src row contributes to one dst row */
1339  for (s_x = 0; s_x != src_width; s_x++, src_buff += 4)
1340  {
1341  if (avl_width <= dst_width)
1342  {
1343  /* src pixel contributes to two dst pixels */
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;
1349  tmp_pix += 4;
1350  tmp = (dst_width - avl_width) * dst_height;
1351  avl_width += src_width;
1352  }
1353  else
1354  {
1355  /* src pixel contributes to one dst pixel */
1356  tmp = dst_width * dst_height;
1357  }
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;
1363  }
1364  }
1365  avl_height -= dst_height;
1366  }
1367  OSD_MemFree( tmp_row );
1368  }
1369 }
1370 
1371 #endif /*OSD_31_BIT || OSD_32_BIT*/
1372 
1373 /*---global function definitions---------------------------------------------*/
1374 
1397 void* DEC_OSDCreateBmpSurf( U32BIT s_width, U32BIT s_height,
1398  U32BIT i_width, U32BIT i_height,
1399  S_IMAGE *image, U32BIT *pStride )
1400 {
1401  void *hw_handle;
1402  void *col_buff;
1403  int stride;
1404 
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)
1407  {
1408  DBGTRACE(TGRAPHICS,"ERR: width=%d height=%d", s_width, s_height);
1409  hw_handle = NULL;
1410  }
1411  else
1412  {
1413  hw_handle = STB_OSDMhegCreateSurface((U16BIT)s_width, (U16BIT)s_height, FALSE, 0 );
1414  }
1415  if (hw_handle != NULL)
1416  {
1417  col_buff = STB_OSDMhegLockBuffer( hw_handle, pStride );
1418 
1420  {
1421  #ifdef OSD_16_BIT
1422  stride = *pStride >> 1;
1423  #endif
1424  }
1425  ELSE
1426  {
1427  #if defined(OSD_31_BIT) || defined(OSD_32_BIT)
1428  stride = *pStride >> 2;
1429  #endif
1430  }
1431  if (col_buff) /* safety check */
1432  {
1433  if (i_height == image->height)
1434  {
1435  if (image->pix_bytes == 3)
1436  {
1438  {
1439  #ifdef OSD_16_BIT
1440  copyRgb16Bit( image->col_buff, image->width, image->height,
1441  (HD2Color *)col_buff, stride );
1442  #endif
1443  }
1444  ELSE
1445  {
1446  #if defined(OSD_31_BIT) || defined(OSD_32_BIT)
1447  copyRgb32Bit( image->col_buff, image->width, image->height,
1448  (HD4Color *)col_buff, stride );
1449  #endif
1450  }
1451  }
1452  else /* image->pix_bytes == 4 */
1453  {
1454  /* just straight copy */
1456  {
1457  #ifdef OSD_16_BIT
1458  copyArgb16Bit( image->col_buff, image->width, image->height,
1459  (HD2Color *)col_buff, stride );
1460  #endif
1461  }
1462  ELSE
1463  {
1464  #if defined(OSD_31_BIT) || defined(OSD_32_BIT)
1465  copyArgb32Bit( image->col_buff, image->width, image->height,
1466  (HD4Color *)col_buff, stride );
1467  #endif
1468  }
1469  }
1470  }
1471  else if (i_height > image->height)
1472  {
1473  if (image->pix_bytes == 3)
1474  {
1475  /* This will be case when hardware is HD screen */
1477  {
1478  #ifdef OSD_16_BIT
1479  expandRgb16Bit( image->col_buff, image->width, image->height,
1480  (HD2Color *)col_buff, (U16BIT)i_width, (U16BIT)i_height, stride );
1481  #endif
1482  }
1483  ELSE
1484  {
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 );
1488  #endif
1489  }
1490  }
1491  else /* image->pix_bytes == 4 */
1492  {
1494  {
1495  #ifdef OSD_16_BIT
1496  expandArgb16Bit( image->col_buff, image->width, image->height,
1497  (HD2Color *)col_buff, (U16BIT)i_width, (U16BIT)i_height, stride );
1498  #endif
1499  }
1500  ELSE
1501  {
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 );
1505  #endif
1506  }
1507  }
1508  }
1509  else /* (i_height < image->height) */
1510  {
1511  /* This will be case when hardware is 1280x720 screen
1512  * and bitmap is resolution 5315 pix/m (ie for 1920x1080 screen)
1513  */
1514  if (image->pix_bytes == 3)
1515  {
1517  {
1518  #ifdef OSD_16_BIT
1519  shrinkRgb16Bit( image->col_buff, image->width, image->height,
1520  (HD2Color *)col_buff, (U16BIT)i_width, (U16BIT)i_height, stride );
1521  #endif
1522  }
1523  ELSE
1524  {
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 );
1528  #endif
1529  }
1530  }
1531  else
1532  {
1534  {
1535  #ifdef OSD_16_BIT
1536  shrinkArgb16Bit( image->col_buff, image->width, image->height,
1537  (HD2Color *)col_buff, (U16BIT)i_width, (U16BIT)i_height, stride );
1538  #endif
1539  }
1540  ELSE
1541  {
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 );
1545  #endif
1546  }
1547  }
1548  }
1549  /* Now do tiling */
1551  {
1552  #ifdef OSD_16_BIT
1553  U32BIT height;
1554  HD2Color *d_buff, *s_buff;
1555  U32BIT width;
1556 
1557  if (s_width > i_width)
1558  {
1559  height = i_height;
1560  s_buff = (HD2Color *)col_buff;
1561  while (height != 0)
1562  {
1563  d_buff = s_buff + i_width;
1564  width = s_width - i_width;
1565  while (width != 0)
1566  {
1567  if (width > i_width)
1568  {
1569  memcpy( d_buff, s_buff, i_width << 1 );
1570  width -= i_width;
1571  d_buff += i_width;
1572  }
1573  else
1574  {
1575  memcpy( d_buff, s_buff, width << 1 );
1576  width = 0;
1577  }
1578  }
1579  s_buff += stride;
1580  height--;
1581  }
1582  }
1583  if (s_height > i_height)
1584  {
1585  s_buff = (HD2Color *)col_buff;
1586  d_buff = s_buff + (i_height * stride);
1587  height = s_height - i_height;
1588  while (height != 0)
1589  {
1590  memcpy( d_buff, s_buff, s_width << 1 );
1591  d_buff += stride;
1592  s_buff += stride;
1593  height--;
1594  }
1595  }
1596  #endif
1597  }
1598  ELSE
1599  {
1600  #if defined(OSD_31_BIT) || defined(OSD_32_BIT)
1601  U32BIT height;
1602  HD4Color *d_buff, *s_buff;
1603  U32BIT width;
1604 
1605  if (s_width > i_width)
1606  {
1607  height = i_height;
1608  s_buff = (HD4Color *)col_buff;
1609  while (height != 0)
1610  {
1611  d_buff = s_buff + i_width;
1612  width = s_width - i_width;
1613  while (width != 0)
1614  {
1615  if (width > i_width)
1616  {
1617  memcpy( d_buff, s_buff, i_width << 2 );
1618  width -= i_width;
1619  d_buff += i_width;
1620  }
1621  else
1622  {
1623  memcpy( d_buff, s_buff, width << 2 );
1624  width = 0;
1625  }
1626  }
1627  s_buff += stride;
1628  height--;
1629  }
1630  }
1631  if (s_height > i_height)
1632  {
1633  s_buff = (HD4Color *)col_buff;
1634  d_buff = s_buff + (i_height * stride);
1635  height = s_height - i_height;
1636  while (height != 0)
1637  {
1638  memcpy( d_buff, s_buff, s_width << 2 );
1639  d_buff += stride;
1640  s_buff += stride;
1641  height--;
1642  }
1643  }
1644  #endif
1645  }
1646 
1647  STB_OSDMhegUnlockBuffer( hw_handle );
1648  }
1649  }
1650  TRACE(TGRAPHICS, ("rtn=0x%x", hw_handle))
1651  return hw_handle;
1652 }
1653 
OSD utility functions.
#define IF_COL_DEPTH(cd)
Definition: mg_ctxt.h:65
U8BIT red
Definition: mg_bitmap.c:47
#define RGBA(r, g, b, a)
Definition: osd_utils.h:54
#define OSD_MemAlloc
Definition: glue_memory.h:96
#define DBGTRACE(...)
Definition: glue_debug.h:126
Debug tracing.
U8BIT * col_buff
Definition: decoder.h:63
#define COLOUR_FORMAT_ARGB4444
Definition: mheg5_control.h:80
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&#39;s size being: (width * height * bytes_per_pixel) Also, when &#39;init&#39; is TRUE, function initialises surface buffer to the specified colour. For pixel colour format of less than four bytes, use least significant bits of &#39;colour&#39;.
U8BIT pix_bytes
Definition: decoder.h:61
#define TRACE_UINT(t, d, l, p)
Definition: glue_debug.h:121
U32BIT HD4Color
Definition: mg_bitmap.c:43
S_COLOUR MeanArgbCol(S_COLOUR cola, U32BIT weighta, S_COLOUR colb, U32BIT weightb)
Definition: mg_bitmap.c:58
uint8_t U8BIT
Definition: techtype.h:82
U8BIT green
Definition: mg_bitmap.c:48
Memory functions.
U16BIT height
Definition: decoder.h:59
#define ELSE
Definition: mg_ctxt.h:66
int32_t S32BIT
Definition: techtype.h:87
U16BIT width
Definition: decoder.h:58
uint16_t U16BIT
Definition: techtype.h:84
The functions in this file are OPTIONALLY provided by Receiver Platform *.
#define FALSE
Definition: techtype.h:68
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...
Definition: mg_bitmap.c:1397
U8BIT alfa
Definition: mg_bitmap.c:46
Interface to OSD.
U8BIT blue
Definition: mg_bitmap.c:49
U16BIT HD2Color
Definition: osd_utils.h:70
#define OSD_MemFree
Definition: glue_memory.h:97
Graphics functions required by the HD MHEG5 engine. All references to colour used in these functions ...
uint32_t U32BIT
Definition: techtype.h:86
void STB_OSDMhegUnlockBuffer(void *surface)
This function informs HW that MHEG5 is finished writing to the buffer.
#define TRACE(t, x)
Definition: glue_debug.h:118