Rev 2388 | Rev 2733 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2388 | Rev 2684 | ||
---|---|---|---|
Line 180... | Line 180... | ||
180 | endp |
180 | endp |
Line 181... | Line 181... | ||
181 | 181 | ||
182 | 182 | ||
183 | 183 | ||
184 | ;;================================================================================================;; |
184 | ;;================================================================================================;; |
185 | proc img.encode.pnm _img, _p_length, _options ;///////////////////////////////////////////////////;; |
185 | proc img.encode.pnm _img, _common, _specific ;////////////////////////////////////////////////////;; |
186 | ;;------------------------------------------------------------------------------------------------;; |
186 | ;;------------------------------------------------------------------------------------------------;; |
- | 187 | ;? Encode image into raw data in pnm format ;; |
|
- | 188 | ;;------------------------------------------------------------------------------------------------;; |
|
187 | ;? Encode image into raw data in pnm format ;; |
189 | ;> [_img] = pointer to image ;; |
188 | ;;------------------------------------------------------------------------------------------------;; |
190 | ;> [_common] = format independent options ;; |
189 | ;> _img = pointer to image ;; |
191 | ;> [_specific] = 0 / pointer to the structure of format specific options ;; |
190 | ;;------------------------------------------------------------------------------------------------;; |
192 | ;;------------------------------------------------------------------------------------------------;; |
- | 193 | ;< eax = 0 / pointer to encoded data ;; |
|
- | 194 | ;< ecx = error code / the size of encoded data ;; |
|
- | 195 | ;;================================================================================================;; |
|
- | 196 | locals |
|
- | 197 | encoded_file rd 1 |
|
- | 198 | encoded_file_size rd 1 |
|
- | 199 | encoded_data_size rd 1 |
|
- | 200 | endl |
|
- | 201 | push ebx |
|
- | 202 | ||
- | 203 | mov ebx, [_img] |
|
- | 204 | mov eax, [ebx + Image.Type] |
|
- | 205 | cmp eax, Image.bpp1 |
|
- | 206 | je .pbm |
|
- | 207 | cmp eax, Image.bpp8 |
|
- | 208 | je .pgm |
|
- | 209 | cmp eax, Image.bpp24 |
|
- | 210 | je .ppm |
|
- | 211 | mov ecx, LIBIMG_ERROR_BIT_DEPTH |
|
- | 212 | jmp .error |
|
- | 213 | .pbm: |
|
- | 214 | mov ecx, [ebx + Image.Width] |
|
- | 215 | add ecx, 7 |
|
- | 216 | shr ecx, 3 |
|
- | 217 | imul ecx, [ebx + Image.Height] |
|
- | 218 | mov [encoded_data_size], ecx |
|
- | 219 | add ecx, (2 + 1) + (2 + pnm._.creator_comment.size + 1) + (5 + 1 + 5 + 1) + (3 + 1) |
|
- | 220 | mov [encoded_file_size], ecx |
|
- | 221 | stdcall [mem.alloc], ecx |
|
- | 222 | mov [encoded_file], eax |
|
- | 223 | test eax, eax |
|
- | 224 | jnz @f |
|
- | 225 | mov ecx, LIBIMG_ERROR_OUT_OF_MEMORY |
|
- | 226 | jmp .error |
|
- | 227 | @@: |
|
- | 228 | mov edi, eax |
|
- | 229 | mov ax, 'P4' |
|
- | 230 | call pnm._.write_header |
|
- | 231 | mov esi, [ebx + Image.Data] |
|
- | 232 | mov ecx, [encoded_data_size] |
|
- | 233 | rep movsb |
|
- | 234 | mov eax, [encoded_file] |
|
- | 235 | mov ecx, [encoded_file_size] |
|
- | 236 | jmp .quit |
|
- | 237 | ||
- | 238 | .pgm: |
|
- | 239 | mov ecx, [ebx + Image.Width] |
|
- | 240 | imul ecx, [ebx + Image.Height] |
|
- | 241 | mov [encoded_data_size], ecx |
|
- | 242 | add ecx, (2 + 1) + (2 + pnm._.creator_comment.size + 1) + (5 + 1 + 5 + 1) + (3 + 1) |
|
- | 243 | mov [encoded_file_size], ecx |
|
- | 244 | stdcall [mem.alloc], ecx |
|
- | 245 | mov [encoded_file], eax |
|
- | 246 | test eax, eax |
|
- | 247 | jnz @f |
|
- | 248 | mov ecx, LIBIMG_ERROR_OUT_OF_MEMORY |
|
- | 249 | jmp .error |
|
- | 250 | @@: |
|
- | 251 | mov edi, eax |
|
- | 252 | mov ax, 'P5' |
|
- | 253 | call pnm._.write_header |
|
- | 254 | mov dword[edi], '255 ' |
|
- | 255 | add edi, 3 |
|
- | 256 | mov byte[edi], 0x0A |
|
- | 257 | add edi, 1 |
|
- | 258 | mov esi, [ebx + Image.Data] |
|
- | 259 | mov ecx, [encoded_data_size] |
|
- | 260 | rep movsb |
|
- | 261 | mov eax, [encoded_file] |
|
- | 262 | mov ecx, [encoded_file_size] |
|
- | 263 | jmp .quit |
|
- | 264 | ||
- | 265 | .ppm: |
|
- | 266 | mov ecx, [ebx + Image.Width] |
|
- | 267 | imul ecx, [ebx + Image.Height] |
|
- | 268 | lea ecx, [ecx*3] |
|
- | 269 | mov [encoded_data_size], ecx |
|
- | 270 | add ecx, (2 + 1) + (2 + pnm._.creator_comment.size + 1) + (5 + 1 + 5 + 1) + (3 + 1) |
|
- | 271 | mov [encoded_file_size], ecx |
|
- | 272 | stdcall [mem.alloc], ecx |
|
- | 273 | mov [encoded_file], eax |
|
- | 274 | test eax, eax |
|
- | 275 | jnz @f |
|
- | 276 | mov ecx, LIBIMG_ERROR_OUT_OF_MEMORY |
|
- | 277 | jmp .error |
|
- | 278 | @@: |
|
- | 279 | mov edi, eax |
|
- | 280 | mov ax, 'P6' |
|
- | 281 | call pnm._.write_header |
|
- | 282 | mov dword[edi], '255 ' |
|
- | 283 | add edi, 3 |
|
- | 284 | mov byte[edi], 0x0A |
|
- | 285 | add edi, 1 |
|
- | 286 | mov esi, [ebx + Image.Data] |
|
- | 287 | mov ecx, [ebx + Image.Width] |
|
- | 288 | imul ecx, [ebx + Image.Height] |
|
- | 289 | @@: |
|
- | 290 | lodsb |
|
- | 291 | mov byte[edi+2], al |
|
- | 292 | lodsb |
|
- | 293 | mov byte[edi+1], al |
|
- | 294 | movsb |
|
- | 295 | add edi, 2 |
|
- | 296 | dec ecx |
|
- | 297 | jnz @b |
|
- | 298 | mov eax, [encoded_file] |
|
- | 299 | mov ecx, [encoded_file_size] |
|
191 | ;< eax = 0 (error) or pointer to encoded data ;; |
300 | jmp .quit |
- | 301 | ||
- | 302 | .error: |
|
192 | ;< _p_length = encoded data length ;; |
303 | xor eax, eax |
193 | ;;================================================================================================;; |
304 | .quit: |
Line 194... | Line 305... | ||
194 | xor eax, eax |
305 | pop ebx |
Line 218... | Line 329... | ||
218 | jmp @b |
329 | jmp @b |
219 | .quit: |
330 | .quit: |
220 | ret |
331 | ret |
221 | endp |
332 | endp |
Line -... | Line 333... | ||
- | 333 | ||
- | 334 | ||
- | 335 | proc pnm._.write_header |
|
- | 336 | stosw |
|
- | 337 | mov byte[edi], 0x0A |
|
- | 338 | add edi, 1 |
|
- | 339 | mov word[edi], '# ' |
|
- | 340 | add edi, 2 |
|
- | 341 | mov esi, pnm._.creator_comment |
|
- | 342 | mov ecx, pnm._.creator_comment.size |
|
- | 343 | rep movsb |
|
- | 344 | mov byte[edi], 0x0A |
|
- | 345 | add edi, 1 |
|
- | 346 | ||
- | 347 | push edi |
|
- | 348 | mov al, ' ' |
|
- | 349 | mov ecx, (5 + 1 + 5) |
|
- | 350 | rep stosb |
|
- | 351 | pop edi |
|
- | 352 | push edi |
|
- | 353 | add edi, 4 |
|
- | 354 | mov eax, [ebx + Image.Width] |
|
- | 355 | mov ecx, 10 |
|
- | 356 | .write_width: |
|
- | 357 | xor edx, edx |
|
- | 358 | div cx |
|
- | 359 | add dl, '0' |
|
- | 360 | mov byte[edi], dl |
|
- | 361 | dec edi |
|
- | 362 | test ax, ax |
|
- | 363 | jnz .write_width |
|
- | 364 | mov eax, [ebx + Image.Height] |
|
- | 365 | pop edi |
|
- | 366 | push edi |
|
- | 367 | add edi, 10 |
|
- | 368 | .write_height: |
|
- | 369 | xor edx, edx |
|
- | 370 | div cx |
|
- | 371 | add dl, '0' |
|
- | 372 | mov byte[edi], dl |
|
- | 373 | dec edi |
|
- | 374 | test ax, ax |
|
- | 375 | jnz .write_height |
|
- | 376 | pop edi |
|
- | 377 | add edi, 11 |
|
- | 378 | mov byte[edi], 0x0A |
|
- | 379 | add edi, 1 |
|
- | 380 | ret |
|
222 | 381 | endp |
|
223 | ;;================================================================================================;; |
382 | ;;================================================================================================;; |
224 | ;;////////////////////////////////////////////////////////////////////////////////////////////////;; |
383 | ;;////////////////////////////////////////////////////////////////////////////////////////////////;; |
225 | ;;================================================================================================;; |
384 | ;;================================================================================================;; |
226 | ;! Below is private data you should never use directly from your code ;; |
385 | ;! Below is private data you should never use directly from your code ;; |
227 | ;;================================================================================================;; |
386 | ;;================================================================================================;; |
228 | ;;////////////////////////////////////////////////////////////////////////////////////////////////;; |
387 | ;;////////////////////////////////////////////////////////////////////////////////////////////////;; |
Line -... | Line 388... | ||
- | 388 | ;;================================================================================================;; |
|
- | 389 |