delorie.com/archives/browse.cgi   search  
Mail Archives: geda-user/2012/06/14/15:48:17

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 <asp11 AT sfu DOT ca>
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: <CA+DWcQZO+-=umy4LdB6MXnKc=uGpLp1M7k392cnigVmzGDWy2g AT mail DOT gmail DOT com>
<20120529092557 DOT 62e0178d AT svelte>
<CA+DWcQYSXxvKbcHgFknZ_tyGiTMJj8OvTE4H0csF7gYRD0saFA AT mail DOT gmail DOT com>
<20120530140222 DOT GA21786 AT visitor2 DOT iram DOT es>
<CA+DWcQZ3Wt_xK_3P6OsHxzSaSrO+qyrqCd7YE-e75aLT1ZaPyg AT mail DOT gmail DOT com>
<CA+DWcQa0bqv5yxzEjQ+09=bPku--u7HnZgXmKx4AUYfmWTCrVQ AT mail DOT gmail DOT com>
<20120608215309 DOT GC7353 AT malakian DOT lan>
<CA+DWcQasatN9TiG0XToxmDZTonCgz0=vETxDKABmzMc-tHqH=A AT mail DOT gmail DOT com>
<CA+DWcQby6+hNQKJaUqhGBgVrDZsYKodypC6+8Z-AV+0HU7e3aw AT mail DOT gmail DOT com>
<20120609184751 DOT GA9728 AT malakian DOT lan>
MIME-Version: 1.0
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

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 <ben AT benbergman DOT ca>
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 <colour>
+In photo-realistic mode, export the solder mask as this colour. Parameter 
+@code{<colour>} 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{<colour>} 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{<colour>} 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<gdImageSY (im); y++)
 	    {
 	      color_struct p, cop;
+              color_struct mask_colour, silk_colour;
 	      int cc, mask, silk;
 	      int transparent;
 	     
@@ -899,27 +1048,50 @@ png_do_export (HID_Attr_Val * options)
 		    rgb (&cop, 220, 145, 230);
 		  else
 		    {
-		      rgb (&cop, 140, 150, 160);
-
-		      r = (rand() % 5 - 2) * 2;
-		      cop.r += r;
-		      cop.g += r;
-		      cop.b += r;
-
+                      if (options[HA_photo_plating].int_value == PLATING_GOLD)
+                        {
+                          // ENIG
+                          rgb (&cop, 185, 146, 52);
+
+                          // increase top shadow to increase shininess
+                          if (cc == TOP_SHADOW)
+                            blend (&cop, 0.7, &cop, &white);
+                        }
+                      else if (options[HA_photo_plating].int_value == PLATING_TIN)
+                        {
+                          // tinned
+                          rgb (&cop, 140, 150, 160);
+
+                          // add some variation to make it look more matte
+                          r = (rand() % 5 - 2) * 2;
+                          cop.r += r;
+                          cop.g += r;
+                          cop.b += r;
+                        }
+                      else if (options[HA_photo_plating].int_value == PLATING_SILVER)
+                        {
+                          // silver
+                          rgb (&cop, 192, 192, 185);
+
+                          // increase top shadow to increase shininess
+                          if (cc == TOP_SHADOW)
+                            blend (&cop, 0.7, &cop, &white);
+                        }
+                      else if (options[HA_photo_plating].int_value == PLATING_COPPER)
+                        {
+                          // copper
+                          rgb (&cop, 184, 115, 51);
+
+                          // increase top shadow to increase shininess
+                          if (cc == TOP_SHADOW)
+                            blend (&cop, 0.7, &cop, &white);
+                        }
 		    }
 		  
 		  if (cc == TOP_SHADOW)
-		    {
-		      cop.r = 255 - (255 - cop.r) * 0.7;
-		      cop.g = 255 - (255 - cop.g) * 0.7;
-		      cop.b = 255 - (255 - cop.b) * 0.7;
-		    }
+                    blend (&cop, 0.7, &cop, &white);
 		  if (cc == BOTTOM_SHADOW)
-		    {
-		      cop.r *= 0.7;
-		      cop.g *= 0.7;
-		      cop.b *= 0.7;
-		    }
+                    blend (&cop, 0.7, &cop, &black);
 		}
 
 	      if (photo_drill && !gdImageGetPixel (photo_drill, x, y)) 
@@ -929,18 +1101,19 @@ png_do_export (HID_Attr_Val * options)
 		}
 	      else if (silk)
 		{
-		  if (silk == TOP_SHADOW)
-		    rgb (&p, 255, 255, 255);
-		  else if (silk == BOTTOM_SHADOW)
-		    rgb (&p, 192, 192, 192);
-		  else
-		    rgb (&p, 224, 224, 224);
-		}
+                  silk_colour = silk_colours[options[HA_photo_silk_colour].int_value];
+                  blend (&p, 1.0, &silk_colour, &silk_colour);
+                  if (silk == TOP_SHADOW)
+                    add (&p, 1.0, &p, 1.0, &silk_top_shadow);
+                  else if (silk == BOTTOM_SHADOW)
+                    subtract (&p, 1.0, &p, 1.0, &silk_bottom_shadow);
+	      	}
 	      else if (mask)
 		{
 		  p = cop;
-		  p.r /= 2;
-		  p.b /= 2;
+                  mask_colour = mask_colours[options[HA_photo_mask_colour].int_value];
+                  multiply (&p, &p, &mask_colour);
+                  add (&p, 1, &p, 0.2, &mask_colour);
 		  if (mask == TOP_SHADOW)
 		    blend (&p, 0.7, &p, &white);
 		  if (mask == BOTTOM_SHADOW)
-- 
1.7.10.2



- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019