schoolpost / PiDNG

Create Adobe DNG RAW files using Python. Works with any Bayer RAW Data including native support for Raspberry Pi cameras.
MIT License
199 stars 37 forks source link

wrong type for Rational in DNGTags #55

Closed SuTanTank closed 2 years ago

SuTanTank commented 2 years ago
class DNGTags:
    def __init__(self):
        self.__tags__ = dict()

    def set(self, tag, value):
        if isinstance(value, int):
            self.__tags__[tag] = (value,)
        elif isinstance(value, float):
            self.__tags__[tag] = (value,)
        elif isinstance(value, str):
            self.__tags__[tag] = value
        elif len(value) > 1:
            self.__tags__[tag] = value
        else:
            self.__tags__[tag] = (value,)

    def get(self, tag):
        return self.__tags__[tag]

    def list(self):
        l = list()
        for k, v in self.__tags__.items():
            l.append((k, v))
        return l
def setValue(self, value):
        if   self.DataType == Type.Byte:      self.Value = struct.pack('<%sB' % len(value), *value)
        ...
        elif self.DataType == Type.Rational:
            self.Value = struct.pack('<%sL' % (len(value)*2), *[item for sublist in value for item in sublist])

When the input value is a single rational number, what's is the acceptable value to be set?

As setValue() defined, value should be a 2D array, like [[a, b]], but DNGTags.set() will convert single element list to tuple.