48f6bb2003-09-14Andreas Sigfridsson /* || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information. */ #include "global.h"
d1e7842003-12-14Martin Nilsson #include "program.h" #include "module_support.h" #include "interpret.h" #include "builtin_functions.h" #include "mapping.h" #include "operators.h"
48f6bb2003-09-14Andreas Sigfridsson 
d1e7842003-12-14Martin Nilsson #include "image_machine.h"
48f6bb2003-09-14Andreas Sigfridsson #include "atari.h" extern struct program *image_program;
0893982013-02-02Henrik Grubbström (Grubba) /* Some format references: * * http://oreilly.com/www/centers/gff/formats/atari/index.htm * http://wiki.multimedia.cx/index.php?title=Neochrome * http://www.mediatel.lu/workshop/graphic/2D_fileformat/h_atari.html */
d5a7122003-09-14Martin Nilsson /*! @module Image
48f6bb2003-09-14Andreas Sigfridsson  */
d5a7122003-09-14Martin Nilsson /*! @module NEO
efb47c2003-12-15Martin Nilsson  *! Decodes images from the Atari image editor Neochrome.
48f6bb2003-09-14Andreas Sigfridsson  */
d5a7122003-09-14Martin Nilsson /*! @decl mapping _decode(string data)
efb47c2003-12-15Martin Nilsson  *! Low level decoding of the NEO file contents in @[data].
d5a7122003-09-14Martin Nilsson  *! @returns *! @mapping *! @member Image.Image "image" *! The decoded bitmap
efb47c2003-12-15Martin Nilsson  *! @member array(Image.Image) "images" *! Coler cycled images.
d5a7122003-09-14Martin Nilsson  *! @member string "filename" *! The filename stored into the file. *! @member int(0..15) "right_limit" *! @member int(0..15) "left_limit" *! The palette color range to be color cycled. *! @member int(0..255) "speed" *! The animation speed, expressed as the number of VBLs *! per animation frame. *! @member string "direction" *! Color cycling direction. Can be either @expr{"left"@} *! or @expr{"right"@}.
b2846c2003-12-14Martin Nilsson  *! @member array(array(int(0..255))) "palette" *! The palette to be used for color cycling.
d5a7122003-09-14Martin Nilsson  *! @endmapping */
48f6bb2003-09-14Andreas Sigfridsson void image_neo_f__decode(INT32 args) {
d1e7842003-12-14Martin Nilsson  unsigned int i, res, size = 0;
48f6bb2003-09-14Andreas Sigfridsson  struct atari_palette *pal=0; struct object *img; struct pike_string *s, *fn;
262cd82003-10-25Martin Nilsson  unsigned char *q;
7d60af2004-05-19Martin Nilsson  ONERROR err;
48f6bb2003-09-14Andreas Sigfridsson 
391ac52018-08-05Martin Nilsson  get_all_args( NULL, args, "%S", &s );
48f6bb2003-09-14Andreas Sigfridsson  if(s->len!=32128) Pike_error("This is not a NEO file (wrong file size).\n"); q = (unsigned char *)s->str; res = q[3]; if(q[2]!=0 || (res!=0 && res!=1 && res!=2)) Pike_error("This is not a NEO file (invalid resolution).\n"); /* Checks done... */
7131f22003-12-14Martin Nilsson  add_ref(s);
262cd82003-10-25Martin Nilsson  pop_n_elems(args);
48f6bb2003-09-14Andreas Sigfridsson  if(res==0) pal = decode_atari_palette(q+4, 16); else if(res==1) pal = decode_atari_palette(q+4, 4);
0893982013-02-02Henrik Grubbström (Grubba)  else if(res==2) pal = decode_atari_palette(q+4, 2);
7d60af2004-05-19Martin Nilsson  SET_ONERROR(err, free_atari_palette, pal);
48f6bb2003-09-14Andreas Sigfridsson 
5e9fc02015-08-18Per Hedbor  push_static_text("palette");
d1e7842003-12-14Martin Nilsson  for( i=0; i<pal->size; i++ ) { push_int(pal->colors[i].r); push_int(pal->colors[i].g); push_int(pal->colors[i].b); f_aggregate(3); } f_aggregate(pal->size); size += 2;
48f6bb2003-09-14Andreas Sigfridsson  img = decode_atari_screendump(q+128, res, pal);
5e9fc02015-08-18Per Hedbor  push_static_text("image");
48f6bb2003-09-14Andreas Sigfridsson  push_object(img); size += 2;
6981242003-09-14Andreas Sigfridsson  if(q[48]&128) {
efb47c2003-12-15Martin Nilsson  int rl, ll, i; rl = q[49]&0xf; ll = (q[49]&0xf0)>>4;
5e9fc02015-08-18Per Hedbor  push_static_text("right_limit");
efb47c2003-12-15Martin Nilsson  push_int( rl );
5e9fc02015-08-18Per Hedbor  push_static_text("left_limit");
efb47c2003-12-15Martin Nilsson  push_int( ll );
5e9fc02015-08-18Per Hedbor  push_static_text("speed");
6981242003-09-14Andreas Sigfridsson  push_int( q[51] );
5e9fc02015-08-18Per Hedbor  push_static_text("direction");
6981242003-09-14Andreas Sigfridsson  if( q[50]&128 )
5e9fc02015-08-18Per Hedbor  push_static_text("right");
48f6bb2003-09-14Andreas Sigfridsson  else
5e9fc02015-08-18Per Hedbor  push_static_text("left");
efb47c2003-12-15Martin Nilsson 
5e9fc02015-08-18Per Hedbor  push_static_text("images");
efb47c2003-12-15Martin Nilsson  for(i=0; i<rl-ll+1; i++) { if( q[50]&128 ) rotate_atari_palette(pal, ll, rl); else rotate_atari_palette(pal, rl, ll); img = decode_atari_screendump(q+128, res, pal); push_object(img); } f_aggregate(rl-ll+1); size += 10;
48f6bb2003-09-14Andreas Sigfridsson  }
7d60af2004-05-19Martin Nilsson  UNSET_ONERROR(err); free_atari_palette(pal);
efb47c2003-12-15Martin Nilsson  fn = make_shared_binary_string((const char *)q+36, 12);
5e9fc02015-08-18Per Hedbor  push_static_text("filename");
efb47c2003-12-15Martin Nilsson  push_string(fn); size += 2;
7131f22003-12-14Martin Nilsson  free_string(s);
48f6bb2003-09-14Andreas Sigfridsson  f_aggregate_mapping(size); }
d5a7122003-09-14Martin Nilsson /*! @decl Image.Image decode(string data) *! Decodes the image @[data] into an @[Image.Image] object. */
48f6bb2003-09-14Andreas Sigfridsson void image_neo_f_decode(INT32 args) { image_neo_f__decode(args);
5e9fc02015-08-18Per Hedbor  push_static_text("image");
48f6bb2003-09-14Andreas Sigfridsson  f_index(2); }
d5a7122003-09-14Martin Nilsson /*! @endmodule
48f6bb2003-09-14Andreas Sigfridsson  */
d5a7122003-09-14Martin Nilsson /*! @endmodule
48f6bb2003-09-14Andreas Sigfridsson  */
c9eefb2014-08-21Martin Nilsson void init_image_neo(void)
48f6bb2003-09-14Andreas Sigfridsson {
d1e7842003-12-14Martin Nilsson  ADD_FUNCTION("decode", image_neo_f_decode, tFunc(tStr,tObj), 0); ADD_FUNCTION("_decode", image_neo_f__decode, tFunc(tStr,tMap(tStr,tMix)), 0);
48f6bb2003-09-14Andreas Sigfridsson }
c9eefb2014-08-21Martin Nilsson void exit_image_neo(void)
48f6bb2003-09-14Andreas Sigfridsson { }