def __init__(self, file_path, file_name_no_ext, build_folder_path): bmp = BMP(file_path) self.__file_path = file_path self.__file_name_no_ext = file_name_no_ext self.__build_folder_path = build_folder_path self.__colors_count = bmp.colors_count self.__bpp_8 = self.__colors_count > 16
def __init__(self, file_path, file_name_no_ext, build_folder_path, info): bmp = BMP(file_path) self.__file_path = file_path self.__file_name_no_ext = file_name_no_ext self.__build_folder_path = build_folder_path self.__colors_count = bmp.colors_count width = bmp.width height = bmp.height if width != 128 and width % 256 != 0: raise ValueError( 'Affine BGs width must be 128 or divisible by 256: ' + str(width)) if height != 128 and height % 256 != 0: raise ValueError( 'Affine BGs height must be 128 or divisible by 256: ' + str(height)) self.__width = int(width / 8) self.__height = int(height / 8) try: self.__repeated_tiles_reduction = bool( info['repeated_tiles_reduction']) except KeyError: self.__repeated_tiles_reduction = True
def __init__(self, file_path, file_name_no_ext, build_folder_path, info): bmp = BMP(file_path) self.__file_path = file_path self.__file_name_no_ext = file_name_no_ext self.__build_folder_path = build_folder_path self.__colors_count = bmp.colors_count width = bmp.width height = bmp.height if width == 256 and height == 256: self.__sbb = False elif (width == 256 and height == 512) or (width == 512 and height == 256) or (width == 512 and height == 512): self.__sbb = True else: raise ValueError('Invalid regular BG size: (' + str(width) + 'x' + str(height) + ')' + RegularBgItem.valid_sizes_message()) self.__width = int(width / 8) self.__height = int(height / 8) self.__bpp_8 = False try: self.__repeated_tiles_reduction = bool( info['repeated_tiles_reduction']) except KeyError: self.__repeated_tiles_reduction = True try: self.__flipped_tiles_reduction = bool( info['flipped_tiles_reduction']) except KeyError: self.__flipped_tiles_reduction = True if self.__colors_count > 16: try: bpp_mode = str(info['bpp_mode']) except KeyError: bpp_mode = 'bpp_8' if bpp_mode == 'bpp_8': self.__bpp_8 = True elif bpp_mode == 'bpp_4_auto': self.__file_path = self.__build_folder_path + '/' + file_name_no_ext + '.bn_quantized.bmp' print(' Generating bpp4 image in ' + self.__file_path + '...') start = time.time() self.__colors_count = bmp.quantize(self.__file_path) end = time.time() print(' bpp4 image with ' + str(self.__colors_count) + ' colors generated in ' + str(int((end - start) * 1000)) + ' milliseconds') elif bpp_mode != 'bpp_4_manual': raise ValueError('Invalid BPP mode: ' + bpp_mode)
def select_image_2(self): file, file_type = QFileDialog.getOpenFileName(parent=None, caption="选择图像", directory=os.getcwd(), filter="bmp文件(*.bmp)") self.textEdit_2.setText(file) img = BMP(file) image = img.bmp_data #image = image.astype(np.int8) self.image_1 = img showImage = QtGui.QImage(image.astype(np.int8), image.shape[1], image.shape[0], QtGui.QImage.Format_RGB888) pix = QtGui.QPixmap.fromImage(showImage) item = QGraphicsPixmapItem(pix) # 创建像素图元 scene = QGraphicsScene() # 创建场景 scene.addItem(item) self.graphicsView_1.setScene(scene) # 将场景添加至视图
### ### XORs the bitmap data of two images together... why? Uh, I'm not quite sure... ### import sys, struct from bmp import BMP from cStringIO import StringIO if len(sys.argv) != 3: print 'I need two arguments, and the images provided need to have the same dimensions and color depth!' exit(1) else: first_filename = sys.argv[1] second_filename = sys.argv[2] first = BMP(first_filename) second = BMP(second_filename) if first.width != second.width or first.height != second.height or first.bpp != second.bpp: print 'The dimensions and/or bpp differs between the input images!' exit(1) print 'Images are {0}x{1} @ {2} bpp'.format(first.width, first.height, first.bpp) print 'Working...', sys.stdout.flush() out_bitmap_data = "" ff = StringIO(first.bitmap_data) sf = StringIO(second.bitmap_data)
def process(input_file_path, output_file_path): bmp = BMP(input_file_path) bmp.quantize(output_file_path)
#初始化LCD spi = machine.SPI(1, baudrate=8000000, polarity=0, phase=0) d = st7735.ST7735(spi, rst=13, ce=9, dc=12) d.reset() d.begin() #白色背景 d._bground = 0xffff d.fill_screen(d._bground) #画点,(0,0,0)表示黑色 d.pixel(5, 5, d.rgb_to_565(0, 0, 0)) #画线,(0,0,0)表示黑色 lcd_gfx.drawLine(5, 10, 80, 10, d, d.rgb_to_565(0, 0, 0)) #画矩形,(0,0,0)表示黑色 lcd_gfx.drawRect(5, 20, 80, 40, d, d.rgb_to_565(0, 0, 0)) #画圆,(0,0,0)表示黑色 lcd_gfx.drawCircle(40, 90, 20, d, d.rgb_to_565(0, 0, 0)) #写字符 d.p_string(10, 130, 'Hello 01Studio!', d.rgb_to_565(255, 0, 0)) time.sleep_ms(2000) #延时2秒 #显示图片 BMP('flower128x160.bmp', d, 0, 0, 1)
def __init__(self, file_path, file_name_no_ext, build_folder_path, info): bmp = BMP(file_path) self.__file_path = file_path self.__file_name_no_ext = file_name_no_ext self.__build_folder_path = build_folder_path self.__colors_count = bmp.colors_count self.__bpp_8 = self.__colors_count > 16 try: height = int(info['height']) if bmp.height % height: raise ValueError('File height is not divisible by item height: ' + str(bmp.height) + ' - ' + str(height)) except KeyError: height = bmp.height self.__graphics = int(bmp.height / height) width = bmp.width if width == 8: if height == 8: self.__shape = 'SQUARE' self.__size = 'SMALL' elif height == 16: self.__shape = 'TALL' self.__size = 'SMALL' elif height == 32: self.__shape = 'TALL' self.__size = 'NORMAL' elif height == 64: raise ValueError('Invalid sprite size: (' + str(width) + 'x' + str(height) + ')' + SpriteItem.valid_sizes_message()) else: raise ValueError('Invalid sprite height: ' + str(height) + SpriteItem.valid_sizes_message()) elif width == 16: if height == 8: self.__shape = 'WIDE' self.__size = 'SMALL' elif height == 16: self.__shape = 'SQUARE' self.__size = 'NORMAL' elif height == 32: self.__shape = 'TALL' self.__size = 'BIG' elif height == 64: raise ValueError('Invalid sprite size: (: ' + str(width) + 'x' + str(height) + ')' + SpriteItem.valid_sizes_message()) else: raise ValueError('Invalid sprite height: ' + str(height) + SpriteItem.valid_sizes_message()) elif width == 32: if height == 8: self.__shape = 'WIDE' self.__size = 'NORMAL' elif height == 16: self.__shape = 'WIDE' self.__size = 'BIG' elif height == 32: self.__shape = 'SQUARE' self.__size = 'BIG' elif height == 64: self.__shape = 'TALL' self.__size = 'HUGE' else: raise ValueError('Invalid sprite height: ' + str(height) + SpriteItem.valid_sizes_message()) elif width == 64: if height == 8: raise ValueError('Invalid sprite size: (' + str(width) + 'x' + str(height) + ')' + SpriteItem.valid_sizes_message()) elif height == 16: raise ValueError('Invalid sprite size: (' + str(width) + 'x' + str(height) + ')' + SpriteItem.valid_sizes_message()) elif height == 32: self.__shape = 'WIDE' self.__size = 'HUGE' elif height == 64: self.__shape = 'SQUARE' self.__size = 'HUGE' else: raise ValueError('Invalid sprite height: ' + str(height) + SpriteItem.valid_sizes_message()) else: raise ValueError('Invalid sprite width: ' + str(width) + SpriteItem.valid_sizes_message())
### ### "Interlace" a picture - divide every second row's brightness by two, creating a striped appearance ### import sys from bmp import BMP from cStringIO import StringIO if len(sys.argv) == 1: filename = "test.bmp" else: filename = sys.argv[1] b = BMP(filename) print 'Image is {0}x{1} @ {2} bpp'.format(b.width, b.height, b.bpp) print 'Working...', sys.stdout.flush() mod_bitmap = "" # Let's pretend it's a file to make things easy f = StringIO(b.bitmap_data) for row_num in xrange(0, b.height): if row_num & 1 == 0: # Simply copy the data from even rows... mod_bitmap += f.read((b.width * 3) + b.padding_size) else: # ... and divide all pixel values by two on odd rows data = f.read((b.width * 3) + b.padding_size)