reynolds@dasys1.UUCP (Brian Reynolds) (03/19/89)
Hi. Does anyone out there have a program to convert GIF pictures to Spectrum512 format? GIFSHOW.PRG doesn't do a very good job on pictures with more than 16 colors and I thought Spectrum512 might do better. I don't have ftp access so could someone post sources (and/or binaries) or send me e-mail? I would also be interested in any C sources for reading or writing Spectrum files. I have code for reading and writing GIF files and might write this myself if I can figure out Spectrum format. Thanks in advance. ttfn, Brian =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= -- Brian Reynolds Marine Midland Bank "Home of the world's fastest CROBOTS" Phone: (212) 440-5592 UUCP: ...!sun!gotham!marine!reynolds
greg@bilbo (Greg Wageman) (03/22/89)
In article <9041@dasys1.UUCP> reynolds@dasys1.UUCP (Brian Reynolds) writes: > > Hi. Does anyone out there have a program to convert GIF pictures to >Spectrum512 format? GIFSHOW.PRG doesn't do a very good job on >pictures with more than 16 colors and I thought Spectrum512 might do >better. It certainly does! I recommend you get Unispec, from the authors of Spectrum 512. It should be available from your local Atari software dealer. It is capable of reading GIF files and displaying and saving them as Spectrum pictures. >I would also be interested in any C >sources for reading or writing Spectrum files. I have code for >reading and writing GIF files and might write this myself if I can >figure out Spectrum format. Thanks in advance. This isn't entirely trivial; I have written (uncompressed) Spectrum files. There is a text file available on Compuserve in the Ataripro section, under "Miscellaneous", which describes the format and how it is displayed. (I don't want to violate anyone's copyright by reproducing it here.) Here are some details which aren't explicit in that file. The major technical detail is that the palette is changed on the fly, and your code must know which entries in the Spectrum 48-entry palette are available to a particular pixel in each line. There is a Spectrum palette for each scan line except 0, which is not displayed. Palette entries 0, 16, 32 are normally "black" (000), since they are also the background color, and 15, 31, and 47 are not normally used by the picture (they are used for the menu and mouse pointer in the Spectrum 512 program). The first sixteen entries from the Spectrum palette are loaded into the hardware palette registers at the beginning of each line. Entry 0 in the hardware palette is replaced with entry 16 from the Spectrum palette at pixel 1. Entry 1 is replaced with entry 17 at pixel 5, 2 with 18 at pixel 21, 3 with 19 at pixel 25, 4 with 20 at pixel 41, etc. until hardware palette color 15 is replaced with Spectrum palette entry 47 at pixel 305. So the pixel numbers where changes occur run in the pattern: 1, 5, 21, 25, 41, 45, 61, 65, 81, 85, ..., 301, 305. When you write a Spectrum file, you must keep track of which of the Spectrum palette entries are available to the pixel in question when you go to store its color. This can be done using the formulae given in the file cited above. Call the results "minpal" and "maxpal". Initialize your 48-word Spectrum palette array to a "free entry" value, let's say "-1". Set entries 0, 15, 16, 31, 32 and 47 to zero (black). You will also need a 320-byte array to hold the output pixel values. For each pixel in the source scan line, get the pixel color "P". Scan from minpal to maxpal in your Spectrum palette array, testing each entry against P. If it is equal, just set that pixel's value in the output array to the Spectrum palette slot modulo 16. If the result is 15, change it to zero (to conform to the standard). If it isn't there, look for a free slot in that range. (You can combine the search for the color and the search for first free entry in the same loop, to save having to search twice. First test against P. If it's equal, exit the loop; you have a match and don't need a free entry. Otherwise, test for your "free entry" value. If it isn't, continue the loop. If it is, exit the loop. Since you are adding entries from lowest to highest, the first free entry signifies that there are no more colors to test, and this is the entry you want to use.) If you don't find a match, and there are no free entries left, you can use the closest match already in the palette for that pixel. To find the closest match, subtract the red, green, and blue components of the two colors, take the absolute value of each difference, and sum the three values. Keep the subscript of the lowest result so far in a variable. When you have done this for each color between minpal and maxpal, the lowest result will be the closest match; use that entry for the pixel. At the end of this process, you will have a Spectrum palette and a buffer of pixel values for each scan line. You will still need to convert the pixel values to the Atari screen format. You can either do this in your own code, using bit operations, or use the Line-A "setpixel" function to do it for you. Using "setpixel" is by far easier, but bear in mind that if you display the results you will not get a Spectrum picture on the screen, since you are not running the high-speed palette reloading code that Spectrum requires. Longish .signature follows. Skip now, or don't complain! Greg Wageman DOMAIN: greg@sj.ate.slb.com Schlumberger Technologies UUCP: ...!uunet!sjsca4!greg 1601 Technology Drive BIX: gwage San Jose, CA 95110-1397 CIS: 74016,352 (408) 437-5198 GEnie: G.WAGEMAN ------------------ Opinions expressed herein are solely the responsibility of the author. (And the author wouldn't have it any other way.)