Rev 1956 | Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1951 | mario79 | 1 | ;***************************************************************************** |
2 | ; RAW to RAW convert plugin - for zSea image viewer |
||
3 | ; Copyright (c) 2008-2011, Marat Zakiyanov aka Mario79, aka Mario |
||
4 | ; All rights reserved. |
||
5 | ; |
||
6 | ; Redistribution and use in source and binary forms, with or without |
||
7 | ; modification, are permitted provided that the following conditions are met: |
||
8 | ; * Redistributions of source code must retain the above copyright |
||
9 | ; notice, this list of conditions and the following disclaimer. |
||
10 | ; * Redistributions in binary form must reproduce the above copyright |
||
11 | ; notice, this list of conditions and the following disclaimer in the |
||
12 | ; documentation and/or other materials provided with the distribution. |
||
13 | ; * Neither the name of the |
||
14 | ; names of its contributors may be used to endorse or promote products |
||
15 | ; derived from this software without specific prior written permission. |
||
16 | ; |
||
17 | ; THIS SOFTWARE IS PROVIDED BY Marat Zakiyanov ''AS IS'' AND ANY |
||
18 | ; EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
||
19 | ; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
||
20 | ; DISCLAIMED. IN NO EVENT SHALL |
||
21 | ; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
||
22 | ; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
||
23 | ; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
||
24 | ; ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
25 | ; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||
26 | ; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
27 | ;***************************************************************************** |
||
28 | |||
29 | ; Convert: |
||
30 | ; 16b in 8b |
||
31 | ; 1b,2b,3b in 8b |
||
32 | |||
33 | format MS COFF |
||
34 | |||
35 | public EXPORTS |
||
36 | |||
37 | section '.flat' code readable align 16 |
||
38 | |||
39 | ;include 'macros.inc' |
||
40 | include '../../../../macros.inc' |
||
41 | ;--------------------------------------------------------------------- |
||
42 | START: |
||
43 | pushad |
||
44 | mov [pointer],eax |
||
45 | mov eax,[eax+4] |
||
46 | mov [image_file],eax |
||
47 | mov esi,[eax+28] |
||
48 | add esi,eax |
||
49 | mov edi,esi |
||
50 | mov ecx,[eax+32] |
||
51 | ; xor ebx,ebx |
||
52 | ; mov [raw_area],ebx |
||
53 | |||
54 | ; mov ebx,[pointer] |
||
55 | ; movzx eax,word [eax+18] |
||
56 | ; mov [ebx+24],eax |
||
57 | ; jmp .ret_ok |
||
58 | |||
59 | cmp [eax+16],word 16 |
||
60 | je .16b |
||
61 | cmp [eax+12],dword 1 |
||
62 | je .1b |
||
63 | cmp [eax+12],dword 2 |
||
64 | je .2b |
||
65 | cmp [eax+12],dword 4 |
||
66 | je .4b |
||
67 | ;--------------------------------------------------------------------- |
||
68 | .ret_ok: |
||
69 | ; mov ebx,[pointer] |
||
70 | ; mov eax,[raw_area] |
||
71 | ; mov [ebx+20],eax ; store RAW pointer |
||
72 | ; mov [ebx+24],ecx |
||
73 | |||
74 | mov ebx,[image_file] |
||
75 | cmp [ebx+18],word 2 |
||
76 | jne @f |
||
77 | mov eax,[ebx+12] |
||
78 | shr eax,1 |
||
79 | mov [ebx+12],eax |
||
80 | @@: |
||
81 | |||
82 | popad |
||
83 | ret |
||
84 | ;--------------------------------------------------------------------- |
||
85 | .less_8b: |
||
86 | mov edx,[image_file] |
||
87 | mov ecx,[area_size] |
||
88 | add ecx,[edx+28] |
||
89 | mcall 68,20 |
||
90 | mov [image_file],eax |
||
91 | |||
92 | |||
93 | mov ecx,[area_size] |
||
94 | mov eax,ecx |
||
95 | shr ecx,2 |
||
96 | test eax,3 |
||
97 | jz @f |
||
98 | inc ecx |
||
99 | @@: |
||
100 | mov esi,[raw_area] |
||
101 | mov edi,[image_file] |
||
102 | add edi,[edi+28] |
||
103 | cld |
||
104 | rep movsd |
||
105 | |||
106 | mov ecx,[raw_area] |
||
107 | mcall 68,13 |
||
108 | mov eax,[image_file] |
||
109 | mov ebx,[pointer] |
||
110 | mov [ebx+4],eax |
||
111 | popad |
||
112 | ret |
||
113 | ;--------------------------------------------------------------------- |
||
114 | .16b: |
||
115 | cmp [eax+18],word 3 |
||
116 | je @f ;.convert_16_in_8 |
||
117 | cmp [eax+18],word 4 |
||
118 | jne .16b_1 |
||
119 | @@: |
||
120 | xor ebx,ebx |
||
121 | mov bx,[eax+18] |
||
122 | |||
123 | xchg eax,ecx |
||
124 | xor edx,edx |
||
125 | div ebx |
||
126 | xchg ecx,eax |
||
127 | |||
128 | shr ecx,1 |
||
129 | |||
130 | mov [eax+16],word 8 |
||
131 | mov ebx,[eax+12] |
||
132 | shr ebx,1 |
||
133 | mov [eax+12],ebx |
||
134 | |||
135 | mov ebx,eax |
||
136 | ; jmp .ret_ok |
||
137 | |||
138 | .convert_16_in_8: ; converting 16 bit sample to 8 bit |
||
139 | cld |
||
140 | lodsw |
||
141 | mov al,ah |
||
142 | stosb |
||
143 | |||
144 | lodsw |
||
145 | mov al,ah |
||
146 | stosb |
||
147 | |||
148 | lodsw |
||
149 | mov al,ah |
||
150 | stosb |
||
151 | |||
152 | cmp [ebx+18],word 4 |
||
153 | jne @f |
||
154 | lodsw |
||
155 | mov al,ah |
||
156 | stosb |
||
157 | @@: |
||
158 | dec ecx |
||
159 | jnz .convert_16_in_8 |
||
160 | jmp .16b_end |
||
161 | ;--------------------------------------------------------------------- |
||
162 | .16b_1: |
||
163 | cmp [eax+18],word 1 |
||
164 | je @f ;.convert_16_in_8_1 |
||
165 | cmp [eax+18],word 2 |
||
166 | jne .16b_end |
||
167 | @@: |
||
168 | shr ecx,1 |
||
169 | |||
170 | mov [eax+16],word 8 |
||
171 | mov ebx,[eax+12] |
||
172 | shr ebx,1 |
||
173 | mov [eax+12],ebx |
||
174 | |||
175 | .convert_16_in_8_1: |
||
176 | cld |
||
177 | lodsw |
||
178 | ; shr ax,8 |
||
179 | ; mov al,ah |
||
180 | stosb |
||
181 | dec ecx |
||
182 | jnz .convert_16_in_8_1 |
||
183 | ;--------------------------------------------------------------------- |
||
184 | .16b_end: |
||
185 | xor eax,eax |
||
186 | mov [raw_area],eax |
||
187 | jmp .ret_ok |
||
188 | ;--------------------------------------------------------------------- |
||
189 | .4b: |
||
190 | call .get_memory |
||
191 | mov edx,ebx |
||
192 | inc ebx |
||
193 | shr ebx,1 |
||
194 | .4b_1: |
||
195 | push ebx edi |
||
196 | @@: |
||
197 | cld |
||
198 | lodsb |
||
199 | shl eax,8 |
||
200 | mov al,ah |
||
201 | and ah,0xf |
||
202 | shr al,4 |
||
203 | stosw |
||
204 | |||
205 | dec ebx |
||
206 | jnz @b |
||
207 | pop edi ebx |
||
208 | add edi,edx |
||
209 | dec ecx |
||
210 | jnz .4b_1 |
||
211 | |||
212 | jmp .less_8b ;.ret_ok |
||
213 | ;--------------------------------------------------------------------- |
||
214 | .2b: |
||
215 | call .get_memory |
||
216 | ; jmp .ret_ok |
||
217 | ; shr ecx,1 |
||
218 | mov edx,ebx |
||
219 | mov eax,ebx |
||
220 | shr ebx,2 |
||
221 | test eax,3 |
||
222 | jz @f |
||
223 | inc ebx |
||
224 | @@: |
||
225 | mov ebp,ebx |
||
226 | .2b_1: |
||
227 | push ebp edi |
||
228 | @@: |
||
229 | cld |
||
230 | lodsb |
||
231 | |||
232 | mov bl,al |
||
233 | |||
234 | and al,11b |
||
235 | shl ax,8 |
||
236 | |||
237 | mov al,bl |
||
238 | shr al,2 |
||
239 | and al,11b |
||
240 | shl eax,8 |
||
241 | |||
242 | mov al,bl |
||
243 | shr al,4 |
||
244 | and al,11b |
||
245 | shl eax,8 |
||
246 | |||
247 | mov al,bl |
||
248 | shr al,6 |
||
249 | and al,11b |
||
250 | |||
251 | stosd |
||
252 | |||
253 | dec ebp |
||
254 | jnz @b |
||
255 | pop edi ebp |
||
256 | |||
257 | add edi,edx |
||
258 | dec ecx |
||
259 | jnz .2b_1 |
||
260 | |||
261 | jmp .less_8b ;.ret_ok |
||
262 | ;--------------------------------------------------------------------- |
||
263 | .1b: |
||
264 | call .get_memory |
||
265 | mov edx,ebx |
||
266 | mov eax,ebx |
||
267 | shr ebx,3 |
||
268 | test eax,7 |
||
269 | jz @f |
||
270 | inc ebx |
||
271 | @@: |
||
272 | mov ebp,ebx |
||
273 | .1b_1: |
||
274 | push ebp edi |
||
275 | @@: |
||
276 | cld |
||
277 | lodsb |
||
278 | |||
279 | mov bl,al |
||
280 | shr al,4 |
||
281 | and al,1b |
||
282 | shl ax,8 |
||
283 | |||
284 | mov al,bl |
||
285 | shr al,5 |
||
286 | and al,1b |
||
287 | shl eax,8 |
||
288 | |||
289 | mov al,bl |
||
290 | shr al,6 |
||
291 | and al,1b |
||
292 | shl eax,8 |
||
293 | |||
294 | mov al,bl |
||
295 | shr al,7 |
||
296 | ; and al,1b |
||
297 | ; shl eax,8 |
||
298 | |||
299 | stosd |
||
300 | |||
301 | mov al,bl |
||
302 | and al,1b |
||
303 | shl ax,8 |
||
304 | |||
305 | mov al,bl |
||
306 | shr al,1 |
||
307 | and al,1b |
||
308 | shl eax,8 |
||
309 | |||
310 | mov al,bl |
||
311 | shr al,2 |
||
312 | and al,1b |
||
313 | shl eax,8 |
||
314 | |||
315 | mov al,bl |
||
316 | shr al,3 |
||
317 | and al,1b |
||
318 | |||
319 | stosd |
||
320 | |||
321 | dec ebp |
||
322 | jnz @b |
||
323 | pop edi ebp |
||
324 | |||
325 | add edi,edx |
||
326 | dec ecx |
||
327 | jnz .1b_1 |
||
328 | jmp .less_8b ;.ret_ok |
||
329 | ;--------------------------------------------------------------------- |
||
330 | .get_memory: |
||
331 | mov ebx,dword 8 |
||
332 | mov [eax+16],bx |
||
333 | mov [eax+12],ebx |
||
334 | ; mov esi,[eax+28] |
||
335 | ; add esi,eax |
||
336 | ; push ecx |
||
337 | mov ecx,[eax+4] |
||
338 | imul ecx,[eax+8] |
||
339 | push eax |
||
340 | mov [area_size],ecx |
||
341 | mcall 68,12 |
||
342 | ; pop ecx |
||
343 | mov [raw_area],eax |
||
344 | mov edi,eax |
||
345 | pop eax |
||
346 | mov ebx,[eax+4] |
||
347 | mov ecx,[eax+8] |
||
348 | ret |
||
349 | ;--------------------------------------------------------------------- |
||
350 | Convert24b: |
||
351 | pushad |
||
352 | mov [pointer],eax |
||
353 | mov eax,[eax+4] |
||
354 | mov [image_file],eax |
||
355 | |||
356 | mov esi,[eax+28] |
||
357 | add esi,eax |
||
358 | |||
359 | mov ebp,[eax+20] |
||
360 | add ebp,eax |
||
361 | |||
362 | mov ecx,[eax+4] |
||
363 | imul ecx,[eax+8] |
||
364 | push eax ecx |
||
365 | lea ecx,[ecx*3] |
||
366 | mcall 68,12 |
||
367 | mov [raw_area],eax |
||
368 | mov edi,eax |
||
369 | pop ecx eax |
||
370 | |||
371 | cmp [eax+12],dword 32 |
||
372 | je .32b |
||
373 | cmp [eax+12],dword 16 |
||
374 | je .16b |
||
375 | cmp [eax+12],dword 15 |
||
376 | je .15b |
||
377 | cmp [eax+12],dword 8 |
||
378 | je .8b |
||
379 | |||
380 | .ret_ok: |
||
381 | mov ebx,[pointer] |
||
382 | mov eax,[raw_area] |
||
383 | mov [ebx+20],eax ; store RAW pointer |
||
384 | popad |
||
385 | ret |
||
386 | |||
387 | ;--------------------------------------------------------------------- |
||
388 | .32b: |
||
389 | cld |
||
390 | lodsd |
||
391 | |||
392 | stosw |
||
393 | shr eax,16 |
||
394 | stosb |
||
395 | |||
396 | dec ecx |
||
397 | jnz .32b |
||
398 | |||
399 | jmp .ret_ok |
||
400 | ;--------------------------------------------------------------------- |
||
401 | .16b: |
||
402 | cld |
||
403 | lodsw |
||
404 | |||
405 | xor ebx,ebx |
||
406 | ror ax,11 |
||
407 | mov bl,al |
||
408 | and bl,11111b |
||
409 | shl bl,3 |
||
410 | shl ebx,8 |
||
411 | rol ax,6 |
||
412 | mov bl,al |
||
413 | and bl,111111b |
||
414 | shl bl,2 |
||
415 | shl ebx,8 |
||
416 | rol ax,5 |
||
417 | mov bl,al |
||
418 | and bl,11111b |
||
419 | shl bl,3 |
||
420 | mov eax,ebx |
||
421 | |||
422 | cld |
||
423 | stosw |
||
424 | shr eax,16 |
||
425 | stosb |
||
426 | |||
427 | dec ecx |
||
428 | jnz .16b |
||
429 | |||
430 | jmp .ret_ok |
||
431 | ;--------------------------------------------------------------------- |
||
432 | .15b: |
||
433 | cld |
||
434 | lodsw |
||
435 | |||
436 | xor ebx,ebx |
||
437 | ror ax,10 |
||
438 | mov bl,al |
||
439 | and bl,11111b |
||
440 | shl bl,3 |
||
441 | shl ebx,8 |
||
442 | rol ax,5 |
||
443 | mov bl,al |
||
444 | and bl,11111b |
||
445 | shl bl,3 |
||
446 | shl ebx,8 |
||
447 | rol ax,5 |
||
448 | mov bl,al |
||
449 | and bl,11111b |
||
450 | shl bl,3 |
||
451 | mov eax,ebx |
||
452 | |||
453 | cld |
||
454 | stosw |
||
455 | shr eax,16 |
||
456 | stosb |
||
457 | |||
458 | dec ecx |
||
459 | jnz .15b |
||
460 | |||
461 | jmp .ret_ok |
||
462 | ;--------------------------------------------------------------------- |
||
463 | .8b: |
||
464 | xor eax,eax |
||
465 | cld |
||
466 | lodsb |
||
467 | shl eax,2 |
||
468 | mov eax,[eax+ebp] |
||
469 | |||
470 | cld |
||
471 | stosw |
||
472 | shr eax,16 |
||
473 | stosb |
||
474 | |||
475 | dec ecx |
||
476 | jnz .8b |
||
477 | |||
478 | jmp .ret_ok |
||
479 | ;--------------------------------------------------------------------- |
||
480 | align 16 |
||
481 | EXPORTS: |
||
482 | dd szStart, START |
||
483 | dd szVersion, 0x00010001 |
||
484 | dd szConv_24b, Convert24b |
||
485 | dd 0 |
||
486 | |||
487 | szStart db 'START',0 |
||
488 | szVersion db 'version',0 |
||
489 | szConv_24b db 'Convert24b',0 |
||
490 | pointer dd 0 |
||
491 | image_file dd 0 |
||
492 | ;delta dd 0 |
||
493 | ;resolution dd 0 |
||
494 | ;compression dd 0 |
||
495 | raw_area dd 0 |
||
496 | area_size dd 0 |