diff --git a/.gitattributes b/.gitattributes index 98ebc1e4da5261649dbeb185152fa6118383bccc..8ba6b6e091206defbf3f707b3bd415e6d406f7ff 100644 --- a/.gitattributes +++ b/.gitattributes @@ -178,11 +178,13 @@ testfont binary /src/modules/Image/encodings/Makefile.in foreign_ident /src/modules/Image/encodings/_xpm.c foreign_ident /src/modules/Image/encodings/any.c foreign_ident +/src/modules/Image/encodings/avs.c foreign_ident /src/modules/Image/encodings/bmp.c foreign_ident /src/modules/Image/encodings/configure.in foreign_ident /src/modules/Image/encodings/gif.c foreign_ident /src/modules/Image/encodings/gif_lzw.c foreign_ident /src/modules/Image/encodings/gif_lzw.h foreign_ident +/src/modules/Image/encodings/hrz.c foreign_ident /src/modules/Image/encodings/iff.c foreign_ident /src/modules/Image/encodings/ilbm.c foreign_ident /src/modules/Image/encodings/pcx.c foreign_ident diff --git a/src/modules/Image/encodings/Makefile.in b/src/modules/Image/encodings/Makefile.in index e2afbbd41ecd03e491e18719800be96dab5a40eb..e704488dfb69764f136f6bca34c4fa1cf7568e74 100644 --- a/src/modules/Image/encodings/Makefile.in +++ b/src/modules/Image/encodings/Makefile.in @@ -1,7 +1,7 @@ -# $Id: Makefile.in,v 1.23 1999/04/11 07:21:22 per Exp $ +# $Id: Makefile.in,v 1.24 1999/04/12 10:30:02 per Exp $ SRCDIR=@srcdir@ VPATH=@srcdir@:@srcdir@/../../..:../../.. -OBJS = gif.o gif_lzw.o pnm.o x.o xwd.o png.o any.o bmp.o tga.o pcx.o xbm.o _xpm.o ilbm.o iff.o xcf.o +OBJS = gif.o gif_lzw.o pnm.o x.o xwd.o png.o any.o bmp.o tga.o pcx.o xbm.o _xpm.o ilbm.o iff.o xcf.o hrz.o avs.o @SET_MAKE@ diff --git a/src/modules/Image/encodings/avs.c b/src/modules/Image/encodings/avs.c new file mode 100644 index 0000000000000000000000000000000000000000..d7df467cc8bcf83199d56535e78a883a7d1d4311 --- /dev/null +++ b/src/modules/Image/encodings/avs.c @@ -0,0 +1,159 @@ +#include "global.h" + +#include <math.h> +#include <ctype.h> +#include <netinet/in.h> + +#include "stralloc.h" +RCSID("$Id: avs.c,v 1.1 1999/04/12 10:30:03 per Exp $"); +#include "pike_macros.h" +#include "object.h" +#include "constants.h" +#include "interpret.h" +#include "svalue.h" +#include "threads.h" +#include "array.h" +#include "error.h" + + +#include "image.h" +#include "builtin_functions.h" +#include "module_support.h" + +extern struct program *image_program; + +/* +**! module Image +**! submodule AVS +**! +*/ + +/* +**! method object decode(string data) +**! method mapping _decode(string data) +**! method string encode(object image) +**! +**! Handle encoding and decoding of AVS-X images. +**! AVS is rather trivial, and not really useful, but: +**! +**! An AVS file is a raw (uncompressed) 24 bit image file with alpha. +**! The alpha channel is 8 bit, and there is no separate alpha for r, +**! g and b. +*/ + +struct program *image_encoding_avs_program; + +void image_avs_f__decode(INT32 args) +{ + extern void f_aggregate_mapping(INT32 args); + struct object *io, *ao; + struct pike_string *s; + int c; + unsigned int w, h; + unsigned char *q; + get_all_args( "decode", args, "%S", &s); + + q = s->str; + w = q[0]<<24 | q[1]<<16 | q[2]<<8 | q[3]; + h = q[4]<<24 | q[5]<<16 | q[6]<<8 | q[7]; + + if( w <= 0 || h <= 0) + error("This is not an AVS file (w=%d; h=%d)\n", w, h); + + if(w*h*4+8 > s->len) + error("This is not an AVS file (w=%d; h=%d; s=%d)\n",w,h,s->len); + + push_int( w ); + push_int( h ); + io = clone_object( image_program, 2); + push_int( w ); + push_int( h ); + ao = clone_object( image_program, 2); + + for(c=0; c<w*h; c++) + { + rgb_group pix, apix; + apix.r = apix.g = apix.b = q[c*4+8]; + pix.r = q[c*4+9]; + pix.g = q[c*4+10]; + pix.b = q[c*4+11]; + ((struct image *)io->storage)->img[c] = pix; + ((struct image *)ao->storage)->img[c] = apix; + } + pop_n_elems(args); + push_constant_text("image"); + push_object( io ); + push_constant_text("alpha"); + push_object( ao ); + f_aggregate_mapping( 4 ); +} + +void image_avs_f_decode(INT32 args) +{ + extern void f_index(INT32 args); + image_avs_f__decode(args); + push_constant_text("image"); + f_index(2); +} + +void image_avs_f_encode(INT32 args ) +{ + struct object *io, *ao=NULL; + struct image *i, *a=NULL; + rgb_group *is,*as=NULL; + struct pike_string *s; + int x,y; + unsigned int *q; + rgb_group apix = {255, 255, 255}; + get_all_args( "encode", args, "%o", &io); + + if(!(i = (struct image *)get_storage( io, image_program))) + error("Wrong argument 1 to Image.AVS.encode\n"); + + s = begin_shared_string( i->xsize*i->ysize*4+8 ); + MEMSET(s->str, 0, s->len ); + + q = (int *)s->str; + *(q++) = htonl( i->xsize ); + *(q++) = htonl( i->ysize ); + + is = i->img; + if(a) as = a->img; + + for(y=0; y<i->ysize; y++) + for(x=0; x<i->xsize; x++) + { + register int rv = 0; + rgb_group pix = *(is++); + if(as) apix = *(as++); + rv = ((apix.g<<24)|(pix.r<<16)|(pix.g<<8)|pix.b); + *(q++) = htonl(rv); + } + pop_n_elems(args); + push_string( end_shared_string(s) ); +} + +void init_image_avs() +{ + start_new_program(); + add_function( "decode", image_avs_f_decode, "function(string:object)", 0); + add_function( "_decode", image_avs_f__decode, "function(string:mapping)", 0); + add_function( "encode", image_avs_f_encode, "function(object:string)", 0); + image_encoding_avs_program=end_program(); + push_object(clone_object(image_encoding_avs_program,0)); + { + struct pike_string *s=make_shared_string("AVS"); + add_constant(s,sp-1,0); + free_string(s); + } + pop_stack(); +} + +void exit_image_avs() +{ + if(image_encoding_avs_program) + { + free_program(image_encoding_avs_program); + image_encoding_avs_program=NULL; + } +} diff --git a/src/modules/Image/encodings/hrz.c b/src/modules/Image/encodings/hrz.c new file mode 100644 index 0000000000000000000000000000000000000000..a926aa92d709ca8505bdc34b667eb6c6dc0cb161 --- /dev/null +++ b/src/modules/Image/encodings/hrz.c @@ -0,0 +1,130 @@ +#include "global.h" + +#include <math.h> +#include <ctype.h> + +#include "stralloc.h" +RCSID("$Id: hrz.c,v 1.1 1999/04/12 10:30:03 per Exp $"); +#include "pike_macros.h" +#include "object.h" +#include "constants.h" +#include "interpret.h" +#include "svalue.h" +#include "threads.h" +#include "array.h" +#include "error.h" + + +#include "image.h" +#include "builtin_functions.h" +#include "module_support.h" + +extern struct program *image_program; + +/* +**! module Image +**! submodule HRZ +**! +*/ + +/* +**! method object decode(string data) +**! method mapping _decode(string data) +**! method string encode(object image) +**! +**! Handle encoding and decoding of HRZ images. +**! HRZ is rather trivial, and not really useful, but: +**! +**! The HRZ file is always 256x240 with RGB values from 0 to 63. +**! No compression, no header, just the raw RGB data. +**! HRZ is (was?) used for amatuer radio slow-scan TV. +*/ + +struct program *image_encoding_hrz_program; + +void image_hrz_f_decode(INT32 args) +{ + struct object *io; + struct pike_string *s; + int c; + get_all_args( "decode", args, "%S", &s); + + if(s->len != 256*240*3) error("This is not a HRZ file\n"); + + push_int( 256 ); + push_int( 240 ); + io = clone_object( image_program, 2); + + for(c=0; c<256*240; c++) + { + rgb_group pix; + pix.r = s->str[c*3]<<2 | s->str[c*3]>>4; + pix.g = s->str[c*3+1]<<2 | s->str[c*3]>>4; + pix.b = s->str[c*3+2]<<2 | s->str[c*3]>>4; + ((struct image *)io->storage)->img[c] = pix; + } + pop_n_elems(args); + push_object( io ); +} + +void image_hrz_f__decode(INT32 args) +{ + image_hrz_f_decode(args); + push_constant_text("image"); + stack_swap(); + f_aggregate_mapping(2); +} + +void image_hrz_f_encode(INT32 args ) +{ + struct object *io; + struct image *i; + struct pike_string *s; + int x,y; + get_all_args( "encode", args, "%o", &io); + + if(!(i = (struct image *)get_storage( io, image_program))) + error("Wrong argument 1 to Image.HRZ.encode\n"); + + s = begin_shared_string( 256*240*3 ); + + MEMSET(s->str, 0, s->len ); + for(y=0; y<240; y++) + if(y < i->ysize) + for(x=0; x<256; x++) + if(x < i->xsize) + { + int in = (x + y*256)*3; + rgb_group pix = i->img[y*i->xsize+x]; + s->str[in+0] = pix.r >> 2; + s->str[in+1] = pix.g >> 2; + s->str[in+2] = pix.b >> 2; + } + pop_n_elems(args); + push_string( end_shared_string(s) ); +} + +void init_image_hrz() +{ + start_new_program(); + add_function( "decode", image_hrz_f_decode, "function(string:object)", 0); + add_function( "_decode", image_hrz_f__decode, "function(string:mapping)", 0); + add_function( "encode", image_hrz_f_encode, "function(object:string)", 0); + image_encoding_hrz_program=end_program(); + push_object(clone_object(image_encoding_hrz_program,0)); + { + struct pike_string *s=make_shared_string("HRZ"); + add_constant(s,sp-1,0); + free_string(s); + } + pop_stack(); +} + +void exit_image_hrz() +{ + if(image_encoding_hrz_program) + { + free_program(image_encoding_hrz_program); + image_encoding_hrz_program=NULL; + } +} diff --git a/src/modules/Image/image.c b/src/modules/Image/image.c index 1ce59ba78695c2887e507ef6df5057ed84687a7a..b0f41fa72ebd744e881118cb0f25d37bfa961f10 100644 --- a/src/modules/Image/image.c +++ b/src/modules/Image/image.c @@ -1,9 +1,9 @@ -/* $Id: image.c,v 1.123 1999/04/11 22:37:26 per Exp $ */ +/* $Id: image.c,v 1.124 1999/04/12 10:30:14 per Exp $ */ /* **! module Image **! note -**! $Id: image.c,v 1.123 1999/04/11 22:37:26 per Exp $ +**! $Id: image.c,v 1.124 1999/04/12 10:30:14 per Exp $ **! class image **! **! The main object of the <ref>Image</ref> module, this object @@ -97,7 +97,7 @@ #include "stralloc.h" #include "global.h" -RCSID("$Id: image.c,v 1.123 1999/04/11 22:37:26 per Exp $"); +RCSID("$Id: image.c,v 1.124 1999/04/12 10:30:14 per Exp $"); #include "pike_macros.h" #include "object.h" #include "constants.h" @@ -3490,6 +3490,10 @@ extern void exit_image_ilbm(void); extern void init_image_ilbm(void); extern void init_image_xcf(void); extern void exit_image_xcf(void); +extern void init_image_hrz(void); +extern void exit_image_hrz(void); +extern void init_image_avs(void); +extern void exit_image_avs(void); /* dynamic encoders (dependent on other modules, loaded dynamically) */ @@ -3503,6 +3507,7 @@ static struct pike_string *magic_XCF, *magic_TIFF, *magic_PNG, + *magic_PS, *magic_TTF; static struct object *png_object=NULL; @@ -3570,6 +3575,14 @@ static void image_index_magic(INT32 args) SAFE_APPLY_MASTER("resolv",2); return; } + else if (sp[-1].u.string==magic_PS) + { + pop_stack(); + push_string(make_shared_string("_Image_PS")); + push_int(0); + SAFE_APPLY_MASTER("resolv",2); + return; + } ref_push_object(THISOBJ); tmp=sp[-1], sp[-1]=sp[-2], sp[-2]=tmp; @@ -3582,6 +3595,7 @@ void pike_module_init(void) magic_JPEG=make_shared_string("JPEG"); magic_TTF=make_shared_string("TTF"); + magic_PS=make_shared_string("PS"); magic_PNG=make_shared_string("PNG"); magic_XFace=make_shared_string("XFace"); magic_XPM=make_shared_string("XPM"); @@ -3886,6 +3900,8 @@ void pike_module_init(void) init_image_ilbm(); init_image_xcf(); init_image_x(); + init_image_hrz(); + init_image_avs(); } void pike_module_exit(void) @@ -3910,6 +3926,8 @@ void pike_module_exit(void) exit_image_xbm(); exit_image_ilbm(); exit_image_xcf(); + exit_image_hrz(); + exit_image_avs(); if (png_object) { free_object(png_object); @@ -3925,6 +3943,7 @@ void pike_module_exit(void) free_string(magic_XCF); free_string(magic_TIFF); free_string(magic_TTF); + free_string(magic_PS); }