Skip to content
Snippets Groups Projects
Select Git revision
  • 0c183a96b11538464cb16a60fa27c8b2a0d4653a
  • master default protected
  • streebog
  • gost28147
  • master-updates
  • ed448
  • shake256
  • curve448
  • ecc-sqrt
  • gosthash94cp
  • cmac64
  • block16-refactor
  • siv-mode
  • cmac-layout
  • delete-des-compat
  • delete-rsa_blind
  • aes-struct-layout
  • release-3.4-fixes
  • struct-layout
  • attribute-deprecated
  • rename-data-symbols
  • nettle_3.5.1_release_20190627
  • nettle_3.5_release_20190626
  • nettle_3.5rc1
  • nettle_3.4.1_release_20181204
  • nettle_3.4.1rc1
  • nettle_3.4_release_20171119
  • nettle_3.4rc2
  • nettle_3.4rc1
  • nettle_3.3_release_20161001
  • nettle_3.2_release_20160128
  • nettle_3.1.1_release_20150424
  • nettle_3.1_release_20150407
  • nettle_3.1rc3
  • nettle_3.1rc2
  • nettle_3.1rc1
  • nettle_3.0_release_20140607
  • nettle_2.7.1_release_20130528
  • nettle_2.7_release_20130424
  • nettle_2.6_release_20130116
  • nettle_2.5_release_20120707
41 results

nettle-openssl.c

Blame
  • Forked from Nettle / nettle
    Source project has a limited visibility.
    any.c 3.82 KiB
    /* $Id: any.c,v 1.10 1999/05/28 13:30:51 mirar Exp $ */
    
    /*
    **! module Image
    **! note
    **!	$Id: any.c,v 1.10 1999/05/28 13:30:51 mirar Exp $
    **! submodule ANY
    **!
    **!	This method calls the other decoding methods
    **!	and has some heuristics for what type of image
    **!	this is.
    **!
    **!	Methods:
    **!	<ref>decode</ref>, <ref>decode_alpha</ref>,
    **!	<ref>_decode</ref>
    **!
    **! see also: Image
    **!
    */
    #include "global.h"
    
    #include <math.h>
    #include <ctype.h>
    
    #include "stralloc.h"
    RCSID("$Id: any.c,v 1.10 1999/05/28 13:30:51 mirar Exp $");
    #include "pike_macros.h"
    #include "operators.h"
    #include "builtin_functions.h"
    #include "object.h"
    #include "constants.h"
    #include "interpret.h"
    #include "svalue.h"
    #include "threads.h"
    #include "array.h"
    #include "error.h"
    #include "threads.h"
    
    #include "image.h"
    
    void image_gif__decode(INT32 args);
    void image_pnm_decode(INT32 args);
    void image_xwd__decode(INT32 args);
    
    /*
    **! method mapping _decode(string data)
    **! method object decode(string data)
    **! method object decode_alpha(string data)
    **!	Tries heuristics to find the correct method 
    **!	of decoding the data, then calls that method.
    **!
    **! 	The result of _decode() is a mapping that contains
    **!	<pre>
    **!		"type":image data type (ie, "image/jpeg" or similar)
    **!		"image":the image object,
    **!		"alpha":the alpha channel or 0 if N/A
    **!	</pre>
    **!
    **! note
    **!	Throws upon failure.
    */
    
    void image_any__decode(INT32 args)
    {
       if (args!=1 || sp[-args].type!=T_STRING)
          error("Image.ANY.decode: illegal arguments\n");
       
       if (sp[-args].u.string->len<4)
          error("Image.ANY.decode: too short string\n");
    
    #define CHAR2(a,b) ((((unsigned char)(a))<<8)|((unsigned char)(b)))
       /* ok, try the heuristics */
       switch (CHAR2(sp[-args].u.string->str[0],sp[-args].u.string->str[1]))
       {
          case CHAR2('P','1'):
          case CHAR2('P','2'):
          case CHAR2('P','3'):
          case CHAR2('P','4'):
          case CHAR2('P','5'):
          case CHAR2('P','6'):
          case CHAR2('P','7'):
    	 /* ok, a PNM */
    	 img_pnm_decode(1);
    	 push_text("image/x-pnm");
    	 goto simple_image;
    
          case CHAR2(255,216):
    	 /* JFIF */
    	 push_text("Image");
    	 push_int(0);
    	 SAFE_APPLY_MASTER("resolv",2);
    	 push_text("JPEG");
    	 f_index(2);
    	 push_text("decode");
    	 f_index(2);
    	 stack_swap();
    	 f_call_function(2);
    	 push_text("image/jpeg");
    	 goto simple_image;
    
          case CHAR2('P','N'):
    	 /* PNG */
    	 push_text("Image");
    	 push_int(0);
    	 SAFE_APPLY_MASTER("resolv",2);
    	 push_text("PNG");
    	 f_index(2);
    	 push_text("_decode");
    	 f_index(2);
    	 stack_swap();
    	 f_call_function(2);
    	 return;
    
          case CHAR2('G','I'):
    	 /* GIF */
    	 image_gif_decode_map(1);
    	 return;
    
          case CHAR2('F','O'):
    	 /* ILBM (probably) */
    	 img_ilbm_decode(1);
    	 push_text("image/x-ilbm");
    	 goto simple_image;
    
          case CHAR2('B','M'):
    	 /* BMP */
    	 img_bmp__decode(1);
    	 return;
    
          case CHAR2(0,0):
    	 switch (CHAR2(sp[-args].u.string->str[2],sp[-args].u.string->str[3]))
    	 {
    	    case CHAR2(0,'k'):
    	       /* XWD */
    	       image_xwd__decode(1);
    	       return; /* done */
    	 }
    	 
    	 goto unknown_format;
    
          default:
    unknown_format:
    	 error("Unknown image format.\n");	 
       }
    
    simple_image:
       /* on stack: object image,string type */
       f_aggregate(2);
       push_text("image");
       push_text("type");
       f_aggregate(2);
       stack_swap();
       f_mkmapping(2);
       return;
    }
    
    void image_any_decode(INT32 args)
    {
       image_any__decode(args);
       push_text("image");
       f_index(2);
    }
    
    void image_any_decode_alpha(INT32 args)
    {
       image_any__decode(args);
       push_text("alpha");
       f_index(2);
    }
    
    
    /** module *******************************************/
    
    void init_image_any(void)
    {
       add_function("_decode",image_any__decode,
    		"function(string:mapping)",0);
       add_function("decode",image_any_decode,
    		"function(string:object)",0);
       add_function("decode_alpha",image_any_decode_alpha,
    		"function(string:object)",0);
    }
    
    void exit_image_any(void)
    {
    }