home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 10
/
Fresh_Fish_10_2352.bin
/
new
/
gfx
/
conv
/
image2c
/
i2c.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-03-19
|
25KB
|
683 lines
/****************************************************************************
*
* I2C (Image2'C') 1.2
* Copyright © 1994,1995 Udo Schuermann
* All rights reserved
*
* This program uses iffparse.library to load an ILBM from a FORM IFF
* (in plain English, it loads an IFF picture) and produces output that
* can be used directly as part of a struct Image in your 'C' source
* code.
*
* I make this code available as a demonstration of an exceedingly simple,
* yet functional program that uses iffparse.library and does something
* moderately useful with it. Of some interest might be the fact that
* the program extracts a number of additional properties from the file,
* if they are present: ANNO, AUTH, (c), and FVER chunks are inserted in
* the output file as comments. Hopefully, none of these contain the end-
* comment symbol... :-7
*
* THIS PROGRAM MAY *NOT* BE DISTRIBUTED WITHOUT SOURCE CODE AND ALL
* NOTICES INTACT. YOU MAY NOT SELL THIS PROGRAM OR INCLUDE IT WITH
* A COMMERCIAL PRODUCT WITHOUT EXPRESS WRITTEN PERMISSION FROM THE
* AUTHOR. IT IS PERMITTED TO DISTRIBUTE THIS PROGRAM BY ELECTRONIC
* MEANS (USENET), OR AS PART OF FRED FISH'S CD-ROMS OR RELATED
* COLLECTIONS. YOU MAY USE IT FOR INSTRUCTIONAL PURPOSES, AND EVEN
* GIVE IT TO FRIENDS, BUT DON'T YOU SELL IT OR YOUR NAME SHALL BE
* FOREVER STAINED.
*
* Commodore is dead. Long live the Amiga!
*
* Share and enjoy! ;-)
*
* ---------------------------------------------------------------------
*
* This program uses the following CLI template (I am not using standard
* code for that, but am parsing the command line on my own):
*
* ILBMFILE/A,SYMPREFIX/A,NOINFO/S,NOPENS/S,NODATA/S,NOIMAGESTRUCT/S,
* NORGB4/S,USEIFDEFS/S,NOCHIP/S
*
* ILBMFILE/A Must always be given. This is the IFF ILBM input
* file to be converted. I2C supports images up to
* 8 bitplanes deep (actually, any bitplane oriented
* ILBM)
*
* SYMPREFIX/A Must always be given. The symbol prefix for this
* image file. This forms the prefix to all symbols
* in the file.
* Example: A prefix of "myImage_" will generate
* symbols such as "UWORD myImage_ImageData[]"
*
* NOINFO/S This switch will cause image information, such
* such as height, width, depth, number of colors
* to be omitted. See also NOIMAGESTRUCT below!
*
* NOPENS/S This switch will cause pens (used by LoadRGB32()
* for example) to be omitted.
*
* NODATA/S This switch will cause the actual image data to
* be omitted. See also NOIMAGESTRUCT below!
*
* NOIMAGESTRUCT/S This switch will cause a "struct Image ..." item
* to be omitted. This item requires the presence
* of INFO and DATA items; if you specify that either
* or both of those should not be included (NOINFO
* and/or NODATA) but you do not also specify the
* NOIMAGESTRUCT, then I2C will reverse your decision
* on NOINFO and/or NODATA so that the Image struct
* can be built.
*
* ADDRGB4/S This switch will cause register color values to
* be added. Such values are 12-bit only and are
* probably of use only for older software. It is
* for this reason that this is the only switch that
* needs to be specified to add something to the
* code; i.e. if not specified you will NOT get the
* information for this item.
*
* USEIFDEFS/S This switch encloses the INFO, PENS, DATA, IMG,
* and RGB4 sections with #ifdef/#endif constructs
* to allow you to build a source file with ALL
* information, but decide at a later time which
* portions the compiler should include or ignore.
* Use of this switch enables an additional level
* of flexibility, which you may or may not find
* of use.
*
* The following #define statements used BEFORE you
* #include the source code generated by I2C will
* tell the compiler which portions of the file to
* use and which to ignore:
*
* #define I2C_IMAGE_INFO Accept image info
* #define I2C_IMAGE_PENS Accept RGB32 pens
* #define I2C_IMAGE_RGB4 Accept 4-bit pens
* #define I2C_IMAGE_DATA Accept image data
* #define I2C_IMAGE_IMG Accept struct Image
*
* NOCHIP/S Omit the __chip attribute on structures. This may
* be desirable if you are going to remap image colors
* anyway and won't be needing the original in chip
* RAM.
*
* If you are not clear on some of the points described above, you are
* hereby STRONGLY advised to run the program on a test image and see what
* the resulting output file contains. Try this:
*
* I2C TestImage.IFF MyTest_ USEIFDEFS
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <exec/types.h>
#include <libraries/iffparse.h>
#include <proto/dos.h>
#include <proto/iffparse.h>
/* If we define __MYDATE__ from the commandline, then we'll use that instead of
* redefining it to the standard Amiga __AMIGADATE__ (which is broken in SAS/C
* 6.51 whenever both the month and the day require two digits.)
*/
#ifndef __MYDATE__
#define __MYDATE__ __AMIGADATE__
#endif
#define VERSION "1.2"
char const VER[] = "$VER: Image2'C' "VERSION" "__MYDATE__;
BOOL AddINFO = TRUE;
BOOL AddPENS = TRUE;
BOOL AddDATA = TRUE;
BOOL AddRGB4 = FALSE;
BOOL AddIMG = TRUE;
BOOL UseIFDEFs = FALSE;
BOOL UseCHIP = TRUE;
char *ILBMFILE = NULL;
char *SYMPREFIX = NULL;
struct IFFHandle *OpenFileAsIFF( char *filename ) {
struct IFFHandle *iff;
if( iff = AllocIFF() ) {
if( iff->iff_Stream = (ULONG)Open(filename,MODE_OLDFILE) ) { /* open the file stream */
InitIFFasDOS( iff ); /* initialize this as a DOS stream */
if( OpenIFF( iff, IFFF_READ ) == 0 ) /* now open it as an IFF */
return iff; /* and return read-to-go IFF handle */
else
Close( iff->iff_Stream ); /* not an IFF file; close file */
} else
fprintf(stderr,"File unavailable (%s)!\n",filename);
FreeIFF( iff ); /* free the iff handle */
} else
fprintf(stderr,"Out of memory opening (%s)!\n",filename);
return NULL; /* return failure */
} /* OpenFileAsIFF() */
#define ID_ILBM MAKE_ID('I','L','B','M')
#define ID_BMHD MAKE_ID('B','M','H','D')
#define ID_CMAP MAKE_ID('C','M','A','P')
#define ID_BODY MAKE_ID('B','O','D','Y')
#define ID_AUTH MAKE_ID('A','U','T','H')
#define ID_CPRT MAKE_ID('(','c',')',' ')
#define ID_ANNO MAKE_ID('A','N','N','O')
#define ID_FVER MAKE_ID('F','V','E','R')
#define mskHasMask 1 /* the only mask that REALLY needs handling */
#define ByteRun1 1 /* the only compression we understand */
typedef UBYTE Masking;
typedef UBYTE Compression;
struct BitMapHeader {
UWORD w, h;
WORD x, y;
UBYTE nPlanes;
Masking masking;
Compression compression;
UBYTE reserved1;
UWORD transparentColor;
UBYTE xAspect, yAspect;
WORD pageWidth, pageHeight;
};
/* The ByteToWordStream() function, along with a limited set of global variables,
* permits us to produce really lovely, and well-formatted output.
*
* OnNewLine is externally set to 1 whenever we have finished with a scanline so
* that the next time we call ByteToWordStream, we start nicely on a new line.
* If you never use OnNewLine, then all data is merely dumped one word after
* another. NO FUNCTIONALITY IS LOST, it just won't look nice. Your compiler
* doesn't care. Lines are ALWAYS limited to 11 words per line.
*
* LineHeader, if not set to a "" string, is printed before a new line is output,
* so we can print the nice "/× Plane 2 ×/" items before the new plane actually
* begins, but still give this function the chance to clean up the previous line
* by adding a comma and newline to it, etc.
* If you never use LineHeader, you will simply be missing the human-readable
* markers for the bit planes. No biggie. Again, your compiler couldn't care
* less.
*/
#define WORDS_PER_LINE 11
UBYTE OnNewLine = 0;
char LineHeader[64] = "";
void ByteT