#
#
#
import logging
# from PIL import Image
from libs.jpg_bin import JpgBin
from libs.crypto_pub import Signature


class JpgTools:

  def __init__(self):
    self.fh  = None
    self.jpg = None
    self.sig = None
    self.is_processed = False

  #
  # process a jpg file, read only
  #
  def getJpgBin(self, fname):
    self.fh = open(fname, "rb")
    self.jpg = JpgBin()
    retval = self.jpg.processFile(self.fh)
    logging.info("processFile()=={}".format(retval))
    self.is_processed = True
    return self.jpg

  #
  # hash the jpg image data
  #
  def jpgHash(self):
    if (not self.is_processed):
      self.getJpgBin(fname)

    # hash the jpg image data
    self.sig = Signature()
    img_hash = self.jpg.genHash(self.sig.hh)
    logging.info("img_hash-size=={}, img_hash=={}".format(len(img_hash), img_hash))
    return img_hash
