[comp.sys.apollo] APOLLO.gmf format

idurand@geocub.greco-prog.fr (Irene Durand) (11/30/89)

		
	Here is a description of the problem I would like to solve :

	I am using a scanner DATACOPY 734 on an APOLLO station under AEGIS
(Unix like) with the CONTEXT software from MENTOR GRAPHICS.

	I would like to display the pictures from the scanner on my PC
screen . The scanner is able to save the pictures in the APOLLO.gmf format
(Graphic Map File). Once I have transferred this binary file to my PC, the
problem is that I don't get the format description of this file.

	Has somebody got the same problem? Where could I get this format?

			Thank you.....

krowitz%richter@UMIX.CC.UMICH.EDU (David Krowitz) (11/30/89)

You can write a relatively simple Fortran program on your Apollo
to solve this problem. Use the GMF_$ calls to open the bitmap file
and copy it into a GPR bitmap. Then use the GPR_$READ_PIXELS call
to read the pixel values into a memory array and use the standard
Fortran (or C) I/O calls to write the array out in whatever format
you like. I've got a simple Fortran program that does this for
GPR bitmaps which I've included below. Just change the code that
reads in the GPR bitmap to use GMF calls.


 -- David Krowitz

krowitz@richter.mit.edu   (18.83.0.109)
krowitz%richter.mit.edu@eddie.mit.edu
krowitz%richter.mit.edu@mitvma.bitnet
(in order of decreasing preference)
===================================cut here=========================
{*****************************************************************************
 *****                                                                   *****
 *****                            GPRDUMP.PAS                            *****
 *****                                                                   *****
 *****      Program to read GPR bitmap files and dump the color map and  *****
 *****      the contents of the bitmap into a unformatted binary data    *****
 *****      file which can be read by a Fortran program.                 *****
 *****                                                                   *****
 *****                            Version 2                              *****
 *****                  David M. Krowitz September 9, 1988.              *****
 *****                                                                   *****
 *****      Copyright (c) 1988                                           *****
 *****      David M. Krowitz                                             *****
 *****      Massachusetts Institute of Technology                        *****
 *****      Department of Earth, Atmospheric, and Planetary Sciences     *****
 *****************************************************************************
}

PROGRAM GPR_DUMP;
%NOLIST;
%INCLUDE '/sys/ins/base.ins.pas';
%INCLUDE '/sys/ins/error.ins.pas';
%INCLUDE '/sys/ins/gpr.ins.pas';
%INCLUDE '/sys/ins/ios.ins.pas';
%INCLUDE '/sys/ins/pgm.ins.pas';
%INCLUDE '/sys/ins/type_uids.ins.pas';
%LIST;



CONST

{Program version number - should be same as in file header above}

    version_number = 2;


TYPE

    byte = 0..255;

    color_map_entry = PACKED RECORD
                        unused:     byte;
                        red:        byte;
                        green:      byte;
                        blue:       byte;
                      END;

VAR
    infile:             ARRAY[1..80] OF CHAR;
    infile_len:         PINTEGER;
    outfile:            ARRAY[1..80] OF CHAR;
    outfile_len:        PINTEGER;
    out:                IOS_$ID_T;

    hi_plane:           GPR_$PLANE_T;
    bitmap:             GPR_$BITMAP_DESC_T;
    window:             GPR_$WINDOW_T;

    file_bm:            GPR_$BITMAP_DESC_T;                     { Bitmap descriptor for GPR bitmap file }
    file_cm:            GPR_$COLOR_VECTOR_T;                    { Color map for the GPR bitmap file }
    attribs:            GPR_$ATTRIBUTE_DESC_T;
    version:            GPR_$VERSION_T;
    header:             GPR_$BMF_GROUP_HEADER_ARRAY_T;
    groups:             INTEGER;
    created:            BOOLEAN;

    i,j:                LINTEGER;                               { Counters }
    pixel_size:         PINTEGER;                               { Size of bitmap pixels (1 to 8, or 24) }
    pixels_24:          ARRAY[1..4096] OF GPR_$PIXEL_VALUE_T;   { Pixel values read from bitmap }
    pixels_8:           PACKED ARRAY[1..4096] OF CHAR;          { 8-bit pixels from bitmap }
    source:             GPR_$WINDOW_T;                          { Window from which pixels are being read }
    status:             STATUS_$T;



BEGIN


    {Type initial greetings to user.}

    WRITELN ('This is GPRDUMP Version ',version_number:-1,'.');
    WRITELN;


    {Get the names of the input and output files.}

    IF (PGM_$GET_ARG (1, infile, status, SIZEOF(infile)) <> 0) THEN BEGIN
        infile_len := PGM_$GET_ARG (1, infile, status, SIZEOF(infile));
        IF (status.all <> STATUS_$OK) THEN BEGIN
            WRITELN ('**** GPRDUMP: Error - argument 1 exists, but bad status? ****');
            PGM_$EXIT;
        END;
    END
    ELSE BEGIN
        WRITE ('Enter name of GPR bitmap file for input: ');
        READLN (infile);
        infile_len := SIZEOF(infile);
    END;

    IF (PGM_$GET_ARG (2, outfile, status, SIZEOF(outfile)) <> 0) THEN BEGIN
        outfile_len := PGM_$GET_ARG (2, outfile, status, SIZEOF(outfile));
        IF (status.all <> STATUS_$OK) THEN BEGIN
            WRITELN ('**** GPRDUMP: Error - argument 2 exists, but bad status? ****');
            PGM_$EXIT;
        END;
    END
    ELSE BEGIN
        WRITE ('Enter name of unformatted binary file for output: ');
        READLN (outfile);
        outfile_len := SIZEOF(outfile);
    END;


    { Initialize the GPR library with a 1x1 dummy bitmap in main memory }

    WITH window.window_size DO BEGIN
        x_size := 1;
        y_size := 1;
    END;
    GPR_$INIT (gpr_$no_display, 0, window.window_size, 0, bitmap, status);
    IF (status.all <> STATUS_$OK) THEN BEGIN
        WRITELN ('**** GPRDUMP: Error - could not initialize GPR library ****');
        ERROR_$PRINT (status);
        PGM_$EXIT;
    END;


    { Open the output file }

    IOS_$CREATE (outfile, outfile_len, RECORDS_$UID, IOS_$RECREATE_MODE, [IOS_$WRITE_OPT], out, status);
    IF (status.all <> STATUS_$OK) THEN BEGIN
        WRITELN ('**** GPRDUMP: Error - could not open output file ****');
        ERROR_$PRINT (status);
        PGM_$EXIT;
    END;


    { Get the GPR bitmap into memory along with it's color map }

    GPR_$ALLOCATE_ATTRIBUTE_BLOCK (attribs, status);
    GPR_$OPEN_BITMAP_FILE (GPR_$WRITE, infile, infile_len, version, window.window_size, groups, header, attribs, file_bm, created, status);
    IF (status.all <> STATUS_$OK) THEN BEGIN
        WRITELN ('**** GPRDUMP: Error - could not open GPR bitmap file ****');
        ERROR_$PRINT (status);
        PGM_$EXIT;
    END;

    GPR_$INQ_BITMAP_FILE_COLOR_MAP (file_bm, 0, 256, file_cm, status);
    IF (status.all <> STATUS_$OK) THEN BEGIN
        WRITELN ('**** GPRDUMP: Error - could not read color map for bitmap file ****');
        ERROR_$PRINT (STATUS);
        PGM_$EXIT;
    END;


    { Set the current bitmap to be the GPR bitmap file }

    GPR_$SET_BITMAP (file_bm, status);
    IF (status.all <> STATUS_$OK) THEN BEGIN
        WRITELN ('**** GPRDUMP: Error - could not make bitmap file the current bitmap ****');
        ERROR_$PRINT (STATUS);
        PGM_$EXIT;
    END;


    { Calculate pixel size from the number of bitmap sections and the per-section pixel size }

    pixel_size := header[0].n_sects*header[0].pixel_size;


    { Output the size of the bitmap }

    WRITELN ('Bitmap size is: ', window.window_size.x_size:-1, ' by ', window.window_size.y_size:-1);
    WRITELN ('Pixel size is:  ', pixel_size:-1);
    IOS_$PUT (out, [IOS_$PARTIAL_RECORD_OPT], window.window_size, SIZEOF(window.window_size), status);
    IF (status.all <> STATUS_$OK) THEN BEGIN
        WRITELN ('**** GPRDUMP: Error - could not write bitmap size to output file header record ****');
        ERROR_$PRINT (STATUS);
        PGM_$EXIT;
    END;
    IOS_$PUT (out, [], pixel_size, SIZEOF(pixel_size), status);
    IF (status.all <> STATUS_$OK) THEN BEGIN
        WRITELN ('**** GPRDUMP: Error - could not write pixel size to output file header record ****');
        ERROR_$PRINT (STATUS);
        PGM_$EXIT;
    END;


    { Output the color map entries if the bitmap is a psuedo-color (1 to 8 planes) bitmap }

    IF (pixel_size <= 8) THEN BEGIN
        for i := 0 to 255 do writeln (file_cm[i]);
        IOS_$PUT (out, [], file_cm, SIZEOF(file_cm), status);
        IF (status.all <> STATUS_$OK) THEN BEGIN
            WRITELN ('**** GPRDUMP: Error - could not write GPR color map to output file ****');
            ERROR_$PRINT (STATUS);
            PGM_$EXIT;
        END;
    END;


    { Write out the bitmap, one line per record }

    source.window_size.x_size := window.window_size.x_size;
    source.window_size.y_size := 1;
    source.window_base.x_coord := window.window_base.x_coord;
    source.window_base.y_coord := window.window_base.y_coord;

    FOR i := 1 TO window.window_size.y_size DO BEGIN

        GPR_$READ_PIXELS (source, pixels_24, status);
        IF (status.all <> STATUS_$OK) THEN BEGIN
            WRITELN ('**** GPRDUMP: Error - could not read GPR pixel values for line ',i:-1,' ****');
            ERROR_$PRINT (STATUS);
            PGM_$EXIT;
        END;

        FOR j := 1 TO source.window_size.x_size DO BEGIN
            pixels_8[j] := CHR(pixels_24[j]);
            IF (pixels_24[j] > 255) THEN WRITELN ('Warning - pixel value greater than 8-bits');
        END;

        IOS_$PUT (out, [], pixels_8, source.window_size.x_size, status);
        IF (status.all <> STATUS_$OK) THEN BEGIN
            WRITELN ('**** GPRDUMP: Error - could not write pixel values into output file for line ',i:-1,' ****');
            ERROR_$PRINT (STATUS);
            PGM_$EXIT;
        END;

        source.window_base.y_coord := source.window_base.y_coord+1;

    END;


    { Close up the output file and cleanup }

    IOS_$CLOSE (out, status);
    IF (status.all <> STATUS_$OK) THEN BEGIN
        WRITELN ('**** GPRDUMP: Error - could not close output file ****');
        ERROR_$PRINT (STATUS);
        PGM_$EXIT;
    END;


END.

lampi@pnet02.gryphon.com (Michael Lampi) (12/02/89)

The Apollo Graphics Map File format (GMF) is a binary streams file. There are
4 kinds of records: header records, scanline group records, scanline data
records and end-of-bitmap records.

Each occurrence of a header record means the beginning of a separate bitmap.
The file must have a header record as the first record in the file. Following
the header record of a bitmap is a series of scanline group records and
scanline data records intermixed. At the end of a bitmap is an end-of-bitmap
record.

The header record has the following 16-bit fields:
    0001      means 'this is a header record'
    0001      version number of this file format
       x      x dimension of bitmap in bits
       y      y dimension of bitmap in bits
     bpi      resolution of data in bits per inch, to whatever degree of
              accuracy is feasibe. (0 means each bit is one dot regardless of
              dot size of the output device.)

The scanline group record has the following fields, both 16-bit:
    0002      means "this is a scanline group record"
       n      number of scanline records following

A scanline group record signals that the following n records are not to be
interpreted as anything but binary data for the bitmap (scanline data
records).

A scanline data record consists of bits of data for one scanline. Each record
is a simple string of bytes, with the frirst byte in a record being the
leftmost of the scanline and the first bit in a byte being the leftmost of the
byte. Records that do not contain enough bits to equal the x dimension are to
be interpreted as padded on the right with zero bits. Records exceeding the x
dimension of the bitmap are truncated at the xth bit.

If the end-of-bitmap record is encountered before the expected number of
scanlines (y dimension) is read, the remaining scanlines are assumed to
contain zeroes. Extra scanlines are ignored.

One bits are to be printed in black, zero bits are to be printed in white.

The end-of-bitmap record has the following format:
    0003       means "this is an end-of-bitmap record"

-------The above was copied from a memo from Apollo a long time ago....

Michael Lampi               MDL Corporation   213/782-7888   fax 213/782-7927

UUCP: {ames!elroy, <routing site>}!gryphon!pnet02!lampi
INET: lampi@pnet02.gryphon.com
"My opinions are that of my corporation!"