/***************************** Imagout.c ************************************
*
*  Image editor for the Gadget Editor. C source output routine.
*
*  This module by
*  Ray R. Larson   This version: Sept. 28, 1986
*
*
*  This routine is set up to output a single image to a file as C source.
*  It inserts a name supplied by the calling program as part of the
*  names for the image data and Image structure. This can be considered
*  example code for how to output the image data. It is NOT part the
*  normal Image_Ed routines.
****************************************************************************/
char kprintstr[200]; /* work string for debugging output */
           /* because kprintf doesn't work for me */
 
/*  The usual header files to be inserted later  */
#include <intuition/intuition.h>
#include <libraries/dosextens.h>
#include <graphics/gfxbase.h>
#include <graphics/gfx.h>
#include <graphics/display.h>
#include <exec/memory.h>
#include <workbench/workbench.h>
#include <workbench/startup.h>
#include <devices/narrator.h>
#include <devices/audio.h>
#include <libraries/translator.h>
#include <stdio.h>
 
/* outdat writes out the c code for generating the image */
imagout(outtext, im, imagename)
   FILE *outtext;
   struct Image *im;
   char *imagename; /* Names for the image and the file */
   {
    SHORT i, lastword;
    char *c, *comment, uname[40];
 
    /* number of words in imagedata */
    lastword = im->Width/16;
    if (lastword % 16 != 0) lastword +=1;
    lastword *= (im->Height * im->Depth);
 
 
    strcpy(uname,imagename);
    for (c = uname; *c = toupper(*c); c++);
    comment = "/***************************************************************/";
    /* open the output file using the name supplied via */
    /* the fname parameter            */
 
    /* write out the image data (the important part) */
    fprintf(outtext,"%s\n",comment);
    fprintf(outtext,"/*  The following data structure contains the image data  */\n");
    fprintf(outtext,"%s\n",comment);
 
    fprintf(outtext,"USHORT %s_dat[]=  {\n",imagename);
    for (i=0; i<=lastword; i++)
       {fprintf(outtext,"  0x%04x,",
            im->ImageData[i]);
        if (i%8 == 0) fprintf(outtext,"\n");
       }
    fprintf(outtext,"\n     };\n\n");
 
 
    /* write out the image structure */
    fprintf(outtext,"%s\n",comment);
    fprintf(outtext,"/*  The following data structure defines the image  */\n");
    fprintf(outtext,"%s\n\n",comment);
 
    fprintf(outtext,"struct Image %s =  {\n",imagename);
    fprintf(outtext,"       %d, %d, /* Left, Top */\n",im->LeftEdge,im->TopEdge);
    fprintf(outtext,"       %d, %d, /* Width, Height */\n",im->Width,im->Height);
    fprintf(outtext,"       %d,     /* Depth */ \n",im->Depth);
    fprintf(outtext,"       (USHORT *)&%s_dat, /* ImageData */\n",imagename);
    fprintf(outtext,"       0x%02x,  /* PlanePick */\n",im->PlanePick);
    fprintf(outtext,"       0x%02x,  /* PlaneOnOff */\n",im->PlaneOnOff);
    fprintf(outtext,"       NULL     /* Next Image */\n");
    fprintf(outtext,"      }; \n");
    }
 
