cab CUPS Treiber  ---
image.h File Reference
#include <stdio.h>

Go to the source code of this file.

Data Structures

struct  imghead_t
 Internal struct to store basic informations for the image header. More...
 
struct  pictogram
 Internal struct to store informations for images. More...
 

Macros

#define DPMM   12
 Dots per mm. More...
 

Typedefs

typedef struct pictogram pictogram_t
 Internal struct to store informations for images. More...
 

Functions

void write_img_header (FILE *oFile, unsigned int xdim, unsigned int ydim)
 Creates and writes the image header. More...
 
void write_img (pictogram_t *pp, FILE *fp)
 

Macro Definition Documentation

◆ DPMM

#define DPMM   12

Dots per mm.

Definition at line 24 of file image.h.

Referenced by write_img_header().

Typedef Documentation

◆ pictogram_t

typedef struct pictogram pictogram_t

Internal struct to store informations for images.

Function Documentation

◆ write_img()

void write_img ( pictogram_t pp,
FILE *  fp 
)

Definition at line 94 of file image.c.

References pictogram::breite, pictogram::hoehe, and pictogram::inh.

Referenced by print_raster_image().

94  {
95  int i, bwide, wwide, vcount;
96  int zl, pattlen;
97  char *cp, *cp2;
98  short *zeile1, *zeile2;
99 
100  bwide = (pp->breite + 7) >> 3;
101  wwide = (pp->breite + 15) >> 4;
102  zl = 0;
103  vcount = 1;
104 
105  while (zl < pp->hoehe) {
106  zeile1 = pp->inh + (long)zl * (long)wwide;
107  if(zl != pp->hoehe - 1) {
108  /* Check if we can use vertical replicant count */
109  vcount = 0;
110 
111  for(;;) {
112  zeile2 = pp->inh + (long)(zl + 1) * (long)wwide;
113  if(memcmp(zeile1, zeile2, bwide))
114  break;
115  zl++;
116  if(!vcount) {
117  vcount++;
118  }
119  vcount++;
120  if(vcount == 255) {
121  break;
122  }
123  if(zl == pp->hoehe - 1) {
124  break;
125  }
126  }
127 
128  if(vcount) {
129  /* Yes, identical lines, write vrc */
130  fputc(0, fp);
131  fputc(0, fp);
132  fputc(255, fp);
133  fputc(vcount, fp);
134  }
135  }
136  /* Code one line */
137  cp = (char *)zeile1;
138  i = bwide;
139 
140  while(i) {
141  pattlen = 1;
142  i--;
143  if(*cp == '\0') {
144  /* Pruefen, ob lauter 0 */
145  cp++;
146 
147  for(;;) {
148  if(!i) {
149  break;
150  }
151  if(*cp) {
152  break;
153  }
154  cp++;
155  i--;
156  pattlen++;
157  if(pattlen == 127) {
158  break;
159  }
160  }
161  fputc(pattlen, fp);
162  }
163  else if(*cp == (char)255) {
164  /* Check if several 0xFF */
165  cp++;
166 
167  for(;;) {
168  if(!i) {
169  break;
170  }
171  if(*cp != (char)255) {
172  break;
173  }
174  cp++;
175  i--;
176  pattlen++;
177  if(pattlen == 127) {
178  break;
179  }
180  }
181 
182  pattlen += 128;
183  fputc(pattlen, fp);
184  }
185  else {
186  /* Stream of pixels */
187  cp2 = cp; /* Store start position */
188  cp++;
189 
190  for(;;) {
191  if(!i) {
192  break;
193  }
194  if(i<4) {
195  /* Don't abort at end of line */
196  pattlen += i;
197  i = 0;
198  break;
199  }
200  if(*cp == '\0' && *(cp + 1) == '\0' && *(cp + 2) == '\0') {
201  /* Found several 0x00 */
202  break;
203  }
204  if(*cp==(char)255 && *(cp+1)==(char)255 && *(cp+2)==(char)255) {
205  /* Found several 0xFF */
206  break;
207  }
208  pattlen++;
209  i--;
210  cp++;
211  if(pattlen == 252) {
212  break;
213  }
214  if(!i) {
215  break;
216  }
217  }
218 
219  /* Write pattern */
220  fputc(128, fp);
221  fputc(pattlen, fp);
222 
223  while(pattlen--) {
224  fputc(*cp2++, fp);
225  }
226  }
227  }
228  zl++;
229  }
230  /* fclose(fp); */
231  return;
232 }
short * inh
pointer to bitmap
Definition: image.h:43
short breite
width in pixels (16 pixel steps!)
Definition: image.h:41
short hoehe
height in pixels
Definition: image.h:42

◆ write_img_header()

void write_img_header ( FILE *  oFile,
unsigned int  xdim,
unsigned int  ydim 
)

Creates and writes the image header.

Parameters
oFileFile to write the image data
xdimImage width
ydimImage height
Returns

Definition at line 60 of file image.c.

References DPMM, imghead_t::height, imghead_t::length, imghead_t::lines, imghead_t::pattlen, imghead_t::pixels, imghead_t::planes, imghead_t::version, imghead_t::width, and write_word().

Referenced by print_raster_image().

60  {
61  imghead_t img;
62 
63  /* Bildkopf schreiben */
64  write_word(img.version, 1);
65  write_word(img.length, sizeof(imghead_t) / 2);
66  write_word(img.planes, 1);
67  write_word(img.pattlen, 1);
68  write_word(img.width, 1000.0 / DPMM);
69  write_word(img.height, 1000.0 / DPMM);
70  write_word(img.pixels, xdim);
71  write_word(img.lines, ydim);
72 
73  fwrite(&img, sizeof(img), 1, oFile);
74 }
unsigned char planes[2]
1 for monochrome and 4 for 16-col files
Definition: image.h:30
#define DPMM
Dots per mm.
Definition: image.h:24
static void write_word(unsigned char *dest, unsigned short value)
Writes a number as a char ...
Definition: image.c:38
unsigned char pattlen[2]
length in bytes of a pattern
Definition: image.h:31
Internal struct to store basic informations for the image header.
Definition: image.h:27
unsigned char lines[2]
Image height - lines per image.
Definition: image.h:35
unsigned char version[2]
Is normally 1.
Definition: image.h:28
unsigned char width[2]
Width of a pixel in tenths of a millimetre.
Definition: image.h:32
unsigned char length[2]
Header size.
Definition: image.h:29
unsigned char height[2]
Height of a pixel in tenths of a millimetre.
Definition: image.h:33
unsigned char pixels[2]
Image width - pixles per line.
Definition: image.h:34