pcb 4.1.1
An interactive printed circuit board layout editor.

png.c File Reference

#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <math.h>
#include "global.h"
#include "data.h"
#include "error.h"
#include "misc.h"
#include "hid.h"
#include "hid_draw.h"
#include "../hidint.h"
#include "hid/common/hidnogui.h"
#include "hid/common/draw_helpers.h"
#include "png.h"
#include <gd.h>
#include "hid/common/hidinit.h"
Include dependency graph for png.c:

Go to the source code of this file.

Data Structures

struct  color_struct
struct  hid_gc_struct

Defines

#define CRASH   fprintf(stderr, "HID error: pcb called unimplemented PNG function %s.\n", __FUNCTION__); abort()
#define SCALE(w)   ((int)round((w)/scale))
#define SCALE_X(x)   ((int)round(((x) - x_shift)/scale))
#define SCALE_Y(y)   ((int)round(((show_bottom_side ? (PCB->MaxHeight-(y)) : (y)) - y_shift)/scale))
#define SWAP_IF_SOLDER(a, b)   do { Coord c; if (show_bottom_side) { c=a; a=b; b=c; }} while (0)
#define NOT_EDGE_X(x)   ((x) != 0 && (x) != PCB->MaxWidth)
#define NOT_EDGE_Y(y)   ((y) != 0 && (y) != PCB->MaxHeight)
#define NOT_EDGE(x, y)   (NOT_EDGE_X(x) || NOT_EDGE_Y(y))
#define BADC   -1
#define PHOTO_FLIP_X   1
#define PHOTO_FLIP_Y   2
#define FMT_gif   "GIF"
#define FMT_jpg   "JPEG"
#define FMT_png   "PNG"
#define MASK_COLOUR_GREEN   0
#define MASK_COLOUR_RED   1
#define MASK_COLOUR_BLUE   2
#define MASK_COLOUR_PURPLE   3
#define MASK_COLOUR_BLACK   4
#define MASK_COLOUR_WHITE   5
#define PLATING_TIN   0
#define PLATING_GOLD   1
#define PLATING_SILVER   2
#define PLATING_COPPER   3
#define SILK_COLOUR_WHITE   0
#define SILK_COLOUR_BLACK   1
#define SILK_COLOUR_YELLOW   2

Typedefs

typedef struct color_struct color_struct
typedef struct hid_gc_struct hid_gc_struct

Functions

static void png_fill_circle (hidGC gc, Coord cx, Coord cy, Coord radius)
 REGISTER_ATTRIBUTES (png_attribute_list)
static HID_Attributepng_get_export_options (int *n)
static int layer_stack_sort (const void *va, const void *vb)
static void parse_bloat (const char *str)
void png_hid_export_to_file (FILE *the_file, HID_Attr_Val *options)
static void clip (color_struct *dest, color_struct *source)
static void blend (color_struct *dest, double a_amount, color_struct *a, color_struct *b)
static void multiply (color_struct *dest, color_struct *a, color_struct *b)
static void add (color_struct *dest, double a_amount, const color_struct *a, double b_amount, const color_struct *b)
static void subtract (color_struct *dest, double a_amount, const color_struct *a, double b_amount, const color_struct *b)
static void rgb (color_struct *dest, int r, int g, int b)
static void ts_bs (gdImagePtr im)
static void ts_bs_sm (gdImagePtr im)
static void png_do_export (HID_Attr_Val *options)
static void png_parse_arguments (int *argc, char ***argv)
static int png_set_layer (const char *name, int group, int empty)
static hidGC png_make_gc (void)
static void png_destroy_gc (hidGC gc)
static void png_use_mask (enum mask_mode mode)
static void png_set_color (hidGC gc, const char *name)
static void png_set_line_cap (hidGC gc, EndCapStyle style)
static void png_set_line_width (hidGC gc, Coord width)
static void png_set_draw_xor (hidGC gc, int xor_)
static void use_gc (hidGC gc)
static void png_draw_rect (hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2)
static void png_fill_rect (hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2)
static void png_draw_line (hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2)
static void png_draw_arc (hidGC gc, Coord cx, Coord cy, Coord width, Coord height, Angle start_angle, Angle delta_angle)
static void png_fill_polygon (hidGC gc, int n_coords, Coord *x, Coord *y)
static void png_calibrate (double xval, double yval)
static void png_set_crosshair (int x, int y, int a)
void hid_png_init ()

Variables

static HID png_hid
static HID_DRAW png_graphics
static void * color_cache = NULL
static void * brush_cache = NULL
static double bloat = 0
static double scale = 1
static Coord x_shift = 0
static Coord y_shift = 0
static int show_bottom_side
static color_structblack = NULL
static color_structwhite = NULL
static gdImagePtr im = NULL
static gdImagePtr master_im
static gdImagePtr mask_im = NULL
static FILE * f = 0
static int linewidth = -1
static int lastgroup = -1
static gdImagePtr lastbrush = (gdImagePtr)((void *) -1)
static int lastcap = -1
static int print_group [MAX_GROUP]
static int print_layer [MAX_ALL_LAYER]
static int photo_mode
static int photo_flip
static gdImagePtr photo_copper [MAX_ALL_LAYER]
static gdImagePtr photo_silk
static gdImagePtr photo_mask
static gdImagePtr photo_drill
static gdImagePtr * photo_im
static gdImagePtr photo_outline
static int photo_groups [MAX_ALL_LAYER]
static int photo_ngroups
static int photo_has_inners
static int doing_outline
static int have_outline
static const char * filetypes []
static const char * mask_colour_names []
static const color_struct mask_colours []
static const char * plating_type_names []
static const char * silk_colour_names []
static const color_struct silk_colours []
static const color_struct silk_top_shadow = {.r = 21, .g = 21, .b = 21}
static const color_struct silk_bottom_shadow = {.r = 14, .g = 14, .b = 14}
HID_Attribute png_attribute_list []
static int top_group
static int bottom_group
static const char * filename
static BoxTypebounds
static int in_mono
static int as_shown
static int fill_holes
static int smshadows [3][3]
static int shadows [5][5]
static int is_mask
static int is_drill
static int is_copper

Define Documentation

#define BADC   -1

Definition at line 85 of file png.c.

Referenced by png_do_export(), png_set_color(), png_set_layer(), and use_gc().

#define CRASH   fprintf(stderr, "HID error: pcb called unimplemented PNG function %s.\n", __FUNCTION__); abort()

Definition at line 59 of file png.c.

Referenced by png_calibrate().

#define FMT_gif   "GIF"

Definition at line 138 of file png.c.

Referenced by png_do_export(), and REGISTER_ATTRIBUTES().

#define FMT_jpg   "JPEG"

Definition at line 139 of file png.c.

Referenced by png_do_export(), and REGISTER_ATTRIBUTES().

#define FMT_png   "PNG"

Definition at line 140 of file png.c.

Referenced by png_do_export(), and REGISTER_ATTRIBUTES().

#define MASK_COLOUR_BLACK   4
#define MASK_COLOUR_BLUE   2
#define MASK_COLOUR_GREEN   0
#define MASK_COLOUR_PURPLE   3
#define MASK_COLOUR_RED   1
#define MASK_COLOUR_WHITE   5
#define NOT_EDGE (   x,
  y 
)    (NOT_EDGE_X(x) || NOT_EDGE_Y(y))

Definition at line 80 of file png.c.

Referenced by png_draw_line(), and png_fill_polygon().

#define NOT_EDGE_X (   x)    ((x) != 0 && (x) != PCB->MaxWidth)

Definition at line 78 of file png.c.

#define NOT_EDGE_Y (   y)    ((y) != 0 && (y) != PCB->MaxHeight)

Definition at line 79 of file png.c.

#define PHOTO_FLIP_X   1

Definition at line 126 of file png.c.

Referenced by png_do_export().

#define PHOTO_FLIP_Y   2

Definition at line 127 of file png.c.

Referenced by png_do_export().

#define PLATING_COPPER   3

Referenced by png_do_export().

#define PLATING_GOLD   1

Referenced by png_do_export().

#define PLATING_SILVER   2

Referenced by png_do_export().

#define PLATING_TIN   0

Referenced by png_do_export().

#define SCALE (   w)    ((int)round((w)/scale))
#define SCALE_X (   x)    ((int)round(((x) - x_shift)/scale))
#define SCALE_Y (   y)    ((int)round(((show_bottom_side ? (PCB->MaxHeight-(y)) : (y)) - y_shift)/scale))
#define SILK_COLOUR_BLACK   1
#define SILK_COLOUR_WHITE   0
#define SILK_COLOUR_YELLOW   2
#define SWAP_IF_SOLDER (   a,
 
)    do { Coord c; if (show_bottom_side) { c=a; a=b; b=c; }} while (0)

Definition at line 75 of file png.c.

Referenced by png_fill_rect().


Typedef Documentation

typedef struct color_struct color_struct
typedef struct hid_gc_struct hid_gc_struct

Function Documentation

static void add ( color_struct dest,
double  a_amount,
const color_struct a,
double  b_amount,
const color_struct b 
) [static]

Definition at line 696 of file png.c.

References color_struct::b, clip(), color_struct::g, and color_struct::r.

Referenced by gts_container_add(), and png_do_export().

Here is the call graph for this function:

static void blend ( color_struct dest,
double  a_amount,
color_struct a,
color_struct b 
) [static]

Definition at line 680 of file png.c.

References color_struct::b, color_struct::g, and color_struct::r.

Referenced by png_do_export().

static void clip ( color_struct dest,
color_struct source 
) [static]

Definition at line 666 of file png.c.

Referenced by add(), and subtract().

static int layer_stack_sort ( const void *  va,
const void *  vb 
) [static]

Definition at line 510 of file png.c.

References GetLayerGroupNumberByNumber().

Referenced by png_hid_export_to_file().

Here is the call graph for this function:

static void multiply ( color_struct dest,
color_struct a,
color_struct b 
) [static]

Definition at line 688 of file png.c.

References color_struct::b, color_struct::g, and color_struct::r.

Referenced by png_do_export().

static void parse_bloat ( const char *  str) [static]

Definition at line 533 of file png.c.

References bloat, GetValueEx(), and scale.

Referenced by png_do_export().

Here is the call graph for this function:

static void png_calibrate ( double  xval,
double  yval 
) [static]

Definition at line 1816 of file png.c.

References CRASH.

Referenced by hid_png_init().

static void png_destroy_gc ( hidGC  gc) [static]

Definition at line 1378 of file png.c.

Referenced by hid_png_init().

static void png_draw_arc ( hidGC  gc,
Coord  cx,
Coord  cy,
Coord  width,
Coord  height,
Angle  start_angle,
Angle  delta_angle 
) [static]

Definition at line 1700 of file png.c.

References color_struct::c, hid_gc_struct::color, doing_outline, im, linewidth, M_PI, NormalizeAngle(), png_fill_circle(), SCALE, SCALE_X, SCALE_Y, show_bottom_side, start_angle, use_gc(), hid_gc_struct::width, x, and y.

Referenced by hid_png_init().

Here is the call graph for this function:

static void png_draw_line ( hidGC  gc,
Coord  x1,
Coord  y1,
Coord  x2,
Coord  y2 
) [static]
static void png_draw_rect ( hidGC  gc,
Coord  x1,
Coord  y1,
Coord  x2,
Coord  y2 
) [static]

Definition at line 1610 of file png.c.

References color_struct::c, hid_gc_struct::color, im, SCALE_X, SCALE_Y, and use_gc().

Referenced by hid_png_init().

Here is the call graph for this function:

static void png_fill_circle ( hidGC  gc,
Coord  cx,
Coord  cy,
Coord  radius 
) [static]

Definition at line 1764 of file png.c.

References bloat, color_struct::c, hid_gc_struct::color, doing_outline, im, hid_gc_struct::is_erase, linewidth, SCALE, SCALE_X, SCALE_Y, and use_gc().

Referenced by hid_png_init(), png_draw_arc(), and png_draw_line().

Here is the call graph for this function:

static void png_fill_polygon ( hidGC  gc,
int  n_coords,
Coord x,
Coord y 
) [static]

Definition at line 1789 of file png.c.

References color_struct::c, hid_gc_struct::color, doing_outline, im, linewidth, malloc(), NOT_EDGE, SCALE_X, SCALE_Y, and use_gc().

Referenced by hid_png_init().

Here is the call graph for this function:

static void png_fill_rect ( hidGC  gc,
Coord  x1,
Coord  y1,
Coord  x2,
Coord  y2 
) [static]

Definition at line 1619 of file png.c.

References bloat, color_struct::c, hid_gc_struct::color, doing_outline, im, linewidth, SCALE_X, SCALE_Y, SWAP_IF_SOLDER, and use_gc().

Referenced by hid_png_init(), and png_draw_line().

Here is the call graph for this function:

static HID_Attribute* png_get_export_options ( int *  n) [static]

Definition at line 491 of file png.c.

References derive_default_filename(), PCBType::Filename, PCB, and png_attribute_list.

Referenced by hid_png_init(), and png_do_export().

Here is the call graph for this function:

static hidGC png_make_gc ( void  ) [static]
static void png_parse_arguments ( int *  argc,
char ***  argv 
) [static]

Definition at line 1202 of file png.c.

References hid_parse_command_line(), and hid_register_attributes().

Referenced by hid_png_init().

Here is the call graph for this function:

static void png_set_color ( hidGC  gc,
const char *  name 
) [static]
static void png_set_crosshair ( int  x,
int  y,
int  a 
) [static]

Definition at line 1822 of file png.c.

Referenced by hid_png_init().

static void png_set_draw_xor ( hidGC  gc,
int  xor_ 
) [static]

Definition at line 1490 of file png.c.

Referenced by hid_png_init().

static void png_set_line_cap ( hidGC  gc,
EndCapStyle  style 
) [static]

Definition at line 1478 of file png.c.

References hid_gc_struct::cap, and style.

Referenced by hid_png_init().

static void png_set_line_width ( hidGC  gc,
Coord  width 
) [static]

Definition at line 1484 of file png.c.

References hid_gc_struct::width.

Referenced by hid_png_init().

static void png_use_mask ( enum mask_mode  mode) [static]

Definition at line 1384 of file png.c.

References __FUNCTION__, c, color_struct::c, HID_MASK_CLEAR, HID_MASK_OFF, im, mask_im, master_im, Message(), white, x, and y.

Referenced by hid_png_init().

Here is the call graph for this function:

REGISTER_ATTRIBUTES ( png_attribute_list  )

Definition at line 462 of file png.c.

References HID_Attribute::default_val, FMT_gif, FMT_jpg, FMT_png, and HID_Attr_Val::int_value.

static void rgb ( color_struct dest,
int  r,
int  g,
int  b 
) [static]
static void subtract ( color_struct dest,
double  a_amount,
const color_struct a,
double  b_amount,
const color_struct b 
) [static]

Definition at line 706 of file png.c.

References color_struct::b, clip(), color_struct::g, and color_struct::r.

Referenced by png_do_export().

Here is the call graph for this function:

static void ts_bs ( gdImagePtr  im) [static]

Definition at line 742 of file png.c.

References x, and y.

Referenced by png_do_export().

static void ts_bs_sm ( gdImagePtr  im) [static]

Definition at line 764 of file png.c.

References x, and y.

Referenced by png_do_export().


Variable Documentation

int as_shown

Definition at line 530 of file png.c.

Referenced by eps_hid_export_to_file(), and eps_set_layer().

color_struct* black = NULL [static]

Definition at line 108 of file png.c.

Referenced by png_do_export(), and png_set_color().

double bloat = 0 [static]

Definition at line 67 of file png.c.

BoxType* bounds [static]

Definition at line 529 of file png.c.

Referenced by ComputeCost().

void* brush_cache = NULL [static]

Definition at line 65 of file png.c.

Referenced by png_do_export(), and use_gc().

void* color_cache = NULL [static]

Definition at line 64 of file png.c.

Referenced by png_do_export(), and png_set_color().

int doing_outline [static]

Definition at line 136 of file png.c.

Referenced by png_draw_arc(), png_draw_line(), png_fill_circle(), png_fill_polygon(), and png_fill_rect().

FILE* f = 0 [static]

Definition at line 110 of file png.c.

Referenced by png_do_export(), and png_hid_export_to_file().

const char* filename [static]

Definition at line 528 of file png.c.

const char* filetypes[] [static]
Initial value:
 {















  NULL
}

Definition at line 148 of file png.c.

Definition at line 530 of file png.c.

Definition at line 136 of file png.c.

int in_mono [static]

Definition at line 530 of file png.c.

int is_copper [static]

Definition at line 1213 of file png.c.

Referenced by REGISTER_ATTRIBUTES().

int is_drill [static]

Definition at line 1212 of file png.c.

int is_mask [static]

Definition at line 1211 of file png.c.

gdImagePtr lastbrush = (gdImagePtr)((void *) -1) [static]

Definition at line 113 of file png.c.

Referenced by png_hid_export_to_file(), and use_gc().

int lastcap = -1 [static]

Definition at line 114 of file png.c.

int lastgroup = -1 [static]

Definition at line 112 of file png.c.

Referenced by png_hid_export_to_file().

const char* mask_colour_names[] [static]
Initial value:
 {
  "green",
  "red",
  "blue",
  "purple",
  "black",
  "white",
  NULL
}

Definition at line 168 of file png.c.

const color_struct mask_colours[] [static]
Initial value:
 {
#define MASK_COLOUR_GREEN
  {.r = 60, .g = 160, .b = 60},
#define MASK_COLOUR_RED
  {.r = 140, .g = 25, .b = 25},
#define MASK_COLOUR_BLUE
  {.r = 50, .g = 50, .b = 160},
#define MASK_COLOUR_PURPLE
  {.r = 60, .g = 20, .b = 70},
#define MASK_COLOUR_BLACK
  {.r = 20, .g = 20, .b = 20},
#define MASK_COLOUR_WHITE
  {.r = 167, .g = 230, .b = 162}, 
  {}
}

Definition at line 182 of file png.c.

gdImagePtr mask_im = NULL

Definition at line 109 of file png.c.

Referenced by png_use_mask().

gdImagePtr master_im

Definition at line 109 of file png.c.

Referenced by png_do_export(), png_set_color(), and png_use_mask().

gdImagePtr photo_copper[MAX_ALL_LAYER] [static]

Definition at line 130 of file png.c.

gdImagePtr photo_drill

Definition at line 131 of file png.c.

Referenced by png_set_layer().

Definition at line 129 of file png.c.

int photo_groups[MAX_ALL_LAYER] [static]

Definition at line 133 of file png.c.

int photo_has_inners [static]

Definition at line 134 of file png.c.

gdImagePtr * photo_im

Definition at line 131 of file png.c.

Referenced by png_set_layer().

gdImagePtr photo_mask

Definition at line 131 of file png.c.

Referenced by png_set_layer().

int photo_mode [static]

Definition at line 129 of file png.c.

Definition at line 133 of file png.c.

gdImagePtr photo_outline [static]

Definition at line 132 of file png.c.

Referenced by png_set_layer().

gdImagePtr photo_silk [static]

Definition at line 131 of file png.c.

Referenced by png_set_layer().

const char* plating_type_names[] [static]
Initial value:
 {
#define PLATING_TIN
  "tinned",
#define PLATING_GOLD
  "gold",
#define PLATING_SILVER
  "silver",
#define PLATING_COPPER
  "copper",
  NULL
}

Definition at line 199 of file png.c.

Definition at line 233 of file png.c.

Referenced by png_get_export_options().

Definition at line 62 of file png.c.

Referenced by hid_png_init().

HID png_hid [static]

Definition at line 61 of file png.c.

Referenced by png_make_gc().

int print_group[MAX_GROUP] [static]

Definition at line 115 of file png.c.

int print_layer[MAX_ALL_LAYER] [static]

Definition at line 116 of file png.c.

int shadows[5][5] [static]
Initial value:
 {
  {  1,  1,   1,   1, -1 },
  {  1,  1,   1,  -1, -1 },
  {  1,  1,   0,  -1, -1 },
  {  1, -1,  -1,  -1, -1 },
  { -1, -1,  -1,  -1, -1 },
}

Definition at line 729 of file png.c.

int show_bottom_side [static]

Definition at line 71 of file png.c.

Referenced by png_draw_arc(), and png_hid_export_to_file().

const color_struct silk_bottom_shadow = {.r = 14, .g = 14, .b = 14} [static]

Definition at line 231 of file png.c.

const char* silk_colour_names[] [static]
Initial value:
 {
  "white",
  "black",
  "yellow",
  NULL
}

Definition at line 213 of file png.c.

const color_struct silk_colours[] [static]
Initial value:
 {
#define SILK_COLOUR_WHITE
  {.r = 224, .g = 224, .b = 224},
#define SILK_COLOUR_BLACK
  {.r = 14, .g = 14, .b = 14},
#define SILK_COLOUR_YELLOW
  {.r = 185, .g = 185, .b = 10},
  {}
}

Definition at line 220 of file png.c.

const color_struct silk_top_shadow = {.r = 21, .g = 21, .b = 21} [static]

Definition at line 230 of file png.c.

int smshadows[3][3] [static]
Initial value:
 {
  {  1,  20,   1 },
  { 10,   0, -10 },
  { -1, -20,  -1 },
}

Definition at line 723 of file png.c.

color_struct * white = NULL

Definition at line 108 of file png.c.

Coord x_shift = 0 [static]

Definition at line 69 of file png.c.

Referenced by png_do_export().

Coord y_shift = 0 [static]

Definition at line 70 of file png.c.

Referenced by png_do_export().