Victor Image Processing Library How-to Tips

Manipulate the Palette

To steps used to manipulate the palette
original palette
Original
altered palette
Altered Palette

In this example each palette entry is replaced with a gray tone representing the brightest of the RGB components. This is not a true grayscale, but gives the appearance of grayscale. To create a true grayscale image use the colortogray function in the Victor Library.

Manipulate the Palette - the Visual Basic Source Code

Requires Victor Image Processing Library v 5.1 or higher.
' ........... Defines and declarations ...........
Type RGBQUAD
   rgbBlue As Byte
   rgbGreen As Byte
   rgbRed As Byte
   rgbReserved As Byte
End Type
Declare Function updatebitmapcolortable Lib "VIC32.DLL" (image As imgdes) As Long
Declare Sub CopyPaletteFromImagetoRGBArray Lib "kernel32" Alias "RtlMoveMemory" (ByRef desarrayelement As RGBQUAD, ByVal paletteaddress As Long, ByVal cnt As Long)
Declare Sub CopyPaletteFromRGBArraytoImage Lib "kernel32" Alias "RtlMoveMemory" (ByVal paletteaddress As Long, ByRef srcarrayelement As RGBQUAD, ByVal cnt As Long)
' ........... The function ...........
Public Function changethepalette(ByRef myimage As imgdes) As Long
Dim rcode As Long
Dim j As Integer
Dim colours As Long
Dim mypalette(0 To 255) As RGBQUAD
Dim red As Byte
Dim grn As Byte
Dim blu As Byte
Dim newcolor As Byte
    colours = myimage.colors
    
            ' Copy the image palette into my local palette
    CopyPaletteFromImagetoRGBArray mypalette(0), myimage.palette, colours * 4
        
    For j = 0 To (colours - 1)
        blu = mypalette(j).rgbBlue
        grn = mypalette(j).rgbGreen
        red = mypalette(j).rgbRed
        
            ' ...............  manipulate the palette ...................
        
            ' Pick the brightest colors and create a palette of grays
        newcolor = blu
        If (red > newcolor) Then
            newcolor = red
        End If
        If (grn > newcolor) Then
            newcolor = grn
        End If
        
        blu = newcolor
        grn = newcolor
        red = newcolor
            ' ...........................................................
        
            ' insert the new palette entries
        mypalette(j).rgbBlue = blu
        mypalette(j).rgbGreen = grn
        mypalette(j).rgbRed = red
    Next j
        
    CopyPaletteFromRGBArraytoImage myimage.palette, mypalette(0), colours * 4
    rcode = updatebitmapcolortable(myimage)
        
    changethepalette = rcode
End Function
Victor Image Processing Library

Victor Image Processing Library homepage | Victor Product Summary | more source code




Copyright © 2002 Catenary Systems Inc. All rights reserved. Victor Image Processing Library is a trademark of Catenary Systems.