KiCad PCB EDA Suite
bitmap_io.h File Reference
#include <stdio.h>
#include "bitmap.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 1096 of file bitmap_io.cpp.

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

1097 {
1098  int x, y;
1099  int xx, yy;
1100  int d;
1101  int sw, sh;
1102 
1103  sw = bm->w < 79 ? bm->w : 79;
1104  sh = bm->w < 79 ? bm->h : bm->h * sw * 44 / (79 * bm->w);
1105 
1106  for( yy = sh - 1; yy>=0; yy-- )
1107  {
1108  for( xx = 0; xx<sw; xx++ )
1109  {
1110  d = 0;
1111 
1112  for( x = xx * bm->w / sw; x<(xx + 1) * bm->w / sw; x++ )
1113  {
1114  for( y = yy * bm->h / sh; y<(yy + 1) * bm->h / sh; y++ )
1115  {
1116  if( BM_GET( bm, x, y ) )
1117  {
1118  d++;
1119  }
1120  }
1121  }
1122 
1123  fputc( d ? '*' : ' ', f );
1124  }
1125 
1126  fputc( '\n', f );
1127  }
1128 
1129  return 0;
1130 }
#define BM_GET(bm, x, y)
Definition: bitmap.h:42
int bm_read ( FILE *  f,
double  blacklevel,
potrace_bitmap_t **  bmp 
)

Definition at line 148 of file bitmap_io.cpp.

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

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

Definition at line 1068 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.

1069 {
1070  int w, h, bpr, y, i, c;
1071 
1072  w = bm->w;
1073  h = bm->h;
1074 
1075  bpr = (w + 7) / 8;
1076 
1077  fprintf( f, "P4\n%d %d\n", w, h );
1078 
1079  for( y = h - 1; y>=0; y-- )
1080  {
1081  for( i = 0; i<bpr; i++ )
1082  {
1083  c =
1084  ( *bm_index( bm, i * 8,
1085  y ) >> ( 8 * ( BM_WORDSIZE - 1 - (i % BM_WORDSIZE) ) ) ) & 0xff;
1086  fputc( c, f );
1087  }
1088  }
1089 }
#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 146 of file bitmap_io.cpp.

Referenced by bm_readbody_bmp(), and bm_readbody_pnm().