1
  
2
  
3
  
4
  
5
  
6
  
7
  
8
  
9
  
10
  
11
  
12
  
13
  
14
  
15
  
16
  
17
  
18
  
19
  
20
  
21
  
22
  
23
  
24
  
25
  
26
  
27
  
28
  
29
  
30
  
31
  
32
  
33
  
34
  
35
  
36
  
37
  
38
  
39
  
40
  
41
  
42
  
43
  
44
  
45
  
46
  
47
  
48
  
49
  
50
  
51
  
52
  
53
  
54
  
55
  
56
  
57
  
58
  
59
  
60
  
61
  
62
  
63
  
64
  
65
  
66
  
67
  
68
  
69
  
70
  
71
  
72
  
73
  
74
  
75
  
76
  
77
  
78
  
79
  
80
  
81
  
82
  
/* $Id: pnm.c,v 1.10 1998/04/20 18:53:32 grubba Exp $ */ 
 
/* 
**! module Image 
**! note 
**!     $Id: pnm.c,v 1.10 1998/04/20 18:53:32 grubba Exp $ 
**! class image 
*/ 
 
#include "global.h" 
 
#include <math.h> 
#include <ctype.h> 
 
#include "stralloc.h" 
#include "global.h" 
#include "pike_macros.h" 
#include "object.h" 
#include "constants.h" 
#include "interpret.h" 
#include "svalue.h" 
#include "array.h" 
#include "error.h" 
 
#include "image.h" 
 
#ifdef THIS 
#undef THIS 
#endif 
#define THIS ((struct image *)(fp->current_storage)) 
#define THISOBJ (fp->current_object) 
 
extern struct program *image_program; 
 
/* 
**! method string toppm() 
**!     <b>compability method</b> - do not use in new programs. 
**!      
**!     See <ref>Image.PNM.encode</ref>(). 
**! 
**! returns PPM data 
**! 
**! method object|string frompnm(string pnm) 
**! method object|string fromppm(string pnm) 
**!     <b>compability method</b> - do not use in new programs. 
**!      
**!     See <ref>Image.PNM.decode</ref>(). 
**! 
**! returns the called object or a hint of what wronged. 
**! arg string pnm 
**!     pnm data, as a string 
*/ 
 
void img_pnm_encode_binary(INT32 args); 
void img_pnm_decode(INT32 args); 
 
void image_toppm(INT32 args) 
{ 
   pop_n_elems(args); 
    
   ref_push_object(THISOBJ); 
 
   img_pnm_encode_binary(1); 
} 
 
void image_frompnm(INT32 args) 
{ 
   struct image *img; 
   img_pnm_decode(args); 
    
   img=(struct image*)get_storage(sp[-1].u.object,image_program); 
   if (THIS->img) free(THIS->img); 
   *THIS=*img; 
   THIS->img=malloc(img->xsize*img->ysize*sizeof(rgb_group)+1); 
   if (!THIS->img) error("out of memory\n"); 
   MEMCPY(THIS->img,img->img,img->xsize*img->ysize*sizeof(rgb_group)); 
   pop_n_elems(1); 
   ref_push_object(THISOBJ); 
}