home *** CD-ROM | disk | FTP | other *** search
- ; pcneares.asm
- ;
- ; 5/5/88 by Ted
- ;
- ; Low Level RAM functions for OWL
- ; Find nearest color to given RGB in color map.
- ; THIS FILE IS FOR LARGE-DATA MODELS ONLY
- ;
- ; Copyright (c) 1988, 1989 Oakland Group Inc.
- ; ALL RIGHTS RESERVED
- ;
- ;------------------------REVISION HISTORY--------------------------------------;
- ;------------------------------------------------------------------------------;
- include PCDECL.MAC
-
- SRGB struc
- red db ?
- green db ?
- blue db ?
- SRGB ends
-
- LRGB equ 3
-
- SCOLORMAP struc
- firstpix dw ?
- ;; firstpixhi dw ? ;; opixvals are reduced to 2 bytes now
- nentries dw ?
- rgblev db LRGB*1 dup (?)
- SCOLORMAP ends
-
- PSEG
- ;------------------------------------------------------------------------------;
- ; opixval ocolmap_nearestcol (rgb_struct *rgb, ocolmap_type tcmap)
- ; Find nearest color to rgb in tcmap. Return tpix.
-
- pubproc DIGPRIV ocolmap_nearestcol <rgbaddr, dptr, tcmap, dptr>
-
- push bp
- mov bp, sp
- pushm <ds, es, si, di>
-
- lds si, [bp].rgbaddr
- mov bl, byte ptr[si].red
- mov bh, byte ptr[si].green
- mov cl, byte ptr[si].blue
-
- lds di, [bp].tcmap
-
- mov dx, [di].nentries
- dec dx
- mov dh, dl ; dh = lastentry;
- mov ch, 0 ; ipix starts at 0
-
- ; bl, bh, cl now have source rgb levels
- ; dh has lastentry, ch has ipix = firstpix
-
- ; Search for closest value
- ; Note: distance = (30*dr)^2 + (59*dg)^2 + (11*db)^2
- ;; ax, si for work
- ;; registers: bl,bh,cl=targetcol; ch=ipix; dh = lastentry, ds:di=tcmap[ipix];
- ;; es=minpix
-
- mov bp, -1 ; min diff so far (init to biggest unsigned number)
- tloop:
- mov al, byte ptr ds:[di].rgblev.red
- sub al, bl
- imul al
- mov si, ax
-
- mov al, byte ptr ds:[di].rgblev.green
- sub al, bh
- imul al
- add si, ax
-
- mov al, byte ptr ds:[di].rgblev.blue
- sub al, cl
- imul al
- add ax, si
-
- cmp ax, 0
- jz bingo ; if ax is 0, we hit it exactly, so quit
- keepon:
- add di, LRGB
-
- cmp ax, bp
- jae notmin
- newmin:
- mov bp, ax ; save latest min val
- mov al, ch
- xor ah, ah ; save latest min pix in es
- mov es, ax
- notmin:
-
- cmp ch, dh ; when ch is equal to lastentry we're done
- je done
- inc ch
- jmp short tloop
-
- bingo:
- mov bp, ax ; save latest min val
- mov al, ch
- xor ah, ah ; save latest min pix in es
- mov es, ax
-
- ; loop done now; we got min diff in bp, min entry in es
- done:
- mov ax, es
- ;; mov dx, 0 ; opixval is no longer a long
-
-
- mov bp, sp ; restore frame pointer for access to args again
- add bp, 8 ; account for ds, es, si, di on stack
-
- lds di, [bp].tcmap
- add ax, ds:[di].firstpix ; add firstpix to the entry we found
-
- popm <di, si, es, ds>
- pop bp
- ret
- endproc ocolmap_nearestcol
- ;------------------------------------------------------------------------------;
- ENDPS
- end
- ;------------------------------------------------------------------------------;
-