def load_image_data(self,file): if (self.imageOffset == 0) and (self.bitsPerPixel == 24): self.imageOffset = BITMAP_FILEHEADER_SIZE + self.dib.biSize rowSize = math.ceil(self.imageWidth * self.bitsPerPixel / 32) * 4 # data pixels + pending data self.pixelArraySize = rowSize * abs(self.imageHight) file.seek(self.imageOffset,0) self.fullImageData = file.read(self.pixelArraySize) if self.compression == 0: file.seek(self.imageOffset,0) if self.bitsPerPixel == 1: for i in range(self.imageHight): self.imageData.append([]) #new row in image data row = BitArray(file.read(rowSize)) for j in range(self.imageWidth): self.imageData[i].append(self.colorTable[1 if row[j] == 1 else 0]) elif self.bitsPerPixel == 4: for i in range(self.imageHight): self.imageData.append([]) #new row in image data row = BitArray(file.read(rowSize)) pixels = list(row.cut(4)) for j in range(self.imageWidth): self.imageData[i].append(self.colorTable[pixels[j].int]) elif self.bitsPerPixel == 8: for i in range(self.imageHight): self.imageData.append([]) #new row in image data row = list(file.read(rowSize)) for j in range(self.imageWidth): self.imageData[i].append(self.colorTable[row[j]]) elif self.bitsPerPixel == 16: pass elif self.bitsPerPixel == 24: for i in range(self.imageHight): self.imageData.append([]) #new row in image data row = list(file.read(rowSize)) for j in range(self.imageWidth): blue = row[3 * j + 0] green = row[3 * j + 1] red = row[3 * j + 2] self.imageData[i].append(RGBA(red,green,blue,0)) elif self.bitsPerPixel == 32: pass if self.imageHight > 0: self.imageData = list(reversed(self.imageData))
def __init__(self, section, rows=0, cols=0): self.INVERTED = 0 self.YRES = 8 self.XRES = 6 self.FG_COL = [0x00, 0xff, 0x00, 0xff] self.BG_COL = [0xff, 0xff, 0xff, 0xff] self.BL_COL = [0xff, 0xff, 0xff, 0x00] self.NO_COL = [0x00, 0x00, 0x00, 0x00] res = self.cfg_fetch_raw(section, "resolution", None) if res is None: self.DCOLS = cols self.DROWS = rows else: res = [int(x) for x in res.lower().split("x")] self.DCOLS = res[0] - res[0] % self.XRES self.DROWS = res[1] - res[1] % self.YRES self.cols = self.DCOLS / self.XRES self.rows = self.DROWS / self.YRES self.LCOLS = 0 self.LROWS = 0 #self.CHARS = self.cols * self.rows # unused here, but effects the gif size limit self.graphic_FB = resizeList([], LAYERS, list) self.graphic_resizeFB(rows, cols) color = self.cfg_fetch_raw(section, "foreground", "000000ff") if RGBA.color2RGBA(color, self.FG_COL) < 0: error("%s: ignoring illegal color '%s'", self.name, color) color = self.cfg_fetch_raw(section, "background", "ffffff00") if RGBA.color2RGBA(color, self.BG_COL) < 0: error("%s: ignoring illegal color '%s'", self.name, color) color = self.cfg_fetch_raw(section, "basecolor", "ffffff") if RGBA.color2RGBA(color, self.BL_COL) < 0: error("%s: ignoring illegal color '%s'", self.name, color) self.INVERTED = self.cfg_fetch_num(section, "inverted", 0) fd = open("cfa635_fonts.dat", "r") self.fonts = pickle.load(fd) fd.close()
def load_color_profile(self,file): if self.bitsPerPixel == 1 or self.bitsPerPixel == 4 or self.bitsPerPixel == 8 : self.colorTableSize = (2 ** self.bitsPerPixel) self.colorTableOffset = BITMAP_FILEHEADER_SIZE + self.dibSize file.seek(self.colorTableOffset,0) for i in range(int(self.colorTableSize)): red = int.from_bytes(file.read(1),"big") green = int.from_bytes(file.read(1),'big') blue = int.from_bytes(file.read(1),'big') alpha = int.from_bytes(file.read(1),'big') self.colorTable.append(RGBA(red,green,blue,alpha)) #file.read(1) return True return False
def widget_color(self, section, key, C): C.R = 0 C.G = 0 C.B = 0 C.A = 0 color = self.visitor.cfg_fetch_raw(section, key, None) if color is None: return 0 if color == '': return 0 if RGBA.color2RGBA(color, C) < 0: return 0 return 1
def load_image_data(self, file): if (self.imageOffset == 0) and (self.bitsPerPixel == 24): self.imageOffset = BITMAP_FILEHEADER_SIZE + self.dib.biSize rowSize = math.ceil(self.imageWidth * self.bitsPerPixel / 32) * 4 # data pixels + pending data self.pixelArraySize = rowSize * abs(self.imageHight) file.seek(self.imageOffset, 0) self.fullImageData = file.read(self.pixelArraySize) #--------------------- Progres bar window #---------------------------------- # layout the window layout = [[ sg.ProgressBar(self.imageHight, orientation='h', size=(20, 20), key='progressbar', bar_color=('blue', 'white')) ], [sg.Text(' 0%', key='progress')]] # create the window window = sg.Window('', layout, keep_on_top=True, finalize=True) progress_bar = window['progressbar'] progress_percent = window['progress'] #--------------------- Progres bar window #---------------------------------- if self.compression == 0: file.seek(self.imageOffset, 0) if self.bitsPerPixel == 1: for i in range(self.imageHight): # updating progress bar ---------------------- prc = int(100 * (i + 1) / self.imageHight) progress_percent.update(str(prc) + '%') progress_bar.update_bar(i + 1) #--------------------------------------------- self.imageData.append([]) #new row in image data row = BitArray(file.read(rowSize)) for j in range(self.imageWidth): self.imageData[i].append( self.colorTable[1 if row[j] == 1 else 0]) elif self.bitsPerPixel == 4: for i in range(self.imageHight): # updating progress bar ---------------------- prc = int(100 * (i + 1) / self.imageHight) progress_percent.update(str(prc) + '%') progress_bar.update_bar(i + 1) #--------------------------------------------- self.imageData.append([]) #new row in image data row = BitArray(file.read(rowSize)) pixels = list(row.cut(4)) for j in range(self.imageWidth): self.imageData[i].append( self.colorTable[pixels[j].int]) elif self.bitsPerPixel == 8: for i in range(self.imageHight): # updating progress bar ---------------------- prc = int(100 * (i + 1) / self.imageHight) progress_percent.update(str(prc) + '%') progress_bar.update_bar(i + 1) #--------------------------------------------- self.imageData.append([]) #new row in image data row = list(file.read(rowSize)) for j in range(self.imageWidth): self.imageData[i].append(self.colorTable[row[j]]) elif self.bitsPerPixel == 16: pass elif self.bitsPerPixel == 24: for i in range(self.imageHight): # updating progress bar ---------------------- prc = int(100 * (i + 1) / self.imageHight) progress_percent.update(str(prc) + '%') progress_bar.update_bar(i + 1) #--------------------------------------------- self.imageData.append([]) #new row in image data row = list(file.read(rowSize)) for j in range(self.imageWidth): blue = row[3 * j + 0] green = row[3 * j + 1] red = row[3 * j + 2] self.imageData[i].append(RGBA(red, green, blue, 0)) elif self.bitsPerPixel == 32: pass if self.imageHight > 0: self.imageData = list(reversed(self.imageData)) window.close()