m24h作者
5年0个月前修改于 5年0个月前IP:上海
898604
9楼

今晚又做了一次认真和正式的实践

首先是kicad绘制成PDF后 PS以1200dpi打开为光栅图片

然后发现微软的3d build不够精细 对于一般的电路或许够用 但是这次我的电路有点细 仔细看发现方块不够方 圆焊盘不够圆 此外切片出来的精度也有点不太好 因此Python先写了两个程序 用于提取(展开)和生成(压缩).CWS文件中的特殊PNG图片(那是一种把灰度像素按顺序放在BGR(不是RGB大概是因为小端优先的原因)的特殊格式)

做成了bat方便点

----cwsexp.bat---

0<0# : ^
''' 
@python %~f0 %* 
@goto :eof
'''

from PIL import Image
import numpy
import sys

if len(sys.argv)<3 :
	print('Expand Compressed image in CWS zipped file')
	print('Usage: python',sys.argv[0],'<image file name> <output file name>')
	print('Example: python',sys.argv[0],'a.png b.bmp')
	exit(1)

img = numpy.array(Image.open(sys.argv[1]).convert('RGB'))
(h,w)=img.shape[0:2]
nw=w*3
print ('Original:', w, 'X', h, '  New:', nw, 'X', h)
img2=numpy.empty([h,nw,3], dtype=img.dtype)
for y in range(h):
	for x in range(w):
		img2[y,x*3,0]=img[y,x,2]
		img2[y,x*3,1]=img[y,x,2]
		img2[y,x*3,2]=img[y,x,2]
		img2[y,x*3+1,0]=img[y,x,1]
		img2[y,x*3+1,1]=img[y,x,1]
		img2[y,x*3+1,2]=img[y,x,1]
		img2[y,x*3+2,0]=img[y,x,0]
		img2[y,x*3+2,1]=img[y,x,0]
		img2[y,x*3+2,2]=img[y,x,0]
Image.fromarray(img2).save(sys.argv[2])
exit(0)

---cwscomp.bat---

0<0# : ^
''' 
@python %~f0 %* 
@goto :eof
'''

from PIL import Image
import numpy
import sys

if len(sys.argv)<3 :
	print('Compress normal image to fit CWS zipped file')
	print('Usage: python',sys.argv[0],'<image file name> <output file name>')
	print('Example: python',sys.argv[0],'a.jpg b.png')
	exit(1)

img = numpy.array(Image.open(sys.argv[1]).convert('L'))
(h,w)=img.shape
nw=int((w+2)/3)
print ('Original:', w, 'X', h, '  New:', nw, 'X', h)
img2=numpy.empty([h,nw,3], dtype=img.dtype)
for y in range(h):
	for x in range(nw):
		img2[y,x,2]=img[y,x*3]
		img2[y,x,1]=img[y,x*3+1] if x*3+1<w else 0
		img2[y,x,0]=img[y,x*3+2] if x*3+2<w else 0
		
Image.fromarray(img2).save(sys.argv[2])
exit(0)
评论
文号 / 898604

千古风流
名片专栏发私信
学术分 1
总主题 68 帖总回复 1007 楼拥有证书:进士 学者 机友
注册于 2020/01/22 18:44:43最后登录 2026/10/31 02:54:58
主体类型:个人
所属领域:无
认证方式:手机号
IP归属地:上海

个人简介

个人开源项目: m24h.github.io

笔记
{{note.content}}
{{n.user.username}}
{{fromNow(n.toc)}} {{n.status === noteStatus.disabled ? "已屏蔽" : ""}} {{n.status === noteStatus.unknown ? "正在审核" : ""}} {{n.status === noteStatus.deleted ? '已删除' : ''}}
  • 编辑
  • 删除
  • {{n.status === 'disabled' ? "解除屏蔽" : "屏蔽" }}
我也是有底线的