Subversion Repositories Kolibri OS

Rev

Rev 1593 | Rev 1921 | 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'
1728 clevermous 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
nplanes             rd      1
77
xsize               rw      1
78
ysize               rw      1
1593 dunkaist 79
bpl                 rw      1
1569 dunkaist 80
total_bpl           rd      1
81
line_begin          rd      1
1593 dunkaist 82
retvalue            rd      1                       ; 0 (error) or pointer to image
1569 dunkaist 83
endl
84
 
85
    pusha
86
 
87
    mov     esi,    [_data]
1593 dunkaist 88
    movzx   eax,    byte[esi+pcx_header.nplanes]
1569 dunkaist 89
    mov     [nplanes],  eax
1593 dunkaist 90
    mov     bx,  word[esi+pcx_header.bpl]
91
    mov     [bpl],  bx
92
    mul     bx
93
    shl     eax,    16
94
    mov     ax,     dx
95
    ror     eax,    16
1569 dunkaist 96
    mov     [total_bpl],    eax
97
 
98
    movzx   eax,    word[esi+pcx_header.xmax]
99
    inc     ax
100
    sub     ax,     word[esi+pcx_header.xmin]
101
    mov     [xsize],    ax
102
 
103
    movzx   ebx,    word[esi+pcx_header.ymax]
104
    inc     bx
105
    sub     bx,     word[esi+pcx_header.ymin]
106
    mov     [ysize],    bx
107
 
1593 dunkaist 108
 
109
    cmp     [esi+pcx_header.bpp],   1
110
     jz     .monochrome
111
    cmp     byte[esi+pcx_header.nplanes],   3
112
     jnz    .indexed
113
 
114
 
115
  ._24bit:
116
 
1569 dunkaist 117
      stdcall   img.create, eax, ebx, Image.bpp24
118
    mov     [retvalue], eax
119
    test    eax,    eax
120
     jz     .quit
121
 
122
    movzx   ebx,    [xsize]
123
    movzx   ecx,    [ysize]
124
    mov     edx,    [eax+Image.Data]
125
 
126
    rol     ebx,    16
127
    or      ebx,    ecx
128
    xor     ebx,    [edx]
129
    mov     [eax+Image.Checksum],   ebx
130
 
131
 
132
    mov     esi,    [_data]
133
    add     esi,    128
1593 dunkaist 134
;    mov     edi,    [retvalue]
135
    mov     edi,    [eax+Image.Data]
1569 dunkaist 136
    add     edi,    2
137
    mov     [line_begin],   edi
138
    mov     ebx,    [total_bpl]
139
 
1593 dunkaist 140
  ._24bit.begin:
141
    mov     ax,     word[bpl]
142
  ._24bit.decode:
143
      call      get_byte
144
  ._24bit.write_sequence:
145
    mov     [edi],  dl
1569 dunkaist 146
    dec     ax
147
    add     edi,    [nplanes]
1593 dunkaist 148
    dec     dh
149
     jnz    ._24bit.write_sequence
1569 dunkaist 150
 
151
    test    ax,     ax
1593 dunkaist 152
     jz     ._24bit.end_color_line
153
     jmp    ._24bit.decode
1569 dunkaist 154
 
1593 dunkaist 155
 ._24bit.end_color_line:
1569 dunkaist 156
    test    ebx,    ebx
1593 dunkaist 157
     jz     ._24bit.end_full_line
1569 dunkaist 158
    dec     [line_begin]
159
    mov     edi,    [line_begin]
1593 dunkaist 160
     jmp    ._24bit.begin
1569 dunkaist 161
 
1593 dunkaist 162
  ._24bit.end_full_line:
1569 dunkaist 163
    dec     word[ysize]
164
     jz     .quit
165
    mov     ebx,    [total_bpl]
166
    add     edi,    2
167
    mov     [line_begin],   edi
1593 dunkaist 168
     jmp    ._24bit.begin
1569 dunkaist 169
 
1572 dunkaist 170
 
1593 dunkaist 171
  .indexed:
1572 dunkaist 172
 
173
      stdcall   img.create, eax, ebx, Image.bpp8
174
    mov     [retvalue], eax
175
    test    eax,    eax
176
     jz     .quit
177
 
1593 dunkaist 178
    movzx   ebx,    [xsize]
179
    movzx   ecx,    [ysize]
180
    mov     edx,    [eax+Image.Data]
181
 
182
    rol     ebx,    16
183
    or      ebx,    ecx
184
    xor     ebx,    [edx]
185
    mov     [eax+Image.Checksum],   ebx
186
 
1572 dunkaist 187
    mov     esi,    [_data]
188
    add     esi,    [_length]
189
    sub     esi,    768
190
    mov     edi,    [eax+Image.Palette]
1593 dunkaist 191
    mov      cx,    256
1572 dunkaist 192
  @@:
193
    mov     ebx,    [esi]
194
    bswap   ebx
195
    shr     ebx,    8
196
    mov     [edi],  ebx
197
    add     edi,    4
198
    add     esi,    3
1593 dunkaist 199
    dec     cx
1572 dunkaist 200
     jnz    @b
201
 
202
    mov     esi,    [_data]
203
    add     esi,    128
1593 dunkaist 204
;    mov     edi,    [retvalue]
205
    mov     edi,    [eax+Image.Data]
1572 dunkaist 206
 
1593 dunkaist 207
  .indexed.begin:
208
    mov     ax,     word[bpl]
209
  .indexed.decode:
210
      call      get_byte
211
  .indexed.write_sequence:
212
    mov     [edi], dl
1572 dunkaist 213
    inc     edi
214
    dec     ax
1593 dunkaist 215
    dec     dh
216
     jnz    .indexed.write_sequence
1572 dunkaist 217
 
218
    test    ax,     ax
1593 dunkaist 219
     jz     .indexed.end_line
220
     jmp    .indexed.decode
1572 dunkaist 221
 
1593 dunkaist 222
  .indexed.end_line:
1572 dunkaist 223
    dec     word[ysize]
224
     jz     .quit
1593 dunkaist 225
     jmp    .indexed.begin
1572 dunkaist 226
 
227
 
1593 dunkaist 228
  .monochrome:
1572 dunkaist 229
 
1593 dunkaist 230
      stdcall   img.create, eax, ebx, Image.bpp1
1572 dunkaist 231
    mov     [retvalue], eax
232
    test    eax,    eax
233
     jz     .quit
234
 
235
    movzx   ebx,    [xsize]
236
    movzx   ecx,    [ysize]
237
    mov     edx,    [eax+Image.Data]
238
 
239
    rol     ebx,    16
240
    or      ebx,    ecx
241
    xor     ebx,    [edx]
242
    mov     [eax+Image.Checksum],   ebx
243
 
1593 dunkaist 244
    mov     edi,    [eax+Image.Palette]
245
    mov     [edi],  dword   0x00000000
246
    mov     [edi+4],    dword   0x00ffffff
1572 dunkaist 247
 
248
    mov     esi,    [_data]
249
    add     esi,    128
1593 dunkaist 250
;    mov     edi,    [retvalue]
251
    mov     edi,    [eax+Image.Data]
1572 dunkaist 252
 
1593 dunkaist 253
 
254
  .monochrome.begin:
255
    mov     ebx,    [total_bpl]
1572 dunkaist 256
    mov     ax,     [xsize]
257
 
1593 dunkaist 258
  .monochrome.decode:
259
      call      get_byte
260
  .monochrome.write_sequence:
261
    mov     [edi],  dl
262
    inc     edi
263
    cmp     ax,     8
264
     jng    .monochrome.is_last_byte_in_line
265
    sub     ax,     8
266
    dec     dh
267
     jnz    .monochrome.write_sequence
268
     jmp    .monochrome.decode
1572 dunkaist 269
 
1593 dunkaist 270
  .monochrome.is_last_byte_in_line:
271
    test    ebx,    ebx
1572 dunkaist 272
     jng    @f
1593 dunkaist 273
      call      get_byte
274
     jmp    .monochrome.is_last_byte_in_line
1572 dunkaist 275
  @@:
276
    dec     word[ysize]
1593 dunkaist 277
     jnz    .monochrome.begin
1572 dunkaist 278
     jmp    .quit
279
 
1593 dunkaist 280
 
1572 dunkaist 281
  .quit:
282
    popa
283
    mov     eax,    [retvalue]
284
    ret
285
 
1569 dunkaist 286
endp
287
 
1572 dunkaist 288
 
289
 
1569 dunkaist 290
;;================================================================================================;;
291
proc img.encode.pcx _img, _p_length, _options ;///////////////////////////////////////////////////;;
292
;;------------------------------------------------------------------------------------------------;;
293
;? Encode image into raw data in Targa format                                                     ;;
294
;;------------------------------------------------------------------------------------------------;;
295
;> _img = pointer to image                                                                        ;;
296
;;------------------------------------------------------------------------------------------------;;
297
;< eax = 0 (error) or pointer to encoded data                                                     ;;
298
;< _p_length = encoded data length                                                                ;;
299
;;================================================================================================;;
300
    xor eax, eax
301
    ret
302
endp
303
 
304
 
305
;;================================================================================================;;
306
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
307
;;================================================================================================;;
308
;! Below are private procs you should never call directly from your code                          ;;
309
;;================================================================================================;;
310
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
311
;;================================================================================================;;
1593 dunkaist 312
proc get_byte
1569 dunkaist 313
 
1593 dunkaist 314
    mov     dh,     byte[esi]
315
    inc     esi
316
    cmp     dh,     0xC0
317
     jnb    .cycle1
318
    mov     dl,     dh
319
    mov     dh,     1
320
     jmp    .exit1
321
  .cycle1:
322
    and     dh,     0x3F
323
    mov     dl,     byte[esi]
324
    inc     esi
325
  .exit1:
326
    movzx   ecx,     dh
327
    sub     ebx,    ecx
328
 
329
    ret
330
endp
1569 dunkaist 331
;;================================================================================================;;
332
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
333
;;================================================================================================;;
334
;! Below is private data you should never use directly from your code                             ;;
335
;;================================================================================================;;
336
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
337
;;================================================================================================;;
338
 
339
;