Table of Contents


libmaglo - MAKIchan Graphic (MAG) Loader Library


#include <maglo.h>
int MAGversion(void);
int MAGopen(MagImage *mag, const char *path);
int MAGclose(MagImage *mag);
long MAGcommentSize(MagImage *mag);
char * MAGcomment(MagImage *mag);
char * MAGmacType(MagImage *mag);
char * MAGuserName(MagImage *mag);
unsigned char MAGmacCode(MagImage *mag);
unsigned char MAGmacFlags(MagImage *mag);
unsigned char MAGscrModeCode(MagImage *mag);
int MAGscrMode200Lines(MagImage *mag);
int MAGscrModeNumColors(MagImage *mag);
int MAGpixelWidth(MagImage *mag);
int MAGscrModeIsDigital(MagImage *mag);
int MAGimageStartX(MagImage *mag);
int MAGimageStartY(MagImage *mag);
int MAGimageEndX(MagImage *mag);
int MAGimageEndY(MagImage *mag);
int MAGimageWidth(MagImage *mag);
int MAGimageHeight(MagImage *mag);
int MAGpalette(MagImage *mag, int index);
int MAGReader(MagImage *mag, MagReader *rd);
int MAGReaderDelete(MagReader *rd);
int MAGReaderNextPixel(MagReader *rd, unsigned char *buf);


The libmaglo library supports reading of the MAKIchan Graphic (MAG) format image files. The format is fairly straightforward, however is documented only in Japanese so there are little implementations available.

The MAG format was used in mid-1980s to mid-1990s to store and distribute screenshots and drawings. The format is suited for pattern-based graphics, and supports only 8/16/256-color images.

Libmaglo in a Nutshell

Call MAGopen with a pointer to an already-allocated storage and the path to the MAG file.

Call functions like MAGimageWidth or MAGscrMode200Lines to get information about the image.

Call MAGReader with pointer to the MAGimage and a pointer to an already-allocated storage.

Loop calling MAGReaderNextPixel to retrieve image data.

When entire image is transferred, call MAGReaderDelete and MAGclose sequentially to free memory regions.


The following program converts a MAG file to PPM format.

static int magtoppm(const char *from,FILE *to)
    MagImage m;
    MagReader rd;
    unsigned char pixel[4],palette[256][3];
    unsigned int i,width,height,pxlw,count;
    int err;
    /* Open MagImage */
        fprintf(stderr,"MAGopen error(code=%d)\n",err);
        return -1;
    /* Get info */
    /* copy palettes */
    for(i=0; i<MAGscrModeNumColors(&m); i++)
        unsigned int pal=MAGpalette(&m,i);
    /* print ppm header */
    fprintf(to,"P6\n%d %d\n255\n",width,height);
    /* create MagReader */
        fprintf(stderr,"MAGReader failed(code=%d)\n",err);
        return -1;
    /* copy dots */
        unsigned int k,valid_dots;
        for(k=0; k<valid_dots; k++)
    if(err<0 && err!=MAGERR_DATA_END)
        fprintf(stderr,"MAGReaderNextPixel returns error %d\n",err);
    /* cleanup MAGReader */
    /* cleanup MAGImage */
    return 0;


TOMARI Hisanobu <posco dot grubb at>


libmaglo is distributed as a public domain software.

Table of Contents