[comp.sys.amiga] IFF/ILBM HAM encoded images.

wecker@cookie.dec.com (DAVE CUM GRANO SALIS WECKER) (01/18/87)

I need some information from anyone using iff/ilbm versions of my ray traced
images:

	1)	What did you use to grab the image with?
	2)	Could you "TYPE OPT H" the first couple hundred bytes of
		one (or more) of the files and send it to me?
	3)	What are you displaying the images with?
	4)	Have you been able to edit them?

Here is my problem:

	1)	I am now generating IFF/ILBM files directly from the ray tracer
		(following the RKM to the letter).
	2)	SHOWIFF displays the images non-ham mode (i.e., 6 absolute
		planes which look terrible).
	3)	DPaint states (upon image load) that it is in an "unsupported
		format".
	4)	All the chunks look good: FORMxxxxILBM, BMHD, CAMG, CMAP, BODY
		and have the same hex dump as the GLASS image on Fred Fish's
		distribution.
	5)	The is the last thing holding up distribution of the ray tracer
		for the Amiga and I would REALLY like to get it out the door
		before the end of the month.

Any help would be GREATLY appreciated. Please mail replies back so that we
don't clutter up the net with this. If there is an interesting result, I will
of course post it.

Thanks!
dave	USENET:	decwrl.dec.com!cookie.dec.com!wecker
	ARPA:   wecker%cookie.dec.com@decwrl.dec.com   <-- faster

hadeishi@husc4.UUCP (01/19/87)

In re: questions about HAM mode ILBM,

	The original version of ShowILBM does not read the CAMG chunk,
so it does not get the View.Modes information that you need to display
the image as a HAM mode picture.  DPaint does not edit HAM mode images;
you need a HAM mode paint program, such as Digi-Paint (which was featured
in the first issue of Deluxe News, I believe; the one with Dan Silva
on the cover.)  You can easily modify ShowILBM to read the CAMG chunk,
although you have to wade through the readpict.c code provided with
the IFF source disk (Fish Disk 17, I think).  I've done so, but the
mod is so easy it seems a waste to post the thing.  My slideshow
program, distributed through Electronic Arts on the DPaint Utilities
and Art Disk #1, WILL display HAM mode IFF pictures, but it
crashes upon exit under 1.2 (this HAS been fixed in the update,
which will be released in a little while . . . BTW, the update
supports all DPaint II output formats, and is kinda cool . . . you'll
see it when it comes out.)  You want to get the slideshow program
if you don't want to wade through source code.  I've also
posted my modified ShowILBM on various Bay Area BBS's and the Well;
if you like, I'll post a uuencoded version of the executable on the net,
too (it also displays the image for a slightly longer period of time,
but it doesn't let you determine how long to see the image---I
suppose I could add that, too but I don't have the time to work on
it right now.)  So your images probably ARE in the right format,
you just don't have the right program to view them with yet.
I would recommend Digi-Paint, although I've never used it; it is a
full 4,096 color paint program (!) that allows you to merge multiple
32-color images, and all sorts of stuff, though I bet it's SLOW.

				-Mitsu

keithd@cadovax.UUCP (Keith Doyle) (01/20/87)

In article <7640@decwrl.DEC.COM> wecker@cookie.dec.com (DAVE  CUM GRANO SALIS  WECKER) writes:
>I need some information from anyone using iff/ilbm versions of my ray traced
>images:
>
>	1)	What did you use to grab the image with?

Unfortunately, I renamed the program to 'saveiff' from whatever the original
name was.  I'm not sure where the program came from, though I have the
source.  You type 'saveiff filename' and then it will output a message
something like 'save highest screen in 5 seconds? (y/n)' and then once
you hit return, you have 5 seconds to make sure the screen you want to
save is the highest up on the display.  Works great in any mode.

	3)      What did you display the image with?

I hacked a version of seeilbm to set HAM mode if there are 6 bit planes
in the image.  This is probably an incorrect kludge, but I didn't see any
other obvious way to tell if the IFF file was HAM or not.  It could be a
'halfbrite' screen, but since I don't have that feature anyway, I just
coded it to go into HAM mode.  If anyone knows what a more CORRECT way
of testing the incoming IFF file for HAM mode, let me know.
 
        4)      Have you been able to edit it?

No.

Keith Doyle
#  {ucbvax,ihnp4,decvax}!trwrb!cadovax!keithd
#  cadovax!keithd@ucla-locus.arpa

keithd@cadovax.UUCP (Keith Doyle) (01/21/87)

In article <1042@husc6.UUCP> hadeishi@husc4.UUCP (mitsuharu hadeishi) writes:
>In re: questions about HAM mode ILBM,
>	The original version of ShowILBM does not read the CAMG chunk,
>so it does not get the View.Modes information that you need to display
>the image as a HAM mode picture.

Well, that's ok, as my version of saveiff dosen't create a CAMG chunk
anyway I don't think.  Maybe it should though?  


Keith Doyle
#  {ucbvax,ihnp4,decvax}!trwrb!cadovax!keithd
#  cadovax!keithd@ucla-locus.arpa

carolyn@cbmvax.cbm.UUCP (Carolyn Scheppner) (01/21/87)

   Fish disk #44 contains ViewILBM (source and executable).  It handles
HAM ILBMs, displays in a screen (toggle in title bar to arrange or pull down),
and stays up for as long as you like.

   And get DigiPaint for doing neat things to HAM images.  Tim Jennison
(NewTek) demoed it in our both at CES.  I don't know of any other
paint package for HAM images.  

   That slide show mentioned sounds good too.  Will that display
full-video images as full-video ?

-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Carolyn Scheppner -- CBM   >>Amiga Technical Support<<
                     UUCP  ...{allegra,caip,ihnp4,seismo}!cbmvax!carolyn 
                     PHONE 215-431-9180
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

carolyn@cbmvax.cbm.UUCP (Carolyn Scheppner) (01/22/87)

In article <1333@cadovax.UUCP> keithd@cadovax.UUCP (Keith Doyle) writes:

  (RE: grabbing HAM images)
>Unfortunately, I renamed the program to 'saveiff' from whatever the original
>name was.  I'm not sure where the program came from, though I have the
>source.  You type 'saveiff filename' and then it will output a message
>something like 'save highest screen in 5 seconds? (y/n)'...

   That sounds like my my first screen-saver program.  I forget
what I called it.  It was written using the original IFF code
before the ILBM "CAMG" chunk existed.  So it does NOT save a
CAMG chunk!  And ALL HAM ILBM's should have a CAMG chunk ! 
Note that "CAMG" is an Amiga ViewModes chunk which contains the
flags for HIRES,LACE,HAM, etc.  

   In other words, DO NOT use my old screen-saver to save HAM images.

   We used "Grabbit" (Discovery Software) to save Display'd Wecker pics.
This is a hotkey screen save/dump program which DOES save a CAMG chunk.


 (RE: using planecount of 6 as flag that file is HAM)
>                ...If anyone knows what a more CORRECT way
>of testing the incoming IFF file for HAM mode, let me know.
> 

   Read the IFF ILBM docs description of the CAMG (Amiga ViewModes)
chunk.  If this chunk is found in a file, its contents (a ULONG)
should be used for your screen or viewport/view ViewModes.
If NO CAMG chunk is found, then you must use the BitMapHeader
page width and height to decide if your ViewModes need HIRES
or LACE flag, and I guess you would have to assume HAM for 6 planes.
But every proper HAM ILBM should have a CAMG chunk.  Yours didn't
because you used my old pre-CAMG screen-saver to create the file.

carolyn
-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Carolyn Scheppner -- CBM   >>Amiga Technical Support<<
                     UUCP  ...{allegra,caip,ihnp4,seismo}!cbmvax!carolyn 
                     PHONE 215-431-9180
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

carolyn@cbmvax.UUCP (01/24/87)

NEW SCREENSAVE:

   I mentioned in a previous posting that my old screen-saver was written
before CAMG chunks existed.  Here is my current ScreenSave.c which
can be used for saving HAM screens (and normal screens of course)
as ILBMs.  It now saves the FRONT screen rather than the HIGHEST screen
(when I wrote the old one I didn't know that IntuitionBase->FirstScreen
was the FRONT screen.  I thought it was the oldest screen).

CREATING ICONS:

   This code also provides an example of how to save an Icon for a file.
I created my icon with IconEd and semi-converted it to C source with
a quick and dirty Icon2C that I wrote.  If you want me to post it,
let me know.  Icon2C doesn't even attempt to trace the more complicated
lists (like ToolTypes) and it doesn't convert things like Gadget flags
to labels (it just puts the hex values in the Gadget structure source).
But it has definitely saved me at LEAST the time I took to write it.

CREATING AMIGA STDIO:

   There is also code in ScreenSave to create an Amiga stdio window
if the program is started from WorkBench.  Manx users will undoubtedly
have to modify these routines.

   This program is meant to be linked with AStartup.obj and it
modifies the stdio handles in AStartup if started from WorkBench.
(It opens a CON: window and makes it Amiga stdio so I can use
Amiga.lib's printf() and getchar() regardless of whether I was
started from CLI or WorkBench.)

   As shown in the "Linkage Information", this code must be linked
with several standard IFF object modules.  The -v flag must be used
on the second pass (LC2) of the compiler when compiling this code
and each of the IFF modules.

     carolyn


/***************************************************************************
*  ScreenSave.c --  Save front screen as ILBM file
*                   Saves a CAMG chunk for Amiga ViewModes
*                   by Carolyn Scheppner  CBM  10/86
*     Using IFF rtns by J.Morrison and S.Shaw of Electronic Arts
*       (re-compiled with -v on LC2)
* Linkage information:
* FROM     AStartup.obj, ScreenSave.o, iffw.o, ilbmw.o, packer.o
* TO       ScreenSave
* LIBRARY  Amiga.lib, LC.lib
***************************************************************************/

#include <exec/types.h>
#include <exec/memory.h>
#include <libraries/dos.h>
#include <libraries/dosextens.h>
#include <graphics/gfxbase.h>
#include <graphics/rastport.h>
#include <graphics/gfx.h>
#include <graphics/view.h>

#include <intuition/intuition.h>
#include <intuition/intuitionbase.h>
#include <workbench/workbench.h>
#include <workbench/startup.h>

#include <iff/ilbm.h>

/* From AStartup */
extern  LONG  stdin, stdout, stderr;

/* CAMG Stuff */
typedef struct {
   ULONG ViewModes;
   } CamgChunk;

#define PutCAMG(context, camg)  \
    PutCk(context, ID_CAMG, sizeof(CamgChunk),(BYTE *)camg)

#define bufSize 512

/* Other Stuff */
struct IntuitionBase *IntuitionBase;
struct GfxBase       *GfxBase;
ULONG  IconBase;

struct Screen   *frontScreen;

struct ViewPort *picViewPort;
struct BitMap   *picBitMap;
WORD            *picColorTable;
ULONG            picViewModes;
BOOL fromWB, newStdio;

#define INBUFSZ 40
char sbuf[INBUFSZ];
char nbuf[INBUFSZ];

char conSpec[] = "CON:0/40/639/160/ SaveScreen ";

/* Definitions for ILBM Icon */
USHORT  ILBMimagedata[] = {
 0xFFFF, 0xFFFC,
 0xC000, 0x000C,
 0xC000, 0x000C,
 0xC1E7, 0x9E0C,
 0xC1F8, 0x7E0C,
 0xC078, 0x780C,
 0xC187, 0x860C,
 0xC078, 0x780C,
 0xC1F8, 0x7E0C,
 0xC1E7, 0x9E0C,
 0xC000, 0x000C,
 0xC000, 0x000C,
 0xFFFF, 0xFFFC,
 0x0000, 0x0000,
 0x0000, 0x0000,
/**/
 0xFFFF, 0xFFFC,
 0xFFFF, 0xFFFC,
 0xF800, 0x007C,
 0xF9E0, 0x1E7C,
 0xF980, 0x067C,
 0xF807, 0x807C,
 0xF81F, 0xE07C,
 0xF807, 0x807C,
 0xF980, 0x067C,
 0xF9E0, 0x1E7C,
 0xF800, 0x007C,
 0xFFFF, 0xFFFC,
 0xFFFF, 0xFFFC,
 0x0000, 0x0000,
 0x0000, 0x0000,
/**/
 };

struct Image ILBMimage = {
   0,0,                     /* Leftedge, Topedge */
   30,15,                   /* Width Height */
   2,                       /* Depth */
   &ILBMimagedata[0],       /* Data for image */
   3,0                      /* PlanePick, PlaneOnOff */
   };

struct DiskObject ILBMobject = {
   WB_DISKMAGIC,
   WB_DISKVERSION,

   /* Gadget Structure */
   NULL,                    /* Ptr to next gadget */
   0,0,                     /* Leftedge, Topedge */
   30,15,                   /* Width, Height */
   GADGHBOX|GADGIMAGE,      /* Flags */
   RELVERIFY|GADGIMMEDIATE, /* Activation */
   BOOLGADGET,              /* Type */
   (APTR)&ILBMimage,        /* Render */
   NULL,                    /* Select Render */
   NULL,                    /* Text */
   NULL,NULL,NULL,NULL,     /* Exclude, Special, ID, UserData */

   4,                       /* WBObject type */
   ":ViewILBM",             /* Default tool */
   NULL,                    /* Tool Types */
   NO_ICON_POSITION,        /* Current X */
   NO_ICON_POSITION,        /* Current Y */
   NULL,NULL,NULL,          /* Drawer, ToolWindow, Stack */
   };


main(argc, argv)
int argc;
char **argv;
   {
   LONG            file;
   IFFP            iffp = NO_FILE;
   char            *filename;
   int l;

   newStdio = FALSE;
   fromWB = (argc==0) ? TRUE : FALSE;

   if((fromWB) && (!(newStdio = openStdio(&conSpec[0]))))
      {
      return(0);
      }

   if ((IntuitionBase =
      (struct IntuitionBase *)OpenLibrary("intuition.library",0))==NULL)
         cleanexit("Can't open intuition.library\n");

   if ((GfxBase =
      (struct GfxBase *)OpenLibrary("graphics.library",0))==NULL)
      cleanexit("Can't open graphics.library\n");

   if ((IconBase = OpenLibrary("icon.library",0))==NULL )
      cleanexit("Can't open icon.library\n");

   printf("ScreenSave --- C. Scheppner  CBM  10/86\n");
   printf("   Saves the front screen as an IFF ILBM file\n");
   printf("   A CAMG chunk is saved (for HAM pics, etc.)\n\n");

   if(argc>1)                 /* Passed filename via command line  */
      {
      filename = argv[1];
      }
   else
      {
      printf("Enter filename for save: ");
      l = gets(&nbuf[0]);

      if(l==0)                /* No filename - Exit */
         {
         cleanexit("\nScreen not saved, filename required\n");
         }
      else
         {
         filename = &nbuf[0];
         }
      }

   if (!(file = Open(filename, MODE_NEWFILE)))
      cleanexit("Can't open output file\n");
     
   Write(file,"x",1);  /* 1.1 so Seek to beginning works ? */

   printf("Click here and press <RETURN> when ready: ");
   gets(&sbuf[0]);
   printf("Front screen will be saved in 10 seconds\n");
   Delay(500);

   Forbid();
   frontScreen  = IntuitionBase->FirstScreen;
   Permit();

   picViewPort = &( frontScreen->ViewPort );
   picBitMap = (struct BitMap*)picViewPort->RasInfo->BitMap;
   picColorTable = (WORD *)picViewPort->ColorMap->ColorTable;
   picViewModes = (ULONG)picViewPort->Modes;

   printf("\nSaving...\n");

   iffp = PutPicture(file, picBitMap, picColorTable, picViewModes);
   Close(file);

   if (iffp == IFF_OKAY)
      {
      printf("Screen saved\n");
      if(!(PutDiskObject(filename,&ILBMobject)))
         {
         cleanexit("Error saving icon\n");
         }
      printf("Icon saved\n");
      }
   cleanexit("Done\n");
   }


cleanexit(s)
   char  *s;
   {
   if(*s) printf(s);
   if ((fromWB)&&(*s))    /* Wait so user can read messages */
      {
      printf("\nPRESS RETURN TO EXIT\n");
      gets(&sbuf[0]);
      }
   cleanup();
   exit();
   }

cleanup()
   {
   if (newStdio)  closeStdio();
   if (GfxBase) CloseLibrary(GfxBase);
   if (IntuitionBase) CloseLibrary(IntuitionBase);
   if (IconBase) CloseLibrary(IconBase);
   }


openStdio(conspec)
char *conspec;
   {
   LONG wfile;
   struct Process *proc;
   struct FileHandle *handle;

   if (!(wfile = Open(conspec,MODE_NEWFILE)))  return(0);
   stdin  = wfile;
   stdout = wfile;
   stderr = wfile;
   handle = (struct FileHandle *)(wfile << 2);
   proc = (struct Process *)FindTask(NULL);
   proc->pr_ConsoleTask = (APTR)(handle->fh_Type);
   proc->pr_CIS = (BPTR)stdin;
   proc->pr_COS = (BPTR)stdout;
   return(1);
   }

closeStdio()
   {
   struct Process *proc;
   struct FileHandle *handle;

   if (stdin > 0)  Close(stdin);
   stdin  = -1;
   stdout = -1;
   stderr = -1;
   handle = (struct FileHandle *)(stdin << 2);
   proc = (struct Process *)FindTask(NULL);
   proc->pr_ConsoleTask = NULL;
   proc->pr_CIS = NULL;
   proc->pr_COS = NULL;
   }


gets(s)
char *s;
   {
   int l = 0, max = INBUFSZ - 1;

   while (((*s = getchar()) !='\n' )&&(l < max)) s++, l++;
   *s = NULL;
   return(l);
   }


/* String Functions */

strlen(s)
char *s;
   {
   int i = 0;
   while(*s++) i++;
   return(i);
   }

strcpy(to,from)
char *to, *from;
   {
   do
      {
      *to++ = *from;
      }
   while(*from++);
   }


/** PutPicture() ***********************************************************
 *
 * Put a picture into an IFF file.
 * This procedure calls PutAnILBM, passing in an <x, y> location of <0, 0>,
 * a NULL mask, and a locally-allocated buffer. It also assumes you want to
 * write out all the bitplanes in the BitMap.
 *
 ***************************************************************************/
Point2D nullPoint = {0, 0};

IFFP PutPicture(file, bitmap, colorMap, viewmodes)
      LONG file;  struct BitMap *bitmap;
      WORD *colorMap;  ULONG viewmodes;
   {
   BYTE buffer[bufSize];
   return( PutAnILBM(file, bitmap, NULL,
           colorMap, bitmap->Depth, viewmodes,
           &nullPoint, buffer, bufSize) );
   }    

   
/** PutAnILBM() ************************************************************
 *
 * Write an entire BitMap as a FORM ILBM in an IFF file.
 * This version works for any display mode (C. Scheppner).
 *
 * Normal return result is IFF_OKAY.
 *
 * The utility program IFFCheck would print the following outline of the
 * resulting file:
 *
 *   FORM ILBM
 *     BMHD
 *     CAMG
 *     CMAP
 *     BODY       (compressed)
 *
 ***************************************************************************/
#define CkErr(expression)  {if (ifferr == IFF_OKAY) ifferr = (expression);}

IFFP PutAnILBM(file, bitmap, mask, colorMap, depth,
                                viewmodes, xy, buffer, bufsize)
      LONG file;
      struct BitMap *bitmap;
      BYTE *mask;  WORD *colorMap; UBYTE depth;
      ULONG viewmodes;
      Point2D *xy; BYTE *buffer;  LONG bufsize;
   {
   BitMapHeader bmHdr;
   CamgChunk    camgChunk;
   GroupContext fileContext, formContext;
   IFFP ifferr;
   WORD pageWidth, pageHeight;

   pageWidth  = (bitmap->BytesPerRow) << 3;
   pageHeight = bitmap->Rows;

   ifferr = InitBMHdr(&bmHdr, bitmap, mskNone,
                      cmpByteRun1, 0, pageWidth, pageHeight);
   /* You could write an uncompressed image by passing cmpNone instead
    * of cmpByteRun1 to InitBMHdr. */
   bmHdr.nPlanes = depth;   /* This must be  <= bitmap->Depth */
   if (mask != NULL) bmHdr.masking = mskHasMask;
   bmHdr.x = xy->x;   bmHdr.y = xy->y;

   camgChunk.ViewModes = viewmodes;

   CkErr( OpenWIFF(file, &fileContext, szNotYetKnown) );
   CkErr(StartWGroup(&fileContext, FORM, szNotYetKnown, ID_ILBM, &formContext));

   CkErr( PutBMHD(&formContext, &bmHdr) );
   CkErr( PutCAMG(&formContext, &camgChunk) );
   CkErr( PutCMAP(&formContext, colorMap, depth) );
   CkErr( PutBODY(&formContext, bitmap, mask, &bmHdr, buffer, bufsize) );

   CkErr( EndWGroup(&formContext) );
   CkErr( CloseWGroup(&fileContext) );
   return( ifferr );
   }
   
-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Carolyn Scheppner -- CBM   >>Amiga Technical Support<<
                     UUCP  ...{allegra,caip,ihnp4,seismo}!cbmvax!carolyn 
                     PHONE 215-431-9180
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

haddock@ti-csl.UUCP (01/25/87)

I talked to the folks at NewTek (in Kansas) just this past week
(Jan 22nd) and both the Digi-View update and Digi-Paint programs
will be delayed for yet another two weeks.  In other words, if
they find the bug(s) that they're after, delivery should
commence in about two weeks.


				-Rusty-
-- 
================================================================
Rusty Haddock +++ Texas Instruments, Inc. +++ Dallas, Texas
Computer Science Center, CRD&E +++ CSNET: Haddock@TI-CSL
USENET: {ut-sally!im4u,convex!smu,sun!texsun}!ti-csl!haddock

hadeishi@husc4.UUCP (01/27/87)

In re:
>  That's okay, because my seeilbm doesn't generate a CAMG chunk anyway.

	Please include a CAMG chunk in HAM mode pictures.  Otherwise,
there is no way to distinguish between a HAM mode an a DUALPF
(dual playfield) 6-plane image (or a regular 6-plane image on
a future Amiga.)  Many programs read this chunk to get the View.Modes
information.
				-Mitsu