1 /*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 /* ---- includes ----------------------------------------------------------- */
18
19 #include "b_BasicEm/Functions.h"
20 #include "b_ImageEm/UInt32Image.h"
21
22 /* ------------------------------------------------------------------------- */
23
24 /* ========================================================================= */
25 /* */
26 /* ---- \ghd{ auxiliary functions } ---------------------------------------- */
27 /* */
28 /* ========================================================================= */
29
30 /* ------------------------------------------------------------------------- */
31
32 /* ========================================================================= */
33 /* */
34 /* ---- \ghd{ constructor / destructor } ----------------------------------- */
35 /* */
36 /* ========================================================================= */
37
38 /* ------------------------------------------------------------------------- */
39
bim_UInt32Image_init(struct bbs_Context * cpA,struct bim_UInt32Image * ptrA)40 void bim_UInt32Image_init( struct bbs_Context* cpA,
41 struct bim_UInt32Image* ptrA )
42 {
43 bbs_UInt32Arr_init( cpA, &ptrA->arrE );
44 ptrA->widthE = 0;
45 ptrA->heightE = 0;
46 }
47
48 /* ------------------------------------------------------------------------- */
49
bim_UInt32Image_exit(struct bbs_Context * cpA,struct bim_UInt32Image * ptrA)50 void bim_UInt32Image_exit( struct bbs_Context* cpA,
51 struct bim_UInt32Image* ptrA )
52 {
53 bbs_UInt32Arr_exit( cpA, &ptrA->arrE );
54 ptrA->widthE = 0;
55 ptrA->heightE = 0;
56 }
57
58 /* ------------------------------------------------------------------------- */
59
60 /* ========================================================================= */
61 /* */
62 /* ---- \ghd{ operators } -------------------------------------------------- */
63 /* */
64 /* ========================================================================= */
65
66 /* ------------------------------------------------------------------------- */
67
bim_UInt32Image_copy(struct bbs_Context * cpA,struct bim_UInt32Image * ptrA,const struct bim_UInt32Image * srcPtrA)68 void bim_UInt32Image_copy( struct bbs_Context* cpA,
69 struct bim_UInt32Image* ptrA,
70 const struct bim_UInt32Image* srcPtrA )
71 {
72 #ifdef DEBUG1
73 if( ptrA->arrE.allocatedSizeE < srcPtrA->arrE.allocatedSizeE )
74 {
75 bbs_ERROR0( "void bim_UInt32Image_copy(...):\n"
76 "Unsufficient allocated memory in destination image." );
77 return;
78 }
79 #endif
80 ptrA->widthE = srcPtrA->widthE;
81 ptrA->heightE = srcPtrA->heightE;
82 bbs_UInt32Arr_copy( cpA, &ptrA->arrE, &srcPtrA->arrE );
83 }
84
85 /* ------------------------------------------------------------------------- */
86
bim_UInt32Image_equal(struct bbs_Context * cpA,const struct bim_UInt32Image * ptrA,const struct bim_UInt32Image * srcPtrA)87 flag bim_UInt32Image_equal( struct bbs_Context* cpA,
88 const struct bim_UInt32Image* ptrA,
89 const struct bim_UInt32Image* srcPtrA )
90 {
91 if( ptrA->widthE != srcPtrA->widthE ) return FALSE;
92 if( ptrA->heightE != srcPtrA->heightE ) return FALSE;
93 return bbs_UInt32Arr_equal( cpA, &ptrA->arrE, &srcPtrA->arrE );
94 }
95
96 /* ------------------------------------------------------------------------- */
97
98 /* ========================================================================= */
99 /* */
100 /* ---- \ghd{ query functions } -------------------------------------------- */
101 /* */
102 /* ========================================================================= */
103
104 /* ------------------------------------------------------------------------- */
105
bim_UInt32Image_heapSize(struct bbs_Context * cpA,const struct bim_UInt32Image * ptrA,uint32 widthA,uint32 heightA)106 uint32 bim_UInt32Image_heapSize( struct bbs_Context* cpA,
107 const struct bim_UInt32Image* ptrA,
108 uint32 widthA,
109 uint32 heightA )
110 {
111 return bbs_UInt32Arr_heapSize( cpA, &ptrA->arrE, widthA * heightA );
112 }
113
114 /* ------------------------------------------------------------------------- */
115
bim_UInt32Image_checkSum(struct bbs_Context * cpA,const struct bim_UInt32Image * ptrA)116 uint32 bim_UInt32Image_checkSum( struct bbs_Context* cpA,
117 const struct bim_UInt32Image* ptrA )
118 {
119 uint32 sumL =0 ;
120 uint32 iL;
121 uint32 sizeL = ptrA->arrE.sizeE;
122 const uint32* ptrL = ptrA->arrE.arrPtrE;
123 for( iL =0; iL < sizeL; iL++ )
124 {
125 sumL += *ptrL++;
126 }
127 return sumL;
128 }
129
130 /* ------------------------------------------------------------------------- */
131
132 /* ========================================================================= */
133 /* */
134 /* ---- \ghd{ modify functions } ------------------------------------------- */
135 /* */
136 /* ========================================================================= */
137
138 /* ------------------------------------------------------------------------- */
139
bim_UInt32Image_create(struct bbs_Context * cpA,struct bim_UInt32Image * ptrA,uint32 widthA,uint32 heightA,struct bbs_MemSeg * mspA)140 void bim_UInt32Image_create( struct bbs_Context* cpA,
141 struct bim_UInt32Image* ptrA,
142 uint32 widthA,
143 uint32 heightA,
144 struct bbs_MemSeg* mspA )
145 {
146 if( bbs_Context_error( cpA ) ) return;
147 if( ptrA->arrE.arrPtrE != 0 )
148 {
149 bim_UInt32Image_size( cpA, ptrA, widthA, heightA );
150 }
151 else
152 {
153 bbs_UInt32Arr_create( cpA, &ptrA->arrE, widthA * heightA, mspA );
154 ptrA->widthE = widthA;
155 ptrA->heightE = heightA;
156 }
157 }
158
159 /* ------------------------------------------------------------------------- */
160
bim_UInt32Image_assignExternalImage(struct bbs_Context * cpA,struct bim_UInt32Image * ptrA,struct bim_UInt32Image * srcPtrA)161 void bim_UInt32Image_assignExternalImage( struct bbs_Context* cpA,
162 struct bim_UInt32Image* ptrA,
163 struct bim_UInt32Image* srcPtrA )
164 {
165 struct bbs_MemSeg sharedSegL = bbs_MemSeg_createShared( cpA, srcPtrA->arrE.arrPtrE, srcPtrA->widthE * srcPtrA->heightE );
166
167 if( ptrA->arrE.arrPtrE != 0 )
168 {
169 bbs_ERROR0( "void bim_UInt32Image_assignExternalImage( ... ): image was already created once" );
170 return;
171 }
172
173 bim_UInt32Image_create( cpA,
174 ptrA,
175 srcPtrA->widthE,
176 srcPtrA->heightE,
177 &sharedSegL );
178 }
179
180 /* ------------------------------------------------------------------------- */
181
bim_UInt32Image_size(struct bbs_Context * cpA,struct bim_UInt32Image * ptrA,uint32 widthA,uint32 heightA)182 void bim_UInt32Image_size( struct bbs_Context* cpA,
183 struct bim_UInt32Image* ptrA,
184 uint32 widthA,
185 uint32 heightA )
186 {
187 if( ptrA->arrE.allocatedSizeE < widthA * heightA )
188 {
189 bbs_ERROR0( "void bim_UInt32Image_size( struct bim_UInt32Image*, uint32 sizeA ):\n"
190 "Unsufficient allocated memory" );
191 return;
192 }
193 ptrA->widthE = widthA;
194 ptrA->heightE = heightA;
195 bbs_UInt32Arr_size( cpA, &ptrA->arrE, widthA * heightA );
196 }
197
198 /* ------------------------------------------------------------------------- */
199
200 /* ========================================================================= */
201 /* */
202 /* ---- \ghd{ I/O } -------------------------------------------------------- */
203 /* */
204 /* ========================================================================= */
205
206 /* ------------------------------------------------------------------------- */
207
bim_UInt32Image_memSize(struct bbs_Context * cpA,const struct bim_UInt32Image * ptrA)208 uint32 bim_UInt32Image_memSize( struct bbs_Context* cpA,
209 const struct bim_UInt32Image* ptrA )
210 {
211 return bbs_SIZEOF16( uint32 )
212 + bbs_SIZEOF16( uint32 ) /* version */
213 + bbs_SIZEOF16( ptrA->widthE )
214 + bbs_SIZEOF16( ptrA->heightE )
215 + bbs_UInt32Arr_memSize( cpA, &ptrA->arrE );
216 }
217
218 /* ------------------------------------------------------------------------- */
219
bim_UInt32Image_memWrite(struct bbs_Context * cpA,const struct bim_UInt32Image * ptrA,uint16 * memPtrA)220 uint32 bim_UInt32Image_memWrite( struct bbs_Context* cpA,
221 const struct bim_UInt32Image* ptrA,
222 uint16* memPtrA )
223 {
224 uint32 memSizeL = bim_UInt32Image_memSize( cpA, ptrA );
225 memPtrA += bbs_memWrite32( &memSizeL, memPtrA );
226 memPtrA += bbs_memWriteUInt32( bim_UINT32_IMAGE_VERSION, memPtrA );
227 memPtrA += bbs_memWrite32( &ptrA->widthE, memPtrA );
228 memPtrA += bbs_memWrite32( &ptrA->heightE, memPtrA );
229 bbs_UInt32Arr_memWrite( cpA, &ptrA->arrE, memPtrA );
230 return memSizeL;
231 }
232
233 /* ------------------------------------------------------------------------- */
234
bim_UInt32Image_memRead(struct bbs_Context * cpA,struct bim_UInt32Image * ptrA,const uint16 * memPtrA,struct bbs_MemSeg * mspA)235 uint32 bim_UInt32Image_memRead( struct bbs_Context* cpA,
236 struct bim_UInt32Image* ptrA,
237 const uint16* memPtrA,
238 struct bbs_MemSeg* mspA )
239 {
240 uint32 memSizeL, versionL;
241 if( bbs_Context_error( cpA ) ) return 0;
242 memPtrA += bbs_memRead32( &memSizeL, memPtrA );
243 memPtrA += bbs_memReadVersion32( cpA, &versionL, bim_UINT32_IMAGE_VERSION, memPtrA );
244 memPtrA += bbs_memRead32( &ptrA->widthE, memPtrA );
245 memPtrA += bbs_memRead32( &ptrA->heightE, memPtrA );
246 bbs_UInt32Arr_memRead( cpA, &ptrA->arrE, memPtrA, mspA );
247
248 if( memSizeL != bim_UInt32Image_memSize( cpA, ptrA ) )
249 {
250 bbs_ERR0( bbs_ERR_CORRUPT_DATA, "uint32 bim_UInt32Image_memRead( const struct bim_UInt32Image* ptrA, const void* memPtrA ):\n"
251 "size mismatch" );
252 return 0;
253 }
254 return memSizeL;
255 }
256
257 /* ------------------------------------------------------------------------- */
258
259 /* ========================================================================= */
260 /* */
261 /* ---- \ghd{ exec functions } --------------------------------------------- */
262 /* */
263 /* ========================================================================= */
264
265 /* ------------------------------------------------------------------------- */
266
bim_UInt32Image_setAllPixels(struct bbs_Context * cpA,struct bim_UInt32Image * ptrA,uint32 valueA,int32 bbpA)267 void bim_UInt32Image_setAllPixels( struct bbs_Context* cpA,
268 struct bim_UInt32Image* ptrA,
269 uint32 valueA,
270 int32 bbpA )
271 {
272 long iL;
273 uint32* ptrL = ptrA->arrE.arrPtrE;
274 for( iL = ptrA->widthE * ptrA->heightE; iL > 0; iL-- )
275 {
276 *ptrL++ = valueA;
277 }
278 }
279
280 /* ------------------------------------------------------------------------- */
281
282 /* ========================================================================= */
283
284
285