KiCad PCB EDA Suite
bitmap_io.h File Reference
#include "bitmap.h"
#include <stdio.h>

Go to the source code of this file.

Functions

int bm_read (FILE *f, double blacklevel, potrace_bitmap_t **bmp)
 
void bm_writepbm (FILE *f, potrace_bitmap_t *bm)
 
int bm_print (FILE *f, potrace_bitmap_t *bm)
 

Variables

const char * bm_read_error
 

Function Documentation

int bm_print ( FILE *  f,
potrace_bitmap_t bm 
)

Definition at line 1146 of file bitmap_io.cpp.

References BM_GET, potrace_bitmap_s::h, and potrace_bitmap_s::w.

1147 {
1148  int x, y;
1149  int xx, yy;
1150  int d;
1151  int sw, sh;
1152 
1153  sw = bm->w < 79 ? bm->w : 79;
1154  sh = bm->w < 79 ? bm->h : bm->h * sw * 44 / ( 79 * bm->w );
1155 
1156  for( yy = sh - 1; yy >= 0; yy-- )
1157  {
1158  for( xx = 0; xx < sw; xx++ )
1159  {
1160  d = 0;
1161 
1162  for( x = xx * bm->w / sw; x < ( xx + 1 ) * bm->w / sw; x++ )
1163  {
1164  for( y = yy * bm->h / sh; y < ( yy + 1 ) * bm->h / sh; y++ )
1165  {
1166  if( BM_GET( bm, x, y ) )
1167  {
1168  d++;
1169  }
1170  }
1171  }
1172 
1173  fputc( d ? '*' : ' ', f );
1174  }
1175 
1176  fputc( '\n', f );
1177  }
1178 
1179  return 0;
1180 }
#define BM_GET(bm, x, y)
Definition: bitmap.h:42
int bm_read ( FILE *  f,
double  blacklevel,
potrace_bitmap_t **  bmp 
)

Definition at line 159 of file bitmap_io.cpp.

References bm_readbody_bmp(), bm_readbody_pnm(), and fgetc_ws().

160 {
161  int magic[2];
162 
163  /* read magic number. We ignore whitespace and comments before the
164  * magic, for the benefit of concatenated files in P1-P3 format.
165  * Multiple P1-P3 images in a single file are not formally allowed
166  * by the PNM standard, but there is no harm in being lenient. */
167 
168  magic[0] = fgetc_ws( f );
169 
170  if( magic[0] == EOF )
171  {
172  return -3;
173  }
174 
175  magic[1] = fgetc( f );
176 
177  if( magic[0] == 'P' && magic[1] >= '1' && magic[1] <= '6' )
178  {
179  return bm_readbody_pnm( f, threshold, bmp, magic[1] );
180  }
181 
182  if( magic[0] == 'B' && magic[1] == 'M' )
183  {
184  return bm_readbody_bmp( f, threshold, bmp );
185  }
186 
187  return -4;
188 }
static int bm_readbody_bmp(FILE *f, double threshold, potrace_bitmap_t **bmp)
Definition: bitmap_io.cpp:612
static int bm_readbody_pnm(FILE *f, double threshold, potrace_bitmap_t **bmp, int magic)
Definition: bitmap_io.cpp:195
static int fgetc_ws(FILE *f)
Definition: bitmap_io.cpp:38
void bm_writepbm ( FILE *  f,
potrace_bitmap_t bm 
)

Definition at line 1119 of file bitmap_io.cpp.

References bm_index, BM_WORDSIZE, potrace_bitmap_s::h, bmp_info_s::h, potrace_bitmap_s::w, and bmp_info_s::w.

1120 {
1121  int w, h, bpr, y, i, c;
1122 
1123  w = bm->w;
1124  h = bm->h;
1125 
1126  bpr = ( w + 7 ) / 8;
1127 
1128  fprintf( f, "P4\n%d %d\n", w, h );
1129 
1130  for( y = h - 1; y >= 0; y-- )
1131  {
1132  for( i = 0; i < bpr; i++ )
1133  {
1134  c = ( *bm_index( bm, i * 8, y ) >> ( 8 * ( BM_WORDSIZE - 1 - ( i % BM_WORDSIZE ) ) ) )
1135  & 0xff;
1136  fputc( c, f );
1137  }
1138  }
1139 }
#define bm_index(bm, x, y)
Definition: bitmap.h:33
#define BM_WORDSIZE
Definition: bitmap.h:24

Variable Documentation

const char* bm_read_error

Definition at line 157 of file bitmap_io.cpp.

Referenced by bm_readbody_bmp(), and bm_readbody_pnm().