home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 310.lha / SGFF < prev    next >
Internet Message Format  |  1980-12-05  |  12KB

  1. From zap!philmtl!uunet!ginosko!gem.mps.ohio-state.edu!tut.cis.ohio-state.edu!ucbvax!hplabs!hpfcso!cunniff Sat Oct 28 01:30:07 EDT 1989
  2. Article 91 of comp.sys.amiga.tech:
  3. Path: zoom!zap!philmtl!uunet!ginosko!gem.mps.ohio-state.edu!tut.cis.ohio-state.edu!ucbvax!hplabs!hpfcso!cunniff
  4. >From: cunniff@hpfcso.HP.COM (Ross Cunniff)
  5. Newsgroups: comp.sys.amiga.tech
  6. Subject: IFF FORM DR2D for structured graphics
  7. Message-ID: <9310003@hpfcso.HP.COM>
  8. Date: 24 Oct 89 14:54:26 GMT
  9. Organization: Hewlett-Packard, Fort Collins, CO, USA
  10. Lines: 403
  11.  
  12. 89/10/03
  13.  
  14. The following is the format of the DR2D IFF FORM file produced
  15. by ProVector, a 2-dimensional structured graphics program.
  16. Each chunk is described by first giving the chunk ID (both in
  17. ASCII and in hex) and then giving the structure associated with
  18. the chunk, as well as any extra definitions that make sense.
  19. Coordinates are specified in IEEE format (see note 1 for a
  20. description of the IEEE format).  Note that most chunks have
  21. both a chunk Size and an object Count.  I know this is redundant;
  22. however, this allows the data structures to be extended in a
  23. compatible manner if it should become necessary in the far future.
  24. Please address questions and comments to:
  25.  
  26.             Ross Cunniff
  27.             ...{ucbvax,hplabs}!hpfcla!cunniff
  28.             cunniff%hpfcrt@hplabs.HP.COM
  29.             (303)-229-4644 -or- (303)-482-6077
  30.  
  31. (or you can post reponses here...)
  32.  
  33.  
  34. FORM (0x464F524D)    /* All drawings are a FORM */
  35.  
  36.     struct FORMstruct {
  37.         LONG    ID;
  38.         LONG    Size;        /* Total size of the file    */
  39.     };
  40.  
  41.  
  42. DR2D (0x44523244)    /* ID of 2D drawing */
  43.  
  44. DRHD (0x44524844)    /* Drawing header */
  45.  
  46.     struct DRHDstruct {
  47.         LONG    ID;
  48.         LONG    Size;        /* Always 18 */
  49.         IEEE    p_xmin, p_ymin,    /* Minimum and maximum */
  50.             p_xmax, p_ymax;    /*   coordinates of the drawing area */
  51.     };
  52.  
  53. CMAP (0x434D4150)    /* Color map */
  54.  
  55.     struct CMAPstruct {
  56.         LONG    ID;
  57.         LONG    Size;        /* Usually 256*3, or 768 */
  58. #define            NUMCOLOR(Size)    (Size / 3)
  59.         UBYTE    ColorMap[NUMCOLOR(Size)][3];
  60.     };
  61.  
  62. PREF (0x50524546)    /* Application preferences */
  63.  
  64.     struct PREFstruct {
  65.         LONG    ID;
  66.         LONG    Size;
  67.         SHORT    NumPrefs;
  68.         UBYTE    PrefStrings[Size - 2];
  69.     };
  70.     /* PrefStrings is an array containing strings of the form
  71.  
  72.         name=value
  73.  
  74.        The strings are null-separated in the array.
  75.        Other applications may safely ignore this chunk,
  76.        although it is requested that applications that
  77.        manipulate DR2D files do not delete preferences
  78.        settings that they do not understand.  Some possible
  79.        settings include:
  80.  
  81.         DATE=10/28/88
  82.         COPYRIGHT=Copyright 1989 by Taliesin, Inc.
  83.         PROGRAM=ProVector
  84.         ARTIST=Ross Cunniff
  85.         LMARGIN=1 inch
  86.         ORIENT=portrait
  87.         ZOOM=1.0 1.0 2.0 2.0
  88.     */
  89.  
  90.  
  91. PATT (0x50415454)    /* 8x8 bitmap fill patterns */ /* OBSOLETE */
  92.  
  93.     struct PATTstruct {
  94.         LONG    ID;
  95.         LONG    Size;        /* 2 + 10*NumPatts */
  96.         SHORT    NumPatts;    /* Typically 16 */
  97.         UBYTE    Patterns[NumPatts][10];
  98.     };
  99.  
  100.     /* The 10 bytes of the patterns are arranged as follows:
  101.          The first byte is the foreground color of the pattern
  102.          The second byte is the background color of the pattern
  103.          The next 8 bytes are the actual rows of the pattern;
  104.         the leftmost pixel in a row is 0x80, the rightmost
  105.         is 0x01. */
  106.  
  107. FONT (0x464F4E54)    /* Font table */
  108.  
  109.     struct FONTstruct {
  110.         LONG    ID;
  111.         LONG    Size;
  112.         SHORT    NumFonts;
  113.         CHAR    FontNames[Size-2];
  114.     };
  115.     /* FontNames is an array containing the names of all the fonts
  116.        used in this drawing.  The names are stored as null-separated
  117.        strings. */
  118.  
  119. FILL (0x46494C4C)    /* Object-oriented fill pattern table */
  120.  
  121.     struct FILLstruct {
  122.         LONG    ID;
  123.         LONG    Size;        /* 2 + sum(sizeof(Patterns)) */
  124.         SHORT    NumPatts;    /* Typically 16 */
  125.         CHAR    Patterns[NumPatts];    /* See note 4 */
  126.     };
  127.  
  128.     /* An object-oriented fill pattern consists of an arbitrary
  129.        number of objects.  The objects are tiled across the
  130.        bounding box of the filled object, and clipped to the
  131.        boundaries of that object. */
  132.  
  133.  
  134. DSYM (0x4453594D)    /* Define a symbol (NOT IMPLEMENTED) */
  135.  
  136.     struct DSYMstruct {
  137.         LONG    ID;
  138.         LONG    Size;
  139.         SHORT    SymbID;            /* Unique ID for this symbol */
  140.         SHORT    NumObjs;
  141.         UBYTE    SymbChunk[Size-4];    /* See note 4 */
  142.     };
  143.  
  144.  
  145. SYMB (0x53594D42)    /* Use a symbol (NOT IMPLEMENTED) */
  146.  
  147.     struct SYMBstruct {
  148.         LONG    ID;
  149.         LONG    Size;            /* Always 22    */
  150.         SHORT    SymbID;            /* Which symbol    */
  151.         USHORT    WhichLayer;        /* Which layer it's in */
  152.         IEEE    XPos, YPos,        /* Where to put it */
  153.             XMag, YMag,        /* How big should it be? */
  154.             Rotation;        /* Angle of rotation */
  155.     };
  156.  
  157. RAST (0x52415354)    /* Raster image */
  158.  
  159.     struct RASTstruct {
  160.         LONG    ID;
  161.         LONG    Size;
  162.         IEEE    XPos, YPos,        /* Virtual coords */
  163.             XSize, YSize;        /* Virtual size */
  164.         SHORT    NumX, NumY, Depth;    /* Actual size */
  165.         UBYTE    Colors[3*(1<<Depth)];    /* Color map */
  166.         UBYTE    Closest[(1<<Depth)];    /* Closest equivs in CMAP */
  167. #define RSIZE(x,y,d)    ((x+15)/16)*y*d
  168.         USHORT    Rast[RSIZE(NumX,NumY,Depth)];    /* Lookups into Colors*/
  169.     };
  170.  
  171. CPLY (0x43504C59)    /* Closed polygon */
  172. OPLY (0x4F504C59)    /* Open polygon, i.e. line segments */
  173.  
  174.     /* Various fill types */
  175.     #define FT_NONE        0    /* No fill            */
  176.     #define FT_COLOR    1    /* Fill with color from palette */
  177.     #define FT_BITMAP    2    /* Fill with bitmap pattern    */
  178.     #define FT_OBJECTS    3    /* Fill with objects [see note 4]) */
  179.  
  180.     /* Various edge types */
  181.     #define ET_MASK        0x07    /* Mask for edge types */
  182.     #define ET_NONE        0x00    /* No edges        */
  183.     #define ET_SOLID    0x01    /* Solid lines        */
  184.     #define ET_DASH        0x02    /* Dashed lines        */
  185.     #define ET_DOT        0x03    /* Dotted lines        */
  186.     #define ET_DOT_DASH    0x04    /* dot-dash-dot-dash    */
  187.  
  188.     /* Arrow head types (NOT IMPLEMENTED) */
  189.     #define AT_MASK        0x18    /* Mask for arrow types */
  190.     #define AT_NONE        0x00    /* No arrowheads    */
  191.     #define AT_FIRST    0x08    /* Arrowhead on first vertex */
  192.     #define AT_LAST        0x10    /* Arrowhead on last vertex */
  193.     #define AT_BOTH        0x18    /* Arrows on first and last vertices */
  194.  
  195.     /* Join types */
  196.     #define JT_MASK        0x60    /* Mask for join types */
  197.     #define JT_MITER    0x20    /* Mitered join */
  198.     #define JT_BEVEL    0x40    /* Beveled join */
  199.     #define JT_ROUND    0x60    /* Round join */
  200.  
  201.     /* Unused bits */
  202.     #define ET_UNUSED    0x80    /* Should always be zero */
  203.  
  204.     typedef struct {
  205.         UBYTE    FillType;    /* One of FT_*, above    */
  206.         UBYTE    FillValue;    /* See note 3        */
  207.         UBYTE    EdgeType;    /* One of ET_*, above    */
  208.         UBYTE    EdgeValue;    /* Edge color index    */
  209.         USHORT    WhichLayer;    /* Which layer it's in    */
  210.         IEEE    EdgeThick;    /* Line width        */
  211.         IEEE    XMin, YMin,    /* Bounding box of obj. */
  212.             XMax, YMax;    /* including line width    */
  213.     } ObjHdr;    /* Size == 26 */
  214.  
  215.     struct POLYstruct {
  216.         LONG    ID;
  217.         LONG    Size;        /* 28 + 4*NumPoints */
  218.         ObjHdr    Styles;
  219.         SHORT    NumPoints;
  220.         IEEE    PolyPoints[NumPoints]; /* See note 2 */
  221.     };
  222.  
  223.  
  224.  
  225. GRUP (0x47525550)    /* Group */
  226.  
  227.     struct GROUPstruct {
  228.         LONG    ID;
  229.         LONG    Size;
  230.         ObjHdr    Info;        /* The style stuff isn't used */
  231.         SHORT    NumObjs;
  232.         UBYTE    GroupChunk[Size-28];    /* See note 4 */
  233.     };
  234.  
  235. XTRN (0x4554524E)    /* Externally controlled group */
  236.  
  237.     /* Flags for application callbacks */
  238.     #define X_MOVE        0x0001    /* 'appl optr move dx dy' */
  239.     #define    X_CLONE        0x0002    /* 'appl optr clone dx dy' */
  240.     #define    X_DELETE    0x0004    /* 'appl optr del' */
  241.     #define    X_ROTATE    0x0008    /* 'appl optr rot cx cy angle' */
  242.     #define    X_RESIZE    0x0010    /* 'appl optr size cx cy sx sy' */
  243.     #define X_CUT        0x0020    /* 'appl optr cut' */
  244.     #define X_COPY        0x0040    /* 'appl optr copy' */
  245.     #define X_PASTE        0x0080    /* 'appl optr paste x y' */
  246.  
  247.     struct XTRNstruct {
  248.         LONG    ID;
  249.         LONG    Size;
  250.         ObjHdr    Info;
  251.         SHORT    NumObjs;
  252.         SHORT    ApplCallBacks;        /* See definitions above */
  253.         SHORT    ApplNameLength;        /* Should ALWAYS be padded */
  254.         char    ApplName[ApplNameLength];
  255.         UBYTE    GroupChunk[Size-32-ApplNameLength];
  256.     };
  257.  
  258. TEXT (0x54455854)    /* A text string */
  259.  
  260.     struct TEXTstruct {
  261.         LONG    ID;
  262.         LONG    Size;        /* 34 + NumChars + NumChars%2 */
  263.         ObjHdr    Styles;
  264.         SHORT    WhichFont;    /* Index into font table */
  265.         IEEE    CharW, CharH,    /* W/H of an individual char    */
  266.             BaseX, BaseY,    /* Start of baseline */
  267.             Rotation;    /* Angle of text (in radians) */
  268.         SHORT    NumChars;
  269.         char    TextChars[NumChars];
  270.         UBYTE    PAD[NumChars%2];/* Padding to make Size even */
  271.     };
  272.  
  273.  
  274. NOTE 1:    IEEE represents a single-precision IEEE floating point number.
  275.     These numbers consist of 32 bits, arranged as follows:
  276.  
  277.     +---------------+---------------+---------------+---------------+
  278.     |s e e e e e e e|e m m m m m m m|m m m m m m m m|m m m m m m m m|
  279.     +---------------+---------------+---------------+---------------+
  280.      31          24 23           16 15            8 7             0
  281.     
  282.     where
  283.         s    is the sign bit of the entire number.  If this
  284.             bit is '1', the number is negative.  If '0',
  285.             the number is positive.
  286.         e    is the 8-bit exponent, in excess-127 form.
  287.             This is the power of two to which the mantissa
  288.             should be raised before using the number
  289.             in calculations.  Excess-127 means that
  290.             127 is added to the exponent before packing
  291.             it into the number. An exponent of 0 here means
  292.             the real exponent is actually -127.  A value
  293.             of 127 means the exponent is actually 0.
  294.             A value of 255 means the exponenent is actually
  295.             128.
  296.         m    is the 23-bit mantissa.  A leading binary
  297.             1 is assumed.  This means that the mantissa
  298.             may vary from 1.0000000 to 1.999999...
  299.     
  300.     The value 0.0000000 is represented by all bits being cleared
  301.     to zero.  Note that on many computers, the natural format
  302.     of single-precision floating point numbers *IS* IEEE.  This
  303.     is true of the Amiga.  There are system calls to transform
  304.     IEEE numbers to and from Motorola FFP numbers, should your
  305.     application require them.
  306.  
  307.  
  308. NOTE 2: The algorithm for drawing polygons is as follows:
  309.  
  310.     typedef union {
  311.         IEEE num;
  312.         LONG bits;
  313.     } Coord;
  314.  
  315.     #define INDICATOR    0xFFFFFFFF
  316.     #define IND_SPLINE    0x00000001
  317.     #define IND_MOVETO    0x00000002
  318.  
  319.     Coord    Temp0, Temp1;
  320.     int    FirstPoint, i, Increment;
  321.  
  322.     /* Initialize the path */
  323.     NewPath();
  324.     FirstPoint = 1;
  325.  
  326.     /* Draw the path */
  327.     i = 0;
  328.     while( i < NumPoints ) {
  329.         Temp0.num = PolyPoints[2*i];    Temp1.num = PolyPoints[2*i + 1];
  330.         if( Temp0.bits == INDICATOR ) {
  331.         /* Increment past the indicator */
  332.         Increment = 1;
  333.         if( Temp1.bits & IND_MOVETO ) {
  334.             /* Close and fill, if appropriate */
  335.             if( ID == CPLY ) {
  336.             FillPath();
  337.             }
  338.             else {
  339.             StrokePath();
  340.             }
  341.  
  342.             /* Set up the new path */
  343.             NewPath();
  344.             FirstPoint = 1;
  345.         }
  346.         if( Temp1.bits & IND_SPLINE ) {
  347.             /* The next 4 points are BSpline control points */
  348.             if( FirstPoint )
  349.             MoveTo(    PolyPoints[2*i + 2], PolyPoints[2*i + 3] );
  350.             else
  351.             LineTo(    PolyPoints[2*i + 2], PolyPoints[2*i + 3] );
  352.             SplineTo(    PolyPoints[2*i + 4], PolyPoints[2*i + 5],
  353.                 PolyPoints[2*i + 6], PolyPoints[2*i + 7],
  354.                 PolyPoints[2*i + 8], PolyPoints[2*i + 9] );
  355.             FirstPoint = 0;
  356.             /* Increment past the control points */
  357.             Increment += 4;
  358.         }
  359.         }
  360.         else {
  361.         if( FirstPoint )
  362.             MoveTo(    PolyPoints[2*i], PolyPoints[2*i + 1] );
  363.         else
  364.             LineTo(    PolyPoints[2*i], PolyPoints[2*i + 1] );
  365.         FirstPoint = 0;
  366.  
  367.         /* Increment past the last endpoint */
  368.         Increment = 1;
  369.         }
  370.  
  371.         /* Add the increment */
  372.         i += Increment;
  373.     }
  374.  
  375.     /* Close the last path */
  376.     if( ID == CPLY ) {
  377.         FillPath();
  378.     }
  379.     else {
  380.         StrokePath();
  381.     }
  382.  
  383.     Fills are according to the even-odd rule, so 'holes' in polygons
  384.     are easy to create (desirable in many cases).  Most objects produced
  385.     by ProVector (polygons, smoothed polygons, ellipses, rectangles,
  386.     and even the rendering of indivdiual characters in fonts) are
  387.     represented by this form.
  388.  
  389.  
  390. NOTE 3: The actual fill of one of these objects is done as follows:
  391.  
  392.     switch( FillType ) {
  393.     case FT_NONE :
  394.         SetNoFill();
  395.         break;
  396.     case FT_COLOR :
  397.         SetSolidFill( Palette[FillValue] );
  398.         break;
  399.     case FT_BITMAP :
  400.         SetSolidFill( Bitmaps[FillValue] );
  401.         break;
  402.     case FT_OBJECTS :
  403.         SetObjFill( FillPats[FillValue] );
  404.         break;
  405.     }
  406.  
  407.     Note also that on most pen plotters, FT_LINES and FT_NONE
  408.     are the only meaningful fills, and other fills may be
  409.     rendered as FT_NONE.
  410.  
  411.  
  412. NOTE 4: The  data in a FILL,  DSYM  or  GRUP chunk is a series of nested
  413.     object chunks.  All object chunks except DSYM, CMAP, PATT, FILL,
  414.     and FONT are allowed in a DSYM or GRUP.
  415.  
  416.  
  417.