pike.git / src / modules / Image / encodings / ilbm.c

version» Context lines:

pike.git/src/modules/Image/encodings/ilbm.c:4:   || for more information.   */      /*   **! module Image   **! submodule ILBM   **!   **! This submodule keep the ILBM encode/decode capabilities   **! of the <ref>Image</ref> module.   **! + **! ILBM is a subtype of the Interchange File Format (IFF) used for + **! storing picture data. ILBM stands for InterLeaved BitMap which + **! refers to the way the pictures are stored. The image data is + **! stored as a varying number of bitplanes, each storing one bit of + **! data for each pixel in the image. The format supports horizontal + **! and vertical RLE (Run Length Encoding) compression. + **! + **! The format also natively supports images using the somewhat + **! esoteric image modes of the original Commodore Amiga, such as HAM + **! (Hold And Modify) + **! + **! The format was commonly used for images on the Amiga. + **!   **! see also: Image, Image.Image, Image.Colortable   */   #include "global.h"      #include "stralloc.h"   #include "object.h"   #include "interpret.h"   #include "svalue.h"   #include "array.h"   #include "mapping.h"
pike.git/src/modules/Image/encodings/ilbm.c:90:   static void image_ilbm___decode(INT32 args)   {    unsigned char *s;    ptrdiff_t len;    struct pike_string *str;    struct mapping *m;    int n;    extern void parse_iff(char *, unsigned char *, ptrdiff_t,    struct mapping *, char *);    -  get_all_args("__decode", args, "%S", &str); +  get_all_args(NULL, args, "%S", &str);       s = (unsigned char *)str->str;    len = str->len;    pop_n_elems(args-1);       for(n=0; n<5; n++)    push_int(0);    push_mapping(m = allocate_mapping(4));       parse_iff("ILBM", s, len, m, "BODY");
pike.git/src/modules/Image/encodings/ilbm.c:290:    suse = unpackByteRun1(body, blen, line, rbyt, eplanes);    break;    }    body += suse;    if((blen -= suse)<0)    break;    planar2chunky(line, rbyt, bmhd->nPlanes, bmhd->w, (INT32 *)(cptr=cline));    if(alpha != NULL)    switch(bmhd->masking) {    case mskNone: -  memset((char *)adest, ~0, bmhd->w*sizeof(*adest)); +  memset(adest, ~0, bmhd->w*sizeof(*adest));    adest += bmhd->w;    break;    case mskHasMask:    {    int bit=0x80;    unsigned char *src = line+bmhd->nPlanes*rbyt;    unsigned char ss = *src++;    for(x=0; x<bmhd->w; x++) {    if(ss&bit) {    adest->r = adest->g = adest->b = 0xff;
pike.git/src/modules/Image/encodings/ilbm.c:434:    struct BMHD bmhd;    struct neo_colortable *ctable = NULL;    int n = 0;    INT32 camg = 0;       if(args>0 && TYPEOF(sp[-args]) == T_STRING) {    image_ilbm___decode(args);    args = 1;    }    -  get_all_args("_decode", args, "%a", &arr); +  get_all_args(NULL, args, "%a", &arr);       if(args>1)    pop_n_elems(args-1);       if(arr->size < 6 ||    TYPEOF(ITEM(arr)[2]) != T_STRING ||    ITEM(arr)[2].u.string->size_shift != 0 ||    TYPEOF(ITEM(arr)[5]) != T_STRING ||    ITEM(arr)[5].u.string->size_shift != 0)    Pike_error("Image.ILBM._decode: illegal argument\n");       parse_bmhd(&bmhd, STR0(ITEM(arr)[2].u.string), ITEM(arr)[2].u.string->len);    -  push_text("image"); +  push_static_text("image");    push_int(bmhd.w);    push_int(bmhd.h);    o=clone_object(image_program,2); -  img=(struct image*)get_storage(o,image_program); +  img=get_storage(o,image_program);    push_object(o);    n++;       if(bmhd.masking != mskNone) { -  push_text("alpha"); +  push_static_text("alpha");    push_int(bmhd.w);    push_int(bmhd.h);    o=clone_object(image_program,2); -  alpha=(struct image*)get_storage(o,image_program); +  alpha=get_storage(o,image_program);    push_object(o);    n++;    }       if(TYPEOF(ITEM(arr)[4]) == T_STRING &&    ITEM(arr)[4].u.string->size_shift == 0 &&    ITEM(arr)[4].u.string->len>=4) {    unsigned char *camgp = STR0(ITEM(arr)[4].u.string);    camg = (camgp[0]<<24)|(camgp[1]<<16)|(camgp[2]<<8)|camgp[3];    }       if((camg & CAMG_HAM)) { -  push_text("ham"); +  push_static_text("ham");    push_int(1);    n++;    }    if((camg & CAMG_EHB)) { -  push_text("ehb"); +  push_static_text("ehb");    push_int(1);    n++;    }       if(TYPEOF(ITEM(arr)[3]) == T_STRING &&    ITEM(arr)[3].u.string->size_shift == 0) {    unsigned char *pal = STR0(ITEM(arr)[3].u.string);    INT32 col, mcol = 1<<bmhd.nPlanes;    ptrdiff_t ncol = ITEM(arr)[3].u.string->len/3;    if((camg & CAMG_HAM))    mcol = (bmhd.nPlanes>6? 64:16);    else if((camg & CAMG_EHB))    mcol >>= 1;    if(ncol>mcol)    ncol = mcol; -  push_text("palette"); +  push_static_text("palette");    for(col=0; col<ncol; col++) {    push_int(*pal++);    push_int(*pal++);    push_int(*pal++);    f_aggregate(3);    }    if((camg & CAMG_EHB) && !(camg & CAMG_HAM)) {    for(col=0; col<ncol; col++) {    struct svalue *old = ITEM(sp[-ncol].u.array);    push_int(old[0].u.integer>>1);    push_int(old[1].u.integer>>1);    push_int(old[2].u.integer>>1);    f_aggregate(3);    }    ncol <<= 1;    } -  f_aggregate(DO_NOT_WARN((INT32)ncol)); +  f_aggregate((INT32)ncol);    push_object(clone_object(image_colortable_program,1)); -  ctable=(struct neo_colortable*)get_storage(sp[-1].u.object, +  ctable=get_storage(sp[-1].u.object,    image_colortable_program);    n++;    }       parse_body(&bmhd, STR0(ITEM(arr)[5].u.string), ITEM(arr)[5].u.string->len,    img, alpha, ctable, !!(camg & CAMG_HAM));       f_aggregate_mapping(2*n);    stack_swap();    pop_stack();
pike.git/src/modules/Image/encodings/ilbm.c:690:    }   }      static struct pike_string *make_body(struct BMHD *bmhd,    struct image *img, struct image *UNUSED(alpha),    struct neo_colortable *ctable)   {    unsigned int x, y;    int rbyt = ((bmhd->w+15)&~15)>>3;    int eplanes = (bmhd->masking == mskHasMask? bmhd->nPlanes+1:bmhd->nPlanes); -  unsigned char *line = alloca(rbyt*eplanes); +  unsigned char *line = xcalloc(rbyt, eplanes);    INT32 *cptr, *cline = alloca((rbyt<<3)*sizeof(INT32));    rgb_group *src = img->img;    struct string_builder bldr;    struct nct_dither dith;    void (*ctfunc)(rgb_group *, unsigned INT32 *, int,    struct neo_colortable *, struct nct_dither *, int) = NULL;       if(ctable != NULL) {    image_colortable_initiate_dither(ctable, &dith, bmhd->w);    ctfunc = image_colortable_index_32bit_function(ctable);    }    -  memset(line, 0, rbyt*eplanes); +     init_string_builder(&bldr, 0);    for(y=0; y<bmhd->h; y++) {    if(ctfunc != NULL) {    ctfunc(src, (unsigned INT32 *)cline, bmhd->w, ctable, &dith, bmhd->w);    src += bmhd->w;    } else {    cptr = cline;    for(x=0; x<bmhd->w; x++) {    /* ILBM-24 */    *cptr++ = (src->b<<16)|(src->g<<8)|src->r;
pike.git/src/modules/Image/encodings/ilbm.c:725:    }    }    chunky2planar(cline, bmhd->w, line, rbyt, bmhd->nPlanes);    if(bmhd->compression == cmpByteRun1)    packByteRun1(line, rbyt, eplanes, &bldr);    else    string_builder_binary_strcat(&bldr, (char *)line, rbyt*eplanes);    }    if(ctable != NULL)    image_colortable_free_dither(&dith); +  free(line);    return finish_string_builder(&bldr);   }      static void image_ilbm_encode(INT32 args)   {    struct object *imgo;    struct mapping *optm = NULL;    struct image *alpha = NULL, *img;    struct neo_colortable *ct = NULL;    struct pike_string *res;    struct BMHD bmhd;    int bpp, n = 0;       extern struct pike_string *make_iff(char *id, struct array *chunks);    -  get_all_args("encode", args, (args>1 && !UNSAFE_IS_ZERO(&sp[1-args])? "%o%m":"%o"), +  get_all_args(NULL, args, (args>1 && !UNSAFE_IS_ZERO(&sp[1-args])? "%o%m":"%o"),    &imgo, &optm);    -  if((img=(struct image*)get_storage(imgo, image_program))==NULL) +  if((img=get_storage(imgo, image_program))==NULL)    Pike_error("Image.ILBM.encode: illegal argument 1\n");       if(optm != NULL) {    struct svalue *s;    if((s = simple_mapping_string_lookup(optm, "alpha"))!=NULL && !UNSAFE_IS_ZERO(s))    if(TYPEOF(*s) != T_OBJECT || -  (alpha=(struct image*)get_storage(s->u.object, image_program))==NULL) +  (alpha=get_storage(s->u.object, image_program))==NULL)    Pike_error("Image.ILBM.encode: option (arg 2) \"alpha\" has illegal type\n");    if((s=simple_mapping_string_lookup(optm, "palette"))!=NULL && !UNSAFE_IS_ZERO(s))    if(TYPEOF(*s) != T_OBJECT || -  (ct=(struct neo_colortable*) +  (ct=    get_storage(s->u.object, image_colortable_program))==NULL)    Pike_error("Image.ILBM.encode: option (arg 2) \"palette\" has illegal type\n");    }       if (!img->img)    Pike_error("Image.ILBM.encode: no image\n");    if (alpha && !alpha->img)    Pike_error("Image.ILBM.encode: no alpha image\n");       if(ct && ct->type == NCT_NONE)