aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Formula/openimageio.rb
blob: 9cbc872ad7fe5b44c6ec9454e2c4c765ca6f5e68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
require 'formula'

class J2kp4files < Formula
  url 'http://pkgs.fedoraproject.org/repo/pkgs/openjpeg/j2kp4files_v1_5.zip/27780ed3254e6eb763ebd718a8ccc340/j2kp4files_v1_5.zip'
  md5 '27780ed3254e6eb763ebd718a8ccc340'
end

class Tiffpic < Formula
  url 'ftp://ftp.remotesensing.org/pub/libtiff/pics-3.8.0.tar.gz'
  sha1 'f50e14335fd98f73c6a235d3ff4d83cf4767ab37'
end

class Bmpsuite < Formula
  url 'http://entropymine.com/jason/bmpsuite/bmpsuite.zip'
  sha1 '2e43ec4d8e6f628f71a554c327433914000db7ba'
  version '1.0.0'
end

class Tgautils < Formula
  url 'http://makseq.com/materials/lib/Code/FileFormats/BitMap/TARGA/TGAUTILS.ZIP'
  sha1 '0902c51e7b00ae70a460250f60d6adc41c8095df'
  version '1.0.0'
end

class OpenexrImages < Formula
  url 'http://download.savannah.nongnu.org/releases/openexr/openexr-images-1.5.0.tar.gz'
  sha1 '22bb1a3d37841a88647045353f732ceac652fd3f'
end

class OiioImages < Formula
  url 'https://github.com/OpenImageIO/oiio-images/tarball/9bf43561f5'
  sha1 '8f12a86098120fd10ceb294a0d3aa1c95a0d3f80'
  version '1.0.0'
end


class Openimageio < Formula
  homepage 'http://openimageio.org'
  url 'https://github.com/OpenImageIO/oiio/tarball/Release-1.0.8'
  sha1 '9ac265c279392117025cc18061742c3c1392d549'

  head 'https://github.com/OpenImageIO/oiio.git'

  depends_on 'cmake' => :build
  depends_on 'pkg-config' => :build
  depends_on 'opencolorio'
  depends_on 'ilmbase'
  depends_on 'openexr'
  depends_on 'boost'
  depends_on 'libtiff'
  depends_on 'jpeg'
  depends_on 'openjpeg'
  depends_on 'cfitsio'
  depends_on 'hdf5'
  depends_on 'field3d'
  depends_on 'webp'
  depends_on 'glew'
  depends_on 'qt'

  def options
    [['--with-tests',  'Dowload 95MB of test images and verify Oiio (~2 min).']]
  end

  def install
    # Oiio is designed to have its testsuite images extracted one directory
    # above the source.  That's not a safe place for HB.  Do the opposite,
    # and move the entire source down into a subdirectory if --with-tests.
    if ARGV.include? '--with-tests' then
      (buildpath+'localpub').install Dir['*']
      chdir 'localpub'
    end

    ENV.append 'MY_CMAKE_FLAGS', "-Wno-dev"   # stops a warning.
    args = ["USE_TBB=1", "EMBEDPLUGINS=1"]


    python_prefix = `python-config --prefix`.strip
    # Python is actually a library. The libpythonX.Y.dylib points to this lib, too.
    if File.exist? "#{python_prefix}/Python"
      # Python was compiled with --framework:
      ENV.append 'MY_CMAKE_FLAGS', "-DPYTHON_LIBRARY='#{python_prefix}/Python'"
      ENV.append 'MY_CMAKE_FLAGS', "-DPYTHON_INCLUDE_DIR='#{python_prefix}/Headers'"
    else
      python_version = `python-config --libs`.match('-lpython(\d+\.\d+)').captures.at(0)
      python_lib = "#{python_prefix}/lib/libpython#{python_version}"
      ENV.append 'MY_CMAKE_FLAGS', "-DPYTHON_INCLUDE_DIR='#{python_prefix}/include/python#{python_version}'"
      if File.exists? "#{python_lib}.a"
        ENV.append 'MY_CMAKE_FLAGS', "-DPYTHON_LIBRARY='#{python_lib}.a'"
      else
        ENV.append 'MY_CMAKE_FLAGS', "-DPYTHON_LIBRARY='#{python_lib}.dylib'"
      end
    end


    # Download standardized test images if the user throws --with-tests.
    # 90% of the images are in tarballs, so they are cached normally.
    # The webp and fits images are loose.  Curl them each install.
    if ARGV.include? '--with-tests' then
      d = buildpath
      mkdir d+'webp-images' do
        curl "http://www.gstatic.com/webp/gallery/[1-5].webp", "-O"
      end
      mkdir d+'fits-images'
      mkdir d+'fits-images/pg93' do
        curl "http://www.cv.nrao.edu/fits/data/tests/pg93/tst000[1-3].fits", "-O"
        curl "http://www.cv.nrao.edu/fits/data/tests/pg93/tst000[5-9].fits", "-O"
        curl "http://www.cv.nrao.edu/fits/data/tests/pg93/tst0013.fits", "-O"
      end
      mkdir d+'fits-images/ftt4b' do
        curl "http://www.cv.nrao.edu/fits/data/tests/ftt4b/file00[1-3].fits", "-O"
        curl "http://www.cv.nrao.edu/fits/data/tests/ftt4b/file0{09,12}.fits", "-O"
      end
      J2kp4files.new.brew { (d+'j2kp4files_v1_5').install Dir['J2KP4files/*'] }
      Tiffpic.new.brew { (d+'libtiffpic').install Dir['*'] }
      Bmpsuite.new.brew { (d+'bmpsuite').install Dir['*'] }
      Tgautils.new.brew { (d+'TGAUTILS').install Dir['*'] }
      OpenexrImages.new.brew { (d+'openexr-images-1.5.0').install Dir['*'] }
      OiioImages.new('oiioimages').brew { (d+'oiio-images').install Dir['*'] }
    end


    # make is a shell wrapper for cmake crafted by the devs (who have Lion).
    system "make", *args
    system "make test" if ARGV.include? '--with-tests'
    # There is no working make install in 1.0.2, devel or HEAD.
    Dir.chdir 'dist/macosx' do
      (lib + which_python ).install 'lib/python/site-packages'
      prefix.install %w[ bin include ]
      lib.install    Dir[ 'lib/lib*' ]
      doc.install    'share/doc/openimageio/openimageio.pdf'
      prefix.install Dir['share/doc/openimageio/*']
    end
  end

  def caveats; <<-EOS.undent
    If OpenImageIO is brewed using non-homebrew Python, then you need to amend
    your PYTHONPATH like so:
      export PYTHONPATH=#{HOMEBREW_PREFIX}/lib/#{which_python}/site-packages:$PYTHONPATH
    EOS
  end

  def which_python
    "python" + `python -c 'import sys;print(sys.version[:3])'`.strip
  end
end