Browse Source

Use gamma 2.2 space when resizing

nagadomi 9 years ago
parent
commit
6e41796328
2 changed files with 18 additions and 4 deletions
  1. 14 0
      lib/iproc.lua
  2. 4 4
      web.lua

+ 14 - 0
lib/iproc.lua

@@ -57,6 +57,20 @@ function iproc.scale(src, width, height, filter)
    im:size(math.ceil(width), math.ceil(height), filter)
    return im:toTensor(t, "RGB", "DHW")
 end
+function iproc.scale_with_gamma22(src, width, height, filter)
+   local conversion
+   src, conversion = iproc.byte2float(src)
+   filter = filter or "Box"
+   local im = gm.Image(src, "RGB", "DHW")
+   im:gammaCorrection(1.0 / 2.2):
+      size(math.ceil(width), math.ceil(height), filter):
+      gammaCorrection(2.2)
+   local dest = im:toTensor("float", "RGB", "DHW")
+   if conversion then
+      dest = iproc.float2byte(dest)
+   end
+   return dest
+end
 function iproc.padding(img, w1, w2, h1, h2)
    local dst_height = img:size(2) + h1 + h2
    local dst_width = img:size(3) + w1 + w2

+ 4 - 4
web.lua

@@ -163,10 +163,10 @@ function APIHandler:post()
 	       x = convert(x, {method = "scale", style = style, prefix = style .. "_scale_" .. hash})
 	    end
 	    if scale == 1 then
-	       x = iproc.scale(x,
-			       math.floor(x:size(3) * (1.6 / 2.0) + 0.5),
-			       math.floor(x:size(2) * (1.6 / 2.0) + 0.5),
-			       "Jinc")
+	       x = iproc.scale_with_gamma22(x,
+					    math.floor(x:size(3) * (1.6 / 2.0) + 0.5),
+					    math.floor(x:size(2) * (1.6 / 2.0) + 0.5),
+					    "Jinc")
 	    end
 	 end
       end