marauder Posted June 10, 2005 Share Posted June 10, 2005 (edited) Hi. Just wondering if anyone has any idea on how to get what colors (as values)are in a gif image? Thanks Edited June 10, 2005 by marauder Link to comment Share on other sites More sharing options...
t0ddie Posted June 10, 2005 Share Posted June 10, 2005 (edited) uhmmm.. pixelgetcolor ?? oh yeah, and you can use the autoit info window if you want them all... you will have to search the entire pic.. might take a few seconds. Edited June 10, 2005 by t0ddie Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you. Link to comment Share on other sites More sharing options...
marauder Posted June 10, 2005 Author Share Posted June 10, 2005 Doesn't that only work for what's on the screen? I'm actually looking for something to read in an image file and get the colors. Thanks Link to comment Share on other sites More sharing options...
buzz44 Posted June 10, 2005 Share Posted June 10, 2005 Do you know of any other programs that can do this? qq Link to comment Share on other sites More sharing options...
marauder Posted June 10, 2005 Author Share Posted June 10, 2005 Actually I've just had a good look at ImageMagick again and using the 'identify' cmd with '-verbose' gives the color table of it with the histogram which it seems shows what colors are in there, so I'm going to make a script to get those colors out. Cool! Link to comment Share on other sites More sharing options...
blindwig Posted June 10, 2005 Share Posted June 10, 2005 do a search and find the GIF format, and write a function to read it out of the file. Shouldn't be too hard, I wrote on to do a similiar thing with BMPs ahwile back, using Pascal. My UDF Threads:Pseudo-Hash: Binary Trees, Flat TablesFiles: Filter by Attribute, Tree List, Recursive Find, Recursive Folders Size, exported to XMLArrays: Nested, Pull Common Elements, Display 2dSystem: Expand Environment Strings, List Drives, List USB DrivesMisc: Multi-Layer Progress Bars, Binary FlagsStrings: Find Char(s) in String, Find String in SetOther UDF Threads I Participated:Base64 Conversions Link to comment Share on other sites More sharing options...
blindwig Posted June 10, 2005 Share Posted June 10, 2005 do a search and find the GIF format, and write a function to read it out of the file. Shouldn't be too hard, I wrote on to do a similiar thing with BMPs ahwile back, using Pascal.<{POST_SNAPBACK}>OK, I just found some documents:http://www.dcs.ed.ac.uk/home/mxr/gfx/2d/GIF87a.txthttp://www.dcs.ed.ac.uk/home/mxr/gfx/2d/GIF89a.txtand it looks like this is how it works:read the 5th byte of the file.1) Check the lowest (0) bit. If it's set to 1 then a color palette is included, otherwise not.2) Get bits 1,2,3 and make a number out of them and add one. Raise this number to the power of 2 and this will be the scale for the strength of the color channels.3) Get the highest 3 bits and make a number out of them and add one. Raise this to the power of 2 and you will get the number of colors in the palette.4) Starting at the 8th byte of the file, read 1 byte per channel (RGB=3 bytes) times the number of colors given (step 3) and scale each channel according to the max value as specified in step 2 My UDF Threads:Pseudo-Hash: Binary Trees, Flat TablesFiles: Filter by Attribute, Tree List, Recursive Find, Recursive Folders Size, exported to XMLArrays: Nested, Pull Common Elements, Display 2dSystem: Expand Environment Strings, List Drives, List USB DrivesMisc: Multi-Layer Progress Bars, Binary FlagsStrings: Find Char(s) in String, Find String in SetOther UDF Threads I Participated:Base64 Conversions Link to comment Share on other sites More sharing options...
blindwig Posted June 10, 2005 Share Posted June 10, 2005 ...read the 5th byte of the file....4) Starting at the 8th byte of the file...<{POST_SNAPBACK}>Oops, I forget the GIF header. Add 6 to those byte counts. My UDF Threads:Pseudo-Hash: Binary Trees, Flat TablesFiles: Filter by Attribute, Tree List, Recursive Find, Recursive Folders Size, exported to XMLArrays: Nested, Pull Common Elements, Display 2dSystem: Expand Environment Strings, List Drives, List USB DrivesMisc: Multi-Layer Progress Bars, Binary FlagsStrings: Find Char(s) in String, Find String in SetOther UDF Threads I Participated:Base64 Conversions Link to comment Share on other sites More sharing options...
blindwig Posted June 14, 2005 Share Posted June 14, 2005 OK, in a fit of boredom, I wrote this function:CODEFunc _GifGetHeader($FileName) Dim $hndFile_GIF, $aReturn[10], $OK = -1, $FileSize ;Verify that file exists and is openable IF $OK Then $hndFile_Gif = FileOpen($FileName, 0) If $hndFile_Gif < 0 Then $OK = 0 EndIf ;Verify that file is the minimum size IF $OK Then $FileSize = FileGetSize($FileName) If $FileSize < 13 Then $OK = 0 EndIf ;Verify that file has GIF signature header If $OK Then $Data = FileRead($hndFile_Gif, 3) If not ($Data == 'GIF') Then $OK = 0 EndIf ;Read GIF image descriptor, verify filesize If $OK Then $aReturn[0] = 9 $Data = FileRead($hndFile_Gif, 3) $aReturn[1] = $Data $Data = _FileReadBin($hndFile_Gif, 7) $aReturn[2] = $Data[2] * 256 + $Data[1] ;Width $aReturn[3] = $Data[4] * 256 + $Data[3] ;Height $aReturn[4] = BitShift(BitAND($Data[5], 128), 7) ;Global Color Palette $aReturn[5] = BitShift(BitAND($Data[5], 64 + 32 + 16), 4) + 1 ;bits of color resolution $aReturn[6] = BitShift(BitAND($Data[5], 8), 3) ;Palette is sorted most- to least-used $aReturn[7] = BitShift(BitAND($Data[5], 1 + 2 + 4), 0) + 1 ;bits per pixel $aReturn[8] = $Data[6] ;background color $aReturn[9] = $Data[7] ;marker = #0 If $aReturn[9] <> 0 then $Ok = 0 If $aReturn[4] And $FileSize < 13 + (2 ^ $aReturn[7]) * 3 Then $OK = 0 EndIf ;Read Global Color Palette If $Ok Then $aReturn[0] = 9 + 2 ^ $aReturn[7] Dim $i, $r ,$g, $b ReDim $aReturn[$aReturn[0] + 1] For $i = 1 To 2 ^ $aReturn[7] $Data = _FileReadBin($hndFile_Gif, 3) ;scale the color values up to 255 $r = $Data[1] * 255 / (2 ^ $aReturn[5] -1) $g = $Data[2] * 255 / (2 ^ $aReturn[5] -1) $b = $Data[3] * 255 / (2 ^ $aReturn[5] -1) ;combine and convert to hex $aReturn[$i+9] = Hex(($r*256+$g)*256+$b,6) Next EndIf ;Close file handle FileClose($hndFile_Gif) ;Return gathered data If $OK Then Return $aReturn Else SetError(1) Return '' EndIfEndFuncIt calls my _FileReadBin() function and returns an array:element 0=number of elements returnedelement 1=GIF versionelement 2=widthelement 3=heightelement 4=color table encludedelement 5=color resolutionelement 6=Palette is sorted by color usageelement 7=bits per pixelelement 8=background colorelement 9=reservedelement 10...=color in 0xRRGGBB format My UDF Threads:Pseudo-Hash: Binary Trees, Flat TablesFiles: Filter by Attribute, Tree List, Recursive Find, Recursive Folders Size, exported to XMLArrays: Nested, Pull Common Elements, Display 2dSystem: Expand Environment Strings, List Drives, List USB DrivesMisc: Multi-Layer Progress Bars, Binary FlagsStrings: Find Char(s) in String, Find String in SetOther UDF Threads I Participated:Base64 Conversions Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now