18,7 → 18,7 |
;;================================================================================================;; |
|
;;================================================================================================;; |
proc img.scale _src, _crop_x, _crop_y, _crop_width, _crop_height, _dst, _scale, _inter, _param1, _param2 ;; |
proc img.scale _src, _crop_x, _crop_y, _crop_width, _crop_height, _dst, _scale_type, _scale_alg, _param1, _param2 ;; |
;;------------------------------------------------------------------------------------------------;; |
;? scale _image ;; |
;;------------------------------------------------------------------------------------------------;; |
28,10 → 28,10 |
;> [_crop_width] = width of cropping rect ;; |
;> [_crop_height] = height of cropping rect ;; |
;> [_dst] = pointer to resulting image / 0 ;; |
;> [_scale] = how to change width and height. see libimg.inc ;; |
;> [_inter] = interpolation algorithm ;; |
;> [_param1] = see libimg.inc ;; |
;> [_param2] = see libimg.inc ;; |
;> [_scale_type] = how to change width and height. see libimg.inc ;; |
;> [_scale_alg] = algorithm to use. see libimg.inc ;; |
;> [_param1] = the first argument passed to _scale_alg algorithm ;; |
;> [_param2] = the second argument passed to _scale_alg algorithm ;; |
;;------------------------------------------------------------------------------------------------;; |
;< eax = 0 / pointer to scaled image ;; |
;< ecx = error code / undefined ;; |
45,11 → 45,11 |
src_width_bytes rd 1 |
src_height_pixels rd 1 |
|
dst_width_pixels rd 1 |
dst_width_pixels_inv rd 1 |
dst_height_pixels rd 1 |
dst_height_pixels_inv rd 1 |
dst_width_bytes rd 1 |
scl_width_pixels rd 1 |
scl_width_pixels_inv rd 1 |
scl_height_pixels rd 1 |
scl_height_pixels_inv rd 1 |
scl_width_bytes rd 1 |
bytes_per_pixel rd 1 |
|
crop_width_pixels_m1 rd 1 |
89,7 → 89,7 |
jne @f |
mov [bytes_per_pixel], 3 |
lea ecx, [ecx*3] |
lea edx, [edx*3] |
lea edx, [ecx*3] |
jmp .lab1 |
@@: |
cmp eax, Image.bpp8g |
104,121 → 104,27 |
add [src_data], edx |
|
|
mov eax, [_scale] |
cmp eax, LIBIMG_SCALE_INTEGER |
je .scale_type.integer |
cmp eax, LIBIMG_SCALE_TILE |
je .scale_type.tile |
cmp eax, LIBIMG_SCALE_FIT_RECT |
je .scale_type.fit_rect |
cmp eax, LIBIMG_SCALE_FIT_WIDTH |
je .scale_type.fit_width |
cmp eax, LIBIMG_SCALE_FIT_HEIGHT |
je .scale_type.fit_height |
cmp eax, LIBIMG_SCALE_FIT_MAX |
je .scale_type.fit_max |
cmp eax, LIBIMG_SCALE_STRETCH |
je .scale_type.stretch |
mov ecx, LIBIMG_ERROR_SCALE |
jmp .error |
|
.scale_type.integer: |
jmp .integer |
.scale_type.tile: |
jmp .tile |
.scale_type.fit_rect: |
mov eax, [_param1] |
shl eax, 16 |
add eax, 0x00008000 |
xor edx, edx |
div [src_width_pixels] |
mov ebx, eax |
mov eax, [_param2] |
shl eax, 16 |
add eax, 0x00008000 |
xor edx, edx |
div [src_height_pixels] |
mov ecx, eax |
cmp ebx, ecx |
jb @f |
mov ebx, ecx |
@@: |
jmp .scale_type.fit_common |
.scale_type.fit_max: |
mov eax, [_param1] |
shl eax, 16 |
add eax, 0x00008000 |
xor edx, edx |
div [src_width_pixels] |
mov ebx, eax |
mov eax, [_param2] |
shl eax, 16 |
add eax, 0x00008000 |
xor edx, edx |
div [src_height_pixels] |
mov ecx, eax |
cmp ebx, ecx |
ja @f |
mov ebx, ecx |
@@: |
jmp .scale_type.fit_common |
.scale_type.fit_width: |
mov eax, [_param1] |
shl eax, 16 |
add eax, 0x00008000 |
xor edx, edx |
div [src_width_pixels] |
mov ebx, eax |
jmp .scale_type.fit_common |
.scale_type.fit_height: |
mov eax, [_param2] |
shl eax, 16 |
add eax, 0x00008000 |
xor edx, edx |
div [src_height_pixels] |
mov ebx, eax |
jmp .scale_type.fit_common |
.scale_type.fit_common: |
mov eax, [src_width_pixels] |
mul ebx |
shr eax, 16 |
mov [dst_width_pixels], eax |
imul eax, [bytes_per_pixel] |
mov [dst_width_bytes], eax |
mov eax, [src_height_pixels] |
mul ebx |
shr eax, 16 |
mov [dst_height_pixels], eax |
jmp .define_inter |
.scale_type.stretch: |
mov eax, [_param1] |
mov [dst_width_pixels], eax |
imul eax, [bytes_per_pixel] |
mov [dst_width_bytes], eax |
mov ecx, [_param2] |
mov [dst_height_pixels], ecx |
jmp .define_inter |
.define_inter: |
mov eax, [_inter] |
cmp eax, LIBIMG_INTER_BILINEAR |
mov eax, [_scale_alg] |
cmp eax, LIBIMG_SCALE_ALG_INTEGER |
je .integer |
cmp eax, LIBIMG_SCALE_ALG_BILINEAR |
je .bilinear |
mov ecx, LIBIMG_ERROR_INTER |
mov ecx, LIBIMG_ERROR_SCALE_ALG |
jmp .error |
|
|
.integer: |
mov eax, [_param1] |
mov ecx, [_crop_width] |
imul ecx, eax |
mov [dst_width_pixels], ecx |
mov [scl_width_pixels], ecx |
mov edx, [_crop_height] |
imul edx, eax |
mov [dst_height_pixels], edx |
mov [scl_height_pixels], edx |
|
mov eax, [_dst] |
test eax, eax |
jnz @f |
stdcall img.create, [dst_width_pixels], [dst_height_pixels], [src_type] |
stdcall img.create, [scl_width_pixels], [scl_height_pixels], [src_type] |
test eax, eax |
jz .error |
mov [_dst], eax |
238,8 → 144,8 |
jmp .error |
|
.integer.bpp8g: |
push [dst_width_pixels] |
pop [dst_width_bytes] |
push [scl_width_pixels] |
pop [scl_width_bytes] |
mov ecx, [_param1] |
; cmp ecx, 1 |
; je .error |
257,10 → 163,10 |
jnz @b |
push esi |
mov esi, edi |
sub esi, [dst_width_bytes] |
sub esi, [scl_width_bytes] |
mov ecx, edx |
dec ecx |
imul ecx, [dst_width_bytes] |
imul ecx, [scl_width_bytes] |
mov eax, ecx |
shr ecx, 2 |
and eax, 0x00000003 |
278,9 → 184,9 |
jmp .quit |
|
.integer.bpp24: |
mov eax, [dst_width_pixels] |
mov eax, [scl_width_pixels] |
lea eax, [eax*3] |
mov [dst_width_bytes], eax |
mov [scl_width_bytes], eax |
mov ecx, [_param1] |
; cmp ecx, 1 |
; je .error |
305,10 → 211,10 |
jnz @b |
push esi |
mov esi, edi |
sub esi, [dst_width_bytes] |
sub esi, [scl_width_bytes] |
mov ecx, edx |
dec ecx |
imul ecx, [dst_width_bytes] |
imul ecx, [scl_width_bytes] |
mov eax, ecx |
shr ecx, 2 |
and eax, 0x00000003 |
327,9 → 233,9 |
jmp .quit |
|
.integer.bpp32: |
mov eax, [dst_width_pixels] |
mov eax, [scl_width_pixels] |
shl eax, 2 |
mov [dst_width_bytes], eax |
mov [scl_width_bytes], eax |
mov ecx, [_param1] |
; cmp ecx, 1 |
; je .error |
347,10 → 253,10 |
jnz @b |
push esi |
mov esi, edi |
sub esi, [dst_width_bytes] |
sub esi, [scl_width_bytes] |
mov ecx, edx |
dec ecx |
imul ecx, [dst_width_bytes] |
imul ecx, [scl_width_bytes] |
shr ecx, 2 |
rep movsd |
pop esi |
365,73 → 271,98 |
jmp .quit |
|
|
.tile: |
.bilinear: |
mov eax, [_scale_type] |
cmp eax, LIBIMG_SCALE_TYPE_FIT_RECT |
je .bilinear.fit_rect |
cmp eax, LIBIMG_SCALE_TYPE_FIT_WIDTH |
je .bilinear.fit_width |
cmp eax, LIBIMG_SCALE_TYPE_FIT_HEIGHT |
je .bilinear.fit_height |
cmp eax, LIBIMG_SCALE_TYPE_FIT_MAX |
je .bilinear.fit_max |
cmp eax, LIBIMG_SCALE_TYPE_STRETCH |
je .bilinear.stretch |
mov ecx, LIBIMG_ERROR_SCALE_TYPE |
jmp .error |
.bilinear.fit_rect: |
mov eax, [_param1] |
mov [dst_width_pixels], eax |
imul eax, [bytes_per_pixel] |
mov [dst_width_bytes], eax |
shl eax, 16 |
add eax, 0x00008000 |
xor edx, edx |
div [src_width_pixels] |
mov ebx, eax |
mov eax, [_param2] |
mov [dst_height_pixels], eax |
|
mov eax, [_dst] |
test eax, eax |
jnz @f |
stdcall img.create, [dst_width_pixels], [dst_height_pixels], [src_type] |
test eax, eax |
jz .error |
mov [_dst], eax |
shl eax, 16 |
add eax, 0x00008000 |
xor edx, edx |
div [src_height_pixels] |
mov ecx, eax |
cmp ebx, ecx |
jb @f |
mov ebx, ecx |
@@: |
mov edi, [eax + Image.Data] |
mov [dst_data], edi |
|
mov esi, [src_data] |
mov eax, [_crop_height] |
cmp eax, [dst_height_pixels] |
jna @f |
mov eax, [dst_height_pixels] |
jmp .bilinear.fit_common |
.bilinear.fit_max: |
mov eax, [_param1] |
shl eax, 16 |
add eax, 0x00008000 |
xor edx, edx |
div [src_width_pixels] |
mov ebx, eax |
mov eax, [_param2] |
shl eax, 16 |
add eax, 0x00008000 |
xor edx, edx |
div [src_height_pixels] |
mov ecx, eax |
cmp ebx, ecx |
ja @f |
mov ebx, ecx |
@@: |
push eax |
mov ecx, [_crop_width] |
cmp ecx, [dst_width_pixels] |
jna @f |
mov ecx, [dst_width_pixels] |
@@: |
imul ecx, [bytes_per_pixel] |
mov edx, ecx |
@@: |
mov ecx, edx |
rep movsb |
jmp .bilinear.fit_common |
.bilinear.fit_width: |
mov eax, [_param1] |
shl eax, 16 |
add eax, 0x00008000 |
xor edx, edx |
div [src_width_pixels] |
mov ebx, eax |
jmp .bilinear.fit_common |
.bilinear.fit_height: |
mov eax, [_param2] |
shl eax, 16 |
add eax, 0x00008000 |
xor edx, edx |
div [src_height_pixels] |
mov ebx, eax |
jmp .bilinear.fit_common |
.bilinear.fit_common: |
mov eax, [src_width_pixels] |
mul ebx |
shr eax, 16 |
mov [scl_width_pixels], eax |
imul eax, [bytes_per_pixel] |
mov [scl_width_bytes], eax |
mov eax, [src_height_pixels] |
mul ebx |
shr eax, 16 |
mov [scl_height_pixels], eax |
jmp .bilinear.common |
.bilinear.stretch: |
mov eax, [_param1] |
mov [scl_width_pixels], eax |
imul eax, [bytes_per_pixel] |
mov [scl_width_bytes], eax |
mov ecx, [_param2] |
mov [scl_height_pixels], ecx |
jmp .bilinear.common |
|
push esi |
mov esi, edi |
sub esi, edx |
mov ecx, [dst_width_bytes] |
sub ecx, edx |
rep movsb |
pop esi |
|
mov ecx, [src_width_bytes] |
sub ecx, edx |
add esi, ecx |
dec eax |
jnz @b |
|
pop eax |
mov esi, [dst_data] |
mov ecx, [dst_height_pixels] |
sub ecx, eax |
imul ecx, [dst_width_bytes] |
rep movsb |
|
.bilinear.common: |
mov eax, [_dst] |
jmp .quit |
|
|
.bilinear: |
mov eax, [_dst] |
test eax, eax |
jnz @f |
stdcall img.create, [dst_width_pixels], [dst_height_pixels], [src_type] |
stdcall img.create, [scl_width_pixels], [scl_height_pixels], [src_type] |
test eax, eax |
jz .error |
mov [_dst], eax |
448,12 → 379,12 |
|
mov eax, 0xffffffff |
xor edx, edx |
div [dst_width_pixels] |
mov [dst_width_pixels_inv], eax |
div [scl_width_pixels] |
mov [scl_width_pixels_inv], eax |
mov eax, 0xffffffff |
xor edx, edx |
div [dst_height_pixels] |
mov [dst_height_pixels_inv], eax |
div [scl_height_pixels] |
mov [scl_height_pixels_inv], eax |
|
mov eax, [src_type] |
cmp eax, Image.bpp8g |
474,7 → 405,7 |
mov [dst_x], 0 |
imul eax, [crop_height_pixels_m1] |
xor edx, edx |
div [dst_height_pixels] |
div [scl_height_pixels] |
mov [rem_y], edx |
imul eax, [src_width_bytes] |
add esi, eax |
486,7 → 417,7 |
|
imul eax, [crop_width_pixels_m1] |
xor edx, edx |
div [dst_width_pixels] |
div [scl_width_pixels] |
add esi, eax |
|
mov ax, word[esi] |
501,12 → 432,12 |
imul edx, esi |
imul ecx, esi |
neg esi |
add esi, [dst_width_pixels] |
add esi, [scl_width_pixels] |
imul eax, esi |
imul ebx, esi |
add eax, edx |
add ebx, ecx |
mov esi, [dst_width_pixels_inv] |
mov esi, [scl_width_pixels_inv] |
mul esi |
mov ecx, edx |
mov eax, ebx |
516,21 → 447,21 |
mov edx, [rem_y] |
imul eax, edx |
neg edx |
add edx, [dst_height_pixels] |
add edx, [scl_height_pixels] |
imul ecx, edx |
add eax, ecx |
mul [dst_height_pixels_inv] |
mul [scl_height_pixels_inv] |
mov byte[edi], dl |
add edi, 1 |
|
add [dst_x], 1 |
mov eax, [dst_x] |
cmp eax, [dst_width_pixels] |
cmp eax, [scl_width_pixels] |
jne .bilinear.bpp8g.pixel |
|
add [dst_y], 1 |
mov eax, [dst_y] |
cmp eax, [dst_height_pixels] |
cmp eax, [scl_height_pixels] |
jne .bilinear.bpp8g.line |
|
mov eax, [_dst] |
546,7 → 477,7 |
mov [dst_x], 0 |
imul eax, [crop_height_pixels_m1] |
xor edx, edx |
div [dst_height_pixels] |
div [scl_height_pixels] |
mov [rem_y], edx |
imul eax, [src_width_bytes] |
add esi, eax |
558,7 → 489,7 |
|
imul eax, [crop_width_pixels_m1] |
xor edx, edx |
div [dst_width_pixels] |
div [scl_width_pixels] |
lea eax, [eax*3] |
add esi, eax |
|
583,12 → 514,12 |
imul edx, esi |
imul ecx, esi |
neg esi |
add esi, [dst_width_pixels] |
add esi, [scl_width_pixels] |
imul eax, esi |
imul ebx, esi |
add eax, edx |
add ebx, ecx |
mov esi, [dst_width_pixels_inv] |
mov esi, [scl_width_pixels_inv] |
mul esi |
mov ecx, edx |
mov eax, ebx |
598,10 → 529,10 |
mov edx, [rem_y] |
imul eax, edx |
neg edx |
add edx, [dst_height_pixels] |
add edx, [scl_height_pixels] |
imul ecx, edx |
add eax, ecx |
mul [dst_height_pixels_inv] |
mul [scl_height_pixels_inv] |
mov byte[edi], dl |
add edi, 1 |
end repeat |
608,12 → 539,12 |
|
add [dst_x], 1 |
mov eax, [dst_x] |
cmp eax, [dst_width_pixels] |
cmp eax, [scl_width_pixels] |
jne .bilinear.bpp24.pixel |
|
add [dst_y], 1 |
mov eax, [dst_y] |
cmp eax, [dst_height_pixels] |
cmp eax, [scl_height_pixels] |
jne .bilinear.bpp24.line |
|
mov eax, [_dst] |
628,7 → 559,7 |
mov [dst_x], 0 |
imul eax, [crop_height_pixels_m1] |
xor edx, edx |
div [dst_height_pixels] |
div [scl_height_pixels] |
mov [rem_y], edx |
imul eax, [src_width_bytes] |
add esi, eax |
640,7 → 571,7 |
|
imul eax, [crop_width_pixels_m1] |
xor edx, edx |
div [dst_width_pixels] |
div [scl_width_pixels] |
shl eax, 2 |
add esi, eax |
|
665,12 → 596,12 |
imul edx, esi |
imul ecx, esi |
neg esi |
add esi, [dst_width_pixels] |
add esi, [scl_width_pixels] |
imul eax, esi |
imul ebx, esi |
add eax, edx |
add ebx, ecx |
mov esi, [dst_width_pixels_inv] |
mov esi, [scl_width_pixels_inv] |
mul esi |
mov ecx, edx |
mov eax, ebx |
680,10 → 611,10 |
mov edx, [rem_y] |
imul eax, edx |
neg edx |
add edx, [dst_height_pixels] |
add edx, [scl_height_pixels] |
imul ecx, edx |
add eax, ecx |
mul [dst_height_pixels_inv] |
mul [scl_height_pixels_inv] |
mov byte[edi], dl |
add edi, 1 |
end repeat |
690,12 → 621,12 |
|
add [dst_x], 1 |
mov eax, [dst_x] |
cmp eax, [dst_width_pixels] |
cmp eax, [scl_width_pixels] |
jne .bilinear.bpp32.pixel |
|
add [dst_y], 1 |
mov eax, [dst_y] |
cmp eax, [dst_height_pixels] |
cmp eax, [scl_height_pixels] |
jne .bilinear.bpp32.line |
|
mov eax, [_dst] |