X-Authentication-Warning: delorie.com: mail set sender to geda-user-bounces using -f X-Recipient: geda-user AT delorie DOT com Date: Thu, 14 Jun 2012 12:41:41 -0700 From: Andrew Poelstra To: geda-user AT delorie DOT com Subject: Re: [geda-user] extra mask, plating, and silk colours in pcb Message-ID: <20120614194141.GA22067@malakian.lan> References: <20120529092557 DOT 62e0178d AT svelte> <20120530140222 DOT GA21786 AT visitor2 DOT iram DOT es> <20120608215309 DOT GC7353 AT malakian DOT lan> <20120609184751 DOT GA9728 AT malakian DOT lan> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20120609184751.GA9728@malakian.lan> User-Agent: Mutt/1.5.20 (2009-12-10) Reply-To: geda-user AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: geda-user AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk I have made the following changes to your patch: 1. Consolidated all 17 patches into one. They all fundamentally do a single thing (add a color-changing feature), all affect the same source file, and the total diff is only ~300 lines. I think this is reasonable. The 17-patch version was over 1000 lines, and largely redundant. (For example, one patch introduced a compilation warning, which the next patch got rid of.) 2. Fixed whitespace. There should be no tabs in source files -- the ones that are there were put in by errant tools, and represent 8 spaces. So if you're editing code with tabs in it, check that your editor has its tabstops set to 8 spaces, so that the spacing will look right on your machine. (Or even better, submit a separate whitespace-fixing patch to get rid of the tabs.) 3. Changed the clip() function to check for both values > 255 and values < 0. Removed the explicit check for < 0 from subtract(). This reduces the potential for bugs. The new patch is as follows. If you're happy to have your name on it, let me know and I'll push it. From 8a232dfc46302cb991d513c6cfa0100c74e326ad Mon Sep 17 00:00:00 2001 From: Benjamin Bergman Date: Thu, 14 Jun 2012 12:30:20 -0700 Subject: [PATCH] Add options to change photo-mode colors. Original patchset by Benjamin Bergman. Minor changes from Andrew Poelstra. Closes-bug: lp-1004796 --- src/hid/png/png.c | 227 ++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 200 insertions(+), 27 deletions(-) diff --git a/src/hid/png/png.c b/src/hid/png/png.c index 892696b..ae349c1 100644 --- a/src/hid/png/png.c +++ b/src/hid/png/png.c @@ -162,6 +162,72 @@ static const char *filetypes[] = { NULL }; + +static const char *mask_colour_names[] = { + "green", + "red", + "blue", + "purple", + "black", + "white", + NULL +}; + +// These values were arrived at through trial and error. +// One potential improvement (especially for white) is +// to use separate color_structs for the multiplication +// and addition parts of the mask math. +static const color_struct mask_colours[] = { +#define MASK_COLOUR_GREEN 0 + {.r = 60, .g = 160, .b = 60}, +#define MASK_COLOUR_RED 1 + {.r = 140, .g = 25, .b = 25}, +#define MASK_COLOUR_BLUE 2 + {.r = 50, .g = 50, .b = 160}, +#define MASK_COLOUR_PURPLE 3 + {.r = 60, .g = 20, .b = 70}, +#define MASK_COLOUR_BLACK 4 + {.r = 20, .g = 20, .b = 20}, +#define MASK_COLOUR_WHITE 5 + {.r = 167, .g = 230, .b = 162}, // <-- needs improvement over FR4 + {} +}; + + +static const char *plating_type_names[] = { +#define PLATING_TIN 0 + "tinned", +#define PLATING_GOLD 1 + "gold", +#define PLATING_SILVER 2 + "silver", +#define PLATING_COPPER 3 + "copper", + NULL +}; + + + +static const char *silk_colour_names[] = { + "white", + "black", + "yellow", + NULL +}; + +static const color_struct silk_colours[] = { +#define SILK_COLOUR_WHITE 0 + {.r = 224, .g = 224, .b = 224}, +#define SILK_COLOUR_BLACK 1 + {.r = 14, .g = 14, .b = 14}, +#define SILK_COLOUR_YELLOW 2 + {.r = 185, .g = 185, .b = 10}, + {} +}; + +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[] = { /* other HIDs expect this to be first. */ @@ -323,6 +389,46 @@ In photo-realistic mode, export the reverse side of the layout. Up-down flip. HID_Boolean, 0, 0, {0, 0, 0}, 0, 0}, #define HA_photo_flip_y 13 +/* %start-doc options "93 PNG Options" +@ftable @code +@cindex photo-mask-colour +@item --photo-mask-colour +In photo-realistic mode, export the solder mask as this colour. Parameter +@code{} can be @samp{green}, @samp{red}, @samp{blue}, or @samp{purple}. +@end ftable +%end-doc +*/ + {"photo-mask-colour", "Colour for the exported colour mask", + HID_Enum, 0, 0, {0, 0, 0}, mask_colour_names, 0}, +#define HA_photo_mask_colour 14 + +/* %start-doc options "93 PNG Options" +@ftable @code +@cindex photo-plating +@item --photo-plating +In photo-realistic mode, export the exposed copper as though it has this type +of plating. Parameter @code{} can be @samp{tinned}, @samp{gold}, +@samp{silver}, or @samp{copper}. +@end ftable +%end-doc +*/ + {"photo-plating", "Type of plating applied to exposed copper in photo-mode", + HID_Enum, 0, 0, {0, 0, 0}, plating_type_names, 0}, +#define HA_photo_plating 15 + +/* %start-doc options "93 PNG Options" +@ftable @code +@cindex photo-silk-colour +@item --photo-silk-colour +In photo-realistic mode, export the silk screen as this colour. Parameter +@code{} can be @samp{white}, @samp{black}, or @samp{yellow}. +@end ftable +%end-doc +*/ + {"photo-silk-colour", "Colour for the exported colour mask", + HID_Enum, 0, 0, {0, 0, 0}, silk_colour_names, 0}, +#define HA_photo_silk_colour 16 + {"ben-mode", ATTR_UNDOCUMENTED, HID_Boolean, 0, 0, {0, 0, 0}, 0, 0}, #define HA_ben_mode 11 @@ -551,7 +657,21 @@ png_hid_export_to_file (FILE * the_file, HID_Attr_Val * options) } static void -blend (color_struct *dest, float a_amount, color_struct *a, color_struct *b) +clip (color_struct *dest, color_struct *source) +{ +#define CLIP(var) \ + dest->var = source->var; \ + if (dest->var > 255) dest->var = 255; \ + if (dest->var < 0) dest->var = 0; + + CLIP (r); + CLIP (g); + CLIP (b); +#undef CLIP +} + +static void +blend (color_struct *dest, double a_amount, color_struct *a, color_struct *b) { dest->r = a->r * a_amount + b->r * (1 - a_amount); dest->g = a->g * a_amount + b->g * (1 - a_amount); @@ -559,6 +679,34 @@ blend (color_struct *dest, float a_amount, color_struct *a, color_struct *b) } static void +multiply (color_struct *dest, color_struct *a, color_struct *b) +{ + dest->r = (a->r * b->r) / 255; + dest->g = (a->g * b->g) / 255; + dest->b = (a->b * b->b) / 255; +} + +static void +add (color_struct *dest, double a_amount, const color_struct *a, double b_amount, const color_struct *b) +{ + dest->r = a->r * a_amount + b->r * b_amount; + dest->g = a->g * a_amount + b->g * b_amount; + dest->b = a->b * a_amount + b->b * b_amount; + + clip (dest, dest); +} + +static void +subtract (color_struct *dest, double a_amount, const color_struct *a, double b_amount, const color_struct *b) +{ + dest->r = a->r * a_amount - b->r * b_amount; + dest->g = a->g * a_amount - b->g * b_amount; + dest->b = a->b * a_amount - b->b * b_amount; + + clip (dest, dest); +} + +static void rgb (color_struct *dest, int r, int g, int b) { dest->r = r; @@ -869,6 +1017,7 @@ png_do_export (HID_Attr_Val * options) for (y=0; y