home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR5 / GIFPAS.ZIP / GIFUTIL.PAS < prev   
Pascal/Delphi Source File  |  1993-06-20  |  22KB  |  545 lines

  1. unit GifUtil;
  2. { GifUtl.pas - (c)Copyright 1993 Sean Wenzel
  3.     Users are given the right to use/modify and distribute this source code as
  4.     long as credit is given where due.  I would also ask that anyone who makes
  5.     use of this source/program drop me a line at my CompuServe address of
  6.     71736,1245.  Just curious...
  7.  
  8.     The unit was written using Borland Pascal v7.0 but I think it should work
  9.     with Turbo Pascal down to 5.5 at the most (or least?).
  10.     This unit has only been tested on my system - an Everex Tempo 386DX
  11.     with its built in SVGA adapter.  If anyone finds/fixes any bugs please
  12.     let me know. (Feel free to send a copy of any code too)
  13.     I have also only tested 3 or 4 256,16, and 2 color interlaced and non-
  14.     interlaced images. (was enough for my needs)
  15.  
  16.  
  17.     Some of the code is very loosely based on DECODER.C (availble online)
  18.     so credit should be given to Steven A. Bennett and Steve Wilhite
  19.  
  20.     The unit is set up to use BGI256.BGI (inlcuded) which is available on CIS
  21.     in the BPASCAL forum library.  The graphics initialization tries to start
  22.     up in 640 by 480 mode.  If an error occurs it'll go down to 320x200
  23.     automatically (well - it should).  For higher res modes change the variable
  24.     GraphMode in the InitGraphics procedure to 3 for 800x600 and 4 for 1024x768.
  25.  
  26.     A sample program (GIF.PAS) is provided to demostrate the use of this unit.
  27.     Basically declare a pointer to the TGIF object then initialize it using a
  28.     line such as TheGif := New(PGif, Init('agif'));  You can then check
  29.     TheGif^.Status for any errors and/or view the GIF headers and ColorTables.
  30.     To switch to Graphics mode and show the GIF image use TheGif^.Decode(True)
  31.     True tells it to beep when done(or boop if some sort of error occured).  
  32.     When finished use Dispose(TheGif, Done) to switch back to textmode and get 
  33.     rid of the object.
  34.  
  35.  
  36.     If anyone cares to speed up the image decoding I'd suggest writing
  37.     TGIF.NextCode in assembler.  The routine is the most heavily called in the
  38.     unit while decoding and on my sytem took up about 5 seconds out of 12 when
  39.     I profiled it. (send me a copy if you can)
  40.  
  41.     I have practically commented every line so that the source should be very
  42.     readable and easy to follow.  Great for learning about GIF's and LZW 
  43.     decompression.
  44.  
  45.  
  46.     Any problems or suggestions drop me a line
  47.  
  48.     Good luck...
  49.                             -Sean
  50.  
  51.     (almost forgot)
  52.     "The Graphics Interchange Format(c) is the Copyright property of
  53.      CompuServe Incorporated. GIF(sm) is a Service Mark property of
  54.      CompuServe Incorporated."
  55.  
  56. }
  57.  
  58.  
  59. {$R-}   {       range checking off }  { Put them on if you like but it slows down the}
  60. {$S-} { stack checking off }  { decoding  (almost doubles it!) }
  61. {$I-} { i/o checking off }
  62.  
  63. interface
  64.  
  65. uses Objects;
  66.  
  67. type
  68.     TDataSubBlock = record
  69.         Size: byte;     { size of the block -- 0 to 255 }
  70.         Data: array[1..255] of byte; { the data }
  71.     end;
  72.  
  73. const
  74.     BlockTerminator: byte = 0; { terminates stream of data blocks }
  75.  
  76. type
  77.     THeader = record
  78.         Signature: array[0..2] of char; { contains 'GIF' }
  79.         Version: array[0..2] of char;   { '87a' or '89a' }
  80.     end;
  81.  
  82.     TLogicalScreenDescriptor = record
  83.         ScreenWidth: word;              { logical screen width }
  84.         ScreenHeight: word;  { logical screen height }
  85.         PackedFields: byte;     { packed fields - see below }
  86.         BackGroundColorIndex: byte;     { index to global color table }
  87.         AspectRatio: byte;      { actual ratio = (AspectRatio + 15) / 64 }
  88.     end;
  89.  
  90. const
  91. { logical screen descriptor packed field masks }
  92.     lsdGlobalColorTable = $80;  { set if global color table follows L.S.D. }
  93.     lsdColorResolution = $70;               { Color resolution - 3 bits }
  94.     lsdSort = $08;                                                  { set if global color table is sorted - 1 bit }
  95.     lsdColorTableSize = $07;                { size of global color table - 3 bits }
  96.                                                             { Actual size = 2^value+1    - value is 3 bits }
  97.  
  98. type
  99.     TColorItem = record     { one item a a color table }
  100.         Red: byte;
  101.         Green: byte;
  102.         Blue: byte;
  103.     end;
  104.  
  105.     TColorTable = array[0..255] of TColorItem;      { the color table }
  106.  
  107. const
  108.     ImageSeperator: byte = $2C;
  109.  
  110. type
  111.     TImageDescriptor = record
  112.         Seperator: byte;                         { fixed value of ImageSeperator }
  113.         ImageLeftPos: word; {Column in pixels in respect to left edge of logical screen }
  114.         ImageTopPos: word;{row in pixels in respect to top of logical screen }
  115.         ImageWidth: word;       { width of image in pixels }
  116.         ImageHeight: word;      { height of image in pixels }
  117.         PackedFields: byte; { see below }
  118.     end;
  119. const
  120.     { image descriptor bit masks }
  121.         idLocalColorTable = $80; { set if a local color table follows }
  122.         idInterlaced = $40;                      { set if image is interlaced }
  123.         idSort = $20;                                            { set if color table is sorted }
  124.         idReserved = $0C;                                { reserved - must be set to $00 }
  125.         idColorTableSize = $07;  { size of color table as above }
  126.  
  127.     Trailer: byte = $3B;    { indicates the end of the GIF data stream }
  128.  
  129. { other extension blocks not currently supported by this unit
  130.     - Graphic Control extension
  131.     - Comment extension           I'm not sure what will happen if these blocks
  132.     - Plain text extension        are encountered but it'll be interesting
  133.     - application extension }
  134.  
  135. const
  136.     ExtensionIntroducer: byte = $21;
  137.     MAXSCREENWIDTH = 800;
  138.  
  139. type
  140.     TExtensionBlock = record
  141.         Introducer: byte;                               { fixed value of ExtensionIntroducer }
  142.         ExtensionLabel: byte;
  143.         BlockSize: byte;
  144.     end;
  145.  
  146.     PCodeItem = ^TCodeItem;
  147.     TCodeItem = record
  148.         Code1, Code2: byte;
  149.     end;
  150.  
  151. const
  152.     MAXCODES = 4095;        { the maximum number of different codes 0 inclusive }
  153.  
  154.  
  155.  
  156. type
  157.     { This is the actual gif object }
  158.     PGif = ^TGif;
  159.     TGif = object(TObject)
  160.         Stream: PBufStream;                                                                     { the file stream for the gif file }
  161.         Header: THeader;                                                                                { gif file header }
  162.         LogicalScreen: TLogicalScreenDescriptor;  { gif screen descriptor }
  163.         GlobalColorTable: TColorTable;            { global color table }
  164.         LocalColorTable: TColorTable;             { local color table }
  165.         ImageDescriptor: TImageDescriptor;        { image descriptor }
  166.         UseLocalColors: boolean;                  { true if local colors in use }
  167.         Interlaced: boolean;                                                                                    { true if image is interlaced }
  168.         LZWCodeSize: byte;                                       { minimum size of the LZW codes in bits }
  169.         ImageData: TDataSubBlock;                { variable to store incoming gif data }
  170.         TableSize: word;                                                 { number of entrys in the color table }
  171.         BitsLeft, BytesLeft: integer;{ bits left in byte - bytes left in block }
  172.         BadCodeCount: word;          { bad code counter }
  173.         CurrCodeSize: integer;       { Current size of code in bits }
  174.         ClearCode: integer;          { Clear code value }
  175.         EndingCode: integer;         { ending code value }
  176.         Slot: word;                                     { position that the next new code is to be added }
  177.         TopSlot: word;      { highest slot position for the current code size }
  178.         HighCode: word;     { highest code that does not require decoding }
  179.         NextByte: integer;      { the index to the next byte in the datablock array }
  180.         CurrByte: byte;                 { the current byte }
  181.         DecodeStack: array[0..MAXCODES] of byte; { stack for the decoded codes }
  182.         Prefix: array[0..MAXCODES] of word;                     { array for code prefixes }
  183.         Suffix: array[0..MAXCODES] of byte;             { array for code suffixes }
  184.         LineBuffer: array[0..MAXSCREENWIDTH] of byte; { array for buffer line output }
  185.         CurrentX, CurrentY: integer;                                            { current screen locations }
  186.         Status: word;                                                                                                           { status of the decode }
  187.         InterlacePass: byte;    { interlace pass number }
  188.         constructor Init(AGIFName: string);
  189.         destructor Done; virtual;
  190.         procedure Error(What: integer);
  191.         procedure InitCompressionStream;        { initializes info for decode }
  192.         procedure ReadSubBlock;                          { reads a data subblock from the stream }
  193.         function NextCode: word;                                        { returns the next available code }
  194.         procedure Decode(Beep: boolean);        { the actual LZW decoding routine }
  195.         procedure DrawLine;                     { writes the drawline buffer to screen }
  196.         procedure InitGraphics;                 { Initializes Graphics mode }
  197.     end;
  198.  
  199. const
  200. { error constants }
  201.     geNoError = 0;                          { no errors found }
  202.     geNoFile = 1;         { gif file not found }
  203.     geNotGIF = 2;         { file is not a gif file }
  204.     geNoGlobalColor = 3;  { no Global Color table found }
  205.     geImagePreceded = 4;  { image descriptor preceeded by other unknown data }
  206.     geEmptyBlock = 5;                       { Block has no data }
  207.     geUnExpectedEOF = 6;  { unexpected EOF }
  208.     geBadCodeSize = 7;    { bad code size }
  209.     geBadCode = 8;                          { Bad code was found }
  210.     geBitSizeOverflow = 9; { bit size went beyond 12 bits }
  211.  
  212. implementation
  213.  
  214. uses Graph, Crt;
  215.  
  216. function Power(A, N: real): real;       { returns A raised to the power of N }
  217. begin
  218.     Power := exp(N * ln(A));
  219. end;
  220.  
  221.  
  222. { TGif }
  223. constructor TGif.Init(AGIFName: string);
  224. begin
  225.     inherited Init;
  226.     if Pos('.',AGifName) = 0 then     { if the filename has no extension add one }
  227.         AGifName := AGifName + '.gif';
  228.     Stream := New(PBufStream, Init(AGifName, stOpen, 2048));
  229.     Stream^.Read(Header, sizeof(Header));                                                                                   { read the header }
  230.     if Header.Signature <> 'GIF' then Error(geNotGIF);                              { is vaild signature }
  231.     Stream^.Read(LogicalScreen, sizeof(LogicalScreen));
  232.     if LogicalScreen.PackedFields and lsdGlobalColorTable = lsdGlobalColorTable then
  233.     begin
  234.         TableSize := trunc(Power(2,(LogicalScreen.PackedFields and lsdColorTableSize)+1));
  235.         Stream^.Read(GlobalColorTable, TableSize*sizeof(TColorItem)); { read Global Color Table }
  236.     end
  237.     else
  238.         Error(geNoGlobalColor);
  239.     Stream^.Read(ImageDescriptor, sizeof(ImageDescriptor)); { read image descriptor }
  240.     if ImageDescriptor.Seperator <> ImageSeperator then                     { verify that it is the descriptor }
  241.         Error(geImagePreceded);
  242.     if ImageDescriptor.PackedFields and idLocalColorTable = idLocalColorTable then
  243.     begin                                                                                                                           { if local color table }
  244.         TableSize := trunc(Power(2,(ImageDescriptor.PackedFields and idColorTableSize)+1));
  245.         Stream^.Read(LocalColorTable, TableSize*sizeof(TColorItem)); { read Local Color Table }
  246.         UseLocalColors := True;
  247.     end
  248.     else
  249.         UseLocalColors := false;
  250.     if ImageDescriptor.PackedFields and idInterlaced = idInterlaced then
  251.     begin
  252.         Interlaced := true;
  253.         InterlacePass := 0;
  254.     end;
  255.     if (Stream = nil) or (Stream^.Status <> stOk) then{ check for stream error }
  256.         Error(geNoFile);
  257.     Status := 0;
  258. end;
  259.  
  260. destructor TGif.Done;
  261. begin
  262.     CloseGraph;
  263.     TextMode(LastMode);
  264.     if Stream <> nil then
  265.         Dispose(Stream, Done);
  266.     inherited Done;
  267. end;
  268.  
  269. procedure TGif.Error(What: integer);
  270. begin
  271.     Status := What;
  272. end;
  273.  
  274. procedure TGif.InitCompressionStream;
  275. var
  276.     I: integer;
  277. begin
  278.     InitGraphics;                           { Initialize the graphics display }
  279.     Stream^.Read(LZWCodeSize, sizeof(byte));{ get minimum code size }
  280.     if not (LZWCodeSize in [2..9]) then     { valid code sizes 2-9 bits }
  281.         Error(geBadCodeSize);
  282.  
  283.     CurrCodeSize := succ(LZWCodeSize); { set the initial code size }
  284.     ClearCode := 1 shl LZWCodeSize;    { set the clear code }
  285.     EndingCode := succ(ClearCode);     { set the ending code }
  286.     HighCode := pred(ClearCode);                     { set the highest code not needing decoding }
  287.     BytesLeft := 0;                    { clear other variables }
  288.     BitsLeft := 0;
  289.     CurrentX := 0;
  290.     CurrentY := 0;
  291. end;
  292.  
  293. procedure TGif.ReadSubBlock;
  294. begin
  295.     Stream^.Read(ImageData.Size, sizeof(ImageData.Size)); { get the data block size }
  296.     if ImageData.Size = 0 then Error(geEmptyBlock); { check for empty block }
  297.     Stream^.Read(ImageData.Data, ImageData.Size);   { read in the block }
  298.     NextByte := 1;                                  { reset next byte }
  299.     BytesLeft := ImageData.Size;                                                                            { reset bytes left }
  300. end;
  301.  
  302. const
  303.     CodeMask: array[0..12] of longint = (  { bit masks for use with Next code }
  304.         0,
  305.         $0001, $0003,
  306.         $0007, $000F,
  307.         $001F, $003F,
  308.         $007F, $00FF,
  309.         $01FF, $03FF,
  310.         $07FF, $0FFF);
  311.  
  312. function TGif.NextCode: word; { returns a code of the proper bit size }
  313. var
  314.     Ret: longint;                                                                                                   { temporary return value }
  315. begin
  316.     if BitsLeft = 0 then                                                                            { any bits left in byte ? }
  317.     begin                                   { any bytes left }
  318.         if BytesLeft <= 0 then                                                          { if not get another block }
  319.             ReadSubBlock;
  320.         CurrByte := ImageData.Data[NextByte]; { get a byte }
  321.         inc(NextByte);                        { set the next byte index }
  322.         BitsLeft := 8;                        { set bits left in the byte }
  323.         dec(BytesLeft);                       { decrement the bytes left counter }
  324.     end;
  325.     ret := CurrByte shr (8 - BitsLeft);                     { shift off any previosly used bits}
  326.     while CurrCodeSize > BitsLeft do        { need more bits ? }
  327.     begin
  328.         if BytesLeft <= 0 then                                                          { any bytes left in block ? }
  329.             ReadSubBlock;                       { if not read in another block }
  330.         CurrByte := ImageData.Data[NextByte]; { get another byte }
  331.         inc(NextByte);                        { increment NextByte counter }
  332.         ret := ret or (CurrByte shl BitsLeft);{ add the remaining bits to the return value }
  333.         BitsLeft := BitsLeft + 8;                                               { set bit counter }
  334.         dec(BytesLeft);                     { decrement bytesleft counter }
  335.     end;
  336.     BitsLeft := BitsLeft - CurrCodeSize;  { subtract the code size from bitsleft }
  337.     ret := ret and CodeMask[CurrCodeSize];{ mask off the right number of bits }
  338.     NextCode := ret;
  339. end;
  340.  
  341. { this procedure initializes the graphics mode and actually decodes the
  342.     GIF image }
  343. procedure TGif.Decode(Beep: boolean);
  344. var
  345.     SP: integer; { index to the decode stack }
  346.  
  347. { local procedure that decodes a code and puts it on the decode stack }
  348. procedure DecodeCode(var Code: word);
  349. begin
  350.     while Code > HighCode do { rip thru the prefix list placing suffixes }
  351.     begin                    { onto the decode stack }
  352.         DecodeStack[SP] := Suffix[Code]; { put the suffix on the decode stack }
  353.         inc(SP);                         { increment decode stack index }
  354.         Code := Prefix[Code];            { get the new prefix }
  355.     end;
  356.     DecodeStack[SP] := Code;        { put the last code onto the decode stack }
  357.     inc(SP);                                                                        { increment the decode stack index }
  358. end;
  359.  
  360. var
  361.     TempOldCode, OldCode: word;
  362.     BufCnt: word;           { line buffer counter }
  363.     Code, C: word;
  364.     CurrBuf: word;  { line buffer index }
  365. begin
  366.     InitGraphics;                                                   { Initialize the graphics mode and RGB palette }
  367.     InitCompressionStream;    { Initialize decoding paramaters }
  368.     OldCode := 0;
  369.     SP := 0;
  370.     BufCnt := ImageDescriptor.ImageWidth; { set the Image Width }
  371.     CurrBuf := 0;
  372.  
  373.     C := NextCode;                                          { get the initial code - should be a clear code }
  374.     while C <> EndingCode do  { main loop until ending code is found }
  375.     begin
  376.         if C = ClearCode then   { code is a clear code - so clear }
  377.         begin
  378.             CurrCodeSize := LZWCodeSize + 1;{ reset the code size }
  379.             Slot := EndingCode + 1;                                 { set slot for next new code }
  380.             TopSlot := 1 shl CurrCodeSize;  { set max slot number }
  381.             while C = ClearCode do
  382.                 C := NextCode;                  { read until all clear codes gone - shouldn't happen }
  383.             if C = EndingCode then
  384.             begin
  385.                 Error(geBadCode);   { ending code after a clear code }
  386.                 break;                                                  { this also should never happen }
  387.             end;
  388.             if C >= Slot { if the code is beyond preset codes then set to zero }
  389.                 then c := 0;
  390.             OldCode := C;
  391.             DecodeStack[sp] := C;                                   { output code to decoded stack }
  392.             inc(SP);                                                                                        { increment decode stack index }
  393.         end
  394.         else   { the code is not a clear code or an ending code so it must }
  395.         begin  { be a code code - so decode the code }
  396.             Code := C;
  397.             if Code < Slot then     { is the code in the table? }
  398.             begin
  399.                 DecodeCode(Code);                                       { decode the code }
  400.                 if Slot <= TopSlot then
  401.                 begin                                                                                           { add the new code to the table }
  402.                     Suffix[Slot] := Code;                   { make the suffix }
  403.                     PreFix[slot] := OldCode;        { the previous code - a link to the data }
  404.                     inc(Slot);                                                              { increment slot number }
  405.                     OldCode := C;                                                   { set oldcode }
  406.                 end;
  407.                 if Slot >= TopSlot then { have reached the top slot for bit size }
  408.                 begin                   { increment code bit size }
  409.                     if CurrCodeSize < 12 then { new bit size not too big? }
  410.                     begin
  411.                         TopSlot := TopSlot shl 1;       { new top slot }
  412.                         inc(CurrCodeSize)                                       { new code size }
  413.                     end
  414.                     else
  415.                         Error(geBitSizeOverflow); { encoder made a boo boo }
  416.                 end;
  417.             end
  418.             else
  419.             begin           { the code is not in the table }
  420.                 if Code <> Slot then                    { code is not the next available slot }
  421.                     Error(geBadCode);  { so error out }
  422.  
  423.                 { the code does not exist so make a new entry in the code table
  424.                  and then translate the new code }
  425.                 TempOldCode := OldCode;  { make a copy of the old code }
  426.                 while OldCode > HighCode do { translate the old code and place it }
  427.                 begin                                   { on the decode stack }
  428.                     DecodeStack[SP] := Suffix[OldCode]; { do the suffix }
  429.                     OldCode := Prefix[OldCode];         { get next prefix }
  430.                 end;
  431.                 DecodeStack[SP] := OldCode;     { put the code onto the decode stack }
  432.                                                                         { but DO NOT increment stack index }
  433.                 { the decode stack is not incremented because because we are only
  434.                     translating the oldcode to get the first character }
  435.                 if Slot <= TopSlot then
  436.                 begin                 { make new code entry }
  437.                     Suffix[Slot] := OldCode;                 { first char of old code }
  438.                     Prefix[Slot] := TempOldCode; { link to the old code prefix }
  439.                     inc(Slot);                   { increment slot }
  440.                 end;
  441.                 if Slot >= TopSlot then { slot is too big }
  442.                 begin                   { increment code size }
  443.                     if CurrCodeSize < 12 then
  444.                     begin
  445.                         TopSlot := TopSlot shl 1;       { new top slot }
  446.                         inc(CurrCodeSize)                                       { new code size }
  447.                     end
  448.                     else
  449.                         Error(geBitSizeOverFlow);
  450.                 end;
  451.                 DecodeCode(Code); { now that the table entry exists decode it }
  452.                 OldCode := C;     { set the new old code }
  453.             end;
  454.         end;
  455.         { the decoded string is on the decode stack so pop it off and put it
  456.          into the line buffer }
  457.         while SP > 0 do
  458.         begin
  459.             dec(SP);
  460.             LineBuffer[CurrBuf] := DecodeStack[SP];
  461.             inc(CurrBuf);
  462.             dec(BufCnt);
  463.             if BufCnt = 0 then  { is the line full ? }
  464.             begin
  465.                 DrawLine;
  466.                 CurrBuf := 0;
  467.                 BufCnt := ImageDescriptor.ImageWidth;
  468.             end;
  469.         end;
  470.     C := NextCode;  { get the next code and go at is some more }
  471.     end;            { now that wasn't all that bad was it? }
  472.     if Beep then
  473.         if Status = 0 then
  474.         begin
  475.             Sound(660);     { Beep if status is ok }
  476.             Delay(50);
  477.             NoSound;
  478.         end
  479.         else
  480.         begin
  481.             Sound(110); { Boop if status is not ok }
  482.             Delay(200);
  483.             NoSound;
  484.         end;
  485. end;
  486.  
  487. procedure TGif.DrawLine;
  488. var
  489.     I: integer;
  490. begin
  491.     for I := 0 to ImageDescriptor.ImageWidth do
  492.         PutPixel(I, CurrentY, LineBuffer[I]);
  493.     inc(CurrentY);
  494.  
  495.     if InterLaced then     { Interlace support }
  496.     begin
  497.         case InterlacePass of
  498.             0: CurrentY := CurrentY + 7;
  499.             1: CurrentY := CurrentY + 7;
  500.             2: CurrentY := CurrentY + 3;
  501.             3: CurrentY := CurrentY + 1;
  502.         end;
  503.         if CurrentY >= ImageDescriptor.ImageHeight then
  504.         begin
  505.             inc(InterLacePass);
  506.             case InterLacePass of
  507.                 1: CurrentY := 4;
  508.                 2: CurrentY := 2;
  509.                 3: CurrentY := 1;
  510.             end;
  511.         end;
  512.     end;
  513. end;
  514.  
  515. procedure TGif.InitGraphics;
  516. var
  517.     GraphDriver: integer;
  518.     GraphMode: integer;
  519.     ErrorCode: integer;
  520.     I: integer;
  521. begin
  522.     GraphDriver := InstallUserDriver('bgi256', nil);
  523.     GraphMode := 2;
  524.     InitGraph(GraphDriver, GraphMode, '\dealer\bin');
  525.     ErrorCode := GraphResult;
  526.     if ErrorCode <> grOk then
  527.     begin
  528.         Writeln('Graphics Error: ', GraphErrorMsg(ErrorCode));
  529.         Halt(99);
  530.     end;
  531.  
  532.     { the following loop sets up the RGB palette }
  533.     if not UseLocalColors then
  534.         for I := 0 to TableSize - 1 do
  535.             SetRGBPalette(I, GlobalColorTable[I].Red div 4, GlobalColorTable[i].Green
  536.                 div 4, GlobalColorTable[I].Blue div 4)
  537.     else
  538.         for I := 0 to TableSize - 1 do
  539.             SetRGBPalette(I, LocalColorTable[I].Red div 4, LocalColorTable[i].Green
  540.                 div 4, LocalColorTable[I].Blue div 4);
  541. end;
  542.  
  543.  
  544. end.
  545.