pike.git / src / modules / _Image_XFace / image_xface.c

version» Context lines:

pike.git/src/modules/_Image_XFace/image_xface.c:1:   /*   || 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"   #include "module.h"   #include "config.h"    -  - #if defined(HAVE_GMP2_GMP_H) && defined(HAVE_LIBGMP2) - #define USE_GMP2 - #else /* !HAVE_GMP2_GMP_H || !HAVE_LIBGMP2 */ - #if defined(HAVE_GMP_H) && defined(HAVE_LIBGMP) - #define USE_GMP - #endif /* HAVE_GMP_H && HAVE_LIBGMP */ - #endif /* HAVE_GMP2_GMP_H && HAVE_LIBGMP2 */ -  +    #include "pike_macros.h" - #include "object.h" +    #include "constants.h"   #include "interpret.h"   #include "svalue.h"   #include "threads.h"   #include "array.h"   #include "mapping.h"   #include "pike_error.h"   #include "stralloc.h" - #include "dynamic_buffer.h" + #include "buffer.h"   #include "operators.h"   #include "builtin_functions.h" -  + #include "pike_types.h"    - #if defined(USE_GMP) || defined(USE_GMP2) + /* Includes <gmp.h> */ + #include "bignum.h"      #include "../Image/image.h"    - /* Kludge for some compilers only defining __STDC__ in strict mode, -  * which leads to <gmp.h> using the wrong token concat method. -  */ - #if !defined(__STDC__) && defined(HAVE_ANSI_CONCAT) && defined(PIKE_MPN_PREFIX) - #define PIKE_LOW_MPN_CONCAT(x,y) x##y - #define PIKE_MPN_CONCAT(x,y) PIKE_LOW_MPN_CONCAT(x,y) - #define __MPN(x) PIKE_MPN_CONCAT(PIKE_MPN_PREFIX,x) - #endif /* !__STDC__ && HAVE_ANSI_CONCAT && PIKE_MPN_PREFIX */ -  - #undef _PROTO - #define _PROTO(x) x -  - #ifdef USE_GMP2 - #include <gmp2/gmp.h> - #else /* !USE_GMP2 */ - #include <gmp.h> - #endif /* USE_GMP2 */ -  - #endif /* USE_GMP || USE_GMP2 */ -  -  +    #define sp Pike_sp      #ifdef DYNAMIC_MODULE   static struct program *image_program=NULL;   #else   extern struct program *image_program;   /* Image module is probably linked static too. */   #endif       - #if defined(USE_GMP) || defined(USE_GMP2) -  +    /*   **! module Image   **! submodule XFace   **!   **! note   **! This module uses <tt>libgmp</tt>.   */         static const unsigned char tab[] = {
pike.git/src/modules/_Image_XFace/image_xface.c:341: Inside #if defined(USE_GMP) || defined(USE_GMP2)
   out++;    }   }      static struct pike_string *encodeface(rgb_group *in)   {    unsigned char face[48][48], newface[48][48];    int i, j;    unsigned long int n;    mpz_t val, dum; -  dynamic_buffer buf; +  struct byte_buffer buf;       for(i=0; i<48; i++)    for(j=0; j<48; j++) {    if(in->r || in->g || in->b)    face[i][j] = 0;    else    face[i][j] = 1;    in++;    }    memcpy(newface, face, sizeof(face));    xform((unsigned char *)face, (unsigned char *)newface);    mpz_init(val);    mpz_set_ui(val, 0);    for(i=2; i>=0; --i)    for(j=2; j>=0; --j)    comp(val, &newface[i*16][j*16], 16, 0); -  buf.s.str = NULL; -  initialize_buf( &buf ); +  buffer_init( &buf );    mpz_init(dum);    i = 0;    while(mpz_cmp_ui(val, 0)) {    n = mpz_fdiv_qr_ui(val, dum, val, 94); -  low_my_putchar( (char)(n+'!'), &buf ); +  buffer_add_char( &buf , (char)(n+'!'));    i++;    }    if (i==0) -  low_my_putchar( '!', &buf ); +  buffer_add_char( &buf , '!');    mpz_clear(dum);    mpz_clear(val); -  return low_free_buf( &buf ); +  return buffer_finish_pike_string( &buf );   }         /*   **! method object decode(string data)   **! method object decode(string data, mapping options)   **! Decodes an X-Face image.   **!   **! The <tt>options</tt> argument may be a mapping   **! containing zero options.   **!   */      static void image_xface_decode(INT32 args)   {    struct object *o;    struct image *img;       if(args<1 || TYPEOF(sp[-args]) != T_STRING) -  Pike_error("Image.XFace.decode: Illegal arguments\n"); +  Pike_error("Illegal arguments\n");       o=clone_object(image_program,0); -  img=(struct image*)get_storage(o,image_program); +  img=get_storage(o,image_program);    if (!img) Pike_error("image no image? foo?\n"); /* should never happen */    img->img=malloc(sizeof(rgb_group)*48*48);    if (!img->img) {    free_object(o); -  Pike_error("Image.XFace.decode: out of memory\n"); +  Pike_error("Out of memory\n");    }    img->xsize=48;    img->ysize=48;    decodeface(sp[-args].u.string->str, sp[-args].u.string->len, img->img);    pop_n_elems(args);    push_object(o);   }         /*
pike.git/src/modules/_Image_XFace/image_xface.c:429: Inside #if defined(USE_GMP) || defined(USE_GMP2)
  **!   */      static void image_xface_encode(INT32 args)   {    struct image *img=NULL;    struct pike_string *res;       if (args<1    || TYPEOF(sp[-args]) != T_OBJECT -  || !(img=(struct image*) -  get_storage(sp[-args].u.object,image_program)) +  || !(img=get_storage(sp[-args].u.object,image_program))    || (args>1 && TYPEOF(sp[1-args]) != T_MAPPING)) -  Pike_error("Image.XFace.encode: Illegal arguments\n"); +  Pike_error("Illegal arguments\n");       if (!img->img) -  Pike_error("Image.XFace.encode: Given image is empty.\n"); +  Pike_error("Given image is empty.\n");       if (img->xsize != 48 || img->ysize != 48) -  Pike_error("Image.XFace.encode: Wrong image dimensions (must be 48 by 48).\n"); +  Pike_error("Wrong image dimensions (must be 48 by 48).\n");       res = encodeface(img->img);       pop_n_elems(args);    if (res == NULL)    push_int(0);    else {    push_string(res);    f_reverse(1);    }
pike.git/src/modules/_Image_XFace/image_xface.c:476: Inside #if defined(USE_GMP) || defined(USE_GMP2)
  **!   **! note   **! There aint no such thing as a X-Face image header.   **! This stuff tells the characteristics of an X-Face image.   **!   */      static void image_xface_decode_header(INT32 args)   {    if(args<1 || TYPEOF(sp[-args]) != T_STRING) -  Pike_error("Image.XFace.decode: Illegal arguments\n"); +  Pike_error("Illegal arguments\n");       pop_n_elems(args);    -  push_text("type"); -  push_text("image/x-xface"); +  ref_push_string(literal_type_string); +  push_static_text("image/x-xface");    -  push_text("xsize"); +  push_static_text("xsize");    push_int(48);    -  push_text("ysize"); +  push_static_text("ysize");    push_int(48);       f_aggregate_mapping(6);   }       - #endif /* USE_GMP || USE_GMP2 */ -  -  +    /*** module init & exit & stuff *****************************************/      PIKE_MODULE_EXIT   {   }      PIKE_MODULE_INIT   { - #if defined(USE_GMP) || defined(USE_GMP2) +    #ifdef DYNAMIC_MODULE -  push_text("Image.Image"); +  push_static_text("Image.Image");    SAFE_APPLY_MASTER("resolv",1);    if (TYPEOF(sp[-1]) == T_PROGRAM)    image_program=program_from_svalue(sp-1);    pop_stack();   #endif /* DYNAMIC_MODULE */       if (image_program)    {    /* function(string,void|mapping(string:int):object) */    ADD_FUNCTION("decode",image_xface_decode,tFunc(tStr tOr(tVoid,tMap(tStr,tInt)),tObj),0);    /* function(string,void|mapping(string:int):object) */    ADD_FUNCTION("decode_header",image_xface_decode_header,tFunc(tStr tOr(tVoid,tMap(tStr,tInt)),tObj),0);    /* function(object,void|mapping(string:int):string) */    ADD_FUNCTION("encode",image_xface_encode,tFunc(tObj tOr(tVoid,tMap(tStr,tInt)),tStr),0);    } -  - #endif /* USE_GMP || USE_GMP2 */ -  +    }