Subversion Repositories Kolibri OS

Rev

Rev 1572 | Rev 1593 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1569 dunkaist 1
;;================================================================================================;;
2
;;//// pcx.asm //// (c) dunkaist, 2010 ///////////////////////////////////////////////////////////;;
3
;;================================================================================================;;
4
;;                                                                                                ;;
5
;; This file is part of Common development libraries (Libs-Dev).                                  ;;
6
;;                                                                                                ;;
7
;; Libs-Dev is free software: you can redistribute it and/or modify it under the terms of the GNU ;;
8
;; Lesser General Public License as published by the Free Software Foundation, either version 2.1 ;;
9
;; of the License, or (at your option) any later version.                                         ;;
10
;;                                                                                                ;;
11
;; Libs-Dev is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without  ;;
12
;; even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU  ;;
13
;; Lesser General Public License for more details.                                                ;;
14
;;                                                                                                ;;
15
;; You should have received a copy of the GNU Lesser General Public License along with Libs-Dev.  ;;
16
;; If not, see .                                                    ;;
17
;;                                                                                                ;;
18
;;================================================================================================;;
19
 
20
include 'pcx.inc'
1572 dunkaist 21
include '../../../../system/board/trunk/debug.inc'
1569 dunkaist 22
 
23
;;================================================================================================;;
24
proc img.is.pcx _data, _length ;//////////////////////////////////////////////////////////////////;;
25
;;------------------------------------------------------------------------------------------------;;
26
;? Determine if raw data could be decoded (is in Targa format)                                    ;;
27
;;------------------------------------------------------------------------------------------------;;
28
;> _data = raw data as read from file/stream                                                      ;;
29
;> _length = data length                                                                          ;;
30
;;------------------------------------------------------------------------------------------------;;
31
;< eax = false / true                                                                             ;;
32
;;================================================================================================;;
33
 
34
    push    ecx edi
35
    xor     eax,    eax
36
 
37
    mov     edi,    [_data]
38
 
39
    cmp     [edi+pcx_header.magic_number],  10
40
     jne    .is_not_pcx
41
    cmp     [edi+pcx_header.version],  5
42
     jne    .is_not_pcx
43
    cmp     [edi+pcx_header.encoding],  1
44
     jne    .is_not_pcx
1580 diamond 45
    cmp     [edi+pcx_header.reserved],  0
1572 dunkaist 46
     jne    .is_not_pcx
1569 dunkaist 47
 
48
    add     edi,    pcx_header.filler
49
    xor     al,     al
50
    mov     ecx,    58
51
    cld
52
    repe    scasb
53
    test    ecx,    ecx
54
     jnz    .is_not_pcx
55
 
56
.is_pcx:
57
    inc     eax
58
 
59
.is_not_pcx:
60
    pop     edi ecx
61
    ret
62
 
63
endp
64
 
65
;;================================================================================================;;
66
proc img.decode.pcx _data, _length, _options ;////////////////////////////////////////////////////;;
67
;;------------------------------------------------------------------------------------------------;;
68
;? Decode data into image if it contains correctly formed raw data in Targa format                ;;
69
;;------------------------------------------------------------------------------------------------;;
70
;> _data = raw data as read from file/stream                                                      ;;
71
;> _length = data length                                                                          ;;
72
;;------------------------------------------------------------------------------------------------;;
73
;< eax = 0 (error) or pointer to image                                                            ;;
74
;;================================================================================================;;
75
locals
76
;  IMGwidth      dd ?
77
;  IMGheight     dd ?
78
;  IMGbpp        dd ?
79
buf                 rb      1
80
nplanes             rd      1
81
xsize               rw      1
82
ysize               rw      1
83
stxsize             rw      1
84
stysize             rw      1
85
total_bpl           rd      1
1572 dunkaist 86
total_bpl_tmp       rd      1
1569 dunkaist 87
line_begin          rd      1
88
retvalue            rd      1
89
 
90
endl
91
 
92
    pusha
93
 
94
    mov     esi,    [_data]
95
 
1572 dunkaist 96
    cmp     [esi+pcx_header.bpp],   1
97
     jz     monochrome
98
    cmp     byte[esi+pcx_header.nplanes],   3
99
     jnz    indexed
100
 
101
 
102
 
103
  _24bit:
1569 dunkaist 104
    xor     eax,   eax
105
    mov     al,    byte[esi+pcx_header.nplanes]
106
    mov     [nplanes],  eax
107
    mul     word[esi+pcx_header.bpl]
108
    mov     [total_bpl],    eax
109
 
110
    movzx   eax,    word[esi+pcx_header.xmax]
111
    inc     ax
112
    sub     ax,     word[esi+pcx_header.xmin]
113
    mov     [xsize],    ax
114
 
115
    movzx   ebx,    word[esi+pcx_header.ymax]
116
    inc     bx
117
    sub     bx,     word[esi+pcx_header.ymin]
118
    mov     [ysize],    bx
119
 
120
      stdcall   img.create, eax, ebx, Image.bpp24
121
    mov     [retvalue], eax
122
    test    eax,    eax
123
     jz     .quit
124
 
125
    movzx   ebx,    [xsize]
126
    movzx   ecx,    [ysize]
127
    mov     edx,    [eax+Image.Data]
128
 
129
    rol     ebx,    16
130
    or      ebx,    ecx
131
    xor     ebx,    [edx]
132
    mov     [eax+Image.Checksum],   ebx
133
 
134
 
135
    mov     esi,    [_data]
136
    add     esi,    128
137
    mov     edi,    [retvalue]
138
    mov     edi,    [edi+Image.Data]
139
    add     edi,    2
140
    mov     [line_begin],   edi
141
    mov     ebx,    [total_bpl]
142
 
143
  .begin:
144
    mov     eax,    [_data]
145
    mov     ax,     word[eax+pcx_header.bpl]
146
  .decode:
147
    mov     dl,     byte[esi]
148
    inc     esi
149
    mov     [buf],  dl
150
    and     dl,     0xC0
151
    cmp     dl,     0xC0
152
     jne    @f
153
    mov     dl,     byte[buf]
154
    and     dl,     0x3F
155
    mov     dh,     [esi]
156
    inc     esi
157
 
158
  .write_sequence:
159
    mov     [edi], dh
160
    dec     ax
161
    dec     ebx
162
    add     edi,    [nplanes]
163
    dec     dl
164
    test    dl,     dl
165
     jnz    .write_sequence
166
 
167
    test    ax,     ax
168
     jz     .end_color_line
169
     jmp    .decode
170
  @@:
171
    mov     dl,     byte[buf]
172
    mov     [edi],  dl
173
    add     edi, [nplanes]
174
    dec     ebx
175
    dec     ax
176
     jz     .end_color_line
177
     jmp    .decode
178
 
179
 .end_color_line:
180
    test    ebx,    ebx
181
     jz     .end_full_line
182
    dec     [line_begin]
183
    mov     edi,    [line_begin]
184
     jmp    .begin
185
 
186
  .end_full_line:
187
    dec     word[ysize]
188
     jz     .quit
189
    mov     ebx,    [total_bpl]
190
    add     edi,    2
191
    mov     [line_begin],   edi
192
     jmp    .begin
193
 
194
  .quit:
195
    popa
196
    mov     eax,    [retvalue]
197
    ret
1572 dunkaist 198
 
199
  indexed:
200
 
201
    xor     eax,   eax
202
    mov     al,    byte[esi+pcx_header.nplanes]
203
    mov     [nplanes],  eax
204
    mul     word[esi+pcx_header.bpl]
205
    mov     [total_bpl],    eax
206
 
207
    movzx   eax,    word[esi+pcx_header.xmax]
208
    inc     ax
209
    sub     ax,     word[esi+pcx_header.xmin]
210
    mov     [xsize],    ax
211
 
212
    movzx   ebx,    word[esi+pcx_header.ymax]
213
    inc     bx
214
    sub     bx,     word[esi+pcx_header.ymin]
215
    mov     [ysize],    bx
216
 
217
      stdcall   img.create, eax, ebx, Image.bpp8
218
    mov     [retvalue], eax
219
    test    eax,    eax
220
     jz     .quit
221
 
222
    mov     esi,    [_data]
223
    add     esi,    [_length]
224
    sub     esi,    768
225
    mov     edi,    [eax+Image.Palette]
226
    mov     ecx,    256
227
  @@:
228
    mov     ebx,    [esi]
229
    and     ebx,    0x00ffffff
230
    bswap   ebx
231
    shr     ebx,    8
232
    mov     [edi],  ebx
233
    add     edi,    4
234
    add     esi,    3
235
    dec     ecx
236
     jnz    @b
237
 
238
    movzx   ebx,    [xsize]
239
    movzx   ecx,    [ysize]
240
    mov     edx,    [eax+Image.Data]
241
 
242
    rol     ebx,    16
243
    or      ebx,    ecx
244
    xor     ebx,    [edx]
245
    mov     [eax+Image.Checksum],   ebx
246
 
247
 
248
    mov     esi,    [_data]
249
    add     esi,    128
250
    mov     edi,    [retvalue]
251
    mov     edi,    [edi+Image.Data]
252
 
253
  .begin:
254
    mov     eax,    [_data]
255
    mov     ax,     word[eax+pcx_header.bpl]
256
  .decode:
257
    mov     dl,     byte[esi]
258
    inc     esi
259
    mov     [buf],  dl
260
    and     dl,     0xC0
261
    cmp     dl,     0xC0
262
     jne    @f
263
    mov     dl,     [buf]
264
    and     dl,     0x3F
265
    mov     dh,     [esi]
266
    inc     esi
267
 
268
  .write_sequence:
269
    mov     [edi], dh
270
    inc     edi
271
    dec     ax
272
    dec     dl
273
     jnz    .write_sequence
274
 
275
    test    ax,     ax
276
     jz     .end_line
277
     jmp    .decode
278
  @@:
279
    mov     dl,     byte[buf]
280
    mov     [edi],  dl
281
    inc     edi
282
    dec     ax
283
     jz     .end_line
284
     jmp    .decode
285
 
286
  .end_line:
287
    dec     word[ysize]
288
     jz     .quit
289
     jmp    .begin
290
 
291
  .quit:
292
    popa
293
    mov     eax,    [retvalue]
294
    ret
295
 
296
 
297
  monochrome:
298
 
299
    xor     eax,    eax
300
    mov     ax,     word[esi+pcx_header.bpl]
301
    mov     [total_bpl],    eax
302
 
303
    movzx   eax,    word[esi+pcx_header.xmax]
304
    inc     ax
305
    sub     ax,     word[esi+pcx_header.xmin]
306
    mov     [xsize],    ax
307
 
308
    movzx   ebx,    word[esi+pcx_header.ymax]
309
    inc     bx
310
    sub     bx,     word[esi+pcx_header.ymin]
311
    mov     [ysize],    bx
312
 
313
      stdcall   img.create, eax, ebx, Image.bpp8
314
    mov     [retvalue], eax
315
    test    eax,    eax
316
     jz     .quit
317
 
318
    mov     edi,    [eax+Image.Palette]
319
    mov     [edi],  dword   0x00000000
320
    mov     [edi+4],    dword   0x00ffffff
321
 
322
    movzx   ebx,    [xsize]
323
    movzx   ecx,    [ysize]
324
    mov     edx,    [eax+Image.Data]
325
 
326
    rol     ebx,    16
327
    or      ebx,    ecx
328
    xor     ebx,    [edx]
329
    mov     [eax+Image.Checksum],   ebx
330
 
331
 
332
    mov     esi,    [_data]
333
    add     esi,    128
334
    mov     edi,    [retvalue]
335
    mov     edi,    [edi+Image.Data]
336
 
337
  .begin:
338
    mov     eax,    [total_bpl]
339
    mov     [total_bpl_tmp],    eax
340
    mov     ax,     [xsize]
341
 
342
  .decode:
343
 
344
    mov     dh,     byte[esi]
345
    inc     esi
346
    mov     [buf],  dh
347
    and     dh,     0xC0
348
    cmp     dh,     0xC0
349
     je    .cycle1
350
    mov     dh,     1
351
    mov     dl,     [buf]
352
     jmp    .exit1
353
  .cycle1:
354
    mov     dh,     [buf]
355
    and     dh,     0x3F
356
    mov     dl,     byte[esi]
357
    inc     esi
358
  .exit1:
359
    push    eax
360
    xor     eax,    eax
361
    mov     al,     dh
362
    sub     [total_bpl_tmp],    eax
363
    pop     eax
364
 
365
 
366
  .write_sequence:
367
    mov     ecx,    7
368
  .go:
369
    bt      edx,    ecx
370
     jnc    @f
371
    mov     [edi],  byte    0x01
372
     jmp    .later
373
  @@:
374
    mov     [edi],  byte    0x00
375
  .later:
376
    inc     edi
377
    dec     ax
378
     jnz    .lol
379
  @@:
380
    cmp     [total_bpl_tmp],    0
381
     jng    @f
382
 
383
    mov     dh,     byte[esi]
384
    inc     esi
385
    mov     [buf],  dh
386
    and     dh,     0xC0
387
    cmp     dh,     0xC0
388
     je    .cycle2
389
    mov     dh,     1
390
    mov     dl,     [buf]
391
     jmp    .exit2
392
  .cycle2:
393
    mov     dh,     [buf]
394
    and     dh,     0x3F
395
    mov     dl,     byte[esi]
396
    inc     esi
397
  .exit2:
398
    push    eax
399
    xor     eax,    eax
400
    mov     al,     dh
401
    sub     [total_bpl_tmp],    eax
402
    pop     eax
403
 
404
     jmp    @b
405
  @@:
406
    dec     word[ysize]
407
     jnz    .begin
408
     jmp    .quit
409
  .lol:
410
    dec     ecx
411
    cmp     ecx,    -1
412
     jne    .go
413
    dec     dh
414
     jnz    .write_sequence
415
     jmp    .decode
416
 
417
  .quit:
418
    popa
419
    mov     eax,    [retvalue]
420
    ret
421
 
1569 dunkaist 422
endp
423
 
1572 dunkaist 424
 
425
 
1569 dunkaist 426
;;================================================================================================;;
427
proc img.encode.pcx _img, _p_length, _options ;///////////////////////////////////////////////////;;
428
;;------------------------------------------------------------------------------------------------;;
429
;? Encode image into raw data in Targa format                                                     ;;
430
;;------------------------------------------------------------------------------------------------;;
431
;> _img = pointer to image                                                                        ;;
432
;;------------------------------------------------------------------------------------------------;;
433
;< eax = 0 (error) or pointer to encoded data                                                     ;;
434
;< _p_length = encoded data length                                                                ;;
435
;;================================================================================================;;
436
    xor eax, eax
437
    ret
438
endp
439
 
440
 
441
;;================================================================================================;;
442
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
443
;;================================================================================================;;
444
;! Below are private procs you should never call directly from your code                          ;;
445
;;================================================================================================;;
446
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
447
;;================================================================================================;;
448
 
449
;;================================================================================================;;
450
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
451
;;================================================================================================;;
452
;! Below is private data you should never use directly from your code                             ;;
453
;;================================================================================================;;
454
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
455
;;================================================================================================;;
456
 
457
;