luceda ipkiss教程 45:在版图上加LOGO

**在设计版图时往往需要加上公司或者学校的LOGO,只需要LOGO的图片,通过代码就可以将LOGO加到版图上,比如:
在这里插入图片描述
**
通过代码可以得到版图上的LOGO:
!在这里插入图片描述
代码如下:

from si_fab import all as pdk
from ipkiss3 import all as i3

# i3.TECH.PURPOSE.DF.POLYGON = i3.TECH.PURPOSE.DRAWING
# i3.TECH.PROCESS.HFW = i3.TECH.PURPOSE.UNUSED

PIL_loaded = False
try:
    from PIL import Image

    PIL_loaded = True
except:
    pass

try:
    import Image

    PIL_loaded = True
except:
    pass


if not PIL_loaded:
    raise AssertionError(" PIL should be installed")


class BitmapGrating(i3.PCell):
    image = i3.DefinitionProperty()
    pixel = i3.ChildCellProperty()

    class Layout(i3.LayoutView):
        pixel_pitch = i3.Size2Property(default=(2.0, 2.0))

        def _generate_instances(self, insts):
            im = self.image
            w = im.size[0]
            h = im.size[1]
            pixels = im.getdata()

            period_x = self.pixel_pitch[0]
            period_y = self.pixel_pitch[1]

            for y in range(h):
                pen_down = False
                for x in range(w):
                    p = pixels[x + y * w]
                    if not pen_down:
                        if p == 0:
                            pen_down = True
                            start_x = x
                    elif not p == 0:
                        pen_down = False
                        n_x = x - start_x
                        if n_x > 1:
                            insts += i3.ARef(
                                reference=self.pixel,
                                origin=(start_x * period_x, -y * period_y),
                                period=(period_x, period_y),
                                n_o_periods=(n_x, 1),
                            )
                        else:
                            insts += i3.SRef(reference=self.pixel, position=(start_x * period_x, -y * period_y))
                if pen_down:
                    n_x = x - start_x + 1
                    if n_x > 1:
                        insts += i3.ARef(
                            reference=self.pixel,
                            origin=(start_x * period_x, -y * period_y),
                            period=(period_x, period_y),
                            n_o_periods=(n_x, 1),
                        )
                    else:
                        insts += i3.SRef(reference=self.pixel, position=(start_x * period_x, -y * period_y))

            return insts


class BitmapGratingFromFile(BitmapGrating):
    image = i3.LockedProperty()
    filename = i3.StringProperty()

    def _default_image(self):
        return Image.open(self.filename).convert("1")


class SquareBitmapGrating(BitmapGrating):
    pixel = i3.ChildCellProperty(locked=True)

    def _default_pixel(self):
        from picazzo3.phc.generic.holes import RectHole

        return RectHole(name="{}_pixel".format(self.name))

    class Layout(BitmapGrating.Layout):
        pixel_size = i3.Size2Property(default=(1.0, 1.0))
        layer = i3.LayerProperty(default=i3.TECH.PPLAYER.WG.TEXT)

        def _default_pixel(self):
            lv = self.cell.pixel.get_default_view(i3.LayoutView)
            lv.set(
                radii=(0.5 * self.pixel_size[0], 0.5 * self.pixel_size[1]),
                process=self.layer.process,
                purpose=self.layer.purpose,
            )
            return lv


class SquareBitmapGratingFromFile(BitmapGratingFromFile, SquareBitmapGrating):
    """Load a bitmap from file and convert it to a grating:
    SquareBitmapGratingFromFile(filename = "xxx", pixel_size = (x,y), pixel_pitch = (x,y))
    """

    pass
if __name__ == '__main__':
    logo = SquareBitmapGratingFromFile(name="logo_fudan", filename="fudan.png")
    logo_layout = logo.Layout(pixel_size=(1.5, 1.5), pixel_pitch=(3.0, 3.0))
    logo_layout.visualize()

  • 17
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值