MHEG5  18.9.0
MHEG5 Documentation
mg_dla_c4.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 #if defined(OSD_31_BIT) || defined(OSD_32_BIT)
29 
30 #define DLA_MEMSET32_THRESHOLD (4)
31 #define DLA_MEMSET32_THRESHOLD_NEXT (16)
32 #define DLA_MEMSET32_MASK (0x3)
33 
34 #define DLA_MEMSET( dp, c, n ) DLA_MemSet32((dp), (c), (n))
35 
36 #define DLA_struct _DLA4_Surface
37 #define DLA_Surface DLA4_Surface
38 #define DLA_FUNCTION(func) DLA_PC4_ ## func
39 #define DLAColor OSDColor
40 
41 static void DLA_MemSet32(void *buf, U32BIT b, U32BIT size);
42 
43 #include "mg_dla.inl"
44 
45 static void DLA_MemSet32(void *buf, U32BIT 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 >> 24);
56  U8BIT b1 = (U8BIT)(b >> 16);
57  U8BIT b2 = (U8BIT)(b >> 8);
58  U8BIT b3 = (U8BIT)b;
59 #else
60  /* Little endian */
61  U8BIT b0 = (U8BIT)b;
62  U8BIT b1 = (U8BIT)(b >> 8);
63  U8BIT b2 = (U8BIT)(b >> 16);
64  U8BIT b3 = (U8BIT)(b >> 24);
65 #endif
66 
67  if (size > DLA_MEMSET32_THRESHOLD)
68  {
69  /* First part is filled "manually" */
70  for (i = 0; i < DLA_MEMSET32_THRESHOLD; ++i)
71  {
72  *p++ = b0;
73  *p++ = b1;
74  *p++ = b2;
75  *p++ = b3;
76  }
77 
78  power = DLA_MEMSET32_THRESHOLD_NEXT;
79  max_power = size;
80  max_power |= max_power >> 1;
81  max_power |= max_power >> 2;
82  max_power |= max_power >> 4;
83  max_power |= max_power >> 8;
84  max_power |= max_power >> 16;
85  remainder = (size << 2) & (max_power << 1);
86  ++max_power;
87  max_power <<= 1;
88 
89  /* Second part is filled in powers of two, by copying larger and
90  * larger blocks.
91  */
92  p = buf;
93  while (power < max_power)
94  {
95  memcpy(p + power, p, power);
96  power <<= 1;
97  }
98 
99  /* Third part is the remainder. It's definitely smaller than what
100  * we already have, so we can use what we have to fill the remainder.
101  */
102  if (remainder > 0)
103  {
104  memcpy(p + power, p, remainder);
105  }
106  }
107  else
108  {
109  /* Too short to be clever - "manual" fill */
110  for (i = 0; i < size; ++i)
111  {
112  *p++ = b0;
113  *p++ = b1;
114  *p++ = b2;
115  *p++ = b3;
116  }
117  }
118 }
119 
120 #endif /* OSD_32_BIT */
uint8_t U8BIT
Definition: techtype.h:82
Dynamic Line-Art utility functions.
System Wide Global Technical Data Type Definitions.
uint32_t U32BIT
Definition: techtype.h:86