Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions src/pidng/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __filter__(self, rawFrame: np.ndarray, filter : types.FunctionType) -> np.nd
return processed


def __process__(self, rawFrame : np.ndarray, tags: DNGTags, compress : bool) -> bytearray:
def __process__(self, rawFrame : np.ndarray, tags: DNGTags, compress : bool, predictor: int = 6) -> bytearray:

width = tags.get(Tag.ImageWidth).rawValue[0]
length = tags.get(Tag.ImageLength).rawValue[0]
Expand All @@ -61,12 +61,20 @@ def __process__(self, rawFrame : np.ndarray, tags: DNGTags, compress : bool) ->
backward_version = DNGVersion.V1_4
# Floating-point data has to be compressed with deflate
if compress:
raise Exception('Compression is not supported for floating-point data')
raise Exception("Compression is not supported for floating-point data")

if compress:
from ljpegCompress import pack16tolj
tile = pack16tolj(rawFrame, int(width*2),
int(length/2), bpp, 0, 0, 0, "", 6)

if predictor == 1:
tile = pack16tolj(rawFrame, int(width),
int(length), bpp, 0, 0, 0, "", 1)
elif predictor == 6:
tile = pack16tolj(rawFrame, int(width*2),
int(length/2), bpp, 0, 0, 0, "", 6)
else:
raise Exception("Predictor must be either 1 or 6")

else:
if bpp == 8:
tile = rawFrame.astype('uint8').tobytes()
Expand Down Expand Up @@ -116,11 +124,12 @@ def __process__(self, rawFrame : np.ndarray, tags: DNGTags, compress : bool) ->

return buf

def options(self, tags : DNGTags, path : str, compress=False) -> None:
def options(self, tags : DNGTags, path : str, compress=False, predictor=6) -> None:
self.__tags_condition__(tags)
self.tags = tags
self.compress = compress
self.path = path
self.predictor = predictor

def convert(self, image : np.ndarray, filename=""):

Expand All @@ -131,7 +140,7 @@ def convert(self, image : np.ndarray, filename=""):
self.__data_condition__(image)
unpacked = self.__unpack_pixels__(image)
filtered = self.__filter__(unpacked, self.filter)
buf = self.__process__(filtered, self.tags, self.compress)
buf = self.__process__(filtered, self.tags, self.compress, self.predictor)

file_output = False
if len(filename) > 0:
Expand Down