Announcement

Collapse
No announcement yet.

Finding nearest color from a particular set of colors! Cubic Search Method?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Finding nearest color from a particular set of colors! Cubic Search Method?

    I found a google website where it mentioned matching a pixel based on a cubic search method or algorithm.
    I have no idea what that is even after googling.
    I would suppose it means finding the nearest RGB or BGR based on a getting the nearest separate color of each of the 3 values in a pixel from the predetermined list of colors.
    i was writing an pseudo code to explain what i thought it might be, but in my mind the logic of my thoughts would not work.
    If there is an example here in this forum. I did not find it or it was described as something else.
    I was hoping one of our math experts here would help me.
    thanks
    p purvis

  • #2
    Hi Paul!

    If I have a map of all colors, I can imagine taking a step in any direction away from the root color and getting a number of "neighbors". Does "nearest color" have a technical meaning that would limit the answer to just one result?

    Comment


    • #3
      Hi Gary, BOO!

      yes Gary, there is more than one result with what i am doing but only one color picked regardless.


      here is some code that will read a bmp file and change colors to the nearest color from an array of colors in the program.
      the new bmp file will be named the same name with "-new.bmp"

      the idea is assign only certain colors to a graphic file for the reasons of either reducing graphic file space or documents.
      right now i am working with just a picture image to see some results.
      i am just putting some colors in the predefined array color list and i am not set on any pattern of colors right now but getting close to that if
      i can get a color compare down. I am sure there can be more than one algorithm.
      the colors will not be hard set in the program but in an external file with an array of colors and just hard set for testing purposes.
      i was using a load graphics to picture routine but removed it because it was not working for me and changing the colors so i took it out
      and just went command line style processing.
      i am sure i can speed up the predetermined array used in some way.



      i had an error in it Gary and it took me some digging
      here is main code
      (color)1 is the current pixel color and (color)2 is a predetermined color compared against
      the (color)2 is processed through a loop of predetermined color array and the lowest result(nearest) is used for that a color replacement
      iresult=SQR( ((Red1-Red2)^2)+((Green1-Green2)^2)+((Blue1-Blue2)^2 ))

      i only compare colors that are found in a graphic file because comparing for just one file takes too long in time to go through 16 million colors but would be
      worth the time processing all colors if a lot of files.need that or the program stayed in memory.


      Code:
      'program to change colors in a bitmap file to predetermined colors by neareast color
      'compiled with pbwin10
      'Compilable Example:
      #COMPILE EXE
      #DIM ALL
      #INCLUDE "Win32API.inc"
      
      
      TYPE RGBtype
          Red AS BYTE
          green AS BYTE
          blue AS BYTE
          dummy AS BYTE
      END TYPE
      UNION LongToRGB
          Colour AS LONG
          RGBcol AS RGBtype
      END UNION
      
      
      
      
      FUNCTION PBMAIN() AS LONG
          LOCAL hbmp AS DWORD
          LOCAL nfile AS DWORD
          LOCAL sfilename AS STRING
          LOCAL sbmp AS STRING
      '    LOCAL iimagexsize,iimageysize AS LONG
      
      
          sfilename=TRIM$(COMMAND$)
      '    sfilename= "a.bmp"
      
          IF NOT ISFILE(sfilename) THEN EXIT FUNCTION
          IF RIGHT$(UCASE$(sfilename),4)<> ".BMP" THEN EXIT FUNCTION
          nFile = FREEFILE
      '    OPEN sfilename FOR BINARY ACCESS READ WRITE LOCK SHARED AS nFile
      '    gET nFile, 19, iimagexsize
      '    GET nFile, 23, iimageysize
      '    CLOSE nFile
      '    if iimagexsize=0& or iimageysize=0& then exit function
      
          GRAPHIC BITMAP LOAD sfilename, 0, 0  TO hBmp
      
          GRAPHIC ATTACH hbmp, 0
          GRAPHIC GET BITS TO sbmp
          change_colors_to_closest_predetermined_colors(sbmp)
          GRAPHIC SET BITS sbmp
      
          sfilename=LEFT$(sfilename,LEN(sfilename)-4)+"-new.bmp"
          IF ISFILE(sfilename) THEN KILL sfilename
          GRAPHIC SAVE sfilename
      
          GRAPHIC DETACH
          GRAPHIC BITMAP END
      END FUNCTION
      
      
      
      FUNCTION change_colors_to_closest_predetermined_colors(BYREF sbmp AS STRING) AS LONG
          LOCAL icounter1,icounter2, iresult,inearest,iusecolor AS LONG
          LOCAL MyColour1 AS LongToRGB
          LOCAL MyColour2 AS LongToRGB
          LOCAL PixelPtr AS LONG PTR
          LOCAL Red1, Green1, Blue1 AS LONG
          LOCAL Red2, Green2, Blue2 AS LONG
      
          DIM iall24bitcolors(0& TO 16777215&) AS LONG
          DIM icolorsavailable(1& TO 28&) AS LONG
      
           icolorsavailable(01)=%RGB_BLACK
           icolorsavailable(02)=%RGB_WHITE
           icolorsavailable(03)=%RGB_GRAY
           icolorsavailable(04)=%RGB_RED
           icolorsavailable(05)=%RGB_GREEN
           icolorsavailable(06)=%RGB_BLUE
           icolorsavailable(07)=%RGB_YELLOW
           icolorsavailable(08)=%RGB_CYAN
           icolorsavailable(09)=%RGB_MAGENTA
           icolorsavailable(10)=%RGB_PINK
           icolorsavailable(11)=%RGB_ANTIQUEWHITE
           icolorsavailable(12)=%RGB_ORANGE
           icolorsavailable(13)=%RGB_TOMATO
           icolorsavailable(14)=%RGB_LIGHTBLUE
           icolorsavailable(15)=%RGB_PEACHPUFF
           icolorsavailable(16)=%RGB_SLATEBLUE
           icolorsavailable(17)=%RGB_BLUEVIOLET
           icolorsavailable(18)=%RGB_MIDNIGHTBLUE
           icolorsavailable(19)=%RGB_BROWN
           icolorsavailable(20)=%RGB_SANDYBROWN
           icolorsavailable(21)=%RGB_SILVER
           icolorsavailable(22)=%RGB_LIME
           icolorsavailable(23)=%RGB_LIGHTBLUE
           icolorsavailable(24)=%RGB_FORESTGREEN
           icolorsavailable(25)=RGB(183,100,82) 'a redish flesh tone
           icolorsavailable(26)=RGB(140,73,64)  'a redish flesh tone
      
      
          PixelPtr = STRPTR(sbmp) + 8
          FOR icounter1 = 1 TO CVL(sbmp,1)*CVL(sbmp,5)
             iall24bitcolors(RGB(@PixelPtr))=1
             INCR PixelPtr
          NEXT icounter1
      
          icounter2=0&
          FOR icounter1=0& TO 16777215&
              IF iall24bitcolors(icounter1) THEN
      '        MyColour1.Colour = iall24bitcolors(icounter1) 'iall24bitcolors(icounter1)
              MyColour1.Colour = RGB(icounter1)
              Red1 = MyColour1.RGBcol.Red
              Green1 = MyColour1.RGBcol.Green
              Blue1 = MyColour1.RGBcol.Blue
              inearest=16777216&
              iusecolor=0&
              FOR icounter2=LBOUND(icolorsavailable()) TO UBOUND(icolorsavailable())
                  MyColour2.Colour = icolorsavailable(icounter2)
                  Red2 = MyColour2.RGBcol.Red
                  Green2 = MyColour2.RGBcol.Green
                  Blue2 = MyColour2.RGBcol.Blue
      
               '   iresult=SQR(((MyColour1.RGBcol.Red-MyColour2.RGBcol.Red)^2)+ _
               '     ((MyColour1.RGBcol.Green-MyColour2.RGBcol.Green)^2) + _
               '     ((MyColour1.RGBcol.Blue-MyColour2.RGBcol.Blue)^2))
                  iresult=SQR( ((Red1-Red2)^2)+((Green1-Green2)^2)+((Blue1-Blue2)^2 ))
                  IF iresult<inearest THEN
                      inearest=iresult
                      iusecolor=icounter2
                  END IF
              NEXT icounter2
              iall24bitcolors(icounter1)=icolorsavailable(iusecolor)
              END IF
          NEXT icounter1
      
          PixelPtr = STRPTR(sbmp) + 8
          FOR icounter1 = 1 TO CVL(sbmp,1)*CVL(sbmp,5)
             @PixelPtr=iall24bitcolors(BGR(@PixelPtr))
             INCR PixelPtr
          NEXT
      END FUNCTION
      p purvis

      Comment


      • #4
        better color list from powerbasic help for testing
        Code:
            DIM icolorsavailable(1& TO 138&) AS LONG
            icolorsavailable(001)= %RGB_BLACK
            icolorsavailable(002)= %RGB_WHITE
            icolorsavailable(003)= %RGB_GRAY
            icolorsavailable(004)= %RGB_RED
            icolorsavailable(005)= %RGB_GREEN
            icolorsavailable(006)= %RGB_BLUE
            icolorsavailable(007)= %RGB_YELLOW
            icolorsavailable(008)= %RGB_CYAN
            icolorsavailable(009)= %RGB_LIME
            icolorsavailable(010)= %RGB_MAGENTA
            icolorsavailable(011)= %RGB_BROWN
            icolorsavailable(012)= %RGB_VIOLET
            icolorsavailable(013)= %RGB_ORANGE
            icolorsavailable(014)= %RGB_PURPLE
            icolorsavailable(015)= %RGB_GOLDENROD
        
            icolorsavailable(016)= %RGB_LIGHTBLUE
            icolorsavailable(017)= %RGB_LIGHTCYAN
            icolorsavailable(018)= %RGB_LIGHTGRAY
            icolorsavailable(019)= %RGB_LIGHTGREEN
            icolorsavailable(020)= %RGB_LIGHTPINK
            icolorsavailable(021)= %RGB_LIGHTYELLOW
        
            icolorsavailable(022)= %RGB_MEDIUMBLUE
            icolorsavailable(023)= %RGB_MEDIUMPURPLE
        
            icolorsavailable(024)= %RGB_DARKBLUE
            icolorsavailable(025)= %RGB_DARKCYAN
            icolorsavailable(026)= %RGB_DARKGRAY
            icolorsavailable(027)= %RGB_DARKGREEN
            icolorsavailable(028)= %RGB_DARKORANGE
            icolorsavailable(029)= %RGB_DARKRED
            icolorsavailable(030)= %RGB_DARKMAGENTA
            icolorsavailable(031)= %RGB_DARKVIOLET
        
            icolorsavailable(032)= %RGB_CORAL
            icolorsavailable(033)= %RGB_ORCHID
            icolorsavailable(034)= %RGB_SEAGREEN
            icolorsavailable(035)= %RGB_SALMON
            icolorsavailable(036)= %RGB_SKYBLUE
            icolorsavailable(037)= %RGB_SLATEBLUE
            icolorsavailable(038)= %RGB_SLATEGRAY
            icolorsavailable(039)= %RGB_TURQUOISE
        
            icolorsavailable(040)= %RGB_PALEGOLDENROD
            icolorsavailable(041)= %RGB_PALEGREEN
            icolorsavailable(042)= %RGB_PALETURQUOISE
            icolorsavailable(043)= %RGB_PALEVIOLETRED
        
            icolorsavailable(044)= %RGB_LIGHTGOLDENRODYELLOW
            icolorsavailable(045)= %RGB_LIGHTCORAL
            icolorsavailable(046)= %RGB_LIGHTSALMON
            icolorsavailable(047)= %RGB_LIGHTSEAGREEN
            icolorsavailable(048)= %RGB_LIGHTSKYBLUE
            icolorsavailable(049)= %RGB_LIGHTSLATEGRAY
            icolorsavailable(050)= %RGB_LIGHTSTEELBLUE
        
            icolorsavailable(051)= %RGB_MEDIUMORCHID
            icolorsavailable(052)= %RGB_MEDIUMSEAGREEN
            icolorsavailable(053)= %RGB_MEDIUMSLATEBLUE
            icolorsavailable(054)= %RGB_MEDIUMSPRINGGREEN
            icolorsavailable(055)= %RGB_MEDIUMTURQUOISE
            icolorsavailable(056)= %RGB_MEDIUMVIOLETRED
        
            icolorsavailable(057)= %RGB_DARKGOLDENROD
            icolorsavailable(058)= %RGB_DARKKHAKI
            icolorsavailable(059)= %RGB_DARKOLIVEGREEN
            icolorsavailable(060)= %RGB_DARKORCHID
            icolorsavailable(061)= %RGB_DARKSALMON
            icolorsavailable(062)= %RGB_DARKSEAGREEN
            icolorsavailable(063)= %RGB_DARKSLATEBLUE
            icolorsavailable(064)= %RGB_DARKSLATEGRAY
            icolorsavailable(065)= %RGB_DARKTURQUOISE
        
            icolorsavailable(066)= %RGB_ALICEBLUE
            icolorsavailable(067)= %RGB_ANTIQUEWHITE
            icolorsavailable(068)= %RGB_AQUAMARINE
            icolorsavailable(069)= %RGB_AZURE
            icolorsavailable(070)= %RGB_BEIGE
            icolorsavailable(071)= %RGB_BISQUE
            icolorsavailable(072)= %RGB_BLANCHEDALMOND
            icolorsavailable(073)= %RGB_BLUEVIOLET
            icolorsavailable(074)= %RGB_BURLYWOOD
            icolorsavailable(075)= %RGB_CADETBLUE
            icolorsavailable(076)= %RGB_CHARTREUSE
            icolorsavailable(077)= %RGB_CHOCOLATE
            icolorsavailable(078)= %RGB_CORNFLOWERBLUE
            icolorsavailable(079)= %RGB_CORNSILK
            icolorsavailable(080)= %RGB_CRIMSON
            icolorsavailable(081)= %RGB_DEEPPINK
            icolorsavailable(082)= %RGB_DEEPSKYBLUE
            icolorsavailable(083)= %RGB_DIMGRAY
            icolorsavailable(084)= %RGB_DODGERBLUE
            icolorsavailable(085)= %RGB_FIREBRICK
            icolorsavailable(086)= %RGB_FLORALWHITE
            icolorsavailable(087)= %RGB_FORESTGREEN
            icolorsavailable(088)= %RGB_GAINSBORO
            icolorsavailable(089)= %RGB_GHOSTWHITE
            icolorsavailable(090)= %RGB_GOLD
            icolorsavailable(091)= %RGB_GREENYELLOW
            icolorsavailable(092)= %RGB_HONEYDEW
            icolorsavailable(093)= %RGB_HOTPINK
            icolorsavailable(094)= %RGB_INDIANRED
            icolorsavailable(095)= %RGB_INDIGO
            icolorsavailable(096)= %RGB_IVORY
            icolorsavailable(097)= %RGB_KHAKI
            icolorsavailable(098)= %RGB_LAVENDER
            icolorsavailable(099)= %RGB_LAVENDERBLUSH
            icolorsavailable(100)= %RGB_LAWNGREEN
            icolorsavailable(101)= %RGB_LEMONCHIFFON
            icolorsavailable(102)= %RGB_LIMEGREEN
            icolorsavailable(103)= %RGB_LINEN
            icolorsavailable(104)= %RGB_MAROON
            icolorsavailable(105)= %RGB_MEDIUMAQUAMARINE
            icolorsavailable(106)= %RGB_MIDNIGHTBLUE
            icolorsavailable(107)= %RGB_MINTCREAM
            icolorsavailable(108)= %RGB_MISTYROSE
            icolorsavailable(109)= %RGB_MOCCASIN
            icolorsavailable(110)= %RGB_NAVAJOWHITE
            icolorsavailable(111)= %RGB_NAVY
            icolorsavailable(112)= %RGB_OLDLACE
            icolorsavailable(113)= %RGB_OLIVE
            icolorsavailable(114)= %RGB_OLIVEDRAB
            icolorsavailable(115)= %RGB_ORANGERED
            icolorsavailable(116)= %RGB_PAPAYAWHIP
            icolorsavailable(117)= %RGB_PEACHPUFF
            icolorsavailable(118)= %RGB_PERU
            icolorsavailable(119)= %RGB_PINK
            icolorsavailable(120)= %RGB_PLUM
            icolorsavailable(121)= %RGB_POWDERBLUE
            icolorsavailable(122)= %RGB_ROSYBROWN
            icolorsavailable(123)= %RGB_ROYALBLUE
            icolorsavailable(124)= %RGB_SADDLEBROWN
            icolorsavailable(125)= %RGB_SANDYBROWN
            icolorsavailable(126)= %RGB_SEASHELL
            icolorsavailable(127)= %RGB_SIENNA
            icolorsavailable(128)= %RGB_SILVER
            icolorsavailable(129)= %RGB_SNOW
            icolorsavailable(130)= %RGB_SPRINGGREEN
            icolorsavailable(131)= %RGB_STEELBLUE
            icolorsavailable(132)= %RGB_TAN
            icolorsavailable(133)= %RGB_TEAL
            icolorsavailable(134)= %RGB_THISTLE
            icolorsavailable(135)= %RGB_TOMATO
            icolorsavailable(136)= %RGB_WHEAT
            icolorsavailable(137)= %RGB_WHITESMOKE
            icolorsavailable(138)= %RGB_YELLOWGREEN
        p purvis

        Comment


        • #5
          all below colors are built into powerbasic compileer pbwin10 and pbcc 4.04
          i removed the hex value indicator to make the hex numbers easier to read and identify, they were hard on my tired eyes
          i put these here because they were listed in my code for testing

          an example of as it was listed orginally
          %RGB_INDIANRED = &H5C5CCD

          Code:
          '     all below colors are built into powerbasic compileer pbwin10
          '     values to the right are hex values
          '
          '     Red Colors
          '     %RGB_INDIANRED            = 5C5CCD
          '     %RGB_LIGHTCORAL           = 8080F0
          '     %RGB_SALMON               = 7280FA
          '     %RGB_DARKSALMON           = 7A96E9
          '     %RGB_LIGHTSALMON          = 7AA0FF
          '     %RGB_CRIMSON              = 3C14DC
          '     %RGB_RED                  = 0000FF
          '     %RGB_FIREBRICK            = 2222B2
          '     %RGB_DARKRED              = 00008B
          '
          '     Pink Colors
          '     %RGB_PINK                 = CBC0FF
          '     %RGB_LIGHTPINK            = C1B6FF
          '     %RGB_HOTPINK              = B469FF
          '     %RGB_DEEPPINK             = 9314FF
          '     %RGB_MEDIUMVIOLETRED      = 8515C7
          '     %RGB_PALEVIOLETRED        = 9370DB
          '
          '     Orange Colors
          '     %RGB_LIGHTSALMON          = 7AA0FF
          '     %RGB_CORAL                = 507FFF
          '     %RGB_TOMATO               = 4763FF
          '     %RGB_ORANGERED            = 0045FF
          '     %RGB_DARKORANGE           = 008CFF
          '     %RGB_ORANGE               = 00A5FF
          '
          '     Yellow Colors
          '     %RGB_GOLD                 = 00D7FF
          '     %RGB_YELLOW               = 00FFFF
          '     %RGB_LIGHTYELLOW          = E0FFFF
          '     %RGB_LEMONCHIFFON         = CDFAFF
          '     %RGB_LIGHTGOLDENRODYELLOW = D2FAFA
          '     %RGB_PAPAYAWHIP           = D5EFFF
          '     %RGB_MOCCASIN             = B5E4FF
          '     %RGB_PEACHPUFF            = B9DAFF
          '     %RGB_PALEGOLDENROD        = AAE8EE
          '     %RGB_KHAKI                = 8CE6F0
          '     %RGB_DARKKHAKI            = 6BB7BD
          '
          '     Purple Colors
          '     %RGB_LAVENDER             = FAE6E6
          '     %RGB_THISTLE              = D8BFD8
          '     %RGB_PLUM                 = DDA0DD
          '     %RGB_VIOLET               = EE82EE
          '     %RGB_ORCHID               = D670DA
          '     %RGB_MAGENTA              = FF00FF
          '     %RGB_MEDIUMORCHID         = D355BA
          '     %RGB_MEDIUMPURPLE         = DB7093
          '     %RGB_BLUEVIOLET           = E22B8A
          '     %RGB_DARKVIOLET           = D30094
          '     %RGB_DARKORCHID           = CC3299
          '     %RGB_DARKMAGENTA          = 8B008B
          '     %RGB_PURPLE               = 800080
          '     %RGB_INDIGO               = 82004B
          '     %RGB_SLATEBLUE            = CD5A6A
          '     %RGB_DARKSLATEBLUE        = 8B3D48
          '     %RGB_MEDIUMSLATEBLUE      = EE687B
          '
          '     Green Colors
          '     %RGB_GREENYELLOW          = 2FFFAD
          '     %RGB_CHARTREUSE           = 00FF7F
          '     %RGB_LAWNGREEN            = 00FC7C
          '     %RGB_LIME                 = 00FF00
          '     %RGB_LIMEGREEN            = 32CD32
          '     %RGB_PALEGREEN            = 98FB98
          '     %RGB_LIGHTGREEN           = 90EE90
          '     %RGB_MEDIUMSPRINGGREEN    = 9AFA00
          '     %RGB_SPRINGGREEN          = 7FFF00
          '     %RGB_MEDIUMSEAGREEN       = 71B33C
          '     %RGB_SEAGREEN             = 578B2E
          '     %RGB_FORESTGREEN          = 228B22
          '     %RGB_GREEN                = 008000
          '     %RGB_DARKGREEN            = 006400
          '     %RGB_YELLOWGREEN          = 32CD9A
          '     %RGB_OLIVEDRAB            = 238E6B
          '     %RGB_OLIVE                = 008080
          '     %RGB_DARKOLIVEGREEN       = 2F6B55
          '     %RGB_MEDIUMAQUAMARINE     = AACD66
          '     %RGB_DARKSEAGREEN         = 8FBC8F
          '     %RGB_LIGHTSEAGREEN        = AAB220
          '     %RGB_DARKCYAN             = 8B8B00
          '     %RGB_TEAL                 = 808000
          '
          '     Blue Colors
          '     %RGB_CYAN                 = FFFF00
          '     %RGB_LIGHTCYAN            = FFFFE0
          '     %RGB_PALETURQUOISE        = EEEEAF
          '     %RGB_AQUAMARINE           = D4FF7F
          '     %RGB_TURQUOISE            = D0E040
          '     %RGB_MEDIUMTURQUOISE      = CCD148
          '     %RGB_DARKTURQUOISE        = D1CE00
          '     %RGB_CADETBLUE            = A09E5F
          '     %RGB_STEELBLUE            = B48246
          '     %RGB_LIGHTSTEELBLUE       = DEC4B0
          '     %RGB_POWDERBLUE           = E6E0B0
          '     %RGB_LIGHTBLUE            = E6D8AD
          '     %RGB_SKYBLUE              = EBCE87
          '     %RGB_LIGHTSKYBLUE         = FACE87
          '     %RGB_DEEPSKYBLUE          = FFBF00
          '     %RGB_DODGERBLUE           = FF901E
          '     %RGB_CORNFLOWERBLUE       = ED9564
          '     %RGB_MEDIUMSLATEBLUE      = EE687B
          '     %RGB_ROYALBLUE            = E16941
          '     %RGB_BLUE                 = FF0000
          '     %RGB_MEDIUMBLUE           = CD0000
          '     %RGB_DARKBLUE             = 8B0000
          '     %RGB_NAVY                 = 800000
          '     %RGB_MIDNIGHTBLUE         = 701919
          '
          '     Brown Colors
          '     %RGB_CORNSILK             = DCF8FF
          '     %RGB_BLANCHEDALMOND       = CDEBFF
          '     %RGB_BISQUE               = C4E4FF
          '     %RGB_NAVAJOWHITE          = ADDEFF
          '     %RGB_WHEAT                = B3DEF5
          '     %RGB_BURLYWOOD            = 87B8DE
          '     %RGB_TAN                  = 8CB4D2
          '     %RGB_ROSYBROWN            = 8F8FBC
          '     %RGB_SANDYBROWN           = 60A4F4
          '     %RGB_GOLDENROD            = 20A5DA
          '     %RGB_DARKGOLDENROD        = 0B86B8
          '     %RGB_PERU                 = 3F85CD
          '     %RGB_CHOCOLATE            = 1E69D2
          '     %RGB_SADDLEBROWN          = 13458B
          '     %RGB_SIENNA               = 2D52A0
          '     %RGB_BROWN                = 2A2AA5
          '     %RGB_MAROON               = 000080
          '
          '     White Colors
          '     %RGB_WHITE                = FFFFFF
          '     %RGB_SNOW                 = FAFAFF
          '     %RGB_HONEYDEW             = F0FFF0
          '     %RGB_MINTCREAM            = FAFFF5
          '     %RGB_AZURE                = FFFFF0
          '     %RGB_ALICEBLUE            = FFF8F0
          '     %RGB_GHOSTWHITE           = FFF8F8
          '     %RGB_WHITESMOKE           = F5F5F5
          '     %RGB_SEASHELL             = EEF5FF
          '     %RGB_BEIGE                = DCF5F5
          '     %RGB_OLDLACE              = E6F5FD
          '     %RGB_FLORALWHITE          = F0FAFF
          '     %RGB_IVORY                = F0FFFF
          '     %RGB_ANTIQUEWHITE         = D7EBFA
          '     %RGB_LINEN                = E6F0FA
          '     %RGB_LAVENDERBLUSH        = F5F0FF
          '     %RGB_MISTYROSE            = E1E4FF
          '
          '     Gray Colors
          '     %RGB_GAINSBORO            = DCDCDC
          '     %RGB_LIGHTGRAY            = D3D3D3
          '     %RGB_SILVER               = C0C0C0
          '     %RGB_DARKGRAY             = A9A9A9
          '     %RGB_GRAY                 = 808080
          '     %RGB_DIMGRAY              = 696969
          '     %RGB_LIGHTSLATEGRAY       = 998877
          '     %RGB_SLATEGRAY            = 908070
          '     %RGB_DARKSLATEGRAY        = 4F4F2F
          '     %RGB_BLACK                = 000000
          p purvis

          Comment


          • #6
            much faster code in finding the nearest color by mostly replacing the power of 2 with simple mutiplication
            i thought i could use a shift operation rather than the power of 2 code but i suppose i do not understand the SHIFT well enough, maybe you cannot use SHIFT on odd numbers.
            i am basically using a large set of predeterminded colors mostly for testing the algorithm

            Code:
            'program to change colors in a bitmap file to predetermined colors by neareast color
            'compiled with pbwin10
            'Compilable Example:
            #COMPILE EXE
            #DIM ALL
            #INCLUDE "Win32API.inc"
            
            
            TYPE RGBtype
                Red AS BYTE
                green AS BYTE
                blue AS BYTE
                dummy AS BYTE
            END TYPE
            UNION LongToRGB
                Colour AS LONG
                RGBcol AS RGBtype
            END UNION
            
            
            
            
            FUNCTION PBMAIN() AS LONG
                LOCAL hbmp AS DWORD
                LOCAL nfile AS DWORD
                LOCAL sinputfilename,soutputfilename AS STRING
                LOCAL sbmp AS STRING
            
                sinputfilename=TRIM$(COMMAND$)
              '  sinputfilename= "a.bmp" 'input filename inserted for testing in pbwin10 ide
            
                IF LEN(sinputfilename)=0& OR NOT ISFILE(sinputfilename) THEN EXIT FUNCTION
                IF RIGHT$(UCASE$(sinputfilename),4)<> ".BMP" THEN EXIT FUNCTION
                soutputfilename=LEFT$(sinputfilename,LEN(sinputfilename)-4)+"-new.bmp"
                IF ISFILE(soutputfilename) THEN KILL soutputfilename
            
                nFile = FREEFILE
            '    OPEN sfilename FOR BINARY ACCESS READ WRITE LOCK SHARED AS nFile
            '    gET nFile, 19, iimagexsize
            '    GET nFile, 23, iimageysize
            '    CLOSE nFile
            '    if iimagexsize=0& or iimageysize=0& then exit function
            
                GRAPHIC BITMAP LOAD sinputfilename, 0, 0  TO hBmp
            
                GRAPHIC ATTACH hbmp, 0
                GRAPHIC GET BITS TO sbmp
                change_colors_to_closest_predetermined_colors(sbmp)
                GRAPHIC SET BITS sbmp
            
                GRAPHIC SAVE soutputfilename
            
                GRAPHIC DETACH
                GRAPHIC BITMAP END
            END FUNCTION
            
            
            
            FUNCTION change_colors_to_closest_predetermined_colors(BYREF sbmp AS STRING) AS LONG
                LOCAL icounter1,icounter2, iresult,inearest,iusecolor AS LONG
                LOCAL MyColour1 AS LongToRGB
                LOCAL MyColour2 AS LongToRGB
                LOCAL PixelPtr AS LONG PTR
                LOCAL idiffred AS LONG
                LOCAL idiffgreen AS LONG
                LOCAL idiffblue AS LONG
            
            
                DIM iall24bitcolors(0& TO 16777215&) AS LONG
            
                DIM icolorsavailable(1& TO 138&) AS LONG
                icolorsavailable(001)= %RGB_BLACK
                icolorsavailable(002)= %RGB_WHITE
                icolorsavailable(003)= %RGB_GRAY
                icolorsavailable(004)= %RGB_RED
                icolorsavailable(005)= %RGB_GREEN
                icolorsavailable(006)= %RGB_BLUE
                icolorsavailable(007)= %RGB_YELLOW
                icolorsavailable(008)= %RGB_CYAN
                icolorsavailable(009)= %RGB_LIME
                icolorsavailable(010)= %RGB_MAGENTA
                icolorsavailable(011)= %RGB_BROWN
                icolorsavailable(012)= %RGB_VIOLET
                icolorsavailable(013)= %RGB_ORANGE
                icolorsavailable(014)= %RGB_PURPLE
            
                icolorsavailable(015)= %RGB_GOLDENROD
            
                icolorsavailable(016)= %RGB_LIGHTBLUE
                icolorsavailable(017)= %RGB_LIGHTCYAN
                icolorsavailable(018)= %RGB_LIGHTGRAY
                icolorsavailable(019)= %RGB_LIGHTGREEN
                icolorsavailable(020)= %RGB_LIGHTPINK
                icolorsavailable(021)= %RGB_LIGHTYELLOW
            
                icolorsavailable(022)= %RGB_MEDIUMBLUE
                icolorsavailable(023)= %RGB_MEDIUMPURPLE
            
                icolorsavailable(024)= %RGB_DARKBLUE
                icolorsavailable(025)= %RGB_DARKCYAN
                icolorsavailable(026)= %RGB_DARKGRAY
                icolorsavailable(027)= %RGB_DARKGREEN
                icolorsavailable(028)= %RGB_DARKORANGE
                icolorsavailable(029)= %RGB_DARKRED
                icolorsavailable(030)= %RGB_DARKMAGENTA
                icolorsavailable(031)= %RGB_DARKVIOLET
            
                icolorsavailable(032)= %RGB_CORAL
                icolorsavailable(033)= %RGB_ORCHID
                icolorsavailable(034)= %RGB_SEAGREEN
                icolorsavailable(035)= %RGB_SALMON
                icolorsavailable(036)= %RGB_SKYBLUE
                icolorsavailable(037)= %RGB_SLATEBLUE
                icolorsavailable(038)= %RGB_SLATEGRAY
                icolorsavailable(039)= %RGB_TURQUOISE
            
                icolorsavailable(040)= %RGB_PALEGOLDENROD
                icolorsavailable(041)= %RGB_PALEGREEN
                icolorsavailable(042)= %RGB_PALETURQUOISE
                icolorsavailable(043)= %RGB_PALEVIOLETRED
            
                icolorsavailable(044)= %RGB_LIGHTGOLDENRODYELLOW
                icolorsavailable(045)= %RGB_LIGHTCORAL
                icolorsavailable(046)= %RGB_LIGHTSALMON
                icolorsavailable(047)= %RGB_LIGHTSEAGREEN
                icolorsavailable(048)= %RGB_LIGHTSKYBLUE
                icolorsavailable(049)= %RGB_LIGHTSLATEGRAY
                icolorsavailable(050)= %RGB_LIGHTSTEELBLUE
            
                icolorsavailable(051)= %RGB_MEDIUMORCHID
                icolorsavailable(052)= %RGB_MEDIUMSEAGREEN
                icolorsavailable(053)= %RGB_MEDIUMSLATEBLUE
                icolorsavailable(054)= %RGB_MEDIUMSPRINGGREEN
                icolorsavailable(055)= %RGB_MEDIUMTURQUOISE
                icolorsavailable(056)= %RGB_MEDIUMVIOLETRED
            
                icolorsavailable(057)= %RGB_DARKGOLDENROD
                icolorsavailable(058)= %RGB_DARKKHAKI
                icolorsavailable(059)= %RGB_DARKOLIVEGREEN
                icolorsavailable(060)= %RGB_DARKORCHID
                icolorsavailable(061)= %RGB_DARKSALMON
                icolorsavailable(062)= %RGB_DARKSEAGREEN
                icolorsavailable(063)= %RGB_DARKSLATEBLUE
                icolorsavailable(064)= %RGB_DARKSLATEGRAY
                icolorsavailable(065)= %RGB_DARKTURQUOISE
            
                icolorsavailable(066)= %RGB_ALICEBLUE
                icolorsavailable(067)= %RGB_ANTIQUEWHITE
                icolorsavailable(068)= %RGB_AQUAMARINE
                icolorsavailable(069)= %RGB_AZURE
                icolorsavailable(070)= %RGB_BEIGE
                icolorsavailable(071)= %RGB_BISQUE
                icolorsavailable(072)= %RGB_BLANCHEDALMOND
                icolorsavailable(073)= %RGB_BLUEVIOLET
                icolorsavailable(074)= %RGB_BURLYWOOD
                icolorsavailable(075)= %RGB_CADETBLUE
                icolorsavailable(076)= %RGB_CHARTREUSE
                icolorsavailable(077)= %RGB_CHOCOLATE
                icolorsavailable(078)= %RGB_CORNFLOWERBLUE
                icolorsavailable(079)= %RGB_CORNSILK
                icolorsavailable(080)= %RGB_CRIMSON
                icolorsavailable(081)= %RGB_DEEPPINK
                icolorsavailable(082)= %RGB_DEEPSKYBLUE
                icolorsavailable(083)= %RGB_DIMGRAY
                icolorsavailable(084)= %RGB_DODGERBLUE
                icolorsavailable(085)= %RGB_FIREBRICK
                icolorsavailable(086)= %RGB_FLORALWHITE
                icolorsavailable(087)= %RGB_FORESTGREEN
                icolorsavailable(088)= %RGB_GAINSBORO
                icolorsavailable(089)= %RGB_GHOSTWHITE
                icolorsavailable(090)= %RGB_GOLD
                icolorsavailable(091)= %RGB_GREENYELLOW
                icolorsavailable(092)= %RGB_HONEYDEW
                icolorsavailable(093)= %RGB_HOTPINK
                icolorsavailable(094)= %RGB_INDIANRED
                icolorsavailable(095)= %RGB_INDIGO
                icolorsavailable(096)= %RGB_IVORY
                icolorsavailable(097)= %RGB_KHAKI
                icolorsavailable(098)= %RGB_LAVENDER
                icolorsavailable(099)= %RGB_LAVENDERBLUSH
                icolorsavailable(100)= %RGB_LAWNGREEN
                icolorsavailable(101)= %RGB_LEMONCHIFFON
                icolorsavailable(102)= %RGB_LIMEGREEN
                icolorsavailable(103)= %RGB_LINEN
                icolorsavailable(104)= %RGB_MAROON
                icolorsavailable(105)= %RGB_MEDIUMAQUAMARINE
                icolorsavailable(106)= %RGB_MIDNIGHTBLUE
                icolorsavailable(107)= %RGB_MINTCREAM
                icolorsavailable(108)= %RGB_MISTYROSE
                icolorsavailable(109)= %RGB_MOCCASIN
                icolorsavailable(110)= %RGB_NAVAJOWHITE
                icolorsavailable(111)= %RGB_NAVY
                icolorsavailable(112)= %RGB_OLDLACE
                icolorsavailable(113)= %RGB_OLIVE
                icolorsavailable(114)= %RGB_OLIVEDRAB
                icolorsavailable(115)= %RGB_ORANGERED
                icolorsavailable(116)= %RGB_PAPAYAWHIP
                icolorsavailable(117)= %RGB_PEACHPUFF
                icolorsavailable(118)= %RGB_PERU
                icolorsavailable(119)= %RGB_PINK
                icolorsavailable(120)= %RGB_PLUM
                icolorsavailable(121)= %RGB_POWDERBLUE
                icolorsavailable(122)= %RGB_ROSYBROWN
                icolorsavailable(123)= %RGB_ROYALBLUE
                icolorsavailable(124)= %RGB_SADDLEBROWN
                icolorsavailable(125)= %RGB_SANDYBROWN
                icolorsavailable(126)= %RGB_SEASHELL
                icolorsavailable(127)= %RGB_SIENNA
                icolorsavailable(128)= %RGB_SILVER
                icolorsavailable(129)= %RGB_SNOW
                icolorsavailable(130)= %RGB_SPRINGGREEN
                icolorsavailable(131)= %RGB_STEELBLUE
                icolorsavailable(132)= %RGB_TAN
                icolorsavailable(133)= %RGB_TEAL
                icolorsavailable(134)= %RGB_THISTLE
                icolorsavailable(135)= %RGB_TOMATO
                icolorsavailable(136)= %RGB_WHEAT
                icolorsavailable(137)= %RGB_WHITESMOKE
                icolorsavailable(138)= %RGB_YELLOWGREEN
            
              ' icolorsavailable(139)=RGB(183,100,82) 'a redish flesh tone
              ' icolorsavailable(140)=RGB(140,73,64)  'a redish flesh tone
            
                'find and assign a positive number to only colors that exist in the graphic bitmap
                'in order to speed up the process of only assigning colors that the closest
                PixelPtr = STRPTR(sbmp) + 8
                FOR icounter1 = 1 TO CVL(sbmp,1)*CVL(sbmp,5)
                   iall24bitcolors(RGB(@PixelPtr))=1&
                   INCR PixelPtr
                NEXT icounter1
            
            'speed test code only on the assigning of closest predefined color
            'LOCAL qFreq, qStart, qStop,qtime AS QUAD
            'LOCAL qwack AS QUAD
            'QueryPerformanceFrequency qFreq    'clock frequency
            'QueryPerformanceCounter   qwack
            'QueryPerformanceCounter   qwack
            'QueryPerformanceCounter   qStart
            
                'loop to find and set assigned found pixels colors with the nearest predefined color from the limited icoloravailable array of colors
                FOR icounter1=0& TO 16777215&
                    IF iall24bitcolors(icounter1) THEN   'this line for only processing colors that are present in the graphic bitmap
                        MyColour1.Colour = RGB(icounter1)
                        inearest=16777216&
                        iusecolor=0&
                        iresult=0&
                        FOR icounter2=LBOUND(icolorsavailable()) TO UBOUND(icolorsavailable())
                            MyColour2.Colour = icolorsavailable(icounter2)
                            'notusing ABS does not seem to alter the final results
                            'idiffred=ABS(MyColour1.RGBcol.Red-MyColour2.RGBcol.Red)
                            'idiffgreen=ABS(MyColour1.RGBcol.Green-MyColour2.RGBcol.Green)
                            'idiffblue=ABS(MyColour1.RGBcol.Blue-MyColour2.RGBcol.Blue)
                            idiffred=MyColour1.RGBcol.Red-MyColour2.RGBcol.Red
                            idiffgreen=MyColour1.RGBcol.Green-MyColour2.RGBcol.Green
                            idiffblue=MyColour1.RGBcol.Blue-MyColour2.RGBcol.Blue
                            iresult=SQR((idiffred*idiffred)+(idiffgreen*idiffgreen)+(idiffblue*idiffblue))
                            IF iresult<inearest THEN
                                inearest=iresult
                                iusecolor=icounter2
                            END IF
                    NEXT icounter2
                    iall24bitcolors(icounter1)=icolorsavailable(iusecolor)
                    END IF
                NEXT icounter1
            
            'speed test code only
            'QueryPerformanceCounter   qStop
            'qtime=qStop-qStart
            'msgbox  " ------- Time "+FORMAT$((qtime)*1000/qFreq, "####.##")+"ms"
            
                'loop to replace the original color pixels with the nearest predefined colors
                PixelPtr = STRPTR(sbmp) + 8
                FOR icounter1 = 1 TO CVL(sbmp,1)*CVL(sbmp,5)
                   @PixelPtr=iall24bitcolors(BGR(@PixelPtr))
                   INCR PixelPtr
                NEXT
            END FUNCTION
            
            
            
            'listing of colors for referrence only
            '     all colors are built into powerbasic compileer pbwin10
            '     values to the right are hex values
            '
            '     Red Colors
            '     %RGB_INDIANRED            = 5C5CCD
            '     %RGB_LIGHTCORAL           = 8080F0
            '     %RGB_SALMON               = 7280FA
            '     %RGB_DARKSALMON           = 7A96E9
            '     %RGB_LIGHTSALMON          = 7AA0FF
            '     %RGB_CRIMSON              = 3C14DC
            '     %RGB_RED                  = 0000FF
            '     %RGB_FIREBRICK            = 2222B2
            '     %RGB_DARKRED              = 00008B
            '
            '     Pink Colors
            '     %RGB_PINK                 = CBC0FF
            '     %RGB_LIGHTPINK            = C1B6FF
            '     %RGB_HOTPINK              = B469FF
            '     %RGB_DEEPPINK             = 9314FF
            '     %RGB_MEDIUMVIOLETRED      = 8515C7
            '     %RGB_PALEVIOLETRED        = 9370DB
            '
            '     Orange Colors
            '     %RGB_LIGHTSALMON          = 7AA0FF
            '     %RGB_CORAL                = 507FFF
            '     %RGB_TOMATO               = 4763FF
            '     %RGB_ORANGERED            = 0045FF
            '     %RGB_DARKORANGE           = 008CFF
            '     %RGB_ORANGE               = 00A5FF
            '
            '     Yellow Colors
            '     %RGB_GOLD                 = 00D7FF
            '     %RGB_YELLOW               = 00FFFF
            '     %RGB_LIGHTYELLOW          = E0FFFF
            '     %RGB_LEMONCHIFFON         = CDFAFF
            '     %RGB_LIGHTGOLDENRODYELLOW = D2FAFA
            '     %RGB_PAPAYAWHIP           = D5EFFF
            '     %RGB_MOCCASIN             = B5E4FF
            '     %RGB_PEACHPUFF            = B9DAFF
            '     %RGB_PALEGOLDENROD        = AAE8EE
            '     %RGB_KHAKI                = 8CE6F0
            '     %RGB_DARKKHAKI            = 6BB7BD
            '
            '     Purple Colors
            '     %RGB_LAVENDER             = FAE6E6
            '     %RGB_THISTLE              = D8BFD8
            '     %RGB_PLUM                 = DDA0DD
            '     %RGB_VIOLET               = EE82EE
            '     %RGB_ORCHID               = D670DA
            '     %RGB_MAGENTA              = FF00FF
            '     %RGB_MEDIUMORCHID         = D355BA
            '     %RGB_MEDIUMPURPLE         = DB7093
            '     %RGB_BLUEVIOLET           = E22B8A
            '     %RGB_DARKVIOLET           = D30094
            '     %RGB_DARKORCHID           = CC3299
            '     %RGB_DARKMAGENTA          = 8B008B
            '     %RGB_PURPLE               = 800080
            '     %RGB_INDIGO               = 82004B
            '     %RGB_SLATEBLUE            = CD5A6A
            '     %RGB_DARKSLATEBLUE        = 8B3D48
            '     %RGB_MEDIUMSLATEBLUE      = EE687B
            '
            '     Green Colors
            '     %RGB_GREENYELLOW          = 2FFFAD
            '     %RGB_CHARTREUSE           = 00FF7F
            '     %RGB_LAWNGREEN            = 00FC7C
            '     %RGB_LIME                 = 00FF00
            '     %RGB_LIMEGREEN            = 32CD32
            '     %RGB_PALEGREEN            = 98FB98
            '     %RGB_LIGHTGREEN           = 90EE90
            '     %RGB_MEDIUMSPRINGGREEN    = 9AFA00
            '     %RGB_SPRINGGREEN          = 7FFF00
            '     %RGB_MEDIUMSEAGREEN       = 71B33C
            '     %RGB_SEAGREEN             = 578B2E
            '     %RGB_FORESTGREEN          = 228B22
            '     %RGB_GREEN                = 008000
            '     %RGB_DARKGREEN            = 006400
            '     %RGB_YELLOWGREEN          = 32CD9A
            '     %RGB_OLIVEDRAB            = 238E6B
            '     %RGB_OLIVE                = 008080
            '     %RGB_DARKOLIVEGREEN       = 2F6B55
            '     %RGB_MEDIUMAQUAMARINE     = AACD66
            '     %RGB_DARKSEAGREEN         = 8FBC8F
            '     %RGB_LIGHTSEAGREEN        = AAB220
            '     %RGB_DARKCYAN             = 8B8B00
            '     %RGB_TEAL                 = 808000
            '
            '     Blue Colors
            '     %RGB_CYAN                 = FFFF00
            '     %RGB_LIGHTCYAN            = FFFFE0
            '     %RGB_PALETURQUOISE        = EEEEAF
            '     %RGB_AQUAMARINE           = D4FF7F
            '     %RGB_TURQUOISE            = D0E040
            '     %RGB_MEDIUMTURQUOISE      = CCD148
            '     %RGB_DARKTURQUOISE        = D1CE00
            '     %RGB_CADETBLUE            = A09E5F
            '     %RGB_STEELBLUE            = B48246
            '     %RGB_LIGHTSTEELBLUE       = DEC4B0
            '     %RGB_POWDERBLUE           = E6E0B0
            '     %RGB_LIGHTBLUE            = E6D8AD
            '     %RGB_SKYBLUE              = EBCE87
            '     %RGB_LIGHTSKYBLUE         = FACE87
            '     %RGB_DEEPSKYBLUE          = FFBF00
            '     %RGB_DODGERBLUE           = FF901E
            '     %RGB_CORNFLOWERBLUE       = ED9564
            '     %RGB_MEDIUMSLATEBLUE      = EE687B
            '     %RGB_ROYALBLUE            = E16941
            '     %RGB_BLUE                 = FF0000
            '     %RGB_MEDIUMBLUE           = CD0000
            '     %RGB_DARKBLUE             = 8B0000
            '     %RGB_NAVY                 = 800000
            '     %RGB_MIDNIGHTBLUE         = 701919
            '
            '     Brown Colors
            '     %RGB_CORNSILK             = DCF8FF
            '     %RGB_BLANCHEDALMOND       = CDEBFF
            '     %RGB_BISQUE               = C4E4FF
            '     %RGB_NAVAJOWHITE          = ADDEFF
            '     %RGB_WHEAT                = B3DEF5
            '     %RGB_BURLYWOOD            = 87B8DE
            '     %RGB_TAN                  = 8CB4D2
            '     %RGB_ROSYBROWN            = 8F8FBC
            '     %RGB_SANDYBROWN           = 60A4F4
            '     %RGB_GOLDENROD            = 20A5DA
            '     %RGB_DARKGOLDENROD        = 0B86B8
            '     %RGB_PERU                 = 3F85CD
            '     %RGB_CHOCOLATE            = 1E69D2
            '     %RGB_SADDLEBROWN          = 13458B
            '     %RGB_SIENNA               = 2D52A0
            '     %RGB_BROWN                = 2A2AA5
            '     %RGB_MAROON               = 000080
            '
            '     White Colors
            '     %RGB_WHITE                = FFFFFF
            '     %RGB_SNOW                 = FAFAFF
            '     %RGB_HONEYDEW             = F0FFF0
            '     %RGB_MINTCREAM            = FAFFF5
            '     %RGB_AZURE                = FFFFF0
            '     %RGB_ALICEBLUE            = FFF8F0
            '     %RGB_GHOSTWHITE           = FFF8F8
            '     %RGB_WHITESMOKE           = F5F5F5
            '     %RGB_SEASHELL             = EEF5FF
            '     %RGB_BEIGE                = DCF5F5
            '     %RGB_OLDLACE              = E6F5FD
            '     %RGB_FLORALWHITE          = F0FAFF
            '     %RGB_IVORY                = F0FFFF
            '     %RGB_ANTIQUEWHITE         = D7EBFA
            '     %RGB_LINEN                = E6F0FA
            '     %RGB_LAVENDERBLUSH        = F5F0FF
            '     %RGB_MISTYROSE            = E1E4FF
            '
            '     Gray Colors
            '     %RGB_GAINSBORO            = DCDCDC
            '     %RGB_LIGHTGRAY            = D3D3D3
            '     %RGB_SILVER               = C0C0C0
            '     %RGB_DARKGRAY             = A9A9A9
            '     %RGB_GRAY                 = 808080
            '     %RGB_DIMGRAY              = 696969
            '     %RGB_LIGHTSLATEGRAY       = 998877
            '     %RGB_SLATEGRAY            = 908070
            '     %RGB_DARKSLATEGRAY        = 4F4F2F
            '     %RGB_BLACK                = 000000
            p purvis

            Comment


            • #7
              Originally posted by Paul Purvis View Post
              I found a google website where it mentioned matching a pixel based on a cubic search method or algorithm.
              I have no idea what that is even after googling.
              I would suppose it means finding the nearest RGB or BGR based on a getting the nearest separate color of each of the 3 values in a pixel from the predetermined list of colors.
              i was writing an pseudo code to explain what i thought it might be, but in my mind the logic of my thoughts would not work.
              If there is an example here in this forum. I did not find it or it was described as something else.
              I was hoping one of our math experts here would help me.
              thanks
              You could try SORT USING by pixels in three arrays of indices.
              The closest match will be the one closest to the list top on all three.
              The world is strange and wonderful.*
              I reserve the right to be horrifically wrong.
              Please maintain a safe following distance.
              *wonderful sold separately.

              Comment


              • #8
                What were you shifting? The whole RGB (or BGR) at once, or each color's byte within a RGB (or BGR) separately?
                Dale

                Comment


                • #9
                  Paul, the attached code produces a colour cube and in the comments is some additional information that may be of value to you. When you are checking the nearest colour values and shifting to a nearer value if you only shift one component you likely won't be able to discern the difference. For example RGB(200,150,131) is virtually the same as RGB(199,150,131) are the same to the human eye. You might notice a difference between RGB(200,150,131) and RGB(193,150,131). I would suggest if changing one of the three colour values to change by 15, if you are changing two of the components then by 7 for each, if three components then by 4. It isn't perfect.
                  Code:
                  #COMPILE EXE
                  #DIM ALL
                  #IF %DEF(%PB_CC32)  ' if to be compiled with PBCC6 or PBCC5, then
                    #CONSOLE OFF      ' this example doesn't need the console window
                  #ENDIF
                  FUNCTION PBMAIN () AS LONG
                    LOCAL gWin, red, green, blue, x, y, z, xx, yy, fnt AS LONG
                    FONT NEW "Lucida Console", 12, 0 TO fnt
                    GRAPHIC WINDOW NEW "", 100,100,900,600 TO gWin
                    GRAPHIC SET OVERLAP 1
                    GRAPHIC SET FONT fnt
                    GRAPHIC CLEAR %GRAY
                                                  'Step 1
                    red=255
                    x=20
                    FOR y=300 TO 555                        'the first(top) pixel has an integer value of 255
                      GRAPHIC SET PIXEL (x,y), RGB(red,0,0) ' first pixel is the same as built in equate  %RGB_RED
                      DECR red                              'last pixel will be red=0 so the rgb value is the same as
                    NEXT y                                  '%RGB_BLACK or RGB(000,000,000), integer value 0
                    GRAPHIC WAITKEY$ (500)
                                                  'Step 2
                    green=0
                    y=555
                    FOR x=20 TO 275
                      GRAPHIC SET PIXEL (x,y), RGB(0, green, 0) 'first pixel in this loop overwrites the last pixel
                      INCR green                                'in the first loop because it is the same value
                    NEXT x                                      ' the last of the loop(rightmost) has the value
                                                                'RGB(0,255,0) same as built in %RGB_LIME int 65280
                    GRAPHIC WAITKEY$ (500)
                                                   'Step 3
                    y=300
                    red=255
                    green=0
                    FOR x=20 TO 275                              ' the last pixel generated is the built in %RGB_YELLOW
                      GRAPHIC SET PIXEL (x,y), RGB(red, green,0) ' RGB(255, 255, 0)   it has the integer value 65535
                      INCR green
                    NEXT x
                    GRAPHIC WAITKEY$ (500)
                                                    'Step 4
                    red=0
                    green= 255
                    x=275
                    FOR y=555 TO 300 STEP -1 'from bottom to top  'Within the developed square the RGB values will range
                      GRAPHIC SET PIXEL (x,y), RGB(red, green,0)  'from RGB(1,1,0) to RGB(254, 254,0) and all integer
                      INCR red                                    'values will be below 65535.
                    NEXT y
                    GRAPHIC WAITKEY$ (500)
                                                   'Step 5
                    red=1
                    FOR y=554 TO 301 STEP -1       ' filling in the square
                      green=1
                      FOR x=21 TO 274
                        GRAPHIC SET PIXEL (x,y), RGB(red, green,0)
                        INCR green
                      NEXT x
                      INCR red
                      GRAPHIC WAITKEY$ (50)
                    NEXT y
                                                  'Step 6
                    GRAPHIC ATTACH gwin, 0, REDRAW
                  
                                                                          ' to integrate the blue component
                    xx=21                                                 'all these colour integer values are greater
                    yy=299                                                '  than 65535
                    red=0                                                 'grays will occur in a diagonal line from
                    green=0                                               'black towards the white
                    blue=0                                                ' other colour affinities may occur between
                    FOR z=1 TO 255                                        ' other opposite corners
                      INCR blue
                      red=0
                      FOR y=555 TO 300 STEP -1
                        green=0
                        FOR x=600 TO 855
                          GRAPHIC SET PIXEL (x,y), RGB(red, green, blue)
                          INCR green
                        NEXT x
                        INCR red
                      NEXT y
                      GRAPHIC REDRAW
                      GRAPHIC WAITKEY$ (15)
                      GRAPHIC COPY gwin, 0, (600,300)-(855,555) TO (xx,yy)
                      GRAPHIC BOX (600,300)-(855,555), 0, %GRAY, %GRAY
                      INCR xx
                      DECR yy
                      GRAPHIC REDRAW
                    NEXT z
                    GRAPHIC COLOR %WHITE, -2
                    GRAPHIC SET POS (500,500)
                    GRAPHIC PRINT "All 16777216 colours appeared."
                    GRAPHIC SET POS (500,520)
                    GRAPHIC PRINT "Press a key to terminate."
                    GRAPHIC REDRAW
                    GRAPHIC WAITKEY$
                    GRAPHIC WINDOW END
                  END FUNCTION
                  Rod
                  "To every unsung hero in the universe
                  To those who roam the skies and those who roam the earth
                  To all good men of reason may they never thirst " - from "Heaven Help the Devil" by G. Lightfoot

                  Comment


                  • #10
                    From post 6 I took it as SHIFT LEFT or SHIFT RIGHT as a replacement for multiply or divide by 2, 4, 8, etc. And that it be done to all 3 colors at the same time, but each color byte individualally. If you SHIFT a 32 bit RGB (or BGR) then LSbit of one byte becomes the MSbit of the next byte. The combined color goes wacko instead of slightly altered to a near color.

                    A multiply or divide may, or may not, be what Paul needs for this job. I did not mean change one bit in one of the colors at a time. My question was to determine if I understood what Paul was saying about powers of 2 and SHIFT in the same sentence.

                    Paul,

                    Yes, SHIFT RIGHT var, 2 (for example) is the same as divide by 4. SHIFT LEFT var, 3 (for example) is the same as multiply by 8.

                    Odd (in binary representation of a number) is just the least signifiant bit being set. Of course they can be shifted or muliplied/divided.

                    With SHIFT RIGHT or divide (integers)((including non-powers of 2)) the LSbit, or bits, fall off the low end into the bit bucket.
                    With SHIFT LEFT or multiply (integers)((including non-powers of 2)) the MSbit, or bits, fall off the high end into the bit bucket.

                    Like I said, you may, or may not, end up needing multiply or divide to find nearest color; but I hope you see that you can not use an operation to a whole RGB/BGR as a LONG or DWORD. But as individual BYTES that are in a LONG or DWORD.

                    You may know this already. So I asked the question before saying anything else.

                    Cheers,
                    Dale

                    Comment


                    • #11
                      I can't see that shifting the bits in the long integer form of the colour or the individual bytes would produce slightly altered colours or even closely related colours. I think XORing the 4th or 5th bit is as far as one should go for 'slightly altered' colours.
                      Rod
                      "To every unsung hero in the universe
                      To those who roam the skies and those who roam the earth
                      To all good men of reason may they never thirst " - from "Heaven Help the Devil" by G. Lightfoot

                      Comment


                      • #12
                        Paul,
                        Wouldn't this...
                        Code:
                         
                        iresult=SQR( ((Red1-Red2)^2)+((Green1-Green2)^2)+((Blue1-Blue2)^2 ))
                        Need to be something like this?
                        Code:
                         
                        NewRed = Red1 + ABS(Red1-Red2) OR NewRed = Red1 - ABS(Red1-Red2) NewGreen = Green1 + ABS(Green1-Green2) OR NewGreen = Green1 - ABS(Green1-Green2) NewBlue = Blue1 + ABS(Blue1-Blue2) OR NewBlue = Blue1 - ABS(Blue1-Blue2)
                        Just looking at the differences that would be...
                        Code:
                        RedChangePlus = ABS(Red1-Red2)
                        OR
                        RedChangeMinus = - ABS(Red1-Red2)
                        
                        GreenChangePlus = ABS(Green1-Green2)
                        OR
                        GreenChangeMinus = - ABS(Green1-Green2)
                        
                        BlueChangePlus = ABS(Blue1-Blue2)
                        OR
                        BlueChangeMinus = - ABS(Blue1-Blue2)
                        
                        OverallChangePlus = RedChangePlus + GreenChangePlus + BlueChangePlus
                        OR
                        OverallChangeMinus = RedChangeMinus + GreenChangeMinus + BlueChangeMinus
                        It is probably best to handle them separate like Kurt and Rodney suggest.

                        Code:
                        IF RedChangePlus <= 4 and GreenChangePlus <= 4 and BlueChangePlus <= 4 THEN
                            iresult = 1
                        ELSEIF RedChangePlus >= 15 OR GreenChangePlus >= 15 or BlueChangePlus >= 15 THEN
                            iresult = 0
                        ELSEIF RedChangePlus >= 7 and GreenChangePlus >= 7 and BlueChangePlus < 7 THEN
                            iresult = 2
                        ELSEIF RedChangePlus >= 7 and GreenChangePlus < 7 and BlueChangePlus >= 7 THEN
                            iresult = 2
                        ELSEIF RedChangePlus < 7 and GreenChangePlus >= 7 and BlueChangePlus >= 7 THEN
                            iresult = 2
                        ELSE
                            iresult = 3
                        END IF
                        Last edited by Jim Fritts; 28 Oct 2018, 04:52 PM.

                        Comment


                        • #13
                          thank you i will have to review this later today.
                          but i did want say that i had some code where i was taking a short cut and not assigning to long variables
                          in the process of creating for about 24 hours, i made some changes
                          some code changes that i have made inside of function - change_colors_to_closest_predetermined_colors

                          hopefully the MyColourx variables are self explanatory.
                          see Paul Dixon's code using MyColour for RGB color to Red, GREEN, BLUE separate variable routine
                          https://forum.powerbasic.com/forum/u...ramming/774590
                          or
                          https://forum.powerbasic.com/forum/u...-to-rgb-or-bgr


                          code 1
                          Code:
                             LOCAL Red1, Green1, Blue1 AS LONG
                              LOCAL Red2, Green2, Blue2 AS LONG
                          
                          'inside loop looper1 at beginng
                          
                               Red1 = MyColour1.RGBcol.Red
                               Green1 = MyColour1.RGBcol.Green
                               Blue1 = MyColour1.RGBcol.Blue
                          
                          'inside of loop looper2 that is nested in loop looper1
                               Red2 = MyColour2.RGBcol.Red
                               Green2 = MyColour2.RGBcol.Green
                               Blue2 = MyColour2.RGBcol.Blue
                               iresult=SQR( ((Red1-Red2)^2)+((Green1-Green2)^2)+((Blue1-Blue2)^2 ))
                          code 2
                          this code allowed the removal of the assigning values to long variables red1, red2, green1, green2, blue1 and blue2
                          Code:
                           'inside of loop looper2 that is nested in loop looper1
                          
                             iresult=SQR(((MyColour1.RGBcol.Red-MyColour2.RGBcol.Red)^2)+ _
                                        ((MyColour1.RGBcol.Green-MyColour2.RGBcol.Green)^2) + _
                                        ((MyColour1.RGBcol.Blue-MyColour2.RGBcol.Blue)^2))

                          found out in test that code 2 was slow, mostly from what i could tell was the power of 2 being used
                          so i worked on the possibility of using SHIFT rather than power and my test did not prove
                          accurate due to lack of experience or simply because it would not work with the values i was presenting to SHIFT
                          tested getting away from power ^2 calculation and found just multiplication was faster

                          code 3
                          went back to assigning values to long variables and placed subtraction calculation on its own lines and
                          used multiplication rather that power
                          Code:
                          'declare long variables and still did not use the red1, red2, green1, green2, blue1 and blue2 long variables
                              LOCAL idiffred AS LONG
                              LOCAL idiffgreen AS LONG
                              LOCAL idiffblue AS LONG
                          
                                         idiffred=MyColour1.RGBcol.Red-MyColour2.RGBcol.Red
                                          idiffgreen=MyColour1.RGBcol.Green-MyColour2.RGBcol.Green
                                          idiffblue=MyColour1.RGBcol.Blue-MyColour2.RGBcol.Blue
                                          iresult=SQR((idiffred*idiffred)+(idiffgreen*idiffgreen)+(idiffblue*idiffblue))
                          p purvis

                          Comment


                          • #14
                            Hi Jim,
                            I thought the same concerning that negative values or using the ABS would of provided difference results and they should.
                            But when i used the same formula for comparing against the set of predefined colors, the desired outcome was the same for getting the best match.
                            .In my mind, it would make a difference.
                            In my test, using ABS added time to the overall loop looper2, so I removed the ABS function.
                            I am still scratching my head over it.
                            I still have some testing on looking at that values being assigned to the iresult variable that are returned..
                            i am running a test now that has gone over 12 hours and likely for couple of days till it is finished.
                            When i looked at this formula the first time and somebody mentioned a cubic search and i did not know
                            what that actually was and thinking it might be different, that is when i asked the forum.
                            p purvis

                            Comment


                            • #15
                              Rodney, i do not think shifting on colors is what i had in mind unless your perspective is seeing something i am not seeing.
                              I am really new to dealing with colors and have not had the experience others have maybe like yourself where you are seeing something i do not see.or understand.

                              Dale and Rodney, i will have to come back to your code or what you have written. It was a long night and i need a mind break.

                              Dale, i thought where i had read many years ago where shifting was far faster than using power.
                              and i have not really had use of it till this function.
                              I once mentioned i though SQR was slow but i believe it was one of the Pauls here that said it was not slow.
                              I must of been thinking of using the power rather the square calculation was slow. I am foggy on my remembrance.
                              p purvis

                              Comment


                              • #16
                                Originally posted by Jim Fritts View Post
                                Paul,
                                Wouldn't this...
                                Code:
                                 
                                iresult=SQR( ((Red1-Red2)^2)+((Green1-Green2)^2)+((Blue1-Blue2)^2 ))
                                Need to be something like this?
                                [CODE] [LEFT]
                                NewRed = Red1 + ABS(Red1-Red2)
                                OR
                                NewRed = Red1 - ABS(Red1-Red2)
                                ...
                                That's the whole purpose of squaring each difference and then taking the root of the sum. It's the basis of the standard statistical method called "root mean square" used in all sorts of areas to get the "standard deviation" for some sort of "signal". Whether each difference is positive or negative is irrelevant to the result.

                                It doesn't matter whether the closest match in the palette is lighter or darker, or which colour it is "tilted towards', you are just looking for the palette colour which has the smallest average difference from the selected pixel for all three primary colours.


                                Comment


                                • #17
                                  Thank you Stuart,
                                  Are you saying this would be the proper way.

                                  i know there are more parentheses in left then in for clarity.

                                  iresult=(Red1 + ABS(Red1-Red2))+(Green1 + ABS(Green1-Green2))+(Blue1 + ABS(Blue1-Blue2))
                                  or
                                  iresult=SQR(Red1 + ABS(Red1-Red2))+(Green1 + ABS(Green1-Green2))+(Blue1 + ABS(Blue1-Blue2)))

                                  p purvis

                                  Comment


                                  • #18

                                    Stewart and Paul,
                                    Below is what I was inferring as a solution rather than using SQR and ^2.
                                    No root means square needed to discern what variance is useful. The selection of a replacement color here would meet Rodney's recommendations.
                                    Code:
                                    RedChangePlus = ABS(Red1-Red2)
                                    GreenChangePlus = ABS(Green1-Green2)
                                    BlueChangePlus = ABS(Blue1-Blue2)
                                    
                                    IF RedChangePlus <= 4 and GreenChangePlus <= 4 and BlueChangePlus <= 4 THEN
                                        iresult = 1
                                    ELSEIF RedChangePlus >= 15 OR GreenChangePlus >= 15 or BlueChangePlus >= 15 THEN
                                        iresult = 0
                                    ELSEIF RedChangePlus >= 7 and GreenChangePlus >= 7 and BlueChangePlus < 7 THEN
                                        iresult = 2
                                    ELSEIF RedChangePlus >= 7 and GreenChangePlus < 7 and BlueChangePlus >= 7 THEN
                                        iresult = 2
                                    ELSEIF RedChangePlus < 7 and GreenChangePlus >= 7 and BlueChangePlus >= 7 THEN
                                        iresult = 2
                                    ELSE
                                        iresult = 3
                                    END IF
                                    I would look for something with an iresult of 1 or 2.

                                    Comment


                                    • #19
                                      Originally posted by Paul Purvis View Post
                                      Thank you Stuart,
                                      Are you saying this would be the proper way.

                                      i know there are more parentheses in left then in for clarity.

                                      iresult=(Red1 + ABS(Red1-Red2))+(Green1 + ABS(Green1-Green2))+(Blue1 + ABS(Blue1-Blue2))
                                      or
                                      iresult=SQR(Red1 + ABS(Red1-Red2))+(Green1 + ABS(Green1-Green2))+(Blue1 + ABS(Blue1-Blue2)))
                                      No, RMS requires squaring and then rooting. Here's a demo I've just knocked up.
                                      Code:
                                      #COMPILE EXE 'PBWin 10
                                      #DIM ALL
                                      
                                      TYPE rgbCol
                                          r AS BYTE
                                          g AS BYTE
                                          b AS BYTE
                                          x AS BYTE
                                      END TYPE
                                      
                                      UNION rgbCols
                                          cols AS LONG
                                          col AS RGBcol
                                      END UNION
                                      
                                      GLOBAL Palette() AS LONG
                                      
                                      FUNCTION PBMAIN () AS LONG
                                          LOCAL strBMap AS STRING
                                          LoadPalette
                                          DISPLAY OPENFILE 0, 0, 0, "Select Bitmap to reduce", "", CHR$("BITMAP", 0, "*.BMP", 0),"", "", 0 TO strBMap
                                          IF strBMap > "" THEN
                                              ColourIt strBMap
                                          ELSE
                                              ? "No file selected"
                                          END IF
                                      END FUNCTION
                                      
                                      FUNCTION ColourIt(strBMap AS STRING) AS LONG
                                          LOCAL l1,l2,l3 AS LONG
                                          LOCAL hBmp AS DWORD
                                          LOCAL lngH,lngW AS LONG
                                          LOCAL col1,col2 AS rgbcols
                                          LOCAL lngMinDif,lngDif,lngPalette AS LONG
                                          LOCAL RDif,GDif,BDif AS LONG
                                          OPEN strBMap FOR BINARY AS #1
                                          GET #1, 19, lngW
                                          GET #1, 23, lngH
                                          CLOSE #1
                                      
                                          GRAPHIC BITMAP LOAD StrBMap, lngW,lngH  TO hBMP
                                          GRAPHIC ATTACH hBMP,0
                                      
                                          FOR l1 = 1 TO lngH
                                              FOR l2 = 1 TO lngW
                                                  GRAPHIC GET PIXEL (l2,l1) TO Col1.cols
                                                  lngMinDif = 16581375 '255 * 255 * 255
                                      
                                                  FOR l3 = 0 TO UBOUND(palette())
                                                      col2.cols = Palette(l3)
                                                      RDif = col1.col.r -col2.col.r
                                                      GDif = col1.col.g - col2.col.g
                                                      BDif =col1.col.b  - col2.col.b
                                                      lngDif = SQR(Rdif*RDif+GDif*GDif + BDif*BDif)
                                                      IF lngDif < lngMinDif THEN
                                                           lngMinDif = lngDif
                                                           lngPalette = l3
                                                      END IF
                                                  NEXT
                                                  GRAPHIC SET PIXEL (l2,l1), Palette(lngPalette)
                                             NEXT
                                           NEXT
                                           GRAPHIC  SAVE "NewBitmap.bmp"
                                          ? "NewBitmap.bmp saved in current directory"
                                      END FUNCTION
                                      
                                      FUNCTION LoadPalette() AS LONG
                                      DIM Palette(141) AS LONG
                                      ' Red Colors
                                      Palette(000) = %RGB_INDIANRED
                                      Palette(001) = %RGB_LIGHTCORAL
                                      Palette(003) = %RGB_SALMON
                                      Palette(005) = %RGB_DARKSALMON
                                      Palette(006) = %RGB_LIGHTSALMON
                                      Palette(007) = %RGB_CRIMSON
                                      Palette(008) = %RGB_RED
                                      Palette(009) = %RGB_FIREBRICK
                                      Palette(010) = %RGB_DARKRED
                                      '
                                      ' Pink Colors
                                      Palette(011) = %RGB_PINK
                                      Palette(012) = %RGB_LIGHTPINK
                                      Palette(013) = %RGB_HOTPINK
                                      Palette(014) = %RGB_DEEPPINK
                                      Palette(015) = %RGB_MEDIUMVIOLETRED
                                      Palette(016) = %RGB_PALEVIOLETRED
                                      '
                                      ' Orange Colors
                                      Palette(017) = %RGB_LIGHTSALMON
                                      Palette(018) = %RGB_CORAL
                                      Palette(019) = %RGB_TOMATO
                                      Palette(020) = %RGB_ORANGERED
                                      Palette(021) = %RGB_DARKORANGE
                                      Palette(022) = %RGB_ORANGE
                                      '
                                      ' Yellow Colors
                                      Palette(023) = %RGB_GOLD
                                      Palette(024) = %RGB_YELLOW
                                      Palette(025) = %RGB_LIGHTYELLOW
                                      Palette(026) = %RGB_LEMONCHIFFON
                                      Palette(027) = %RGB_LIGHTGOLDENRODYELLOW
                                      Palette(028) = %RGB_PAPAYAWHIP
                                      Palette(029) = %RGB_MOCCASIN
                                      Palette(030) = %RGB_PEACHPUFF
                                      Palette(031) = %RGB_PALEGOLDENROD
                                      Palette(032) = %RGB_KHAKI
                                      Palette(033) = %RGB_DARKKHAKI
                                      '
                                      ' Purple Colors
                                      Palette(034) = %RGB_LAVENDER
                                      Palette(035) = %RGB_THISTLE
                                      Palette(036) = %RGB_PLUM
                                      Palette(037) = %RGB_VIOLET
                                      Palette(038) = %RGB_ORCHID
                                      Palette(039) = %RGB_MAGENTA
                                      Palette(040) = %RGB_MEDIUMORCHID
                                      Palette(041) = %RGB_MEDIUMPURPLE
                                      Palette(042) = %RGB_BLUEVIOLET
                                      Palette(043) = %RGB_DARKVIOLET
                                      Palette(044) = %RGB_DARKORCHID
                                      Palette(045) = %RGB_DARKMAGENTA
                                      Palette(046) = %RGB_PURPLE
                                      Palette(047) = %RGB_INDIGO
                                      Palette(048) = %RGB_SLATEBLUE
                                      Palette(049) = %RGB_DARKSLATEBLUE
                                      Palette(050) = %RGB_MEDIUMSLATEBLUE
                                      '
                                      ' Green Colors
                                      Palette(051) = %RGB_GREENYELLOW
                                      Palette(052) = %RGB_CHARTREUSE
                                      Palette(053) = %RGB_LAWNGREEN
                                      Palette(054) = %RGB_LIME
                                      Palette(055) = %RGB_LIMEGREEN
                                      Palette(056) = %RGB_PALEGREEN
                                      Palette(057) = %RGB_LIGHTGREEN
                                      Palette(058) = %RGB_MEDIUMSPRINGGREEN
                                      Palette(059) = %RGB_SPRINGGREEN
                                      Palette(060) = %RGB_MEDIUMSEAGREEN
                                      Palette(061) = %RGB_SEAGREEN
                                      Palette(062) = %RGB_FORESTGREEN
                                      Palette(063) = %RGB_GREEN
                                      Palette(064) = %RGB_DARKGREEN
                                      Palette(065) = %RGB_YELLOWGREEN
                                      Palette(066) = %RGB_OLIVEDRAB
                                      Palette(067) = %RGB_OLIVE
                                      Palette(068) = %RGB_DARKOLIVEGREEN
                                      Palette(069) = %RGB_MEDIUMAQUAMARINE
                                      Palette(070) = %RGB_DARKSEAGREEN
                                      Palette(071) = %RGB_LIGHTSEAGREEN
                                      Palette(072) = %RGB_DARKCYAN
                                      Palette(073) = %RGB_TEAL
                                      '
                                      ' Blue Colors
                                      Palette(074) = %RGB_CYAN
                                      Palette(075) = %RGB_LIGHTCYAN
                                      Palette(076) = %RGB_PALETURQUOISE
                                      Palette(077) = %RGB_AQUAMARINE
                                      Palette(078) = %RGB_TURQUOISE
                                      Palette(079) = %RGB_MEDIUMTURQUOISE
                                      Palette(080) = %RGB_DARKTURQUOISE
                                      Palette(081) = %RGB_CADETBLUE
                                      Palette(082) = %RGB_STEELBLUE
                                      Palette(083) = %RGB_LIGHTSTEELBLUE
                                      Palette(084) = %RGB_POWDERBLUE
                                      Palette(085) = %RGB_LIGHTBLUE
                                      Palette(086) = %RGB_SKYBLUE
                                      Palette(087) = %RGB_LIGHTSKYBLUE
                                      Palette(088) = %RGB_DEEPSKYBLUE
                                      Palette(089) = %RGB_DODGERBLUE
                                      Palette(090) = %RGB_CORNFLOWERBLUE
                                      Palette(091) = %RGB_MEDIUMSLATEBLUE
                                      Palette(092) = %RGB_ROYALBLUE
                                      Palette(093) = %RGB_BLUE
                                      Palette(094) = %RGB_MEDIUMBLUE
                                      Palette(095) = %RGB_DARKBLUE
                                      Palette(096) = %RGB_NAVY
                                      Palette(097) = %RGB_MIDNIGHTBLUE
                                      '
                                      ' Brown Colors
                                      Palette(098) = %RGB_CORNSILK
                                      Palette(099) = %RGB_BLANCHEDALMOND
                                      Palette(100) = %RGB_BISQUE
                                      Palette(101) = %RGB_NAVAJOWHITE
                                      Palette(102) = %RGB_WHEAT
                                      Palette(103) = %RGB_BURLYWOOD
                                      Palette(104) = %RGB_TAN
                                      Palette(105) = %RGB_ROSYBROWN
                                      Palette(106) = %RGB_SANDYBROWN
                                      Palette(107) = %RGB_GOLDENROD
                                      Palette(108) = %RGB_DARKGOLDENROD
                                      Palette(109) = %RGB_PERU
                                      Palette(110) = %RGB_CHOCOLATE
                                      Palette(111)= %RGB_SADDLEBROWN
                                      Palette(112)= %RGB_SIENNA
                                      Palette(113) = %RGB_BROWN
                                      Palette(114) = %RGB_MAROON
                                      '
                                      ' White Colors
                                      Palette(115) = %RGB_WHITE
                                      Palette(126) = %RGB_SNOW
                                      Palette(117) = %RGB_HONEYDEW
                                      Palette(118) = %RGB_MINTCREAM
                                      Palette(119) = %RGB_AZURE
                                      Palette(120) = %RGB_ALICEBLUE
                                      Palette(121) = %RGB_GHOSTWHITE
                                      Palette(122) = %RGB_WHITESMOKE
                                      Palette(123) = %RGB_SEASHELL
                                      Palette(124) = %RGB_BEIGE
                                      Palette(125) = %RGB_OLDLACE
                                      Palette(126) = %RGB_FLORALWHITE
                                      Palette(127) = %RGB_IVORY
                                      Palette(128) = %RGB_ANTIQUEWHITE
                                      Palette(129) = %RGB_LINEN
                                      Palette(130) = %RGB_LAVENDERBLUSH
                                      Palette(131) = %RGB_MISTYROSE
                                      '
                                      ' Gray Colors
                                      Palette(132) = %RGB_GAINSBORO
                                      Palette(133) = %RGB_LIGHTGRAY
                                      Palette(134) = %RGB_SILVER
                                      Palette(135) = %RGB_DARKGRAY
                                      Palette(136) = %RGB_GRAY
                                      Palette(137) = %RGB_DIMGRAY
                                      Palette(138) = %RGB_LIGHTSLATEGRAY
                                      Palette(139) = %RGB_SLATEGRAY
                                      Palette(140) = %RGB_DARKSLATEGRAY
                                      Palette(141) = %RGB_BLACK
                                      
                                      END FUNCTION

                                      Comment


                                      • #20
                                        Not,
                                        Your method is just selecting an item from the palette. There is no comparison to any RGB values to indicate it is an acceptable close match to the current pixel RGB. If that is what Paul wants then go for it Paul.

                                        %RGB_BLACK is &H000000.
                                        So an acceptable replacement to that would be &H000000 up to but not including &H0F0F0F.

                                        %RGB_GRAY is &H808080.
                                        So an acceptable replacement to that would be &H808080 up to but not including &H8F8F8F or down to but not including &H717171.

                                        Comment

                                        Working...
                                        X