From 837edb131db63a4eacb5855bd93e88960d39b031 Mon Sep 17 00:00:00 2001 From: Roman Dvorak Date: Wed, 22 Jun 2022 00:37:47 +0200 Subject: [PATCH 1/2] convert raw2dng script to python3 --- python_raw2dng/pyraw2dng.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/python_raw2dng/pyraw2dng.py b/python_raw2dng/pyraw2dng.py index e8bab27..38a55c8 100755 --- a/python_raw2dng/pyraw2dng.py +++ b/python_raw2dng/pyraw2dng.py @@ -1,4 +1,4 @@ -#!/usr/bin/python2.7 +#!/usr/bin/python # standard python imports import sys @@ -28,7 +28,7 @@ class Type: IFD = (13,4) # IFD (Same as Long) Types = [(getattr(Type,n),n) for n in dir(Type) if n!="__doc__" and n!="__module__"] -Types.sort() + class Tag: Invalid = (0,Type.Invalid) @@ -144,11 +144,11 @@ class Tag: BaselineExposureOffset = (51109,Type.Srational) # 1.4 Spec says rational but mentions negative values? NewRawImageDigest = (51111,Type.Byte) -IfdNames = [n for n in dir(Tag) if n!="__doc__" and n!="__module__"] -IfdValues = [getattr(Tag,n) for n in IfdNames] -IfdIdentifiers = [getattr(Tag,n)[0] for n in IfdNames] -IfdTypes = [getattr(Tag,n)[1][0] for n in IfdNames] -IfdLookup = dict(zip(IfdIdentifiers,IfdNames)) +# IfdNames = [n for n in dir(Tag) if n!="__doc__" and n!="__module__"] +# IfdValues = [getattr(Tag,n) for n in IfdNames] +# IfdIdentifiers = [getattr(Tag,n) for n in IfdNames] +# IfdTypes = [getattr(Tag,n) for n in IfdNames] +# IfdLookup = dict(list(zip(IfdIdentifiers,IfdNames))) class dngHeader(object): def __init__(self): @@ -188,12 +188,12 @@ def setValue(self, value): elif self.DataType == Type.Rational: self.Value = struct.pack('<%sL' % (len(value)*2), *[item for sublist in value for item in sublist]) # ... This... uhm... flattens the list of two value pairs elif self.DataType == Type.Srational: self.Value = struct.pack('<%sl' % (len(value)*2), *[item for sublist in value for item in sublist]) elif self.DataType == Type.Ascii: - self.Value = struct.pack('<%scx0L' % len(value), *value) + self.Value = struct.pack('<%scx0L' % len(value), *[bytes(x, 'utf-8') for x in value]) self.DataCount += 1 elif self.DataType == Type.IFD: - self.Value = "\x00\x00\x00\x00" + self.Value = b'\x00\x00\x00\x00' self.subIFD = value[0] - self.Value += '\x00'*(((len(self.Value)+3) & 0xFFFFFFFC) - len(self.Value)) + self.Value += b'\x00'*(((len(self.Value)+3) & 0xFFFFFFFC) - len(self.Value)) def setBuffer(self, buf, tagOffset, dataOffset): @@ -298,7 +298,7 @@ def dataLen(self): return (totalLength + 3) & 0xFFFFFFFC def write(self): - struct.pack_into(" Date: Sat, 6 Aug 2022 23:45:30 +0200 Subject: [PATCH 2/2] Update README.md --- python_raw2dng/README.md | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/python_raw2dng/README.md b/python_raw2dng/README.md index a819b8a..83c11ac 100644 --- a/python_raw2dng/README.md +++ b/python_raw2dng/README.md @@ -13,11 +13,9 @@ This will, however, automatically make a directory where it will put the output Requirements ------------ -Python 2.7 +Python 3 -This might work in Python 3 as well, but it has not been tested. - -Windows users will need Python 2.7, available here: https://www.python.org/downloads/release/python-278/ +Windows users will need Python, [available here](https://www.python.org/downloads/windows/) Instructions ------------ @@ -26,21 +24,20 @@ Copy the script file, pyraw2dng.py and the raw 16 bit format video into the same Open a terminal in that directory and use a command similar to the following, but replacing (width) and (length) with the horizontal and vertical resolutions of the video, and (filename.raw) with the name of the raw video file. -For Windows: -python pyraw2dng.py -w (width) -l (length) (filename.raw) - Note: Under default install (without python in PATH), the first term "python" has to be replaced with "c:\Python27\python.exe" +### For Windows + + python pyraw2dng.py -w (width) -l (length) (filename.raw) + +Under default install (without python in PATH), the first term "python" has to be replaced with "c:\Python37\python.exe" -For Linux: -./pyraw2dng.py -w (width) -l (length) (filename.raw) +### For Linux: + + ./pyraw2dng.py -w (width) -l (length) (filename.raw) Optional arguments to add to decode 12-bit videos: -The --packed option will decode the raw file as a 12-bit packed format -generated from cameras with a software version v0.3.1 and newer. -The --oldpack option will attempt to decode the raw file as a 12-bit -packed format generated from software versions v0.3.0 and older. However -due bugs in this encoding format, there may be off-by-one pixel errors -in the encoded files. This is most noticeable as colour corruption -after demosiac. + + * --packed option will decode the raw file as a 12-bit packed format generated from cameras with a software version v0.3.1 and newer. + * --oldpack option will attempt to decode the raw file as a 12-bit packed format generated from software versions v0.3.0 and older. However due bugs in this encoding format, there may be off-by-one pixel errors in the encoded files. This is most noticeable as colour corruption after demosiac. If the script runs successfully, there will be a folder with the same name as your file containing the .dng images and the text "(filename).raw" will appear in the terminal.