MHEG5  18.9.0
MHEG5 Documentation
mg_dla_c2.c
Go to the documentation of this file.
1 /*******************************************************************************
2  * Copyright © 2014 The DTVKit Open Software Foundation Ltd (www.dtvkit.org)
3  * Copyright © 2008 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 "techtype.h"
27 
28 #ifdef OSD_16_BIT
29 
30 #define DLA_MEMSET16_THRESHOLD (4)
31 #define DLA_MEMSET16_THRESHOLD_NEXT (8)
32 #define DLA_MEMSET16_MASK (0x3)
33 
34 #define DLA_MEMSET( dp, c, n ) DLA_MemSet16((dp), (c), (n))
35 
36 #define DLA_struct _DLA2_Surface
37 #define DLA_Surface DLA2_Surface
38 #define DLA_FUNCTION(func) DLA_PC2_ ## func
39 #define DLAColor HD2Color
40 
41 static void DLA_MemSet16(void *buf, U16BIT b, U32BIT size);
42 
43 #include "mg_dla.inl"
44 
45 static void DLA_MemSet16(void *buf, U16BIT b, U32BIT size)
46 {
47  U32BIT i;
48  U32BIT max_power;
49  U32BIT remainder;
50  U32BIT power;
51  U8BIT *p = buf;
52 
53 #ifdef DLA_BIG_ENDIAN
54  /* Big endian */
55  U8BIT b0 = (U8BIT)(b >> 8);
56  U8BIT b1 = (U8BIT)b;
57 #else
58  /* Little endian */
59  U8BIT b0 = (U8BIT)b;
60  U8BIT b1 = (U8BIT)(b >> 8);
61 #endif
62 
63  if (size > DLA_MEMSET16_THRESHOLD)
64  {
65  /* First part is filled "manually" */
66  for (i = 0; i < DLA_MEMSET16_THRESHOLD; ++i)
67  {
68  *p++ = b0;
69  *p++ = b1;
70  }
71 
72  power = DLA_MEMSET16_THRESHOLD_NEXT;
73  max_power = size;
74  max_power |= max_power >> 1;
75  max_power |= max_power >> 2;
76  max_power |= max_power >> 4;
77  max_power |= max_power >> 8;
78  max_power |= max_power >> 16;
79  remainder = (size << 1) & max_power;
80  ++max_power;
81 
82  /* Second part is filled in powers of two, by copying larger and
83  * larger blocks.
84  */
85  p = buf;
86  while (power < max_power)
87  {
88  memcpy(p + power, p, power);
89  power <<= 1;
90  }
91 
92  /* Third part is the remainder. It's definitely smaller than what
93  * we already have, so we can use what we have to fill the remainder.
94  */
95  if (remainder > 0)
96  {
97  memcpy(p + power, p, remainder);
98  }
99  }
100  else
101  {
102  /* Too short to be clever - "manual" fill */
103  for (i = 0; i < size; ++i)
104  {
105  *p++ = b0;
106  *p++ = b1;
107  }
108  }
109 }
110 
111 #endif /* OSD_16_BIT */
uint8_t U8BIT
Definition: techtype.h:82
Dynamic Line-Art utility functions.
uint16_t U16BIT
Definition: techtype.h:84
System Wide Global Technical Data Type Definitions.
uint32_t U32BIT
Definition: techtype.h:86