def glCreateWindow(self, width, height): """ Function that instantiate a new Object from Bitmap, this initialize the framebuffer :param width: width of the image that will be render :param height: height of the the image that will be render :return: """ self.window = Bitmap(width, height)
def OnRecolor(self, message): logging.info("OnRecolor():") bmp = FileManager().CurrentFile().data Bitmap.Recolor(bmp, message.data) self.Refresh() pub.sendMessage("UpdateBitmap")
def main(): # example use python3 Task_06.py example0.tga -e 4 tga, header, footer, wid, hi = read_tga(sys.argv[1]) if sys.argv[2] == '-e': bitmap = Bitmap(tga[18:len(tga) - 26], wid, hi) k = int(sys.argv[3]) res1, b, res2, quantified = encode(bitmap, k) res1, res2 = bytes(convert_to_list(res1)), bytes(convert_to_list(res2)) save_output(header, footer, res1, b, res2, quantified) elif sys.argv[2] == "-d": data = tga[18:-26] bitmap = decode(data) with open("out_dec_low.tga", "wb") as f: f.write(header + bitmap + footer)
def spheres(max_r, min_r, n): P = ThermalPrinter.ThermalPrinter("/dev/ttyUSB0") B = Bitmap.Bitmap() B.height = kHeight B.width_bytes = kWidth//8 step = (max_r - min_r)//n radii = [max_r] while max_r - step > min_r: max_r -= step radii.append(max_r) radii.insert(0, max_r) canvas = blank_canvas() cx, cy = kWidth//2, kHeight//2 for r in radii: for x in range(kWidth): for y in range(kHeight): a = random.uniform(0,1) if math.sqrt((x-cx)**2 + (y-cy)**2) < r: D = 0.5 + ( math.asin( (x-cx)/math.sqrt(r**2 - (y-cy)**2) ) ) / math.pi a = random.uniform(0,1) a = norm_exp(a,-1) #a = sigmoid(a) if a >= D: canvas[y][x] = kBlack else: canvas[y][x] = kWhite else: if (x/kWidth) > a: canvas[y][x] = kBlack else: canvas[y][x] = kWhite data = img_to_bytes(canvas) B.image_data = data P.print_bitmap(B) P.feed(1) P.send_bytes("spheres - chog 2018") P.feed(3)
def print_bitmap(self, bitmap): #for i in range(bitmap.height): # can only send upto 256 bytes at a time chunk_height_limit = 256 // bitmap.width_bytes for row in range(bitmap.height): self.send_bytes(ASCII_DC2, '*', 1, bitmap.width_bytes) for b in bitmap.image_data[row*bitmap.width_bytes: (row+1)*bitmap.width_bytes]: self.send_byte(not_byte(b)) # for row in range(bitmap.height-chunk_height_limit, -1, -1*chunk_height_limit): # print("a") # self.send_bytes(ASCII_DC2, '*', chunk_height_limit, bitmap.width_bytes) # for b in bitmap.image_data[row*bitmap.width_bytes: (row+chunk_height_limit)*bitmap.width_bytes]: # self.send_byte(not_byte(b)) if __name__ == "__main__": printer = ThermalPrinter("/dev/ttyUSB0") printer.feed(2) image = Bitmap.Bitmap() image.load_file("demo.bmp") printer.print_bitmap(image) printer.send_bytes("Choggy Carrots - 2018") time.sleep(0.5) printer.feed(3)
def glCreateWindow(width, heigth): global screen screen = Bitmap(width, heigth)
class SoftwareRender(object): """ Class that use bitmap to abstract a software render """ def __init__(self, filename): self.glInit() self.filename = filename def glInit(self): """ Function that start necessary variables for software renderer :return: """ self.window = "" def glCreateWindow(self, width, height): """ Function that instantiate a new Object from Bitmap, this initialize the framebuffer :param width: width of the image that will be render :param height: height of the the image that will be render :return: """ self.window = Bitmap(width, height) def glViewPort(self, x, y, width, height): """ Function that call glViewPort of Bitmap and create a viewport where the image will be visible :param x: number that represent the horizontal coord where the viewport will be drawn :param y: number that represent the vertical coord where the viewport will be drawn :param width: width of the viewport :param height: heigth of the viewport :return: """ self.window.glViewPort(x, y, width, height) def glClear(self): """ Function that use glclear() function from Bitmap :return: """ self.window.glclear() def glClearColor(self, r, g, b): """ Function that use glClearColor from Bitmap :param r: amount of red :param g: amount of green :param b: amount of blue :return: """ self.window.glClearColor(r, g, b) def glVertex(self, x, y): """ Function that use glVertex from Bitmap :param x: relative horizontal coord of the point :param y: relative vertical coord of the point :return: """ self.window.glVertex(x, y) def glColor(self, r, g, b): """ Function that use glColor from Bitmap :param r: amount of red :param g: amount of green :param b: amount of b :return: """ self.window.glColor(r, g, b) def glFinish(self): """ Function that use write method from Bitmap, it save the specifications of the image in a file with filename specified by the user :return: """ self.window.write(self.filename) def square(self, size): self.window.square(size) # draw left line def drawLeftLine(self, padding): self.window.drawLeftLine(padding) # draw rigth line def drawRightLine(self, padding): self.window.drawRightLine(padding) # draw top line def drawTopLine(self, padding): self.window.drawTopLine(padding) # draw botton line def drawBottomLine(self, padding): self.window.drawBottomLine(padding) def diagonal(self): self.window.diagonal() def random_point(self): self.window.random_point() def random_point_color(self): self.window.random_point_color() def sky(self, stars): self.window.sky(stars) def glLine(self, xo, yo, xf, yf): self.window.glLine(xo, yo, xf, yf)
def OnPaint(self, event): logging.info("DrawPanel.OnPaint()") d = FileManager().CurrentFile().data dc = wx.BufferedPaintDC(self, Bitmap.Scale(d, self.scale))
def __init__(self, oldbmp, bmp): self.bmp = bmp self.RedoBitmap = Bitmap.Copy(bmp) # image after change self.UndoBitmap = oldbmp # image before change
def UpdateOld(self): self.olddata = Bitmap.Copy(self.data)
def New(self, w, h): File.New(self) self.data = Bitmap.New(w, h)
def OnPaint(self, event): d = FileManager().CurrentFile().data dc = wx.BufferedPaintDC(self,Bitmap.Scale(d,self.scale))