aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xgerbimg.py45
-rw-r--r--led_drv.GTP372
-rw-r--r--led_drv.TXT163
3 files changed, 565 insertions, 15 deletions
diff --git a/gerbimg.py b/gerbimg.py
index c092df4..5bb1229 100755
--- a/gerbimg.py
+++ b/gerbimg.py
@@ -14,7 +14,21 @@ from gerber.render import GerberCairoContext
import numpy as np
import cv2
-def paste_image(target_gerber:str, outline_gerber:str, source_img:np.ndarray, extend_overlay_r_mil:float=12, extend_picture_r_mil:float=2):
+def paste_image(
+ target_gerber:str,
+ outline_gerber:str,
+ source_img:np.ndarray,
+ subtract_gerber:list=[],
+ extend_overlay_r_mil:float=12,
+ extend_picture_r_mil:float=2,
+ debugdir:str=None):
+ debugctr = 0
+ def debugimg(img, name):
+ nonlocal debugctr
+ if debugdir:
+ cv2.imwrite(path.join(debugdir, '{:02d}{}.png'.format(debugctr, name)), img)
+ debugctr += 1
+
outline = gerber.loads(outline_gerber)
(minx, maxx), (miny, maxy) = outline.bounds
grbw, grbh = maxx - minx, maxy - miny
@@ -32,6 +46,9 @@ def paste_image(target_gerber:str, outline_gerber:str, source_img:np.ndarray, ex
ctx = GerberCairoContext(scale=scale)
ctx.render_layer(target, settings=fg, bgsettings=bg)
ctx.render_layer(outline, settings=fg, bgsettings=bg)
+ for sub in subtract_gerber:
+ layer = gerber.loads(sub)
+ ctx.render_layer(layer, settings=fg, bgsettings=bg)
ctx.dump(img_file)
original_img = cv2.imread(img_file, cv2.IMREAD_GRAYSCALE)
@@ -41,11 +58,9 @@ def paste_image(target_gerber:str, outline_gerber:str, source_img:np.ndarray, ex
_, target_img = cv2.threshold(target_img, 255//(1+r), 255, cv2.THRESH_BINARY)
qr = 1+2*max(1, int(extend_picture_r_mil/1000 * scale))
- # source_img = cv2.blur(source_img, (r, r))
- # cv2.imwrite('/tmp/03blurred.png', source_img)
source_img = source_img[::-1]
_, source_img = cv2.threshold(source_img, 127, 255, cv2.THRESH_BINARY)
- cv2.imwrite('/tmp/06thresh.png', source_img)
+ debugimg(source_img, 'thresh')
tgth, tgtw = target_img.shape
padded_img = np.zeros(shape=(max(imgh, tgth), max(imgw, tgtw)), dtype=source_img.dtype)
@@ -55,12 +70,12 @@ def paste_image(target_gerber:str, outline_gerber:str, source_img:np.ndarray, ex
offy += int(grbh*scale - imgh) // 2
padded_img[offy:offy+imgh, offx:offx+imgw] = source_img
- cv2.imwrite('/tmp/10padded.png', padded_img)
- cv2.imwrite('/tmp/20target.png', target_img)
+ debugimg(padded_img, 'padded')
+ debugimg(target_img, 'target')
out_img = (np.multiply((padded_img/255.0), (target_img/255.0) * -1 + 1) * 255).astype(np.uint8)
- cv2.imwrite('/tmp/30multiplied.png', out_img)
- cv2.imwrite('/tmp/40vis.png', out_img + original_img)
+ debugimg(out_img, 'multiplied')
+ debugimg(out_img + original_img, 'vis')
plot_contours(out_img, target, offx=(min(tminx, minx), min(tminy, miny)), scale=scale)
@@ -78,9 +93,6 @@ def plot_contours(img:np.ndarray, layer:gerber.rs274x.GerberFile, offx:tuple, sc
aperture = list(layer.apertures)[0]
- # XXX
- layer.primitives.clear()
-
from gerber.primitives import Line, Region
debug('offx', offx, 'scale', scale)
@@ -155,12 +167,13 @@ def replace_file_in_zip(zip_path, filename, contents):
zipout.writestr(filename, contents)
shutil.move(tempname, zip_path)
-def paste_image_file(zip_or_dir, target, outline, source_img):
+def paste_image_file(zip_or_dir, target, outline, source_img, subtract=[], debugdir=None):
if path.isdir(zip_or_dir):
tname, target = find_gerber_in_dir(zip_or_dir, target)
_, outline = find_gerber_in_dir(zip_or_dir, outline)
+ subtract = [ layer for _fn, layer in (find_gerber_in_dir(zip_or_dir, elem) for elem in subtract) ]
- out = paste_image(target, outline, source_img)
+ out = paste_image(target, outline, source_img, subtract, debugdir=debugdir)
# XXX
with open('/tmp/out.GTO', 'w') as f:
@@ -170,7 +183,7 @@ def paste_image_file(zip_or_dir, target, outline, source_img):
tname, target = find_gerber_in_zip(zip_or_dir, target)
_, outline = find_gerber_in_zip(zip_or_dir, outline)
- out = paste_image(target, outline, source_img)
+ out = paste_image(target, outline, source_img, debugdir=debugdir)
replace_file_in_zip(zip_or_dir, tname, out)
else:
raise ValueError('{} does not look like either a folder or a zip file')
@@ -182,11 +195,13 @@ if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('-t', '--target', default='.GTO', help='Target layer. Filename or extension in target folder/zip')
+ parser.add_argument('-s', '--subtract', default=['.GTP', '.TXT'], nargs='*', help='Layer to subtract. Filename or extension in target folder/zip')
parser.add_argument('-o', '--outline', default='.GKO', help='Target outline layer. Filename or extension in target folder/zip')
+ parser.add_argument('-d', '--debug', type=str, help='Directory to place debug files into')
parser.add_argument('zip_or_dir', default='.', nargs='?', help='Optional folder or zip with target files')
parser.add_argument('source', help='Source image')
args = parser.parse_args()
source_img = cv2.imread(args.source, cv2.IMREAD_GRAYSCALE)
- paste_image_file(args.zip_or_dir, args.target, args.outline, source_img)
+ paste_image_file(args.zip_or_dir, args.target, args.outline, source_img, args.subtract, args.debug)
diff --git a/led_drv.GTP b/led_drv.GTP
new file mode 100644
index 0000000..99c48c6
--- /dev/null
+++ b/led_drv.GTP
@@ -0,0 +1,372 @@
+G04 Layer_Color=8421504*
+%FSLAX25Y25*%
+%MOIN*%
+G70*
+G01*
+G75*
+G04:AMPARAMS|DCode=10|XSize=25.59mil|YSize=64.96mil|CornerRadius=1.92mil|HoleSize=0mil|Usage=FLASHONLY|Rotation=0.000|XOffset=0mil|YOffset=0mil|HoleType=Round|Shape=RoundedRectangle|*
+%AMROUNDEDRECTD10*
+21,1,0.02559,0.06112,0,0,0.0*
+21,1,0.02175,0.06496,0,0,0.0*
+1,1,0.00384,0.01088,-0.03056*
+1,1,0.00384,-0.01088,-0.03056*
+1,1,0.00384,-0.01088,0.03056*
+1,1,0.00384,0.01088,0.03056*
+%
+%ADD10ROUNDEDRECTD10*%
+%ADD11R,0.03543X0.02756*%
+%ADD12R,0.07480X0.04331*%
+%ADD13R,0.02756X0.03543*%
+%ADD14O,0.05512X0.01772*%
+%ADD15R,0.05512X0.05906*%
+%ADD16O,0.02756X0.09843*%
+%ADD17O,0.01378X0.05906*%
+%ADD18R,0.03937X0.03937*%
+%ADD19R,0.12992X0.10630*%
+%ADD20R,0.03937X0.10630*%
+%ADD21R,0.05906X0.05512*%
+D10*
+X73051Y110925D02*
+D03*
+X78051D02*
+D03*
+X83051D02*
+D03*
+X88051D02*
+D03*
+X93051D02*
+D03*
+X98051D02*
+D03*
+X103051D02*
+D03*
+X108051D02*
+D03*
+X73051Y133169D02*
+D03*
+X78051D02*
+D03*
+X83051D02*
+D03*
+X88051D02*
+D03*
+X93051D02*
+D03*
+X98051D02*
+D03*
+X103051D02*
+D03*
+X108051D02*
+D03*
+X206909Y106988D02*
+D03*
+X211910D02*
+D03*
+X216910D02*
+D03*
+X221909D02*
+D03*
+X226909D02*
+D03*
+X231909D02*
+D03*
+X236910D02*
+D03*
+X241910D02*
+D03*
+X206909Y129232D02*
+D03*
+X211910D02*
+D03*
+X216910D02*
+D03*
+X221909D02*
+D03*
+X226909D02*
+D03*
+X231909D02*
+D03*
+X236910D02*
+D03*
+X241910D02*
+D03*
+Y85925D02*
+D03*
+X236910D02*
+D03*
+X231909D02*
+D03*
+X226909D02*
+D03*
+X221909D02*
+D03*
+X216910D02*
+D03*
+X211910D02*
+D03*
+X206909D02*
+D03*
+X241910Y63681D02*
+D03*
+X236910D02*
+D03*
+X231909D02*
+D03*
+X226909D02*
+D03*
+X221909D02*
+D03*
+X216910D02*
+D03*
+X211910D02*
+D03*
+X206909D02*
+D03*
+X108051Y85925D02*
+D03*
+X103051D02*
+D03*
+X98051D02*
+D03*
+X93051D02*
+D03*
+X88051D02*
+D03*
+X83051D02*
+D03*
+X78051D02*
+D03*
+X73051D02*
+D03*
+X108051Y63681D02*
+D03*
+X103051D02*
+D03*
+X98051D02*
+D03*
+X93051D02*
+D03*
+X88051D02*
+D03*
+X83051D02*
+D03*
+X78051D02*
+D03*
+X73051D02*
+D03*
+D11*
+X116142Y132087D02*
+D03*
+Y126181D02*
+D03*
+X118110Y113189D02*
+D03*
+Y119095D02*
+D03*
+X270079Y129331D02*
+D03*
+Y135236D02*
+D03*
+X251575Y117913D02*
+D03*
+Y112008D02*
+D03*
+X264567Y130118D02*
+D03*
+Y124213D02*
+D03*
+X270079Y123819D02*
+D03*
+Y117913D02*
+D03*
+Y112402D02*
+D03*
+Y106496D02*
+D03*
+X264567Y112402D02*
+D03*
+Y106496D02*
+D03*
+X302362Y111221D02*
+D03*
+Y117126D02*
+D03*
+X198031Y72638D02*
+D03*
+Y78543D02*
+D03*
+X175591Y97441D02*
+D03*
+Y103347D02*
+D03*
+X182677Y97441D02*
+D03*
+Y91535D02*
+D03*
+X114567Y108071D02*
+D03*
+Y102165D02*
+D03*
+X107087Y102953D02*
+D03*
+Y97047D02*
+D03*
+X101575Y102953D02*
+D03*
+Y97047D02*
+D03*
+X63386Y76968D02*
+D03*
+Y82874D02*
+D03*
+X7874Y57087D02*
+D03*
+Y62992D02*
+D03*
+X11811Y132480D02*
+D03*
+Y138386D02*
+D03*
+D12*
+X140748Y113189D02*
+D03*
+X126181D02*
+D03*
+Y122244D02*
+D03*
+X140748D02*
+D03*
+D13*
+X130512Y129528D02*
+D03*
+X136417D02*
+D03*
+X288779Y88976D02*
+D03*
+X282874D02*
+D03*
+X288386Y106299D02*
+D03*
+X282480D02*
+D03*
+X128937Y72047D02*
+D03*
+X134843D02*
+D03*
+X14764Y51181D02*
+D03*
+X8858D02*
+D03*
+D14*
+X293504Y112303D02*
+D03*
+Y114862D02*
+D03*
+Y117421D02*
+D03*
+Y119980D02*
+D03*
+X277362Y112303D02*
+D03*
+Y114862D02*
+D03*
+Y117421D02*
+D03*
+Y119980D02*
+D03*
+D15*
+X281890Y98425D02*
+D03*
+X289764D02*
+D03*
+X15748Y70866D02*
+D03*
+X23622D02*
+D03*
+X15748Y60236D02*
+D03*
+X23622D02*
+D03*
+D16*
+X166949Y110039D02*
+D03*
+X161949D02*
+D03*
+X156949D02*
+D03*
+X151949D02*
+D03*
+X166949Y90748D02*
+D03*
+X161949D02*
+D03*
+X156949D02*
+D03*
+X151949D02*
+D03*
+D17*
+X120374Y79921D02*
+D03*
+X122933D02*
+D03*
+X125492D02*
+D03*
+X128051D02*
+D03*
+X130610D02*
+D03*
+X133169D02*
+D03*
+X135728D02*
+D03*
+X138287D02*
+D03*
+X140847D02*
+D03*
+X143405D02*
+D03*
+X120374Y101969D02*
+D03*
+X122933D02*
+D03*
+X125492D02*
+D03*
+X128051D02*
+D03*
+X130610D02*
+D03*
+X133169D02*
+D03*
+X135728D02*
+D03*
+X138287D02*
+D03*
+X140847D02*
+D03*
+X143405D02*
+D03*
+D18*
+X7874Y42717D02*
+D03*
+Y36024D02*
+D03*
+X15748Y42717D02*
+D03*
+Y36024D02*
+D03*
+D19*
+X19685Y110039D02*
+D03*
+D20*
+X28740Y86811D02*
+D03*
+X19685D02*
+D03*
+X10630D02*
+D03*
+D21*
+X43307Y94882D02*
+D03*
+Y102756D02*
+D03*
+M02*
diff --git a/led_drv.TXT b/led_drv.TXT
new file mode 100644
index 0000000..1ff7f0b
--- /dev/null
+++ b/led_drv.TXT
@@ -0,0 +1,163 @@
+M48
+;Layer_Color=9474304
+;FILE_FORMAT=2:5
+INCH,LZ
+;TYPE=PLATED
+T1F00S00C0.01200
+T2F00S00C0.01600
+T3F00S00C0.02400
+T4F00S00C0.03150
+T5F00S00C0.03937
+T6F00S00C0.04291
+T7F00S00C0.04724
+T8F00S00C0.06299
+T9F00S00C0.06693
+T10F00S00C0.12835
+;TYPE=NON_PLATED
+T11F00S00C0.12598
+%
+T01
+X0054724Y0049606
+Y0055905
+X0062598Y0070472
+X007559Y0070866
+X0086614Y0069291
+X0088189Y0057874
+X01Y0070472
+X0104464Y0070079
+X0105118Y007874
+X0122441Y0087795
+X0129921Y006496
+X0132433Y0067085
+X0135433Y0066929
+X0138582Y006811
+X0138189Y0063386
+X0136221Y006063
+X0117323Y0058268
+X0116535Y0048425
+X0120866Y0049213
+X0146063Y0075197
+X0146457Y0078347
+X0080709Y0080709
+X0168504Y0072835
+X0169685Y0069291
+X0193701Y007126
+X019685Y0067716
+X0201181Y006811
+X0214173Y0069685
+X0212598Y0072835
+X0236221Y007126
+X0248819Y0064173
+X0251575Y0052756
+X0227559Y0056299
+X0194881Y0084252
+X0199606Y0122047
+X0200394Y0129921
+X0216929Y0123228
+X022559Y0135827
+X0244488Y0136221
+X0245669Y0132283
+X0255906Y0129921
+X023937Y0113386
+X0294357Y0106299
+X0144488Y013937
+X01209Y0149179
+X0114173Y0135827
+X011063Y0124409
+X0106299Y0116141
+X01Y0127559
+X0089764Y0138583
+X0079921Y012559
+X0069291Y0127165
+X0059449Y0129134
+T02
+X010748Y005315
+X0116535Y0077559
+T03
+X0146063Y0062598
+X0139085Y0071763
+X0139764Y0137795
+X0126378Y0146063
+T04
+X003937Y0064961
+Y0084646
+X0177165
+Y0064961
+Y0112205
+Y013189
+X003937
+Y0112205
+T05
+X0157874Y0014134
+Y0024134
+Y0034134
+Y0044134
+X0007087Y0145
+Y0155
+T06
+X0072205Y0033779
+X008311
+X0094016
+X0104921
+X0110374Y0044961
+X0099468
+X0088563
+X0077658
+X0066752
+X0204567Y0045276
+X0215472
+X0226378
+X0237283
+X0248189
+X0242736Y0034095
+X0231831
+X0220925
+X021002
+X0215472Y0153858
+X0204567
+X021002Y0165039
+X0220925
+X0231831
+X0242736
+X0248189Y0153858
+X0237283
+X0226378
+X0110394
+X0099488
+X0088583
+X0077677
+X0066772
+X0072224Y0165039
+X008313
+X0094035
+X0104941
+T07
+X0334646Y0068425
+Y0088425
+Y0108425
+Y0128425
+T08
+X0285433Y0062992
+X0305118
+Y0133858
+X0285433
+T09
+X0267717Y0098425
+X0307087
+T10
+X003937Y003937
+X0137756
+X0177185Y0039685
+X0275571
+X0275571Y0159449
+X0177185
+X0137776
+X003939
+T11
+X0011811Y0019685
+X015748Y0062992
+X0326772Y0019685
+Y0177165
+X015748Y0133858
+X0011811Y0177165
+M30