Picworks file format

From Atari Wiki
Revision as of 20:56, 8 February 2017 by Lp (talk | contribs) (New page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
Picworks    *.CP3

Always compressed 640x400 st high resolution images.

Files do not seem to have any resolution or bit plane info stored in them. The file
extension seems to be the only way to determine the contents.

Assuming the following:
uint8 *file=malloc(file_size); /* load file in array */
uint32 *bmap=malloc(32000);
decode_cp3(file, bmap);

/* ported to PureC from Picworks v1 GFABASIC source code */
/* Written by Lonny Pursell - placed in to Public Domain 2/8/2017 */
void decode_cp3(uint8 *data, uint32 *bmap) {
    register uint16 *dpeek, cnt, i, c;
    register uint32 *lpeek, src=0, dst=0, offset, tmp1, tmp2;

    dpeek = (uint16*)data;
    cnt = dpeek[src++];
    offset = 2L+2L+4L*(uint32)cnt;  /* offset into file */
    lpeek = (uint32*)&data[offset]; /* base of long table */
    offset = 0;                     /* reset index */

    for (c=0; c<cnt; c++) {
        src++;
        if (dpeek[src]) {
            for (i=0; i<dpeek[src]; i++) {
                bmap[dst++] = lpeek[offset++];
                bmap[dst++] = lpeek[offset++];
            }
        }
        src++;
        tmp1 = lpeek[offset++];
        tmp2 = lpeek[offset++];
        for (i=0; i<dpeek[src]; i++) {
            bmap[dst++] = tmp1;
            bmap[dst++] = tmp2;
        }
    }
    while (dst<8000L) { /* 32000/4 */
        bmap[dst++] = lpeek[offset++];
        bmap[dst++] = lpeek[offset++];
    }
}

Back to ST Picture Formats