def add(self, fpath): def bmp2array(bm): h, w = bm.GetSize() im = bm.ConvertToImage() array = np.fromstring(bytes(im.GetData()), dtype=np.uint8) array = array.reshape(w, h, array.shape[0] / w / h) alpha = image_GetAlpha(im) if alpha is not None: alpha = np.fromstring(bytes(image_GetAlpha(im)), dtype=np.uint8).reshape(w, h, -1) else: alpha = np.zeros((w, h, 1), dtype=np.uint8) + 255 return array, alpha, def array2bmp(array, alpha): w = array.shape[0] h = array.shape[1] im = wxEmptyImage(h, w) im.SetData(array.tostring()) image_SetAlpha(im, alpha) return im.ConvertToBitmap() def alpha_composite(ca, cb, aa, ab): resc = ca.copy().astype(float) resa = aa.copy().astype(float) ca = ca.astype(float) cb = cb.astype(float) aa = aa.astype(float) / 255. ab = ab.astype(float) / 255. for k in range(3): resc[:, :, k] = (np.multiply(ca[:, :, k], aa[:, :, 0]) + np.multiply(np.multiply(cb[:, :, k], ab[:, :, 0]), 1. - aa[:, :, 0])) resa[:, :, 0] = aa[:, :, 0] + np.multiply(ab[:, :, 0], (1. - aa[:, :, 0])) resa = (resa * 255).astype(np.uint8) resc = resc.astype(np.uint8) return resc, resa if fpath[-4:] == '.png': bm = wxBitmapFromImage(wx.Image(fpath, wx.BITMAP_TYPE_PNG)) if fpath[-4:] == '.bmp': bm = wxBitmapFromImage(wx.Image(fpath, wx.BITMAP_TYPE_BMP)) fpath2 = os.path.join(os.path.dirname(fpath), 'suppress.png') bm2 = wxBitmapFromImage(wx.Image(fpath2, wx.BITMAP_TYPE_PNG)) array, alpha = bmp2array(bm) array2, alpha2 = bmp2array(bm2) array3, alpha3 = alpha_composite(array2, array, alpha2, alpha) bm3 = array2bmp(array3, alpha3) idx = ImageFiles._list.Add(bm) idx2 = ImageFiles._list.Add(bm3) if self.IsOk(idx) is False: print("can not read " + fpath) idx = -1 idx2 = -1 return idx, idx2
def add(self, fpath): def bmp2array(bm): h, w = bm.GetSize() im = bm.ConvertToImage() array = np.fromstring(bytes(im.GetData()),dtype=np.uint8) array = array.reshape(w, h, array.shape[0]/w/h) alpha = image_GetAlpha(im) if alpha is not None: alpha = np.fromstring(bytes(image_GetAlpha(im)), dtype=np.uint8).reshape(w, h, -1) else: alpha = np.zeros((w, h, 1), dtype=np.uint8)+255 return array, alpha, def array2bmp(array, alpha): w = array.shape[0] h = array.shape[1] im = wxEmptyImage(h, w) im.SetData(array.tostring()) image_SetAlpha(im, alpha) return im.ConvertToBitmap() def alpha_composite(ca, cb, aa, ab): resc = ca.copy().astype(float) resa = aa.copy().astype(float) ca = ca.astype(float) cb = cb.astype(float) aa = aa.astype(float)/255. ab = ab.astype(float)/255. for k in range(3): resc[:,:,k] = (np.multiply(ca[:,:,k],aa[:,:,0]) + np.multiply(np.multiply(cb[:,:,k],ab[:,:,0]), 1.-aa[:,:,0])) resa[:,:,0] = aa[:,:,0] + np.multiply(ab[:,:,0], (1.-aa[:,:,0])) resa = (resa*255).astype(np.uint8) resc = resc.astype(np.uint8) return resc, resa if fpath[-4:] == '.png': bm = wxBitmapFromImage(wx.Image(fpath,wx.BITMAP_TYPE_PNG)) if fpath[-4:] == '.bmp': bm = wxBitmapFromImage(wx.Image(fpath,wx.BITMAP_TYPE_BMP)) fpath2 = os.path.join(os.path.dirname(fpath), 'suppress.png') bm2 = wxBitmapFromImage(wx.Image(fpath2, wx.BITMAP_TYPE_PNG)) array, alpha = bmp2array(bm) array2, alpha2 = bmp2array(bm2) array3, alpha3 = alpha_composite(array2, array, alpha2, alpha) bm3 = array2bmp(array3, alpha3) idx=ImageFiles._list.Add(bm) idx2=ImageFiles._list.Add(bm3) if self.IsOk(idx) is False: print("can not read "+fpath) idx = -1 idx2 = -1 return idx, idx2
def __init__(self, parent, id, *args, **kargs): wx.Panel.__init__(self, parent, id, *args, **kargs) self.parent = parent self.font = wx.Font(9, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, 'Courier 10 Pitch') from ifigure.ifigure_config import icondir path = os.path.join(icondir, 'image', 'slider.png') self._bbmp = wxBitmapFromImage(wx.Image(path, wx.BITMAP_TYPE_PNG)) self._value = [0.5] self._range = [0, 1] self._sheight = 6 self._hmargin = 10 self._vmargin = 3 self._bheight = self._vmargin * 2 + self._sheight self._bwidth = 6 w, h = self._bbmp.GetSize() self._bheight = h self._bwidth = w self._vmargin = (h - self._sheight) / 2 self._b = None self._isDrawn = False self._generate_motion_event = False self.SetMinSize((w * 5, h)) self.Bind(wx.EVT_PAINT, self.OnPaint) self.Bind(wx.EVT_SIZE, self.OnSize) self.Bind(wx.EVT_MOUSE_EVENTS, self.OnMouseEvent)
def __init__(self, parent, id, *args, **kargs): wx.Panel.__init__(self, parent, id, *args, **kargs) self.parent = parent self.font = wx.Font(9, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, 'Courier 10 Pitch') from ifigure.ifigure_config import icondir path = os.path.join(icondir, 'image', 'slider.png') self._bbmp = wxBitmapFromImage(wx.Image(path,wx.BITMAP_TYPE_PNG)) self._value = [0.5] self._range = [0, 1] self._sheight = 6 self._hmargin = 10 self._vmargin = 3 self._bheight = self._vmargin*2 + self._sheight self._bwidth = 6 w, h = self._bbmp.GetSize() self._bheight = h self._bwidth = w self._vmargin = (h - self._sheight)/2 self._b = None self._isDrawn = False self._generate_motion_event = False self.SetMinSize((w*5, h)) self.Bind(wx.EVT_PAINT, self.OnPaint) self.Bind(wx.EVT_SIZE, self.OnSize) self.Bind(wx.EVT_MOUSE_EVENTS, self.OnMouseEvent)