PrismPlus version 1.2 Enhancements and Changes Prism version 1.2 (now called Prism Plus) contains the following major enhancements. Your Prism distribution disk contains two versions of Prism. The program called Prism is identical to the original version, and can be used in any Amiga with at least 512K memory. The program called PrismPlus is the new enhanced update of Prism, and REQUIRES AT LEAST 1MB OF RAM MEMORY. The following enhancements apply ONLY to the PrismPlus program. When PrismPlus is started either from the Amiga Workbench, or CLI, an requester will come up first allowing you to choose both the screen sizd, and picture size you would like to work with allowing you to produce pictures larger than your screen, or work in OverScan mode. If you choose a picture size larger than your screen size, you can use the arrow keys to scroll around the picture in the same manner as Dpaint II. Prism ALWAYS starts you in the exact center of your picture regardless of the size chosen from the parameters requester. SPECIAL NOTE!! HAM pictures take quite a lot of memory, so keep in mind your particular memory limitations when deciding how large a picture you want to make. A 1024x1024 Interlaced Hi-Res HAM picture requires 3.6MB of RAM!!! Files saved under the ILBM (IFF) format can now be used by any other program or viewer which uses standard IFF formats. (i.e. Showall, Digi-View, etc.). PrismPlus now supports IFF brushes in either HAM or standard mode. (brushes may be used from Dpaint, Images, Digi-Paint etc.). You will notice a new type of IFF format in the file requesters called "RGBN"/ This new IFF format is a special type of file which integrates with our new Ray-Tracing Animation program called "Silver", due to be released in mid-September. PrismPlus also now contains some very sophisticated "heuristic" routines to determine the best color fit for your current picture, eliminating the dreaded "HAM JAGGIES". Once the "best fit" has been determined, a 16 color palette is established. This new palette option is displayed on the right side of the 4096 color palette. Additionall, PrismPlus will attemtp to clean uyour image in "real-time" as you paint. REMEMBER that the more colors you add to your picture beyond the initial palette PrismPlus has created, the more HAM jaggies that could appear. To remedy this situation you can always use the create palette option to have PrismPlus create a new palette and again clean the jaggies. PrismPlus also now supports Genlock. With the "Genlock" option selected from the color menu, you may select ANY pen color as your color zero, or genlock color. Any area painted with this pen color will be transparent to the Genlock device. If you are going to the overscan option with PrismPlus, YOU MUST replace your "system-configuration" file with the file on the disk called "Overscan-configuration". To do this, delete the file called "system-configuration" in the "devs" subdirectory, rename the Overscan-configuration to "system-configuration" and copy it to the devs subdirectory and re-boot your Amiga. (You may need to fine turn the horizontal adjustment of your particular monitor to get the best picture. The new menu items are as follows: The "RESET" option allows you to leave the current Prism window and select another screen and/or resolution size. (Remember to save your work, as using the "RESET" option eliminates the current picture from memory). The "SCALING" option allows you to load picutres and brushes from various resolutions and Prism will automatically re-fit the correct aspect ratio of the picture or brush. ------------------------------------------------------------------------------- TABLE OF CONTENTS Introduction 2 Getting Started 4 Prism Tools (gadgets & requesters) 5 General Commands 6 Prism Keyboard Equivelants 11 Unique Operations (copy, grab, flood & fonts) 13 Technical Reference 16 Warranty & Support 24 ------------------------------------------------------------------------------- IF YOU DON'T READ MANUALS.... It's OK (sort of). Assuming you already know how to operate your Amiga Computer, and one of the paint programs available like, Deluxe Paint, Images, or Graphicraft, you will have very little trouble in working with Prism. This User guides, is arranged to get you going quickly. Why do you need another paint program? With fine programs like Deluxe Paint and Images available, is there really a need for just another paint program? The answer is absolutely YES!, because Prism is not just another paint program. Unlike other paint programs, Prism does not restrict you to the standard 32 color palette. Prism allows you to use the entire 4,096 color palette available on the Amiga at one time, in one picture, using the HAM (Hold and Modify) color mode. Using Prism, you can now enhance your Digitized pictures, or add an additional 4,096 colors to your current masterpieces. Prism will allow you to cut areas from one picture and add them to another, or add text. Prism can also use 16 color fonts created by the Calligrapher without the hassle of having to run another program first. With Prism you can now un-leash the Creative Power of your Amiga. What is HAM? In most cases, the maximum number of bit planes that an Amiga screen can use is five, however in HAM mode, six bit planes can be used. Since high-resolution screens cannot use more than four bit planes, the HAM mode is confined to the 320 x 200, and 320 x 400 interlaced mode. Normally, the maximum number of colors that you can display onscreen at one time is 32, since there are only 32 hardware color registers for your use. The HAM mode, allows you to bypass this limitation and display all 4096 colors the Amiga is capable of onscreen at once. This is achieved by the way the pen number of each dot on the screen display is interpreted. When the HAm mode is active, the highest two bits of the pen number control how the lower four bits of that number are interpreted. When the top two bits are both zeros, the lower four bits are interpreted as a pen number from 0 to 15, as normal. When one or more of these top two bits are set to one, however the interpretation is very different. In that case, determining the color of the pizel is a two-part process. Page 2 ------------------------------------------------------------------------------- First you begin by making the color of the pixel the same as that of the next pixel to the left. Then, you modify one of the three color components of the pixel (red, blue, or green) by changing it to the value of the lower four bits of the pen value. Which color component is changed depends on the value in the high-order two bits. If those bits are set to 01, the blue component is modified. If they are set to 10, the red bits of the pixel to the left are replaced. And if they are set to 11, the green component is the one that is changed. This, then is the basic explanation of Hold and Modify. Your color selection is extended from the normal 32 colors by allowing you to copy (HOLD) two of the three color values used by the preceding pixel and to change (MODIFY) the other value to the new value specified by the lower four bits of the pen number. Although HAM mode allows you to display a lot of colors at once, remember that you have limited control over the color selection of any one pixel. Since you can change only one color value per pixel, to change colors entirely takes three pixels. Another limitation of HAM, is that when you use a number of pixels in a row, the color of each succeeding pixel depends on that of the pixel to the left. Changing the color value of the first pixel in that row could change all of the pixels that appear to it's right. Because of these limitations, the HAM mode is a little more difficult to use in freehand drawing. On the other hand, the extended color resolution that HAM affords can be used quite successfully in applications such as digitizing color video Images. If you find that you are having problems with colors shifting on the right side of the areas you are drawing or editing, try using a shade of the color you want slightly higher or lower in value. We hav also found that the color shifts in HAM when a perpendicular line is reached. Page 3 ------------------------------------------------------------------------------- GETTING STARTED This manual assumes you already know how to operate your Amiga computer. If not, please read your "Introduction to Amiga" manual which came with your computer. Menu selections, are chosen in the standard Intuition format by using the "right" mouse button to select the menu item from the title bar, and releasing the mouse button when the correct choice is reached. Start your Amiga using Kickstart version 1.2 (or later). When the "Insert Workbench" message appears on the monitor screen, insert your Prism program disk. When the workbench appears on your monitor, double click the Prism program icon to start the program. (Note: If you have an Amiga with 512K, you may want to run teh program fron the CLI, allowing you a little more free memory.) HARDWARE REQUIREMENTS Prism requires a minimum of 512K memory. Extended memory beyond 512K, sometimes called "fastram", greatly enhances the speed and ease of use of Prism. An external Disk Drive or Hard Drive is recommended for data storage, though you may use Prism on an Amiga with only an internal Drive. MAKING BACKUPS As Prism is designed to be used under Amiga's multi-tasking environment, it is not copy-protected. You may use any of the standard disk-copy methods described in your "Introduction to Amiga" manual to duplicate the Prism program disk. In fact, we urge you to make a Backup copy of the Prism program disk, and store the original program disk in a safe place, as future upgrades to Prism will require you to return your original Prism program disk to us. Page 4 ------------------------------------------------------------------------------- PRISM TOOLS -------- !Tools ! Tools On/Off -------- !000000! !OOOOOO! Built in Brushes !oooooo! !......! -------- !::::::! 4096 Color Palette -------- Undo Last Action ! Undo ! ------- Dotted Freehand Drawing !S ! S ! Continuous Freehand Drawing -------- Straight Line !/ ! ) ! Curve -------- Ploygon !/\!/\ ! Hollow/Filled Rectangle ! !\/ ! -------- Hollow/Filled Circle !O !() ! Hollow/Filled Elipse -------- Spray Gun !:=! Q ! Flood Fill -------- Magnify !0 ! T ! Text !| ! ! -------- !Clear ! Clear Screen -------- PRISM TOOLS MENU !---------------! ! Diamond ! ! Emerald ! ! Garnet ! !---------------! ! ^ 17 Size ! ! ^ 1 Zoom ! ! \/ Normal ! ! Underline ! ! Bold ! ! Italic ! !---------------! ! List Fonts ! ! OK Cancel ! ----------------- PRISM FONT LISTER PRISM 4096 COLOR PALETTE (see palette.pic) Page 5 ------------------------------------------------------------------------------- PROJECT MENU NEW - Clears the Screen of all Images OPEN - Retrieves a previous saved Prism RGB4 file, or any standard IFF image file. SAVE AS - Saves Prism files to disk. Save as: RGB4 - Saves file in unique Prism format. Save as: ILBM - Saves file in standard IFF/HAM format PRINT - Prints the current Picture file displayed on the screen, using the printer selected in the "Preferences" menu. To print Cyan, Magenta & Yellow color separations, select the "Red", "Green" & "Blue" options from the "Display" menu and print 1 copy of each. QUIT - Quits the program, and returns to the Amiga workbench, or CLI. REGION MENU Control NEW - Allows ut and grab functions on a new region without affecting operations performed on a previous region. RESTORE - Will restore the current picture file to it's original form eliminating all changes, providing the "LOCK" function has been activated. KEEP - Keeps changes made to the current selected region, allowing further non destructive changes to be made to the region. SWAP - Swaps the information in the currently selected region with information in the buffer area. FLOOD - Floods the currently selected region with the current pen color, or used with the "ADD COLOR" option, to globally change one color to another. NOT REGION - Used twice to de-select one part of a region, when more than one object is to be selected for a copy or grab operation. Makes the new region everything that is not part of the current region in conjunction with the fill operations. ADD FILL - Used when selecting more than one area to copy or grab. Discards the outline after the fill. FILL ONLY - Used when only selecting one area to copy or grab. Page 7 ------------------------------------------------------------------------------- FILL OFF - Used to da-activate the "Fill Only " or "Add Fill" functions, when defining regions. LOCK - Fixes thge current picture in memory allowing the file to be restored, to original format, if the changes made to the files is not desired. COPY - Allows the currently filled region(s) to be lifted from the current picture file and be pasted on another area of the picture on on another picture. (similar to a brush, but you cannot paint with it). GRAB - Similar to Copy, except that a "Hole" is created where the region is lifted, and the hole is filled by the new area the brush is placed on. FLAGS BORDER - Eliminated all but the outline of the currently selected region during a COPY or GRAB operation to allow better visual positioning of the brush (May be used with INVERSE). INVERSE - Creates a "negative" Image of the currently selected region during a COPY or GRAB operation to allow better visual positioning of the brush. (May be used with BORDER). Page 8 ------------------------------------------------------------------------------- HORIZ FLIP - Flips the currently selected region (brush) left to right. (The entire screen may also be flipped if it has been selected as the current region). VERT FLIP - The same as HORIZ FLIP, but the image is flipped top to bottom. BRUSH MENU PAINT - Selects normal mode for painting or drawing. ERASER - Allows erasure of painted, or drawn areas. (DOES NOT ERASE ANYTHING ONCE IT HAS BEEN SAVED!) INVERSE - Paints or draws in Inverse (negative) mode. UNDO LAST - Undoes last function prior to mouse click. SET COLOR - Invokes the 4096 color palette. PICK COLOR - Allows current pen color to be picked directly from screen without invoking the Color palette. Page 9 ------------------------------------------------------------------------------- SET FONT - Invokes the Font menu for choosing Fonts for text mode. SCREEN MENU DRAG BAR - Hides or displays the Drag (Title Bar). GADGETS - Hides or Displays the Gadget (Tools) menu. DISPLAY MENU RED ONLY - Only the Red layer of the current picture is displayed. GREEN ONLY - Only the Green Layer of the current Picture file is displayed. BLUE ONLY - Only the Blue Layer of the current picture file is displayed. Page 10 ------------------------------------------------------------------------------- PRISM KEYBOARD EQUIVELANTS Function Keys: F1 - Add Fill and Copy F2 - Add Fill and Grab F3 - Select Paint Brush F4 - Select Eraser Brush F5 - Select Inverse Brush F6 - Region Lock On/Off F7 - Cycle Crosshairs: type 1, type 2, none... F8 - Brush On/Off F9 - Drag/Title Bar On/Off F10 - Tools/Gadgets On/Off Cursor Keys: UN-SHIFTED - Scroll in Zoom mode SHIFTED UP/DOWN - Zoom In/Out SHIFTED LEFT/RIGHT - Scroll in Zoom Mode Fast ALT'ED - Position Regions/Text Normal Keys: 0-9 - Select round or square brushes B - Change Border Color to Current Pen Color c - Unfilled Circle C - Filled circle d - Continuous Freehand Tool D - Continuous Freehand Tool with 1 Pixel Brush e - Unfilled Elipse E - Filled Elipse f - Flood Filled Tool K - Clear Screen l - Connected Line Tool L - Connected Line Tool with 1 Pixel Brush Page 11 ------------------------------------------------------------------------------- m - Pick Zoom Center n - New Region p - Color Palette q - Curve Tool Q - Curve Tool with 1 Pixel Brush r - Unfilled rectangle R - Filled Rectangle s - Dotted Freehand Tool S - Spray Gun Tool t - Text Requester (same as "T" when in Text Mode) T - Set Text Font u - Undo v - Straight Line Tool V - Straight Line Tool x - Horizontal Flip Region/Brush X - Horizontal Flip Screen y - Vertical Flip Region/Screen Y - Vertical Flip Screen z - Zoom On/Off + - Cycle to Larger Brush Tool (shifted or unshifted '=') - - Cycle to Samller Brush Tool > - Zoom In < - Zoom Out , - Pick Color from Screen . - Dotted Freehand Tool with 1 Pixel Brush space-bar - Aborts Current Command RIGHT AMIGA KEYS: b - 4096 Color palette c - Copy Region/Brush d - Drag/Title Bar On/Off e - Eraser Brush f - Floot Fill Region g - Grab Region/Brush i - Inverse Brush k - Keep Region l - Lock Region On/Off n - New Region p - Paint Brush o - Gadgets/Tools On/Off Page 12 ------------------------------------------------------------------------------- r - Restore Picture s - Swap Region t - Set Text Font u - Undo Last Command , - Pick Color from Screen UNIQUE OPERATIONS As you have seen so far, Prism is very easy to use. There are however, some unique, and very powerful functions designed into Prism, which need a little explanation. USING TEXT & FONTS You may have noticed that with other programs, there is a limited amount of different fonts that can be chosen from the font menu at any one time. With the advent of lower cost hard drives, superb font prograns like the Calligrapher, and lower cost memory, dealing with a larger number of fonts has been a problem. We have designed a special file requester to only handle fonts. This special text requester like Prism's unique file requester, will handle an unlimited amount of files. When you initially ask for the font menu, the font file requester will appear on the left side of the screen. In order to conserve memory, the only initial font listed is the system "Topaz" font. To see the total list of fonts available in your system "Click" the "List Fonts" button on the file requester. Once the list of fonts is loaded into memory, "Click" on either purple bar to cycle forward or backward in the font list. When the font you would like to use appears in the black area, "Click" the "OK" button and the desired font will be loaded. (Note: Only the font directory list remains in memory, and each different font will be loaded into memory as it is needed). 4096 COLOR PALETTE The Prism color palette is divided into 4 areas. The 6 multi-color squares in the middle of the palette, are the main or coarse color selection areas. By holding down the "LEFT" mouse button, and moving the mouse around in any one of the color squares, you can see the various shades of color, and how they relate to each other. The 3 gradient bars at the top of the palette labeled "R", "G", & "B" are the "fine" color adjustments. Once you have picked a general color from the color squares, the gradient bars will allow you to see and pick any of the shades available for that particular color. On the right side of the color palette, next to the 6 color squares, directly beneath the "OK" button, is the"Last colors used" area. Each time another is selected and drawn with, a paint chip of that color is stacked in the middle area. On either side of the "Last Used" area is the current selected pen color, you can select any of the last used chips instead of selecting from the color bars, making it easier to use the same color a number of times. (Remember that you can also pick a color directly from your picture using the Page 13 ------------------------------------------------------------------------------- "Pick Color" option or by using the equivelant keystroke). Once you picked the desired color, simply "Click" the "OK" button at the top right corner of the palette. COPY, GRAB, & LOCK The most powerful features of Prism are contained in the 'REGION' menu. The 'COPY' function is similar to creating a brush, except that you can't paint with it, but you can place it anywhere you like on the picture youare working on, or you can open another picture and place the brush on it. To create a single brush, turn the "LOCK" on. By activating the "LOCK" function, you will always be able to restore your picture in case you make a mistake. Use one of the drawing tools, like circle, rectangle, or the continuous freehand tool to define the area you want to copy, making sure that the area is totally enclosed. Press the F1 key. The cursor will display the word "PICK". You can then pick which region you want for your brush, indside the area you defined, or outside the area you defined. Once the mouse is clicked, the area will be lifted, and you can then place it where you want. Selecting a different drawing tool or pressing the space bar, will de-activate the copy mode. To make a multiple area brush, first lock and define your areas as described above. Instead of pressing the F1 key, select "ADD FILL" from the "MODIFY" menu. This time when the "PICK" cursor appears, click the mouse in each area that you want to include in your brush. When all the areas are filled, select "FILL OFF" from the "MODIFY" menu, and select "COPY" or use the key equivelant. If you decide taht you have too many regions selected, use the "NOT REGION" function to de-select any number of regions before you do your copy. IMPORTANT!! Prism remembers everything! Once you have finished a COPY or GRAB function remember to select "NEW" from the control menu to tell Prism that you have finished with one region and are ready to begin working on another region. The procedure for doing a "GRAB" is the same as doing a "COPY", except that the grab option, creates a "hole" in the area where the region was selected. This function can be very useful, when moving parts of one picture to another. To perform a grab, define the area you want to replace in the sam way as doing a copy, a good example would be having a picture of an Amiga on your screen. Open another picture, for example a digitized image of a person's face. Place the grabbed area over the lips. (Using the "BORDER" and "INVERSE" functions, will make it much easier for you to position your grab.) and click the mouse button. Your original picture will return with the grabbed lips on the monitor screen! GLOBAL COLOR CHANGES There is at times a need to change one entire color to another. This can be especially difficult when working with digitized images, as so many different colors are "dithered" together. Page 14 ------------------------------------------------------------------------------- Prism's "ADD COLOR" option makes this process a simple one. First select the color you want to change by picking it directly from the screen using the "PICK COLOR" option or it's keystroke equivelant (works with New Region also). Then choose the "ADD COLOR" option from the "MODIFY" menu. The third step is to choose the new color you want to use, by either picking it from the palette, or by picking it from the screen. The last step is to choose the "FLOOD" option from the "MODIFY" menu. This will change the first color to the second, in the entire picture. COLOR SEPARATIONS For those users who may want their masterpieces printed by commercial means, we have provided you with a means to make TRUE cyan, magenta & yellow color separations. Before printing, select the Red, Blue, & Green layers individually from the Display menu. Selecting the Red layer will print Cyan. Selecting the Blue layer will print Magenta. Selecting the Green layer will print Yellow. If you have a color printer, you might want to make three color transparencies, one of each color. When registered and put together you will have a full color slide! Page 15 ------------------------------------------------------------------------------- TECHNICAL INFORMATION The following section is provided for those users, who may be interested in Prism's memory management functions, and the way RGB4 files are constructed. MEMORY MANAGEMENT The following section explains the memory management techniques used by Prism in order to maintain maximum speed of operation. Memory 96K - Picture (12 bit planes) - Low Resolution 96K - Undo Buffer (12 bit planes) 48K - Screen (6 bit planes) - HAM 56K - Misc. (7 bit planes) 65K - Code 4K - Stack ------------- 365K total The above figure is exclusive of memory required for intuition messages, fonts, menu/screen swap area, filenames, and I/O. Each processed PRISM picture is in a 96K in a proprietary format. The 96K is computed using the following formula. 3 colors*4 planes/color*8K/plane The 96K pictures can hold more information than the HAM screen is capable of displaying. "PRISM" shows it's best representation of the 96K picture on the HAM screen. Menu options allow you to see the Red, Green, and Blue parts of the picture separately, with no loss at all in quality. When the user paints on the screen, the changes are first made in the 96K image, and then the changes for the HAM screen are calculated and displayed. Most of the slowness in PRISM is in calculatying the changes to the HAM screen (about 4 seconds for the entire screen). The only other slowness the user should notice is in compressing and expanding the 96K files during I/O. The 96K internal representation of each picture makes it possible to flood fill the same region over and over again, in different colors, for example, and never lose the original shape in converting the picture to the HAM display. Page 16 ------------------------------------------------------------------------------- In addition to the two 96K areas (picture and undo), you should be aware of the undo mask and the region mask. The undo mask holds the shape of the area that can be undone (usually the pattern of the last brush stroke, but can be different, i.e. after opening a new picture, or after clearing the screen). The region mask holds the shape of the area that can be affected by the various region commands,(copy, grab, flood, restore, etc.). In the simplest case, the region mask is the same as the undo mask, but the region can be "locked" so that it may accumulate several brush strokes. When the region is locked, PRISM will "NOT" paint over it on the screen, except when clearing the screen or loading a new picture. When the region mask is set, the undo buffer ALWAYS contains what was on the screen before it became part of the region. So it is like a "Super-Undo" mask. There is a "restore-region" command, a "swap-region", and a "keep region" command to copy data in the region to/from the undo buffer. WORKING WITH REGIONS When working with regions, you should always be aware that there are really 2 "pictures": The one that you see on the screen, and the one in the undo buffer. The one in the undo buffer is what you get when you do a "copy region" or a "restore region". The one you see is what gets filled by "flood region" and what is kept by "keep region". "Swap region" exchanges the two. Using the "ALT" cursor keys moves one region and uncovers the other (undo). With one exception, whatever you paint on the screen gets included in the region. If the region isn't locked, what you paint becomes the new region. (i.e. the region mask is cleared first.) If it's locked, what you paint gets added to the region. The one execption is when you paint with the "eraser" brushes. The "eraser" brushes erase region information, PERIOD! It resores the "what you see" part of the region from the undo part, and shrinks the region. (eraser strokes can be "undone"). It is not necessary to "lock" the region before erasing it. When the "eraser" is selected, the region mask does not get cleared at each brush stroke. There are also region commands to take the "complement" of a region. ("Not Region"), to add fill to a region ("Add Fill"), to add fill, but only keep the new (filled-in) part ("Fill-Only"), to add everything on the screen with a given color to the region ("Add Color") and to clear the region ("New Region"). The "lock" region command should only be used to: 1.) add more brush strokes to the region 2.) preserve the region mask during a clear screen ("NEW") or when loading a new picture. 3.) to lock part of the picture so you can't paint over it. (NOTE - what you paint gets added to the region though). Page 17 ------------------------------------------------------------------------------- SOME WARNINGS ! When you paint with a region locked, none of the new paint is stored in the undo area unless you select "keep region" or "swap region". When you select "copy region" what gets copied is from the undo part of the region, so don't put "lock" on and spend alot of time painting something that you will want to copy somewhere else, with out selecting "keep region" before copying it. Also, a new region does NOT restore the region from the undo buffer before clearing the region mask. "RGB4" IFF 4-BIT RGB IMAGE DATA INTRODUCTION FORM RGB4 is used to store compressed 4-bit RGB data. It incorporates a compression technique (another "variation of Huffmann coding") that is well suited for slowly varying 4-bit data. It was developed for use in the program "PRISM", and RGB4 editor/painter program incorporating the Amiga's HAM (Hold and Modify) screen display mode. REFERENCES AND TRADEMARKS Any good book on data compression will cover Huffmann coding in one form or another. It is a form of "entropy reduction" coding that reproduces the original data in its exact form. Compression/decompression alogrithms are outlined below. Amiga is a trademark of Commodore-Amiga, Inc. PRISM is a trademark of Impulse, Inc. IFF SPECIFICATIONS The standard IFF layout for storing an image is to put three FORM RGM4's in a LIST RGB4, with the Red component appearing first, followed by the Green and Blue components. Each FORM RGB4 must have a BMHD (bitmap header) chunk, a COMP (compression) chunk, and a BODY chunk associated with it. Since the FORM's are stored in a list, the BMHD and COMP chunks can be stored in a PROP chunk. The BMHD chunk should be the same for all three components, so its natureal place would be in a PROP chunk. The COMP chunk(s) contain the data that the decompression algorithn will use, so it/they should go in tthe PROM/FORM chunk(s) depending on whether the same decompression alogrithm will be used to decode all three FORM's. In any case, the BODY chunks must be preceded by the corresponding BMHD and COMP chunk(s). The BMHD chunk is identical to the BMHD chunk in FORM ILBM's. Page 18 ------------------------------------------------------------------------------- The compression component (of the "strict BitMapHeader") should be set to w. The COMP chunk, and the form of the BODY chunk is specific to FORM REG4. Notes: 1) If more than one image is to be stored in a file, they should be put in a CAT of LIST RGB4's. 2) Every LIST RGB4 should contain three FORM RGB4's. 3) The name "RGB4" should not be used as a LIST type for anything but a true 3-component RGB4 image. BACKGROUND The compression technique transforms each byte into zero or more bits in a way that guarantees that no (transformed) byte will match the high order bits of any other (transformed) byte. (e.g. If an "A" is represented as tjhe binary sequence "101", then no other byte will have the form "101xxx"--so when the sequence "101" is obtained, there is no question as to whether or not it is a full character.) The RGB4 BODY chunk is bit-packed transformed data. The bit data is packed with the first bit in the high order position of the first byte. The compression technique works best on "low entropy" data - that is to say: mopst often are represented with the fewest bits. For that reason, there are two more steps in encoding/decoding the image. In encoding, each horizontal scan line is first transformed into a sequence of differences. So the sequence (X1,X2,X3,...) is first changed to (X1,X2-X1,X3-X2,..). In decoding, one starts with a zero (at the left edge of the line), and adds the succeeding values. So, first one obtains 0 + X1 = X1; then 0 + X1 + (X2-X1) = X2; and so on. The values X1, X2, etc. are 4-bit numbers, and in all additions and subtractions, only the least 4-bits are retained. (e.g. 12 + 13 -> 9,9-13 -> 12, etc.) This usually results in alot of 0's, 1's and 15's - 15's since -1 is represented as 15. Then the other step is: in encoding, part the 4-bit values into 8-bit bytes with the first value in the high order part of the first byte (after calculating the differences); and in decoding, split the decoded bytes into 4-bit numbers before "un-differencing". One might wonder why this last step is necessary - after all if there are alot of 0's, 1's and 15's, it produces alot of 00's, 01's 10's, 0F's, 11's, 1F's, and FF's. And 0's, 1's and 15's comprise 18.75% of the 4-bit numbers, but the other collection is only about 3.5% of the byte values. Page 19 ------------------------------------------------------------------------------ But, it also produces alot of 0x's, 1x's, Fx's, x0's, x1's and xF's, where x is not 0, 1 or F. These account for another 30.5% of the byte values. Detailed statistical calculations show that for un-correlated data, there is no difference in the amount of compression that is theoretically possible in the two cases. Un-correlated data is data in which there may be an uneven statistical distribution, but that knowing the value of one particular "character" doesn't make it any easier to predict the value of some other character. The original images are highly correlated for example. If a particular pixel is red, say, then adjacent pixels are likely to be red, or close to red. After differencing the data, that statement becomes the statement that there are alot of "0"'s, "1"'s, and "F"'s in the data. But one can also make the statement that in the original image, pixels which are two away from a red pixel are likely to be red also. After the differencing, this statement becomes the statement that "1"'s are likely to be followed by "-1"'s ("F"'s), and that "2"'s are likely to be followed by "-2"'s or "-1"'s, etc. Since adjacent 4-bit numbers are combined to make bytes, this means that there are also alot of 1F's, 1E's, 2F's, 2E's, etc. Testing showed that for normal images, indeed, better compression was obtained with the 8-bit data.) The compression one obtains depends on the type of image, but generally falls in the range of 50-80% with 60% as typical. COMPRESSION ALGORITHY The standard way of assigning bit sequences to byte value is: 1) Summarize the data - build a 256-entry table containing the number of types each character appears in the data. 2) Build a "tree" structure with end branches corresponding to the characters with non-zero entries in the above table: a) Start with the end branches, and maintain a total count for each branch - with starting values from the table in (1). b) Find the two branches with the least counts and combine them into one forked branch. Add the two totals to get the new branch total. c) Continue the process until the whole tree is built and there is one total, and one (root) branch. d) Starting at each end branch, count the number of forks you have to pass to reach the root branch. This is the number of bits it will take to represent the character. Page 20 ------------------------------------------------------------------------------- (e.g. if there is only one character, there is only one brahcn; it is the root branch, so it is represented in zero bits. If there are two characters, each one appears on the first fork off the root branch, so each one is represented in one bit.) 3) Build a table of bytes (for output - this will be the COMP chunk) with the highest bit count as the first entry; the number of characters represented in 0 bits as the 2nd entry; the number represented in 1 bit as the 3rd entry; and so on, until there are N + 2 entries, where N is the Following these, put the 0-bit character if there is one; the 1-bit character(s) is there are any; the 2-bit characters; and so on. 4) Assign bit sequences to the characters (in the order they are listed in (3) following this algorithm: 0) Set R = 1, n = 0. i) If n is the maximum bit length, quit ii) Set N = (number of n-bit characters) iii) Set R = 2 * R - N iv) Assign R,R + 1, R + 2,....R + N - 1 to the N chars. v) Set n = n + 1, and go to (i). Check at end: If n is non-zero, R should be 0. 5) Notes: a) Record the bit-lengths for each character too. b) The numbers R, R + 1, R + 2,... will always fit in a byte (So long bit sequences all start with a bunch of zeros). c) The maximum bit length can be as large as 255 (Only theoretically - with less than 8 meg of data, the maximum will be no more than 35). d) The high order bits in R, R + 1,...come first in the bit-packed data. COMP (Compression) CHUNK Page 21 ------------------------------------------------------------------------------- The COMP chunk is described in (3) above. It looks like: !---------------------------! ! 'COMP' ! !---------------------------! ! N ! byte 0 ! <# of 0-bit characters> ! byte 1 ! <# of 1-bit characters ! byte 2 ! ... ! ... ! <# of N-bit characters> ! byte N-1 ! <0-bit chars>* ! byte N + 2 ! <1-bit chars>* ! byte N + 2 + ! ... ! ... ! * ! ... ! ? ! byte-X !---------------------------! The maximum size of the COMP chunk is 1 + 36 + 256 + 1 = 294 butes. (Subject to the 8 meg condition in 5c above.) The optional byte should be added (if necessary) to make an even length chunk. The size field should count the paddin gbyte when it is included - rumor has it that some IFF readers don't properly skip over such bytes if they aren't counted in the size ? Using byte values to store the character counds presents one slight (problem ?) to watch for. For very random data, this method of compression can sometimes lead to the final result that all characters are represented in eight bits - in other words, no compression. In that case, the number of 8-bit characters will be 256. The 256 will be truncated to eight bits and will appear as a zero in the <# of 8-bit chars> field. "N" will be "8" though, so there is no ambiguity, but it is still a special case that WILL BE HANDLED by reader software. BODY CHUNK Usin the techniques described above, first "difference" each scan line. Then build the compression table(s). Then construct the BOD"Y chunk by translating the bytes into bit sequences, and packing them into the chunk with the first bit in the high order position of the first byte. Process the data from left to right across the scan lines, working downwards from the upper left corner of the image. Pad the chunk with an extra byte if it is necessary to make an even number of bytes, and include the pad byte in the chunk size. DECOMPRESSION ALGORIGHM To decompress the bit-packed data, the COMP and BMHD chunks must have been processed before the BODY chunk is encountered. Page 22 -------------------------------------------------------------------------------- From the BMHD chunk, one obtains the number of 4-bit values, and hence the number of bytes, to decode for each scan line. The COMP chunk contains the data necessary to decompress the bit-packed data. From the COMP chunk, build two N + 1 byte tables, where N is the first byte of the chunk, using this algorithm: 0) Set 1 = N + 2, R = 1, n = 0 i) Set R = R - <# of n-bit characters> ii) Store R and 1 in the n-th positions in the tables. iii) Set 1 = 1 + <# of n-bit characters> iv) If n = N, quit v) Otherwise, set n = n + 1, R = R * 2, and go to (i) The table of "T" values (1Table[] below) is used to determine when one has unpacked enough bits to call it a full character. In processing the BODY chunk, use the following algorighm: 0) Set D = n = count = lines = 0, pixels = i) If D >=RTable[n] go to (iv) ii) Set D = D * 2 + iii) Set n = n + 1, and go to (i) iv) Decode one byte as COMP[D - RTable[n] + 1Table[n] ]. v) Set D = 0, n = 0, count = count + 2 vi) If count < pixels, go (i) vii) Split the count/2 bytes into their 4-bit parts viii) "Un-difference" the scan line (See above in BACKGROUND) ix) [split the 4-bit data into 4 bitplanes ? ] x) Set lines = lines + 1 xi) If more lines to decode, goto (1) Notes: 1) "D", "n", and the two tables can be unsigned bytes with no problems. 2) The , is always left shifted out of a "current" byte, and a count of "bits left" is maintained. When there are no bits left in the "current" byute, move on to the next byte in the BODY chunk. Some smart buffering and a "buffer count" will keep disk activity to a minimum. (i.e. 512 byte I/O calls are nice - especially if the first call reads only enough bytes to place the file position at a multiple of 512. If you have the space, higher multiples of 512 are even nicer. You may want to make the last I/O call read only up to the end of the BODY chunk - use the chunk size and keep track of the number of bytes you read.) Page 23 ------------------------------------------------------------------------------- PARTING NOTES You may have noticed that the operation of Prism is almost identical to other paint programs. This is no accident. As we feel that programs like Deluxe Paint have become the de-facto standard in which all Amiga paint programs are compared to, we have emulated as much of this type of paint program's functions as Prism allows. Page 24 ------------------------------------------------------------------------------- These Prism!.docs are brought to you by Southern Star..