Subversion Repositories Kolibri OS

Rev

Rev 1593 | Rev 1921 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1593 Rev 1728
1
;;================================================================================================;;
1
;;================================================================================================;;
2
;;//// pcx.asm //// (c) dunkaist, 2010 ///////////////////////////////////////////////////////////;;
2
;;//// pcx.asm //// (c) dunkaist, 2010 ///////////////////////////////////////////////////////////;;
3
;;================================================================================================;;
3
;;================================================================================================;;
4
;;                                                                                                ;;
4
;;                                                                                                ;;
5
;; This file is part of Common development libraries (Libs-Dev).                                  ;;
5
;; This file is part of Common development libraries (Libs-Dev).                                  ;;
6
;;                                                                                                ;;
6
;;                                                                                                ;;
7
;; Libs-Dev is free software: you can redistribute it and/or modify it under the terms of the GNU ;;
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 ;;
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.                                         ;;
9
;; of the License, or (at your option) any later version.                                         ;;
10
;;                                                                                                ;;
10
;;                                                                                                ;;
11
;; Libs-Dev is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without  ;;
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  ;;
12
;; even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU  ;;
13
;; Lesser General Public License for more details.                                                ;;
13
;; Lesser General Public License for more details.                                                ;;
14
;;                                                                                                ;;
14
;;                                                                                                ;;
15
;; You should have received a copy of the GNU Lesser General Public License along with Libs-Dev.  ;;
15
;; You should have received a copy of the GNU Lesser General Public License along with Libs-Dev.  ;;
16
;; If not, see .                                                    ;;
16
;; If not, see .                                                    ;;
17
;;                                                                                                ;;
17
;;                                                                                                ;;
18
;;================================================================================================;;
18
;;================================================================================================;;
19
 
19
 
20
include 'pcx.inc'
20
include 'pcx.inc'
21
include '../../../../system/board/trunk/debug.inc'
21
;include '../../../../system/board/trunk/debug.inc'
22
 
22
 
23
;;================================================================================================;;
23
;;================================================================================================;;
24
proc img.is.pcx _data, _length ;//////////////////////////////////////////////////////////////////;;
24
proc img.is.pcx _data, _length ;//////////////////////////////////////////////////////////////////;;
25
;;------------------------------------------------------------------------------------------------;;
25
;;------------------------------------------------------------------------------------------------;;
26
;? Determine if raw data could be decoded (is in Targa format)                                    ;;
26
;? Determine if raw data could be decoded (is in Targa format)                                    ;;
27
;;------------------------------------------------------------------------------------------------;;
27
;;------------------------------------------------------------------------------------------------;;
28
;> _data = raw data as read from file/stream                                                      ;;
28
;> _data = raw data as read from file/stream                                                      ;;
29
;> _length = data length                                                                          ;;
29
;> _length = data length                                                                          ;;
30
;;------------------------------------------------------------------------------------------------;;
30
;;------------------------------------------------------------------------------------------------;;
31
;< eax = false / true                                                                             ;;
31
;< eax = false / true                                                                             ;;
32
;;================================================================================================;;
32
;;================================================================================================;;
33
 
33
 
34
    push    ecx edi
34
    push    ecx edi
35
    xor     eax,    eax
35
    xor     eax,    eax
36
 
36
 
37
    mov     edi,    [_data]
37
    mov     edi,    [_data]
38
 
38
 
39
    cmp     [edi+pcx_header.magic_number],  10
39
    cmp     [edi+pcx_header.magic_number],  10
40
     jne    .is_not_pcx
40
     jne    .is_not_pcx
41
    cmp     [edi+pcx_header.version],  5
41
    cmp     [edi+pcx_header.version],  5
42
     jne    .is_not_pcx
42
     jne    .is_not_pcx
43
    cmp     [edi+pcx_header.encoding],  1
43
    cmp     [edi+pcx_header.encoding],  1
44
     jne    .is_not_pcx
44
     jne    .is_not_pcx
45
    cmp     [edi+pcx_header.reserved],  0
45
    cmp     [edi+pcx_header.reserved],  0
46
     jne    .is_not_pcx
46
     jne    .is_not_pcx
47
 
47
 
48
    add     edi,    pcx_header.filler
48
    add     edi,    pcx_header.filler
49
    xor     al,     al
49
    xor     al,     al
50
    mov     ecx,    58
50
    mov     ecx,    58
51
    cld
51
    cld
52
    repe    scasb
52
    repe    scasb
53
    test    ecx,    ecx
53
    test    ecx,    ecx
54
     jnz    .is_not_pcx
54
     jnz    .is_not_pcx
55
 
55
 
56
.is_pcx:
56
.is_pcx:
57
    inc     eax
57
    inc     eax
58
 
58
 
59
.is_not_pcx:
59
.is_not_pcx:
60
    pop     edi ecx
60
    pop     edi ecx
61
    ret
61
    ret
62
 
62
 
63
endp
63
endp
64
 
64
 
65
;;================================================================================================;;
65
;;================================================================================================;;
66
proc img.decode.pcx _data, _length, _options ;////////////////////////////////////////////////////;;
66
proc img.decode.pcx _data, _length, _options ;////////////////////////////////////////////////////;;
67
;;------------------------------------------------------------------------------------------------;;
67
;;------------------------------------------------------------------------------------------------;;
68
;? Decode data into image if it contains correctly formed raw data in Targa format                ;;
68
;? Decode data into image if it contains correctly formed raw data in Targa format                ;;
69
;;------------------------------------------------------------------------------------------------;;
69
;;------------------------------------------------------------------------------------------------;;
70
;> _data = raw data as read from file/stream                                                      ;;
70
;> _data = raw data as read from file/stream                                                      ;;
71
;> _length = data length                                                                          ;;
71
;> _length = data length                                                                          ;;
72
;;------------------------------------------------------------------------------------------------;;
72
;;------------------------------------------------------------------------------------------------;;
73
;< eax = 0 (error) or pointer to image                                                            ;;
73
;< eax = 0 (error) or pointer to image                                                            ;;
74
;;================================================================================================;;
74
;;================================================================================================;;
75
locals
75
locals
76
nplanes             rd      1
76
nplanes             rd      1
77
xsize               rw      1
77
xsize               rw      1
78
ysize               rw      1
78
ysize               rw      1
79
bpl                 rw      1
79
bpl                 rw      1
80
total_bpl           rd      1
80
total_bpl           rd      1
81
line_begin          rd      1
81
line_begin          rd      1
82
retvalue            rd      1                       ; 0 (error) or pointer to image 
82
retvalue            rd      1                       ; 0 (error) or pointer to image 
83
endl
83
endl
84
 
84
 
85
    pusha
85
    pusha
86
 
86
 
87
    mov     esi,    [_data]
87
    mov     esi,    [_data]
88
    movzx   eax,    byte[esi+pcx_header.nplanes]
88
    movzx   eax,    byte[esi+pcx_header.nplanes]
89
    mov     [nplanes],  eax
89
    mov     [nplanes],  eax
90
    mov     bx,  word[esi+pcx_header.bpl]
90
    mov     bx,  word[esi+pcx_header.bpl]
91
    mov     [bpl],  bx
91
    mov     [bpl],  bx
92
    mul     bx
92
    mul     bx
93
    shl     eax,    16
93
    shl     eax,    16
94
    mov     ax,     dx
94
    mov     ax,     dx
95
    ror     eax,    16
95
    ror     eax,    16
96
    mov     [total_bpl],    eax
96
    mov     [total_bpl],    eax
97
 
97
 
98
    movzx   eax,    word[esi+pcx_header.xmax]
98
    movzx   eax,    word[esi+pcx_header.xmax]
99
    inc     ax
99
    inc     ax
100
    sub     ax,     word[esi+pcx_header.xmin]
100
    sub     ax,     word[esi+pcx_header.xmin]
101
    mov     [xsize],    ax
101
    mov     [xsize],    ax
102
 
102
 
103
    movzx   ebx,    word[esi+pcx_header.ymax]
103
    movzx   ebx,    word[esi+pcx_header.ymax]
104
    inc     bx
104
    inc     bx
105
    sub     bx,     word[esi+pcx_header.ymin]
105
    sub     bx,     word[esi+pcx_header.ymin]
106
    mov     [ysize],    bx
106
    mov     [ysize],    bx
107
 
107
 
108
 
108
 
109
    cmp     [esi+pcx_header.bpp],   1
109
    cmp     [esi+pcx_header.bpp],   1
110
     jz     .monochrome
110
     jz     .monochrome
111
    cmp     byte[esi+pcx_header.nplanes],   3
111
    cmp     byte[esi+pcx_header.nplanes],   3
112
     jnz    .indexed
112
     jnz    .indexed
113
 
113
 
114
 
114
 
115
  ._24bit:
115
  ._24bit:
116
 
116
 
117
      stdcall   img.create, eax, ebx, Image.bpp24
117
      stdcall   img.create, eax, ebx, Image.bpp24
118
    mov     [retvalue], eax
118
    mov     [retvalue], eax
119
    test    eax,    eax
119
    test    eax,    eax
120
     jz     .quit
120
     jz     .quit
121
 
121
 
122
    movzx   ebx,    [xsize]
122
    movzx   ebx,    [xsize]
123
    movzx   ecx,    [ysize]
123
    movzx   ecx,    [ysize]
124
    mov     edx,    [eax+Image.Data]
124
    mov     edx,    [eax+Image.Data]
125
 
125
 
126
    rol     ebx,    16
126
    rol     ebx,    16
127
    or      ebx,    ecx
127
    or      ebx,    ecx
128
    xor     ebx,    [edx]
128
    xor     ebx,    [edx]
129
    mov     [eax+Image.Checksum],   ebx
129
    mov     [eax+Image.Checksum],   ebx
130
 
130
 
131
 
131
 
132
    mov     esi,    [_data]
132
    mov     esi,    [_data]
133
    add     esi,    128
133
    add     esi,    128
134
;    mov     edi,    [retvalue]
134
;    mov     edi,    [retvalue]
135
    mov     edi,    [eax+Image.Data]
135
    mov     edi,    [eax+Image.Data]
136
    add     edi,    2
136
    add     edi,    2
137
    mov     [line_begin],   edi
137
    mov     [line_begin],   edi
138
    mov     ebx,    [total_bpl]
138
    mov     ebx,    [total_bpl]
139
 
139
 
140
  ._24bit.begin:
140
  ._24bit.begin:
141
    mov     ax,     word[bpl]
141
    mov     ax,     word[bpl]
142
  ._24bit.decode:
142
  ._24bit.decode:
143
      call      get_byte
143
      call      get_byte
144
  ._24bit.write_sequence:
144
  ._24bit.write_sequence:
145
    mov     [edi],  dl
145
    mov     [edi],  dl
146
    dec     ax
146
    dec     ax
147
    add     edi,    [nplanes]
147
    add     edi,    [nplanes]
148
    dec     dh
148
    dec     dh
149
     jnz    ._24bit.write_sequence
149
     jnz    ._24bit.write_sequence
150
 
150
 
151
    test    ax,     ax
151
    test    ax,     ax
152
     jz     ._24bit.end_color_line
152
     jz     ._24bit.end_color_line
153
     jmp    ._24bit.decode
153
     jmp    ._24bit.decode
154
 
154
 
155
 ._24bit.end_color_line:
155
 ._24bit.end_color_line:
156
    test    ebx,    ebx
156
    test    ebx,    ebx
157
     jz     ._24bit.end_full_line
157
     jz     ._24bit.end_full_line
158
    dec     [line_begin]
158
    dec     [line_begin]
159
    mov     edi,    [line_begin]
159
    mov     edi,    [line_begin]
160
     jmp    ._24bit.begin
160
     jmp    ._24bit.begin
161
 
161
 
162
  ._24bit.end_full_line:
162
  ._24bit.end_full_line:
163
    dec     word[ysize]
163
    dec     word[ysize]
164
     jz     .quit
164
     jz     .quit
165
    mov     ebx,    [total_bpl]
165
    mov     ebx,    [total_bpl]
166
    add     edi,    2
166
    add     edi,    2
167
    mov     [line_begin],   edi
167
    mov     [line_begin],   edi
168
     jmp    ._24bit.begin
168
     jmp    ._24bit.begin
169
 
169
 
170
 
170
 
171
  .indexed:
171
  .indexed:
172
 
172
 
173
      stdcall   img.create, eax, ebx, Image.bpp8
173
      stdcall   img.create, eax, ebx, Image.bpp8
174
    mov     [retvalue], eax
174
    mov     [retvalue], eax
175
    test    eax,    eax
175
    test    eax,    eax
176
     jz     .quit
176
     jz     .quit
177
 
177
 
178
    movzx   ebx,    [xsize]
178
    movzx   ebx,    [xsize]
179
    movzx   ecx,    [ysize]
179
    movzx   ecx,    [ysize]
180
    mov     edx,    [eax+Image.Data]
180
    mov     edx,    [eax+Image.Data]
181
 
181
 
182
    rol     ebx,    16
182
    rol     ebx,    16
183
    or      ebx,    ecx
183
    or      ebx,    ecx
184
    xor     ebx,    [edx]
184
    xor     ebx,    [edx]
185
    mov     [eax+Image.Checksum],   ebx
185
    mov     [eax+Image.Checksum],   ebx
186
 
186
 
187
    mov     esi,    [_data]
187
    mov     esi,    [_data]
188
    add     esi,    [_length]
188
    add     esi,    [_length]
189
    sub     esi,    768
189
    sub     esi,    768
190
    mov     edi,    [eax+Image.Palette]
190
    mov     edi,    [eax+Image.Palette]
191
    mov      cx,    256
191
    mov      cx,    256
192
  @@:
192
  @@:
193
    mov     ebx,    [esi]
193
    mov     ebx,    [esi]
194
    bswap   ebx
194
    bswap   ebx
195
    shr     ebx,    8
195
    shr     ebx,    8
196
    mov     [edi],  ebx
196
    mov     [edi],  ebx
197
    add     edi,    4
197
    add     edi,    4
198
    add     esi,    3
198
    add     esi,    3
199
    dec     cx
199
    dec     cx
200
     jnz    @b
200
     jnz    @b
201
 
201
 
202
    mov     esi,    [_data]
202
    mov     esi,    [_data]
203
    add     esi,    128
203
    add     esi,    128
204
;    mov     edi,    [retvalue]
204
;    mov     edi,    [retvalue]
205
    mov     edi,    [eax+Image.Data]
205
    mov     edi,    [eax+Image.Data]
206
 
206
 
207
  .indexed.begin:
207
  .indexed.begin:
208
    mov     ax,     word[bpl]
208
    mov     ax,     word[bpl]
209
  .indexed.decode:
209
  .indexed.decode:
210
      call      get_byte
210
      call      get_byte
211
  .indexed.write_sequence:
211
  .indexed.write_sequence:
212
    mov     [edi], dl
212
    mov     [edi], dl
213
    inc     edi
213
    inc     edi
214
    dec     ax
214
    dec     ax
215
    dec     dh
215
    dec     dh
216
     jnz    .indexed.write_sequence
216
     jnz    .indexed.write_sequence
217
 
217
 
218
    test    ax,     ax
218
    test    ax,     ax
219
     jz     .indexed.end_line
219
     jz     .indexed.end_line
220
     jmp    .indexed.decode
220
     jmp    .indexed.decode
221
 
221
 
222
  .indexed.end_line:
222
  .indexed.end_line:
223
    dec     word[ysize]
223
    dec     word[ysize]
224
     jz     .quit
224
     jz     .quit
225
     jmp    .indexed.begin
225
     jmp    .indexed.begin
226
 
226
 
227
 
227
 
228
  .monochrome:
228
  .monochrome:
229
 
229
 
230
      stdcall   img.create, eax, ebx, Image.bpp1
230
      stdcall   img.create, eax, ebx, Image.bpp1
231
    mov     [retvalue], eax
231
    mov     [retvalue], eax
232
    test    eax,    eax
232
    test    eax,    eax
233
     jz     .quit
233
     jz     .quit
234
 
234
 
235
    movzx   ebx,    [xsize]
235
    movzx   ebx,    [xsize]
236
    movzx   ecx,    [ysize]
236
    movzx   ecx,    [ysize]
237
    mov     edx,    [eax+Image.Data]
237
    mov     edx,    [eax+Image.Data]
238
 
238
 
239
    rol     ebx,    16
239
    rol     ebx,    16
240
    or      ebx,    ecx
240
    or      ebx,    ecx
241
    xor     ebx,    [edx]
241
    xor     ebx,    [edx]
242
    mov     [eax+Image.Checksum],   ebx
242
    mov     [eax+Image.Checksum],   ebx
243
 
243
 
244
    mov     edi,    [eax+Image.Palette]
244
    mov     edi,    [eax+Image.Palette]
245
    mov     [edi],  dword   0x00000000
245
    mov     [edi],  dword   0x00000000
246
    mov     [edi+4],    dword   0x00ffffff
246
    mov     [edi+4],    dword   0x00ffffff
247
 
247
 
248
    mov     esi,    [_data]
248
    mov     esi,    [_data]
249
    add     esi,    128
249
    add     esi,    128
250
;    mov     edi,    [retvalue]
250
;    mov     edi,    [retvalue]
251
    mov     edi,    [eax+Image.Data]
251
    mov     edi,    [eax+Image.Data]
252
 
252
 
253
 
253
 
254
  .monochrome.begin:
254
  .monochrome.begin:
255
    mov     ebx,    [total_bpl]
255
    mov     ebx,    [total_bpl]
256
    mov     ax,     [xsize]
256
    mov     ax,     [xsize]
257
 
257
 
258
  .monochrome.decode:
258
  .monochrome.decode:
259
      call      get_byte
259
      call      get_byte
260
  .monochrome.write_sequence:
260
  .monochrome.write_sequence:
261
    mov     [edi],  dl
261
    mov     [edi],  dl
262
    inc     edi
262
    inc     edi
263
    cmp     ax,     8
263
    cmp     ax,     8
264
     jng    .monochrome.is_last_byte_in_line
264
     jng    .monochrome.is_last_byte_in_line
265
    sub     ax,     8
265
    sub     ax,     8
266
    dec     dh
266
    dec     dh
267
     jnz    .monochrome.write_sequence
267
     jnz    .monochrome.write_sequence
268
     jmp    .monochrome.decode
268
     jmp    .monochrome.decode
269
 
269
 
270
  .monochrome.is_last_byte_in_line:
270
  .monochrome.is_last_byte_in_line:
271
    test    ebx,    ebx
271
    test    ebx,    ebx
272
     jng    @f
272
     jng    @f
273
      call      get_byte
273
      call      get_byte
274
     jmp    .monochrome.is_last_byte_in_line
274
     jmp    .monochrome.is_last_byte_in_line
275
  @@:
275
  @@:
276
    dec     word[ysize]
276
    dec     word[ysize]
277
     jnz    .monochrome.begin
277
     jnz    .monochrome.begin
278
     jmp    .quit
278
     jmp    .quit
279
 
279
 
280
 
280
 
281
  .quit:
281
  .quit:
282
    popa
282
    popa
283
    mov     eax,    [retvalue]
283
    mov     eax,    [retvalue]
284
    ret
284
    ret
285
 
285
 
286
endp
286
endp
287
 
287
 
288
 
288
 
289
 
289
 
290
;;================================================================================================;;
290
;;================================================================================================;;
291
proc img.encode.pcx _img, _p_length, _options ;///////////////////////////////////////////////////;;
291
proc img.encode.pcx _img, _p_length, _options ;///////////////////////////////////////////////////;;
292
;;------------------------------------------------------------------------------------------------;;
292
;;------------------------------------------------------------------------------------------------;;
293
;? Encode image into raw data in Targa format                                                     ;;
293
;? Encode image into raw data in Targa format                                                     ;;
294
;;------------------------------------------------------------------------------------------------;;
294
;;------------------------------------------------------------------------------------------------;;
295
;> _img = pointer to image                                                                        ;;
295
;> _img = pointer to image                                                                        ;;
296
;;------------------------------------------------------------------------------------------------;;
296
;;------------------------------------------------------------------------------------------------;;
297
;< eax = 0 (error) or pointer to encoded data                                                     ;;
297
;< eax = 0 (error) or pointer to encoded data                                                     ;;
298
;< _p_length = encoded data length                                                                ;;
298
;< _p_length = encoded data length                                                                ;;
299
;;================================================================================================;;
299
;;================================================================================================;;
300
    xor eax, eax
300
    xor eax, eax
301
    ret
301
    ret
302
endp
302
endp
303
 
303
 
304
 
304
 
305
;;================================================================================================;;
305
;;================================================================================================;;
306
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
306
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
307
;;================================================================================================;;
307
;;================================================================================================;;
308
;! Below are private procs you should never call directly from your code                          ;;
308
;! Below are private procs you should never call directly from your code                          ;;
309
;;================================================================================================;;
309
;;================================================================================================;;
310
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
310
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
311
;;================================================================================================;;
311
;;================================================================================================;;
312
proc get_byte
312
proc get_byte
313
 
313
 
314
    mov     dh,     byte[esi]
314
    mov     dh,     byte[esi]
315
    inc     esi
315
    inc     esi
316
    cmp     dh,     0xC0
316
    cmp     dh,     0xC0
317
     jnb    .cycle1
317
     jnb    .cycle1
318
    mov     dl,     dh
318
    mov     dl,     dh
319
    mov     dh,     1
319
    mov     dh,     1
320
     jmp    .exit1
320
     jmp    .exit1
321
  .cycle1:
321
  .cycle1:
322
    and     dh,     0x3F
322
    and     dh,     0x3F
323
    mov     dl,     byte[esi]
323
    mov     dl,     byte[esi]
324
    inc     esi
324
    inc     esi
325
  .exit1:
325
  .exit1:
326
    movzx   ecx,     dh
326
    movzx   ecx,     dh
327
    sub     ebx,    ecx
327
    sub     ebx,    ecx
328
 
328
 
329
    ret
329
    ret
330
endp
330
endp
331
;;================================================================================================;;
331
;;================================================================================================;;
332
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
332
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
333
;;================================================================================================;;
333
;;================================================================================================;;
334
;! Below is private data you should never use directly from your code                             ;;
334
;! Below is private data you should never use directly from your code                             ;;
335
;;================================================================================================;;
335
;;================================================================================================;;
336
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
336
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
337
;;================================================================================================;;
337
;;================================================================================================;;
338
 
338
 
339
;
339
;