Rev 2733 | Rev 3503 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2733 | Rev 3499 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | ;;================================================================================================;; |
1 | ;;================================================================================================;; |
2 | ;;//// pcx.asm //// (c) dunkaist, 2010,2012 //////////////////////////////////////////////////////;; |
2 | ;;//// pcx.asm //// (c) dunkaist, 2010,2012-2013 /////////////////////////////////////////////////;; |
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 ;; |
Line 28... | Line 28... | ||
28 | ;> _length = data length ;; |
28 | ;> _length = data length ;; |
29 | ;;------------------------------------------------------------------------------------------------;; |
29 | ;;------------------------------------------------------------------------------------------------;; |
30 | ;< eax = false / true ;; |
30 | ;< eax = false / true ;; |
31 | ;;================================================================================================;; |
31 | ;;================================================================================================;; |
Line 32... | Line 32... | ||
32 | 32 | ||
33 | push ecx edi |
33 | push edi |
Line 34... | Line 34... | ||
34 | xor eax, eax |
34 | xor eax, eax |
Line 35... | Line -... | ||
35 | - | ||
36 | mov edi, [_data] |
- | |
37 | 35 | ||
38 | cmp byte[edi + pcx_header.magic_number], 0x0A |
36 | mov edi, [_data] |
39 | jne .is_not_pcx |
37 | |
40 | cmp byte[edi + pcx_header.version], 5 |
38 | mov ecx, [edi] |
41 | jne .is_not_pcx |
39 | shl ecx, 8 |
42 | cmp byte[edi + pcx_header.encoding], 1 |
40 | cmp ecx, 0x01050a00 |
Line 43... | Line 41... | ||
43 | jne .is_not_pcx |
41 | jne .is_not_pcx |
44 | cmp byte[edi + pcx_header.reserved], 0 |
- | |
45 | jne .is_not_pcx |
42 | cmp byte[edi + pcx_header.reserved], 0 |
46 | - | ||
47 | add edi, pcx_header.filler |
43 | jne .is_not_pcx |
48 | xor al, al |
- | |
49 | mov ecx, 58 |
44 | |
Line 50... | Line 45... | ||
50 | cld |
45 | add edi, pcx_header.filler |
51 | repe scasb |
46 | mov ecx, 58/2 |
52 | test ecx, ecx |
- | |
53 | jnz .is_not_pcx |
47 | repe scasw |
54 | 48 | jne .is_not_pcx |
|
55 | .is_pcx: |
49 | |
56 | inc eax |
50 | .is_pcx: |
Line 57... | Line 51... | ||
57 | 51 | inc eax |
|
Line 70... | Line 64... | ||
70 | ;> _length = data length ;; |
64 | ;> _length = data length ;; |
71 | ;;------------------------------------------------------------------------------------------------;; |
65 | ;;------------------------------------------------------------------------------------------------;; |
72 | ;< eax = 0 (error) or pointer to image ;; |
66 | ;< eax = 0 (error) or pointer to image ;; |
73 | ;;================================================================================================;; |
67 | ;;================================================================================================;; |
74 | locals |
68 | locals |
75 | nplanes rd 1 |
69 | num_planes rd 1 |
76 | xsize rd 1 |
70 | width rd 1 |
77 | ysize rd 1 |
71 | height rd 1 |
78 | bpl rd 1 |
72 | bp_plane rd 1 |
79 | total_bpl rd 1 |
73 | bp_scanline rd 1 |
80 | line_begin rd 1 |
74 | line_begin rd 1 |
- | 75 | cur_scanline rd 1 |
|
81 | retvalue rd 1 ; 0 (error) or pointer to image |
76 | retvalue rd 1 ; 0 (error) or pointer to image |
82 | endl |
77 | endl |
Line 83... | Line 78... | ||
83 | 78 | ||
Line 84... | Line 79... | ||
84 | pusha |
79 | pusha |
85 | 80 | ||
86 | mov esi, [_data] |
81 | mov esi, [_data] |
87 | movzx eax, byte[esi + pcx_header.nplanes] |
82 | movzx eax, byte[esi + pcx_header.nplanes] |
88 | mov [nplanes], eax |
83 | mov [num_planes], eax |
89 | movzx ebx, word[esi + pcx_header.bpl] |
84 | movzx ebx, word[esi + pcx_header.bpl] |
90 | mov [bpl], ebx |
85 | mov [bp_plane], ebx |
Line 91... | Line 86... | ||
91 | imul eax, ebx |
86 | imul eax, ebx |
92 | mov [total_bpl], eax |
87 | mov [bp_scanline], eax |
93 | 88 | ||
94 | movzx eax, word[esi + pcx_header.xmax] |
89 | movzx eax, word[esi + pcx_header.xmax] |
Line 95... | Line 90... | ||
95 | sub ax, word[esi + pcx_header.xmin] |
90 | sub ax, word[esi + pcx_header.xmin] |
96 | inc eax |
91 | inc eax |
97 | mov [xsize], eax |
92 | mov [width], eax |
98 | 93 | ||
Line 99... | Line 94... | ||
99 | movzx ebx, word[esi + pcx_header.ymax] |
94 | movzx ebx, word[esi + pcx_header.ymax] |
100 | sub bx, word[esi + pcx_header.ymin] |
95 | sub bx, word[esi + pcx_header.ymin] |
101 | inc ebx |
96 | inc ebx |
102 | mov [ysize], ebx |
97 | mov [height], ebx |
Line 103... | Line 98... | ||
103 | 98 | ||
- | 99 | cmp [esi + pcx_header.bpp], 1 |
|
- | 100 | jz .monochrome |
|
- | 101 | cmp byte[esi + pcx_header.nplanes], 3 |
|
- | 102 | jnz .indexed |
|
Line 104... | Line 103... | ||
104 | cmp [esi + pcx_header.bpp], 1 |
103 | |
105 | jz .monochrome |
104 | |
106 | cmp byte[esi + pcx_header.nplanes], 3 |
105 | .24bit: |
107 | jnz .indexed |
106 | stdcall img.create, [bp_plane], 1, Image.bpp24 |
Line 108... | Line 107... | ||
108 | 107 | mov [cur_scanline], eax |
|
109 | 108 | test eax, eax |
|
110 | .24bit: |
109 | jz .quit |
111 | - | ||
112 | stdcall img.create, eax, ebx, Image.bpp24 |
- | |
Line 113... | Line 110... | ||
113 | mov [retvalue], eax |
110 | |
114 | test eax, eax |
111 | stdcall img.create, [width], [height], Image.bpp24 |
115 | jz .quit |
- | |
116 | 112 | mov [retvalue], eax |
|
117 | mov esi, [_data] |
- | |
118 | add esi, 128 ; skip header |
- | |
119 | mov edi, [eax + Image.Data] |
- | |
120 | add edi, 2 |
113 | test eax, eax |
121 | mov [line_begin], edi |
- | |
122 | - | ||
123 | .24bit.scanline: |
- | |
124 | mov ebx, [total_bpl] |
- | |
125 | .24bit.color_line: |
- | |
126 | mov edx, [bpl] |
- | |
127 | .24bit.next_byte: |
114 | jz .quit |
128 | call pcx._.get_byte |
- | |
129 | sub edx, ecx |
115 | |
130 | @@: |
116 | mov esi, [_data] |
131 | mov [edi], al |
- | |
132 | add edi, [nplanes] |
117 | add esi, sizeof.pcx_header |
133 | dec ecx |
118 | mov edx, [eax + Image.Data] |
134 | jnz @b |
- | |
135 | - | ||
136 | test edx, edx |
- | |
137 | jnz .24bit.next_byte |
119 | |
138 | - | ||
139 | .24bit.end_color_line: |
- | |
140 | test ebx, ebx |
- | |
141 | jz .24bit.end_full_line |
- | |
142 | dec [line_begin] |
- | |
143 | mov edi, [line_begin] |
- | |
144 | jmp .24bit.color_line |
- | |
145 | 120 | .24bit.scanline: |
|
- | 121 | mov edi, [cur_scanline] |
|
Line 146... | Line 122... | ||
146 | .24bit.end_full_line: |
122 | mov ebx, [bp_scanline] |
147 | dec [ysize] |
- | |
148 | jz .quit |
123 | @@: |
149 | add edi, 2 |
124 | call pcx._.get_byte |
150 | bt [xsize], 0 |
125 | rep stosb |
151 | jnc @f |
126 | test ebx, ebx |
Line 152... | Line 127... | ||
152 | sub edi, 3 |
127 | jnz @b |
153 | @@: |
128 | stdcall pcx._.scanline_unpack, [width], [cur_scanline], [num_planes] |
154 | mov [line_begin], edi |
129 | dec [height] |
155 | jmp .24bit.scanline |
130 | jnz .24bit.scanline |
156 | 131 | jmp .quit |
|
157 | 132 | ||
158 | .indexed: |
133 | |
159 | 134 | .indexed: |
|
- | 135 | stdcall img.create, [width], [height], Image.bpp8i |
|
160 | stdcall img.create, eax, ebx, Image.bpp8i |
136 | mov [retvalue], eax |
161 | mov [retvalue], eax |
137 | test eax, eax |
162 | test eax, eax |
138 | jz .quit |
- | 139 | ||
- | 140 | mov ebx, eax |
|
163 | jz .quit |
141 | mov esi, [_data] |
164 | 142 | add esi, [_length] |
|
165 | mov ebx, eax |
143 | sub esi, 256*3 ; rgb triplets |
166 | mov esi, [_data] |
144 | mov edi, [eax + Image.Palette] |
Line 167... | Line 145... | ||
167 | add esi, [_length] |
145 | mov ecx, 256 |
168 | sub esi, 768 |
146 | mov eax, 0x0000ff00 |
169 | mov edi, [eax + Image.Palette] |
147 | @@: |
Line 170... | Line 148... | ||
170 | mov ecx, 256 |
148 | mov al, [esi + 0] |
171 | xor eax, eax |
149 | mov [edi + 2], ax |
172 | @@: |
- | |
173 | lodsw |
- | |
174 | xchg al, ah |
150 | mov al, [esi + 1] |
175 | shl eax, 8 |
- | |
176 | lodsb |
151 | mov [edi + 1], al |
177 | stosd |
152 | mov al, [esi + 2] |
178 | dec ecx |
153 | mov [edi + 0], al |
179 | jnz @b |
154 | add esi, 3 |
180 | - | ||
181 | mov esi, [_data] |
155 | add edi, 4 |
182 | add esi, 128 |
156 | dec ecx |
183 | mov edi, [ebx + Image.Data] |
157 | jnz @b |
Line 184... | Line 158... | ||
184 | 158 | ||
185 | .indexed.line: |
- | |
186 | mov ebx, [total_bpl] |
159 | mov esi, [_data] |
187 | .indexed.next_byte: |
160 | add esi, sizeof.pcx_header |
188 | call pcx._.get_byte |
161 | mov edi, [ebx + Image.Data] |
189 | @@: |
162 | |
Line 190... | Line 163... | ||
190 | stosb |
163 | .indexed.scanline: |
191 | dec ecx |
164 | mov ebx, [bp_scanline] |
192 | jnz @b |
165 | @@: |
Line 193... | Line 166... | ||
193 | test ebx, ebx |
166 | call pcx._.get_byte |
194 | jnz .indexed.next_byte |
167 | rep stosb |
195 | 168 | test ebx, ebx |
|
Line 196... | Line -... | ||
196 | dec [ysize] |
- | |
197 | jnz .indexed.line |
169 | jnz @b |
198 | jmp .quit |
170 | dec [height] |
199 | - | ||
200 | - | ||
201 | .monochrome: |
171 | jnz .indexed.scanline |
202 | - | ||
203 | stdcall img.create, eax, ebx, Image.bpp1 |
172 | jmp .quit |
204 | mov [retvalue], eax |
173 | |
205 | test eax, eax |
174 | |
206 | jz .quit |
175 | .monochrome: |
207 | 176 | stdcall img.create, [width], [height], Image.bpp1 |
|
208 | mov edi, [eax + Image.Palette] |
177 | mov [retvalue], eax |
209 | mov [edi], dword 0xff000000 |
178 | test eax, eax |
Line 210... | Line -... | ||
210 | mov [edi + 4], dword 0xffffffff |
- | |
211 | 179 | jz .quit |
|
212 | mov esi, [_data] |
180 | |
213 | add esi, 128 |
181 | mov edi, [eax + Image.Palette] |
214 | mov edi, [eax + Image.Data] |
182 | mov [edi], dword 0xff000000 |
215 | 183 | mov [edi + 4], dword 0xffffffff |
|
Line 260... | Line 228... | ||
260 | ;;================================================================================================;; |
228 | ;;================================================================================================;; |
261 | ;;////////////////////////////////////////////////////////////////////////////////////////////////;; |
229 | ;;////////////////////////////////////////////////////////////////////////////////////////////////;; |
262 | ;;================================================================================================;; |
230 | ;;================================================================================================;; |
263 | proc pcx._.get_byte |
231 | proc pcx._.get_byte |
Line -... | Line 232... | ||
- | 232 | ||
264 | 233 | mov ecx, 1 |
|
265 | xor ecx, ecx |
234 | xor eax, eax |
266 | lodsb |
235 | lodsb |
267 | cmp al, 0xC0 |
- | |
268 | setb cl |
236 | cmp eax, 0xc0 |
269 | jb .done |
237 | jb @f |
270 | and al, 0x3F |
238 | and eax, 0x3f |
271 | mov cl, al |
239 | mov ecx, eax |
272 | lodsb |
240 | lodsb |
273 | .done: |
241 | @@: |
274 | sub ebx, ecx |
242 | sub ebx, ecx |
275 | ret |
243 | ret |
Line -... | Line 244... | ||
- | 244 | endp |
|
- | 245 | ||
- | 246 | ||
- | 247 | proc pcx._.scanline_unpack _width, _scanline, _num_planes |
|
- | 248 | push esi |
|
- | 249 | ||
- | 250 | mov esi, [_scanline] |
|
- | 251 | mov ebx, [_num_planes] |
|
- | 252 | dec ebx |
|
- | 253 | ||
- | 254 | .plane: |
|
- | 255 | mov ecx, [_width] |
|
- | 256 | mov edi, edx |
|
- | 257 | add edi, ebx |
|
- | 258 | @@: |
|
- | 259 | mov al, [esi] |
|
- | 260 | mov [edi], al |
|
- | 261 | add esi, 1 |
|
- | 262 | add edi, [_num_planes] |
|
- | 263 | dec ecx |
|
- | 264 | jnz @b |
|
- | 265 | bt dword[_width], 0 |
|
- | 266 | adc esi, 0 |
|
- | 267 | dec ebx |
|
- | 268 | jns .plane |
|
- | 269 | ||
- | 270 | mov edx, edi |
|
276 | endp |
271 | pop esi |
277 | 272 | ret |
|
278 | 273 | endp |
|
279 | ;;================================================================================================;; |
274 | ;;================================================================================================;; |
280 | ;;////////////////////////////////////////////////////////////////////////////////////////////////;; |
275 | ;;////////////////////////////////////////////////////////////////////////////////////////////////;; |