# # # from PIL import Image # # 0xFF,0xD8 - Start of Image # 0xFF,0xEn - App Exif data # 0xFF,0xD8 - DQT - Define Quantization Table # 0xFF,0xDD - DRI - Define Restart Interval # 0xFF,0xFE - Comments # 0xFF,0xC0 - SOF0 - Start of Frame # 0xFF,0xC2 - SOF2 - Start of Frame # 0xFF,0xC4 - DHT - Define Huffman Tables # 0xFF,0xDA - SOS - Start of Scan # 0xFF,0xDn - RST - Restart (n=0..7) # 0xFF,0xEn - Application # 0xFF,0xD9 # # # https://en.wikipedia.org/wiki/JPEG class JpgTools: BUF_CHUNK_SIZE = 2048 data_buf = None data_idx = None fh = None def __init__(self): pass # def jpgHash(self): def findMarkers(self): last_idx = len(self.data_buf) while while ord(self.data_buf[self.data_idx]) != 0xFF: self.data_idx = self.data_idx+1 for idx in range(last_idx): while self.data_buf: self.getBytes pass def processFile(self, fname): self.data_buf = self.fh.read(self.BUF_CHUNK_SIZE) while self.data_buf: (ret, fin) = self.findMarkers() # def getBytes(self, fname): if (not self.fh): self.fh = open(fname, "rb") self.data_buf = self.fh.read(self.BUF_CHUNK_SIZE) def processFile(self, fname): self.fh = open(fname, "rb") self.data_buf = self.fh.read(self.BUF_CHUNK_SIZE) if (self.data_buf): self.data_idx = 0 findMarkers() # def process_OLD(self, fname): Image.open(fname) # image as a sequence object containing pixel values bin_data = list( im.getdata() ) # returns a string containing pixel data, using the standard "raw" encoder im.tostring() # def getJpgBin_OLD(self, fname): img_h = Image.open(fname) img_bin = list(img_h.getdata()) return img_bin