home *** CD-ROM | disk | FTP | other *** search
-
-
- I was exploring BBS's one day and came across one for IBM's that
- had several digitized images in GIF format. Out of curiousity, I
- downloaded a couple and tried to display them using 'giffy'.
- Nothing coherent. Still curious I put together a quick program to
- decode GIF(which uses a form LZW compression-interesting in
- itself) and saved the pictures in a more simpler format. When I
- make reference to TMP files in this doc, I'm referring to this
- format, which is as follows:
-
-
- struct TMPFILE
- {
- SHORT ImageWidth,ImageHeight,NoOfColorRegisters;
- Struct COLORREGISTER ColorRegisters[NoOfColorRegisters];
- UBYTE Image[ImageHeight][ImageWidth];
- }
-
- where struct COLORREGISTER is
-
- struct COLORREGISTER
- {
- UBYTE red;
- UBYTE green;
- UBYTE blue;
- }
- ** Note that the picture is Image[y][x] not Image[x][y] **
-
-
- The Image array indexes into the ColorRegisters array, which hold
- the actual color values. For example-The red component of a pixel
- (x,y) is given by the value of ColorRegisters[Image[y][x]].red.
- A value of 255 is all the way on. A value of 0 is all the way
- off. Since the Amiga can only display 4 bits per color component
- the following equation should be used:
-
- temp=ColorRegisters[Image[y][x]].red
- RedComponent = (tmp>>4)&0x0f;
-
- And'ing the value with 0x0f probably isn't necessary but helps
- conceptually.
-
-
- If the Image is Interlaced, GIFtoTMP will use exit(5) upon
- completion in addition to a written message. This allows you to
- check for this condition in a CLI script file. See the file
- 'convert' for an example. The file Unlace can then be used to
- un-interlace the image.
-
-
- The last program, TMPtoIFF, is the heart of this series. When
- converting the TMP file into an Amiga IFF file, the number of
- color registers must be reduced (usually from 256). TMPtoIFF
- currently offers three algorithms to do this:
-
- Popularity-Merely chooses the top most used colors
-
- Median Cut-Thinks of the colors as points in three dimensional
- space (Red,Green+Blue) and draws a box that
- encloses all points. The program then divides that
- box into two boxes with an equal number of colors in
- each side. (A pure white screen would only have one
- color-even though it is used in thousands of pixels)
- The boxes are continuously divided along their
- longest axis until there are as many boxes as the
- number of colors that you want. Then the colors in
- each box are averaged and those values are used in
- the final color map.
-
- Weighted Median Cut-I modified the above algorithm so that as
- it's dividing each box along its longest axis, it
- tries to put an equal number of pixels in each side
- (which of course is impossible to do exactly)
- This produces averaged colors closer to the majority
- colors, but also provides the variety that the
- Median Cut does
-
- After one of the above algorithms is run, each pixel in the
- original image is replaced with the closest value in the final
- color map. If a HAM image is requested, the program uses one of
- the above algorithms to produce the color register values. This
- works very well in practice.
-
-
- Summary of Files:
-
- GIFtoTMP Converts GIF files into TMP files
-
- Unlace Will unlace a TMP file. Use only if
- GIFtoTMP indicates it as such
-
- TMPtoIFF Converts TMP files into IFF files
-
- convert the CLI file I use to convert the images
- usage as such:
-
- convert giffilepath giffilename [options for TMPtoIFF]
-
-
- The usage of each file (except convert) can be found be typing
- the name of each file and pressing return.
-
- I've only tried this progam on 320x200 and 320x240 images. If you
- try larger images, like 640x400 make sure you have a lot of
- memory. Although I wrote this program specifically for converting
- IBM GIF images to Amiga IFF images, it will hopefully work on
- most GIF files. Let me know if you have any problems. One that I
- already know of is if you specify a final image of 5 bit
- planes(32 colors) and the original GIF image has less than 32
- colors.
-
-
- Mark Podlipec
- 111-4 BroadMeadow Rd
- Marlboro MA 01752
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-