Subversion Repositories Kolibri OS

Rev

Rev 2691 | Rev 2733 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2691 Rev 2692
Line 96... Line 96...
96
	jz	.old1
96
	jz	.old1
97
	cmp	eax, 40		; 0x28
97
	cmp	eax, 40		; 0x28
98
	jz	.normal
98
	jz	.normal
99
	cmp	eax, 56		; 0x38
99
	cmp	eax, 56		; 0x38
100
	je	.normal
100
	je	.normal
101
	cmp	eax, 108	; 0x6C
101
	cmp	eax, 0x6C
-
 
102
	je	.normal
-
 
103
	cmp	eax, 0x7C
102
	jnz	.error
104
	jnz	.error
103
; convert images with <= 8 bpp to 8bpp, other - to 32 bpp
105
; convert images with <= 8 bpp to 8bpp, other - to 32 bpp
104
.normal:
106
.normal:
105
	m2m	eax, Image.bpp8
107
	m2m	eax, Image.bpp8
106
	cmp	byte [ebx + 14], 8	; bit count
108
	cmp	byte [ebx + 14], 8	; bit count
Line 257... Line 259...
257
	pop	edi esi ebx
259
	pop	edi esi ebx
258
	ret
260
	ret
259
endp
261
endp
Line 260... Line 262...
260
 
262
 
261
;;================================================================================================;;
263
;;================================================================================================;;
262
proc img.encode.bmp _img, _p_length, _options ;///////////////////////////////////////////////////;;
264
proc img.encode.bmp _img, _common, _specific ;////////////////////////////////////////////////////;;
263
;;------------------------------------------------------------------------------------------------;;
265
;;------------------------------------------------------------------------------------------------;;
264
;? Encode image into raw data in BMP format                                                       ;;
266
;? Encode image into raw data in BMP format                                                       ;;
265
;;------------------------------------------------------------------------------------------------;;
267
;;------------------------------------------------------------------------------------------------;;
-
 
268
;> [_img]      = pointer to image                                                                 ;;
-
 
269
;> [_common]   = format independent options                                                       ;;
266
;> _img = pointer to image                                                                        ;;
270
;> [_specific] = 0 / pointer to the structure of format specific options                          ;;
267
;;------------------------------------------------------------------------------------------------;;
271
;;------------------------------------------------------------------------------------------------;;
268
;< eax = 0 (error) or pointer to encoded data                                                     ;;
272
;< eax = 0 / pointer to encoded data                                                              ;;
269
;< _p_length = encoded data length                                                                ;;
273
;< ecx = error code / the size of encoded data                                                    ;;
-
 
274
;;================================================================================================;;
-
 
275
locals
-
 
276
	bytes_per_scanline	rd 1
-
 
277
	encoded_file		rd 1
-
 
278
	encoded_file_size	rd 1
-
 
279
	encoded_data_size	rd 1
-
 
280
endl
-
 
281
	mov	ebx, [_img]
-
 
282
	mov	eax, [ebx + Image.Type]
-
 
283
	cmp	eax, Image.bpp24
-
 
284
	je	.bpp24
-
 
285
	cmp	eax, Image.bpp32
-
 
286
	je	.bpp32
-
 
287
	mov	ecx, LIBIMG_ERROR_BIT_DEPTH
-
 
288
	jmp	.error
-
 
289
 
-
 
290
  .bpp24:
-
 
291
	mov	eax, [ebx + Image.Width]
-
 
292
	call	img._.get_scanline_len
-
 
293
	test	eax, 0x03
-
 
294
	jz	@f
-
 
295
	and	al, 0xfc
-
 
296
	add	eax, 4
-
 
297
    @@:
-
 
298
	mov	[bytes_per_scanline], eax
-
 
299
	imul	eax, [ebx + Image.Height]
-
 
300
	mov	[encoded_data_size], eax
-
 
301
	add	eax, 108 + 14
-
 
302
	mov	[encoded_file_size], eax
-
 
303
	stdcall	[mem.alloc], eax
-
 
304
	test	eax, eax
-
 
305
	jz	.error
-
 
306
	mov	[encoded_file], eax
-
 
307
	mov	edi, eax
-
 
308
 
-
 
309
	mov	word[edi], 'BM'
-
 
310
	add	edi, 2
-
 
311
	mov	eax, [encoded_file_size]
-
 
312
	stosd
-
 
313
	xor	eax, eax
-
 
314
	stosd
-
 
315
	mov	eax, 108 + 14
-
 
316
	stosd
-
 
317
	mov	eax, 108
-
 
318
	stosd
-
 
319
	mov	eax, [ebx + Image.Width]
-
 
320
	stosd
-
 
321
	mov	eax, [ebx + Image.Height]
-
 
322
	stosd
-
 
323
	mov	ax, 1	; Planes
-
 
324
	stosw
-
 
325
	mov	ax, 24	; BitCount
-
 
326
	stosw
-
 
327
	mov	eax, bmp.BI_RGB
-
 
328
	stosd
-
 
329
	mov	eax, [encoded_data_size]
-
 
330
	stosd
-
 
331
	mov	eax, 0x00000B13
-
 
332
	stosd
-
 
333
	stosd
-
 
334
	xor	eax, eax
-
 
335
	stosd
-
 
336
	stosd
-
 
337
	mov	eax, 'BGRs'
-
 
338
	stosd
-
 
339
	xor	eax, eax
-
 
340
	stosd
-
 
341
	stosd
-
 
342
	stosd
-
 
343
	stosd
-
 
344
	stosd
-
 
345
	stosd
-
 
346
	stosd
-
 
347
	stosd
-
 
348
	stosd
-
 
349
	stosd
-
 
350
	stosd
-
 
351
	stosd
-
 
352
	mov	eax, 2
-
 
353
	stosd
-
 
354
	xor	eax, eax
-
 
355
	stosd
-
 
356
	stosd
-
 
357
	stosd
-
 
358
 
-
 
359
	mov	esi, [ebx + Image.Data]
-
 
360
	mov	ecx, [ebx + Image.Width]
-
 
361
	lea	ecx, [ecx*3]
-
 
362
	mov	eax, [ebx + Image.Height]
-
 
363
	mov	edx, [bytes_per_scanline]
-
 
364
	sub	edx, ecx
-
 
365
	mov	dh, cl
-
 
366
	and	dh, 3
-
 
367
	shr	ecx, 2
-
 
368
	push	ecx
-
 
369
	add	edi, [encoded_data_size]
-
 
370
	sub	edi, [bytes_per_scanline]
-
 
371
    @@:
-
 
372
	pop	ecx
-
 
373
	push	ecx
-
 
374
	rep	movsd
-
 
375
	mov	cl, dh
-
 
376
	rep	movsb
-
 
377
	mov	cl, dl
-
 
378
	add	edi, ecx
-
 
379
	sub	edi, [bytes_per_scanline]
-
 
380
	sub	edi, [bytes_per_scanline]
-
 
381
	dec	eax
-
 
382
	jnz	@b
-
 
383
	pop	ecx
-
 
384
	mov	eax, [encoded_file]
-
 
385
	mov	ecx, [encoded_file_size]
-
 
386
	jmp	.quit
-
 
387
 
-
 
388
  .bpp32:
-
 
389
	mov	eax, [ebx + Image.Width]
-
 
390
	call	img._.get_scanline_len
-
 
391
	mov	[bytes_per_scanline], eax
-
 
392
	imul	eax, [ebx + Image.Height]
-
 
393
	mov	[encoded_data_size], eax
-
 
394
	add	eax, 0x7C + 14
-
 
395
	mov	[encoded_file_size], eax
-
 
396
	stdcall	[mem.alloc], eax
-
 
397
	test	eax, eax
-
 
398
	jz	.error
-
 
399
	mov	[encoded_file], eax
-
 
400
	mov	edi, eax
-
 
401
 
-
 
402
	mov	word[edi], 'BM'
-
 
403
	add	edi, 2
-
 
404
	mov	eax, [encoded_file_size]
-
 
405
	stosd
-
 
406
	xor	eax, eax
-
 
407
	stosd
-
 
408
	mov	eax, 0x7C + 14
-
 
409
	stosd
-
 
410
	mov	eax, 0x7C
-
 
411
	stosd
-
 
412
	mov	eax, [ebx + Image.Width]
-
 
413
	stosd
-
 
414
	mov	eax, [ebx + Image.Height]
-
 
415
	stosd
-
 
416
	mov	ax, 1	; Planes
-
 
417
	stosw
-
 
418
	mov	ax, 32	; BitCount
-
 
419
	stosw
-
 
420
	mov	eax, 3	; WTF? bmp.BI_RGB
-
 
421
	stosd
-
 
422
	mov	eax, [encoded_data_size]
-
 
423
	stosd
-
 
424
	mov	eax, 0x00000B13
-
 
425
	stosd
-
 
426
	stosd
-
 
427
	xor	eax, eax
-
 
428
	stosd
-
 
429
	stosd
-
 
430
	mov	eax, 0xFF000000
-
 
431
	stosd
-
 
432
	shr	eax, 8
-
 
433
	stosd
-
 
434
	shr	eax, 8
-
 
435
	stosd
-
 
436
;	shr	eax, 8
-
 
437
	xor	eax, eax
-
 
438
	stosd
-
 
439
	mov	eax, 'BGRs'
-
 
440
	stosd
-
 
441
	xor	eax, eax
-
 
442
	stosd
-
 
443
	stosd
-
 
444
	stosd
-
 
445
	stosd
-
 
446
	stosd
-
 
447
	stosd
-
 
448
	stosd
-
 
449
	stosd
-
 
450
	stosd
-
 
451
	stosd
-
 
452
	stosd
-
 
453
	stosd
-
 
454
	mov	eax, 2
-
 
455
	stosd
-
 
456
	xor	eax, eax
-
 
457
	stosd
-
 
458
	stosd
-
 
459
	stosd
-
 
460
 
-
 
461
	mov	esi, [ebx + Image.Data]
-
 
462
	mov	ecx, [ebx + Image.Width]
-
 
463
	mov	eax, [ebx + Image.Height]
-
 
464
	add	edi, [encoded_data_size]
-
 
465
	sub	edi, [bytes_per_scanline]
-
 
466
	push	ecx
-
 
467
  .next_line:
-
 
468
	pop	ecx
-
 
469
	push	ecx
-
 
470
	push	eax
-
 
471
    @@:
-
 
472
	dec	ecx
-
 
473
	js	@f
-
 
474
	lodsd
-
 
475
	rol	eax, 8
-
 
476
	stosd
-
 
477
	jmp	@b
-
 
478
    @@:
-
 
479
	sub	edi, [bytes_per_scanline]
-
 
480
	sub	edi, [bytes_per_scanline]
-
 
481
	pop	eax
-
 
482
	dec	eax
-
 
483
	jnz	.next_line
-
 
484
	pop	ecx
-
 
485
	mov	eax, [encoded_file]
-
 
486
	mov	ecx, [encoded_file_size]
-
 
487
	jmp	.quit
-
 
488
 
270
;;================================================================================================;;
489
  .error:
-
 
490
	xor	eax, eax
271
	xor	eax, eax
491
  .quit:
272
	ret
492
	ret
Line 273... Line 493...
273
endp
493
endp