00001
00002
00003
00004
00005 from imagesettings import *
00006
00007 class ReferenceFile:
00008 """Stores data about reference and input files used to generate output.
00009 """
00010 def __init__(self, infname, fname, w, h, stretch):
00011 """Constructor.
00012
00013 Creates the reference file.
00014
00015 Data members:
00016 Name : Filename of the reference file.
00017 InputSize : Size of the input file.
00018 Size : Size of the reference file.
00019 Width : Width of the reference file in px.
00020 Height : Height of the reference file in px.
00021 Colors : Count of unique colors in the file.
00022 """
00023 self.Name = fname
00024 inparams = run_bash("gm identify -format \"%w %h\" '" +\
00025 infname + "'").split(" ")
00026 self.InputName = infname
00027 self.InputSize = file_size(infname)
00028 if w or h:
00029 inwidth = int(inparams[0])
00030 inheight = int(inparams[1])
00031 if w and w[-1] == "%":
00032 w = clamp(int(inwidth * float(w[:-1]) / 100.0), 1, 1048576)
00033 if h and h[-1] == "%":
00034 h = clamp(int(inheight * float(h[:-1]) / 100.0), 1, 1048576)
00035 file_convert("png", PNGSettings(9, 6, "truecolor", 8, False), infname,
00036 self.Name, [w, h, stretch])
00037 refparams = run_bash("gm identify -format \"%w %h %k\" '" + self.Name\
00038 + "'").split(" ")
00039 self.Size = file_size(self.Name)
00040 self.Width = int(refparams[0])
00041 self.Height = int(refparams[1])
00042 self.Colors = int(refparams[2])