243 lines
15 KiB
NASM
243 lines
15 KiB
NASM
INCLUDE ..\COMMON\COMMON.INC
|
|
INCLUDE ..\COMMON\MATH.INC
|
|
INCLUDE ..\NNTP\ASMUTIL.INC
|
|
SMART
|
|
LOCALS
|
|
.386
|
|
.MODEL FLAT
|
|
.DATA
|
|
sOutColIterator DD ?
|
|
JumpTable:
|
|
TrailZero DD Trail0
|
|
TrailOne DD Trail1
|
|
TrailTwo DD Trail2
|
|
TrailThree DD Trail3
|
|
|
|
SIZE_RGB888 EQU 3
|
|
|
|
.CODE
|
|
_resampleClipRow proc near ; short resampleClip(char *lpIn,char *lpOut,DWORD inLen,DWORD outLen)
|
|
LOCAL sampleFactor:DWORD,runningFactor:DWORD=LocalLength
|
|
push ebp ; save stack frame
|
|
mov ebp,esp ; create new stack frame
|
|
sub esp,LocalLength ; adjust stack for local
|
|
push esi ; save source index register
|
|
push edi ; save destination
|
|
push ebx ; save ebx register
|
|
mov eax,[ebp+10h] ; move inLen to eax register
|
|
cmp eax,0000h ; compare inLen to zero
|
|
jle @@errorExit ; if it's less or equal then exit
|
|
mov ebx,[ebp+14h] ; move outLen to ebx register
|
|
cmp ebx,0000h ; compare outLen to zero
|
|
jle @@errorExit ; if it's less or equal then exit
|
|
dec eax ; decrement inLen
|
|
shl eax,10h ; multiply inLen by 65536L
|
|
divide eax,ebx ; divide ((inLen-1L)*65536L)/outLen
|
|
mov sampleFactor,eax ; store the factor
|
|
dec ebx ; ebx has (outLen-1)
|
|
mov ecx,ebx ; copy (outLen-1) to ecx
|
|
mov edi,[ebp+0Ch] ; move lpOut to destination index register
|
|
mov eax,size RGB888 ; move sizeof(RGB888) to eax register
|
|
multiply eax,ecx ; multiply (outLen-1)*sizeof(RGB888)
|
|
add edi,eax ; edi=lpOut+(outLen-1L)
|
|
mov esi,[ebp+08h] ; move lpIn to source index register
|
|
multiply ecx,sampleFactor ; multiply (outLen-1)*sampleFactor
|
|
mov runningFactor,eax ; save this into runningFactor
|
|
@@loopControl: ; loop control sync address
|
|
cmp ecx,0000h ; make sure we're within boundary
|
|
jl @@exit ; if not then we exit
|
|
mov eax,runningFactor ; move last running factor into eax
|
|
round ; round it off
|
|
mov ebx,size RGB888 ; get size of RGB888 to ebx register
|
|
multiply eax,ebx ; multiply running factor by sizeof(RGB888)
|
|
mov dl,byte ptr[esi+eax] ; copy blue into dl
|
|
mov byte ptr[edi],dl ; copy blue into target
|
|
mov dl,byte ptr[esi+eax+1] ; copy green into dl
|
|
mov byte ptr[edi+1],dl ; copy green into target
|
|
mov dl,byte ptr[esi+eax+2] ; copy red into dl
|
|
mov byte ptr[edi+2],dl ; copy red into target
|
|
mov eax,sampleFactor ; move sampleFactor into eax register
|
|
sub runningFactor,eax ; subtract from running factor
|
|
dec ecx ; decrement counter
|
|
sub edi,size RGB888 ; advance (backwards) along lpOut array
|
|
jmp @@loopControl ; continue processing
|
|
@@errorExit: ; error exit return sync address
|
|
xor ax,ax ; clear ax register on error
|
|
jmp @@endProcedure ; jump to end procedure
|
|
@@exit: ; exit sync address
|
|
mov ax,01h ; set ax register on success
|
|
@@endProcedure: ; end procedure sync address
|
|
pop ebx ; restore ebx register
|
|
pop edi ; restore destination index register
|
|
pop esi ; restore source index register
|
|
add esp,LocalLength ; remove locals off stack
|
|
pop ebp ; restore previous stack frame
|
|
retn ; return near to caller
|
|
_resampleClipRow endp
|
|
_resampleClipCol proc near ; short resampleClip(char *lpIn,char *lpOut,DWORD inLen,DWORD inWidth,DWORD outLen,DWORD outWidth)
|
|
LOCAL sampleFactor:DWORD,runningFactor:DWORD=LocalLength
|
|
push ebp ; save stack frame
|
|
mov ebp,esp ; create new stack frame
|
|
sub esp,LocalLength ; adjust stack for local
|
|
push esi ; save source index register
|
|
push edi ; save destination
|
|
push ebx ; save ebx register
|
|
mov edx,[ebp+1Ch] ; move outWidth to edx register
|
|
mov eax,size RGB888 ; move sizeof(RGB888) to eax register
|
|
multiply eax,edx ; eax=outWidth*sizeof(RGB888)
|
|
mov sOutColIterator,eax ; save column iterator
|
|
mov eax,[ebp+10h] ; move inLen to eax register
|
|
cmp eax,0000h ; compare inLen to zero
|
|
jle @@errorExit ; if it's less or equal then exit
|
|
mov ebx,[ebp+18h] ; move outLen to ebx register
|
|
cmp ebx,0000h ; compare outLen to zero
|
|
jle @@errorExit ; if it's less or equal then exit
|
|
dec eax ; decrement inLen
|
|
shl eax,10h ; multiply inLen by 65536L
|
|
divide eax,ebx ; divide ((inLen-1L)*65536L)/outLen
|
|
mov sampleFactor,eax ; store the factor
|
|
dec ebx ; ebx has (outLen-1)
|
|
mov ecx,ebx ; copy (outLen-1) to ecx
|
|
mov edi,[ebp+0Ch] ; move lpOut to destination index register
|
|
mov eax,[ebp+1Ch] ; move outWidth to eax register
|
|
multiply eax,ecx ; multiply (outLen-1)*width
|
|
mov edx,size RGB888 ; move sizeof(RGB888) to edx
|
|
multiply eax,edx ; eax has ((outLen-1)*outWidth)*sizeof(RGB888)
|
|
add edi,eax ; edi=lpOut+((outLen-1)*outWidth)*sizeof(RGB888), points to end of array
|
|
mov esi,[ebp+08h] ; move lpIn to source index register
|
|
multiply ecx,sampleFactor ; multiply (outLen-1)*sampleFactor
|
|
mov runningFactor,eax ; save this into runningFactor
|
|
@@loopControl: ; loop control sync address
|
|
cmp ecx,0000h ; make sure we're within boundary
|
|
jl @@exit ; if not then we exit
|
|
mov eax,runningFactor ; move last running factor into eax
|
|
round ; round it off
|
|
mov edx,[ebp+14h] ; move inWidth to edx register
|
|
multiply eax,edx ; eax=inWidth*runningFactor
|
|
mov edx,size RGB888 ; move sizeof(RGB888) to edx register
|
|
multiply eax,edx ; eax=(inWidth*runningFactor)*sizeof(RGB888)
|
|
mov dl,byte ptr[esi+eax] ; copy blue into dl
|
|
mov byte ptr[edi],dl ; copy blue into target
|
|
mov dl,byte ptr[esi+eax+1] ; copy green into dl
|
|
mov byte ptr[edi+1],dl ; copy green into target
|
|
mov dl,byte ptr[esi+eax+2] ; copy red into dl
|
|
mov byte ptr[edi+2],dl ; copy red into target
|
|
mov eax,sampleFactor ; move sampleFactor into eax register
|
|
sub runningFactor,eax ; subtract from running factor
|
|
dec ecx ; decrement counter
|
|
sub edi,sOutColIterator ; advance backwards along lpOutArray
|
|
jmp @@loopControl ; continue processing
|
|
@@errorExit: ; error exit return sync address
|
|
xor ax,ax ; clear ax register on error
|
|
jmp @@endProcedure ; jump to end procedure
|
|
@@exit: ; exit sync address
|
|
mov ax,01h ; set ax register on success
|
|
@@endProcedure: ; end procedure sync address
|
|
pop ebx ; restore ebx register
|
|
pop edi ; restore destination index register
|
|
pop esi ; restore source index register
|
|
add esp,LocalLength ; remove locals off stack
|
|
pop ebp ; restore previous stack frame
|
|
retn ; return near to caller
|
|
_resampleClipCol endp
|
|
copy MACRO
|
|
mov ecx,[ebx].ImageInfo@@mSrcWidthFactor ; move count of bytes into ecx register
|
|
mov edx,ecx ; move count of bytes into edx register
|
|
shr ecx,0002h ; divide count of bytes by sizeof(dword)
|
|
and edx,00003h ; get remainder into edx register
|
|
repnz movsd ; copy the column (esi->edi)
|
|
jmp dword ptr[edx*4+JumpTable] ; finish off the remaining bytes
|
|
Trail0: ; zero trailing bytes sync address
|
|
jmp @@endCopy ; we're all done
|
|
Trail1: ; 1 trailing byte sync address
|
|
mov al,byte ptr[esi] ; move source byte into al register
|
|
mov byte ptr [edi],al ; ... and copy it over to destination
|
|
inc esi ; increment source index
|
|
inc edi ; increment destination
|
|
jmp @@endCopy ; we're all done
|
|
Trail2: ; 2 trailing bytes sync address
|
|
mov ax,word ptr[esi] ; move a word value from source
|
|
mov word ptr[edi],ax ; move word value into destination
|
|
add esi,2 ; increment source index
|
|
add edi,2 ; increment destination index
|
|
jmp @@endCopy ; we're all done here
|
|
Trail3: ; 3 trailing bytes sync address
|
|
mov ax,word ptr[esi] ; move a word value from source
|
|
mov word ptr[edi],ax ; copy word value to destination
|
|
mov al,byte ptr[edi+2] ; move next byte to al
|
|
mov byte ptr[edi+2],al ; copy to destination
|
|
add esi,3 ; increment source index register
|
|
add edi,3 ; increment destination index register
|
|
@@endCopy: ; we're all done here
|
|
ENDM
|
|
_setAt proc near ; int setAt(ImageInfo *pImageInfo,DWORD row,DWORD col)
|
|
push ebp ; save previous stack frame
|
|
mov ebp,esp ; create new frame
|
|
push esi ; save source index register
|
|
push edi ; save destination index register
|
|
push ebx ; save ebx register
|
|
mov ebx,[ebp+08h] ; move (ImageInfo*) to ebx register
|
|
cld ; clear the direction flag
|
|
mov eax,[ebx].ImageInfo@@mSrcWidth ; move source image width into eax register
|
|
multiply eax,SIZE_RGB888 ; multiply width by sizeof(RGB888)
|
|
mov [ebx].ImageInfo@@mSrcWidthFactor,eax ; replace factor into structure
|
|
mov eax,[ebx].ImageInfo@@mDstWidth ; move destination image width into eax register
|
|
multiply eax,SIZE_RGB888 ; multiply width by sizeof(RGB888)
|
|
mov [ebx].ImageInfo@@mDstWidthFactor,eax ; replace factor into structure
|
|
mov esi,[ebx].ImageInfo@@mSrcRGB888 ; move source RGB888* to source index
|
|
multiply [ebx].ImageInfo@@mDstRow,[ebx].ImageInfo@@mDstWidth ; multiply source width by source row->eax
|
|
add eax,[ebx].ImageInfo@@mDstCol ; add in the destination column
|
|
multiply eax,SIZE_RGB888 ; multiply result by sizeof(RGB888)
|
|
mov edi,[ebx].ImageInfo@@mDstRGB888 ; move RGB888* to esi
|
|
add edi,eax ; add in the offset, result to esi
|
|
@@rowLoop: ; row loop sync address
|
|
copy ; copy the column
|
|
mov eax,[ebx].ImageInfo@@mDstWidthFactor ; move destination width factor to eax
|
|
sub eax,[ebx].ImageInfo@@mSrcWidthFactor ; get difference between source and destination
|
|
add edi,eax ; add to destination so it sits at next row
|
|
inc [ebx].ImageInfo@@mSrcRow ; increment source row
|
|
mov eax,[ebx].ImageInfo@@mSrcRow ; replace row counter
|
|
cmp eax,[ebx].ImageInfo@@mSrcHeight ; cmp row to image height
|
|
jl @@rowLoop ; if less then keep going
|
|
@@imageDone: ; done processing sync address
|
|
pop ebx ; restore ebx register
|
|
pop edi ; restore destination index register
|
|
pop esi ; restore source index register
|
|
pop ebp ; restore previous stack frame
|
|
retn ; return near to caller
|
|
_setAt endp
|
|
_copyBGRRGB proc near ; void copyBGRRGB(RGB *pRGB,BGR *pBGR,int count,int output_components)
|
|
push ebp ; save frame
|
|
mov ebp,esp ; create new frame
|
|
push ebx ; save ebx register
|
|
push ecx ; save ecx register
|
|
push esi ; save source index register
|
|
push edi ; save destination index register
|
|
mov ebx,[ebp+14h] ; move output_components to ebx register
|
|
mov ecx,[ebp+10h] ; move item count to ecx, one item is a single XXX component
|
|
mov edi,[ebp+08h] ; move pRGB to edi register
|
|
mov esi,[ebp+0Ch] ; move pBGR to esi register
|
|
add esi,ebx ; add (output_components) to esi
|
|
dec esi ; subtract one to get index
|
|
@@copyLoop: ; copyLoop sync address
|
|
mov ax,word ptr[esi-1] ; get a word value from source into ax register
|
|
rol ax,08h ; swap the bytes in this word
|
|
mov word ptr[edi],ax ; write the word value out to destination
|
|
mov al,byte ptr[esi-2] ; move source blue component into al
|
|
mov byte ptr[edi+2],al ; move blue component into destination blue
|
|
add esi,ebx ; add output_components to esi
|
|
add edi,SIZE_RGB888 ; increment destination index to next component
|
|
loopnz @@copyLoop ; continue through count items
|
|
pop edi ; restore destination index register
|
|
pop esi ; restore source index register
|
|
pop ecx ; restore ecx register
|
|
pop ebx ; restore ebx register
|
|
pop ebp ; restore previous frame
|
|
retn ; return near to caller
|
|
_copyBGRRGB endp
|
|
public _resampleClipRow
|
|
public _resampleClipCol
|
|
public _copyBGRRGB
|
|
public _setAt
|
|
END
|