Skip to content

Commit

Permalink
Refactoring: extract method
Browse files Browse the repository at this point in the history
  • Loading branch information
jabriffa committed Jun 13, 2018
1 parent dc4a3ab commit 8b2fdcd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
14 changes: 14 additions & 0 deletions pyshared/jbcr2.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,17 @@ def decode_lossless_jpeg(filename):
os.rmdir(tmpfolder)

return a, len(components)

## unslice sensor image

def unslice(a, width, height, slices):
# make a list of the width of each slice
slice_widths = [slices[1]] * slices[0] + [slices[2]]
assert sum(slice_widths) == width
# next unslice image
I = np.zeros((height, width), dtype=np.dtype('>H'))
for i, sw in enumerate(slice_widths):
col_s = sum(slice_widths[0:i])
col_e = col_s + sw
I[:,col_s:col_e] = a.flat[col_s*height:col_e*height].reshape(height,sw)
return I
10 changes: 1 addition & 9 deletions raw_decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,11 @@ def main():

# convert lossless JPEG encoded input file to raw data
a, components = jbcr2.decode_lossless_jpeg(args.input)

# obtain required parameters from RAW file
width,height = tiff.get_sensor_size()
slices = tiff.get_slices()
# make a list of the width of each slice
slice_widths = [slices[1]] * slices[0] + [slices[2]]
assert sum(slice_widths) == width
# next unslice image
I = np.zeros((height, width), dtype=np.dtype('>H'))
for i, sw in enumerate(slice_widths):
col_s = sum(slice_widths[0:i])
col_e = col_s + sw
I[:,col_s:col_e] = a.flat[col_s*height:col_e*height].reshape(height,sw)
I = jbcr2.unslice(a, width, height, slices)

# save result
jbtiff.pnm_file.write(I.astype('>H'), open(args.output,'wb'))
Expand Down

0 comments on commit 8b2fdcd

Please sign in to comment.