diff options
author | Vladimir S. FONOV <vladimir.fonov@gmail.com> | 2017-03-23 05:14:12 +0300 |
---|---|---|
committer | Soumith Chintala <soumith@gmail.com> | 2017-03-23 05:14:12 +0300 |
commit | 705393fabf51581b98142c9223c5aee6b62bb131 (patch) | |
tree | fd00058595869bf7bd5d67d88d3db0a343e7c95c /init.lua | |
parent | fc214c0292f014d71312b1bbb3c54a75e0cda3b6 (diff) |
Added code to compress tensor into PNG in-memory similar to compressJPG, also added a test (#211)
Diffstat (limited to 'init.lua')
-rw-r--r-- | init.lua | 17 |
1 files changed, 16 insertions, 1 deletions
@@ -173,7 +173,8 @@ local function savePNG(filename, tensor) dok.error('libpng package not found, please install libpng','image.savePNG') end tensor = clampImage(tensor) - tensor.libpng.save(filename, tensor) + local save_to_file = 1 + tensor.libpng.save(filename, tensor, save_to_file) end rawset(image, 'savePNG', savePNG) @@ -203,6 +204,20 @@ function image.getPNGsize(filename) return torch.Tensor().libpng.size(filename) end +local function compressPNG(tensor) + if not xlua.require 'libpng' then + dok.error('libpng package not found, please install libpng', + 'image.compressPNG') + end + tensor = clampImage(tensor) + local b = torch.ByteTensor() + local save_to_file = 0 + tensor.libpng.save("", tensor, save_to_file, b) + return b +end +rawset(image, 'compressPNG', compressPNG) + + local function processJPG(img, depth, tensortype) local MAXVAL = 255 if tensortype ~= 'byte' then |