Skip to content

Commit

Permalink
use original pHash source code & extract patch to support alpha chann…
Browse files Browse the repository at this point in the history
…el PNGs

fix PR#20 => westonplatter#23
  • Loading branch information
ryoga-chan committed Nov 22, 2023
1 parent 6fe4bdc commit 9141857
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ ext/phashion_ext
!ext/phashion_ext/extconf.rb
!ext/phashion_ext/phashion_ext.c
!ext/phashion_ext/pHash-0.9.6.tar.gz
!ext/phashion_ext/patches
lib/phashion_ext.bundle
5 changes: 5 additions & 0 deletions ext/phashion_ext/extconf.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'mkmf'
require 'fileutils'

BASEDIR = File.expand_path(File.dirname(__FILE__))
BUNDLE = Dir.glob("#{BASEDIR}/pHash-*.tar.gz").first
Expand All @@ -19,6 +20,10 @@
puts(cmd = "tar xzf #{BUNDLE} 2>&1")
raise "'#{cmd}' failed" unless system(cmd)

puts "patching pHash sources for PNG alpha channel support"
puts(cmd = "patch -d pHash-0.9.6 -p1 < #{File.join 'patches', 'png_alpha.diff'}")
raise "'#{cmd}' failed" unless system(cmd)

Dir.chdir(BUNDLE_PATH) do
puts(cmd = "env CXXFLAGS='#{$CXXFLAGS}' CFLAGS='#{$CFLAGS}' LDFLAGS='#{$LDFLAGS}' ./configure --prefix=#{BASEDIR} --disable-audio-hash --disable-video-hash --disable-shared --with-pic 2>&1")
raise "'#{cmd}' failed" unless system(cmd)
Expand Down
Binary file modified ext/phashion_ext/pHash-0.9.6.tar.gz
Binary file not shown.
16 changes: 16 additions & 0 deletions ext/phashion_ext/patches/png_alpha.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--- pHash-0.9.6-orig/src/pHash.cpp 2013-04-13 19:23:12.000000000 +0200
+++ pHash-0.9.6-mod/src/pHash.cpp 2013-11-25 02:53:36.000000000 +0100
@@ -369,10 +369,9 @@
if (src.spectrum() == 3){
img = src.RGBtoYCbCr().channel(0).get_convolve(meanfilter);
} else if (src.spectrum() == 4){
- int width = img.width();
- int height = img.height();
- int depth = img.depth();
- img = src.crop(0,0,0,0,width-1,height-1,depth-1,2).RGBtoYCbCr().channel(0).get_convolve(meanfilter);
+ int width = src.width();
+ int height = src.height();
+ img = src.crop(0,0,0,0,width-1,height-1,0,2).RGBtoYCbCr().channel(0).get_convolve(meanfilter);
} else {
img = src.channel(0).get_convolve(meanfilter);
}

0 comments on commit 9141857

Please sign in to comment.