joonsrenderer 1.1-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (255) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +53 -0
  3. data/.mvn/extensions.xml +8 -0
  4. data/CHANGELOG.md +2 -0
  5. data/Gemfile +6 -0
  6. data/LICENSE +674 -0
  7. data/README.md +2 -0
  8. data/Rakefile +43 -0
  9. data/docs/.gitignore +6 -0
  10. data/docs/_config.yml +20 -0
  11. data/docs/_includes/footer.html +38 -0
  12. data/docs/_includes/head.html +15 -0
  13. data/docs/_includes/header.html +27 -0
  14. data/docs/_includes/icon-github.html +1 -0
  15. data/docs/_includes/icon-github.svg +1 -0
  16. data/docs/_includes/icon-twitter.html +1 -0
  17. data/docs/_includes/icon-twitter.svg +1 -0
  18. data/docs/_layouts/default.html +20 -0
  19. data/docs/_layouts/page.html +14 -0
  20. data/docs/_layouts/post.html +15 -0
  21. data/docs/_posts/2017-01-08-animated_ray_tracing.md +72 -0
  22. data/docs/_posts/2017-01-08-welcome.md +78 -0
  23. data/docs/_sass/_base.scss +206 -0
  24. data/docs/_sass/_layout.scss +242 -0
  25. data/docs/_sass/_syntax-highlighting.scss +71 -0
  26. data/docs/about.md +12 -0
  27. data/docs/assets/Animation.ogv +0 -0
  28. data/docs/assets/Animation.png +0 -0
  29. data/docs/assets/basic.png +0 -0
  30. data/docs/assets/basic_traced.png +0 -0
  31. data/docs/css/main.scss +38 -0
  32. data/docs/favicon.ico +0 -0
  33. data/docs/feed.xml +30 -0
  34. data/docs/index.html +38 -0
  35. data/joonsrenderer.gemspec +23 -0
  36. data/lib/joonsrenderer.rb +12 -0
  37. data/lib/joonsrenderer/version.rb +3 -0
  38. data/pom.rb +75 -0
  39. data/pom.xml +163 -0
  40. data/src/main/java/SunflowGUI.java +1354 -0
  41. data/src/main/java/joons/JRFiller.java +79 -0
  42. data/src/main/java/joons/JRImagePanel.java +141 -0
  43. data/src/main/java/joons/JRRecorder.java +183 -0
  44. data/src/main/java/joons/JRStatics.java +199 -0
  45. data/src/main/java/joons/JoonsRenderer.java +837 -0
  46. data/src/main/java/org/sunflow/AsciiFileSunflowAPI.java +98 -0
  47. data/src/main/java/org/sunflow/Benchmark.java +313 -0
  48. data/src/main/java/org/sunflow/BinaryFileSunflowAPI.java +228 -0
  49. data/src/main/java/org/sunflow/FileSunflowAPI.java +354 -0
  50. data/src/main/java/org/sunflow/PluginRegistry.java +322 -0
  51. data/src/main/java/org/sunflow/RealtimeBenchmark.java +125 -0
  52. data/src/main/java/org/sunflow/RenderObjectMap.java +344 -0
  53. data/src/main/java/org/sunflow/SunflowAPI.java +762 -0
  54. data/src/main/java/org/sunflow/SunflowAPIInterface.java +277 -0
  55. data/src/main/java/org/sunflow/core/AccelerationStructure.java +20 -0
  56. data/src/main/java/org/sunflow/core/AccelerationStructureFactory.java +36 -0
  57. data/src/main/java/org/sunflow/core/BucketOrder.java +21 -0
  58. data/src/main/java/org/sunflow/core/Camera.java +125 -0
  59. data/src/main/java/org/sunflow/core/CameraLens.java +29 -0
  60. data/src/main/java/org/sunflow/core/CausticPhotonMapInterface.java +15 -0
  61. data/src/main/java/org/sunflow/core/Display.java +78 -0
  62. data/src/main/java/org/sunflow/core/Filter.java +27 -0
  63. data/src/main/java/org/sunflow/core/GIEngine.java +42 -0
  64. data/src/main/java/org/sunflow/core/Geometry.java +157 -0
  65. data/src/main/java/org/sunflow/core/GlobalPhotonMapInterface.java +21 -0
  66. data/src/main/java/org/sunflow/core/ImageSampler.java +26 -0
  67. data/src/main/java/org/sunflow/core/Instance.java +224 -0
  68. data/src/main/java/org/sunflow/core/InstanceList.java +83 -0
  69. data/src/main/java/org/sunflow/core/IntersectionState.java +120 -0
  70. data/src/main/java/org/sunflow/core/LightSample.java +104 -0
  71. data/src/main/java/org/sunflow/core/LightServer.java +382 -0
  72. data/src/main/java/org/sunflow/core/LightSource.java +67 -0
  73. data/src/main/java/org/sunflow/core/Modifier.java +16 -0
  74. data/src/main/java/org/sunflow/core/Options.java +20 -0
  75. data/src/main/java/org/sunflow/core/ParameterList.java +758 -0
  76. data/src/main/java/org/sunflow/core/PhotonStore.java +62 -0
  77. data/src/main/java/org/sunflow/core/PrimitiveList.java +70 -0
  78. data/src/main/java/org/sunflow/core/Ray.java +219 -0
  79. data/src/main/java/org/sunflow/core/RenderObject.java +25 -0
  80. data/src/main/java/org/sunflow/core/Scene.java +377 -0
  81. data/src/main/java/org/sunflow/core/SceneParser.java +58 -0
  82. data/src/main/java/org/sunflow/core/Shader.java +30 -0
  83. data/src/main/java/org/sunflow/core/ShadingCache.java +84 -0
  84. data/src/main/java/org/sunflow/core/ShadingState.java +939 -0
  85. data/src/main/java/org/sunflow/core/Statistics.java +85 -0
  86. data/src/main/java/org/sunflow/core/Tesselatable.java +36 -0
  87. data/src/main/java/org/sunflow/core/Texture.java +128 -0
  88. data/src/main/java/org/sunflow/core/TextureCache.java +48 -0
  89. data/src/main/java/org/sunflow/core/accel/BoundingIntervalHierarchy.java +652 -0
  90. data/src/main/java/org/sunflow/core/accel/KDTree.java +833 -0
  91. data/src/main/java/org/sunflow/core/accel/NullAccelerator.java +30 -0
  92. data/src/main/java/org/sunflow/core/accel/UniformGrid.java +329 -0
  93. data/src/main/java/org/sunflow/core/bucket/BucketOrderFactory.java +26 -0
  94. data/src/main/java/org/sunflow/core/bucket/ColumnBucketOrder.java +21 -0
  95. data/src/main/java/org/sunflow/core/bucket/DiagonalBucketOrder.java +28 -0
  96. data/src/main/java/org/sunflow/core/bucket/HilbertBucketOrder.java +65 -0
  97. data/src/main/java/org/sunflow/core/bucket/InvertedBucketOrder.java +28 -0
  98. data/src/main/java/org/sunflow/core/bucket/RandomBucketOrder.java +49 -0
  99. data/src/main/java/org/sunflow/core/bucket/RowBucketOrder.java +21 -0
  100. data/src/main/java/org/sunflow/core/bucket/SpiralBucketOrder.java +43 -0
  101. data/src/main/java/org/sunflow/core/camera/FisheyeLens.java +25 -0
  102. data/src/main/java/org/sunflow/core/camera/PinholeLens.java +43 -0
  103. data/src/main/java/org/sunflow/core/camera/SphericalLens.java +22 -0
  104. data/src/main/java/org/sunflow/core/camera/ThinLens.java +107 -0
  105. data/src/main/java/org/sunflow/core/display/FastDisplay.java +119 -0
  106. data/src/main/java/org/sunflow/core/display/FileDisplay.java +83 -0
  107. data/src/main/java/org/sunflow/core/display/FrameDisplay.java +97 -0
  108. data/src/main/java/org/sunflow/core/display/ImgPipeDisplay.java +109 -0
  109. data/src/main/java/org/sunflow/core/filter/BlackmanHarrisFilter.java +28 -0
  110. data/src/main/java/org/sunflow/core/filter/BoxFilter.java +16 -0
  111. data/src/main/java/org/sunflow/core/filter/CatmullRomFilter.java +29 -0
  112. data/src/main/java/org/sunflow/core/filter/CubicBSpline.java +32 -0
  113. data/src/main/java/org/sunflow/core/filter/GaussianFilter.java +24 -0
  114. data/src/main/java/org/sunflow/core/filter/LanczosFilter.java +30 -0
  115. data/src/main/java/org/sunflow/core/filter/MitchellFilter.java +28 -0
  116. data/src/main/java/org/sunflow/core/filter/SincFilter.java +25 -0
  117. data/src/main/java/org/sunflow/core/filter/TriangleFilter.java +16 -0
  118. data/src/main/java/org/sunflow/core/gi/AmbientOcclusionGIEngine.java +57 -0
  119. data/src/main/java/org/sunflow/core/gi/FakeGIEngine.java +48 -0
  120. data/src/main/java/org/sunflow/core/gi/InstantGI.java +194 -0
  121. data/src/main/java/org/sunflow/core/gi/IrradianceCacheGIEngine.java +268 -0
  122. data/src/main/java/org/sunflow/core/gi/PathTracingGIEngine.java +65 -0
  123. data/src/main/java/org/sunflow/core/light/DirectionalSpotlight.java +103 -0
  124. data/src/main/java/org/sunflow/core/light/ImageBasedLight.java +303 -0
  125. data/src/main/java/org/sunflow/core/light/PointLight.java +72 -0
  126. data/src/main/java/org/sunflow/core/light/SphereLight.java +166 -0
  127. data/src/main/java/org/sunflow/core/light/SunSkyLight.java +362 -0
  128. data/src/main/java/org/sunflow/core/light/TriangleMeshLight.java +296 -0
  129. data/src/main/java/org/sunflow/core/modifiers/BumpMappingModifier.java +37 -0
  130. data/src/main/java/org/sunflow/core/modifiers/NormalMapModifier.java +34 -0
  131. data/src/main/java/org/sunflow/core/modifiers/PerlinModifier.java +80 -0
  132. data/src/main/java/org/sunflow/core/parser/Keyword.java +39 -0
  133. data/src/main/java/org/sunflow/core/parser/RA2Parser.java +107 -0
  134. data/src/main/java/org/sunflow/core/parser/RA3Parser.java +68 -0
  135. data/src/main/java/org/sunflow/core/parser/SCAbstractParser.java +299 -0
  136. data/src/main/java/org/sunflow/core/parser/SCAsciiParser.java +251 -0
  137. data/src/main/java/org/sunflow/core/parser/SCBinaryParser.java +156 -0
  138. data/src/main/java/org/sunflow/core/parser/SCParser.java +1403 -0
  139. data/src/main/java/org/sunflow/core/parser/ShaveRibParser.java +174 -0
  140. data/src/main/java/org/sunflow/core/parser/TriParser.java +79 -0
  141. data/src/main/java/org/sunflow/core/photonmap/CausticPhotonMap.java +429 -0
  142. data/src/main/java/org/sunflow/core/photonmap/GlobalPhotonMap.java +530 -0
  143. data/src/main/java/org/sunflow/core/photonmap/GridPhotonMap.java +308 -0
  144. data/src/main/java/org/sunflow/core/primitive/Background.java +55 -0
  145. data/src/main/java/org/sunflow/core/primitive/BanchoffSurface.java +100 -0
  146. data/src/main/java/org/sunflow/core/primitive/Box.java +210 -0
  147. data/src/main/java/org/sunflow/core/primitive/CornellBox.java +476 -0
  148. data/src/main/java/org/sunflow/core/primitive/CubeGrid.java +318 -0
  149. data/src/main/java/org/sunflow/core/primitive/Cylinder.java +104 -0
  150. data/src/main/java/org/sunflow/core/primitive/Hair.java +275 -0
  151. data/src/main/java/org/sunflow/core/primitive/JuliaFractal.java +266 -0
  152. data/src/main/java/org/sunflow/core/primitive/ParticleSurface.java +114 -0
  153. data/src/main/java/org/sunflow/core/primitive/Plane.java +163 -0
  154. data/src/main/java/org/sunflow/core/primitive/QuadMesh.java +413 -0
  155. data/src/main/java/org/sunflow/core/primitive/Sphere.java +101 -0
  156. data/src/main/java/org/sunflow/core/primitive/SphereFlake.java +234 -0
  157. data/src/main/java/org/sunflow/core/primitive/Torus.java +145 -0
  158. data/src/main/java/org/sunflow/core/primitive/TriangleMesh.java +849 -0
  159. data/src/main/java/org/sunflow/core/renderer/BucketRenderer.java +491 -0
  160. data/src/main/java/org/sunflow/core/renderer/MultipassRenderer.java +237 -0
  161. data/src/main/java/org/sunflow/core/renderer/ProgressiveRenderer.java +171 -0
  162. data/src/main/java/org/sunflow/core/renderer/SimpleRenderer.java +106 -0
  163. data/src/main/java/org/sunflow/core/shader/AmbientOcclusionShader.java +53 -0
  164. data/src/main/java/org/sunflow/core/shader/AnisotropicWardShader.java +216 -0
  165. data/src/main/java/org/sunflow/core/shader/ConstantShader.java +31 -0
  166. data/src/main/java/org/sunflow/core/shader/DiffuseShader.java +65 -0
  167. data/src/main/java/org/sunflow/core/shader/GlassShader.java +147 -0
  168. data/src/main/java/org/sunflow/core/shader/IDShader.java +27 -0
  169. data/src/main/java/org/sunflow/core/shader/MirrorShader.java +68 -0
  170. data/src/main/java/org/sunflow/core/shader/NormalShader.java +32 -0
  171. data/src/main/java/org/sunflow/core/shader/PhongShader.java +89 -0
  172. data/src/main/java/org/sunflow/core/shader/PrimIDShader.java +30 -0
  173. data/src/main/java/org/sunflow/core/shader/QuickGrayShader.java +63 -0
  174. data/src/main/java/org/sunflow/core/shader/ShinyDiffuseShader.java +98 -0
  175. data/src/main/java/org/sunflow/core/shader/SimpleShader.java +24 -0
  176. data/src/main/java/org/sunflow/core/shader/TexturedAmbientOcclusionShader.java +31 -0
  177. data/src/main/java/org/sunflow/core/shader/TexturedDiffuseShader.java +31 -0
  178. data/src/main/java/org/sunflow/core/shader/TexturedPhongShader.java +31 -0
  179. data/src/main/java/org/sunflow/core/shader/TexturedShinyDiffuseShader.java +31 -0
  180. data/src/main/java/org/sunflow/core/shader/TexturedWardShader.java +31 -0
  181. data/src/main/java/org/sunflow/core/shader/UVShader.java +27 -0
  182. data/src/main/java/org/sunflow/core/shader/UberShader.java +149 -0
  183. data/src/main/java/org/sunflow/core/shader/ViewCausticsShader.java +33 -0
  184. data/src/main/java/org/sunflow/core/shader/ViewGlobalPhotonsShader.java +25 -0
  185. data/src/main/java/org/sunflow/core/shader/ViewIrradianceShader.java +25 -0
  186. data/src/main/java/org/sunflow/core/shader/WireframeShader.java +83 -0
  187. data/src/main/java/org/sunflow/core/tesselatable/BezierMesh.java +254 -0
  188. data/src/main/java/org/sunflow/core/tesselatable/FileMesh.java +251 -0
  189. data/src/main/java/org/sunflow/core/tesselatable/Gumbo.java +1147 -0
  190. data/src/main/java/org/sunflow/core/tesselatable/Teapot.java +237 -0
  191. data/src/main/java/org/sunflow/image/Bitmap.java +15 -0
  192. data/src/main/java/org/sunflow/image/BitmapReader.java +39 -0
  193. data/src/main/java/org/sunflow/image/BitmapWriter.java +79 -0
  194. data/src/main/java/org/sunflow/image/BlackbodySpectrum.java +16 -0
  195. data/src/main/java/org/sunflow/image/ChromaticitySpectrum.java +55 -0
  196. data/src/main/java/org/sunflow/image/Color.java +374 -0
  197. data/src/main/java/org/sunflow/image/ColorEncoder.java +94 -0
  198. data/src/main/java/org/sunflow/image/ColorFactory.java +122 -0
  199. data/src/main/java/org/sunflow/image/ConstantSpectralCurve.java +21 -0
  200. data/src/main/java/org/sunflow/image/IrregularSpectralCurve.java +57 -0
  201. data/src/main/java/org/sunflow/image/RGBSpace.java +207 -0
  202. data/src/main/java/org/sunflow/image/RegularSpectralCurve.java +30 -0
  203. data/src/main/java/org/sunflow/image/SpectralCurve.java +118 -0
  204. data/src/main/java/org/sunflow/image/XYZColor.java +50 -0
  205. data/src/main/java/org/sunflow/image/formats/BitmapBlack.java +27 -0
  206. data/src/main/java/org/sunflow/image/formats/BitmapG8.java +36 -0
  207. data/src/main/java/org/sunflow/image/formats/BitmapGA8.java +30 -0
  208. data/src/main/java/org/sunflow/image/formats/BitmapRGB8.java +40 -0
  209. data/src/main/java/org/sunflow/image/formats/BitmapRGBA8.java +40 -0
  210. data/src/main/java/org/sunflow/image/formats/BitmapRGBE.java +60 -0
  211. data/src/main/java/org/sunflow/image/formats/BitmapXYZ.java +38 -0
  212. data/src/main/java/org/sunflow/image/formats/GenericBitmap.java +73 -0
  213. data/src/main/java/org/sunflow/image/readers/BMPBitmapReader.java +39 -0
  214. data/src/main/java/org/sunflow/image/readers/HDRBitmapReader.java +155 -0
  215. data/src/main/java/org/sunflow/image/readers/IGIBitmapReader.java +104 -0
  216. data/src/main/java/org/sunflow/image/readers/JPGBitmapReader.java +39 -0
  217. data/src/main/java/org/sunflow/image/readers/PNGBitmapReader.java +40 -0
  218. data/src/main/java/org/sunflow/image/readers/TGABitmapReader.java +141 -0
  219. data/src/main/java/org/sunflow/image/writers/EXRBitmapWriter.java +395 -0
  220. data/src/main/java/org/sunflow/image/writers/HDRBitmapWriter.java +54 -0
  221. data/src/main/java/org/sunflow/image/writers/IGIBitmapWriter.java +75 -0
  222. data/src/main/java/org/sunflow/image/writers/PNGBitmapWriter.java +39 -0
  223. data/src/main/java/org/sunflow/image/writers/TGABitmapWriter.java +63 -0
  224. data/src/main/java/org/sunflow/math/BoundingBox.java +340 -0
  225. data/src/main/java/org/sunflow/math/MathUtils.java +159 -0
  226. data/src/main/java/org/sunflow/math/Matrix4.java +573 -0
  227. data/src/main/java/org/sunflow/math/MovingMatrix4.java +119 -0
  228. data/src/main/java/org/sunflow/math/OrthoNormalBasis.java +110 -0
  229. data/src/main/java/org/sunflow/math/PerlinScalar.java +331 -0
  230. data/src/main/java/org/sunflow/math/PerlinVector.java +132 -0
  231. data/src/main/java/org/sunflow/math/Point2.java +36 -0
  232. data/src/main/java/org/sunflow/math/Point3.java +133 -0
  233. data/src/main/java/org/sunflow/math/QMC.java +209 -0
  234. data/src/main/java/org/sunflow/math/Solvers.java +142 -0
  235. data/src/main/java/org/sunflow/math/Vector3.java +197 -0
  236. data/src/main/java/org/sunflow/system/BenchmarkFramework.java +73 -0
  237. data/src/main/java/org/sunflow/system/BenchmarkTest.java +17 -0
  238. data/src/main/java/org/sunflow/system/ByteUtil.java +119 -0
  239. data/src/main/java/org/sunflow/system/FileUtils.java +27 -0
  240. data/src/main/java/org/sunflow/system/ImagePanel.java +282 -0
  241. data/src/main/java/org/sunflow/system/Memory.java +18 -0
  242. data/src/main/java/org/sunflow/system/Parser.java +162 -0
  243. data/src/main/java/org/sunflow/system/Plugins.java +142 -0
  244. data/src/main/java/org/sunflow/system/RenderGlobalsPanel.java +209 -0
  245. data/src/main/java/org/sunflow/system/SearchPath.java +67 -0
  246. data/src/main/java/org/sunflow/system/Timer.java +53 -0
  247. data/src/main/java/org/sunflow/system/UI.java +112 -0
  248. data/src/main/java/org/sunflow/system/UserInterface.java +46 -0
  249. data/src/main/java/org/sunflow/system/ui/ConsoleInterface.java +48 -0
  250. data/src/main/java/org/sunflow/system/ui/SilentInterface.java +28 -0
  251. data/src/main/java/org/sunflow/util/FastHashMap.java +220 -0
  252. data/src/main/java/org/sunflow/util/FloatArray.java +77 -0
  253. data/src/main/java/org/sunflow/util/IntArray.java +77 -0
  254. data/src/test/java/a_maintest.java +129 -0
  255. metadata +300 -0
@@ -0,0 +1,237 @@
1
+ package org.sunflow.core.tesselatable;
2
+
3
+ public class Teapot extends BezierMesh {
4
+ // teapot data, from: http://www.cs.ucsb.edu/~cs280/winter2004/hw2/
5
+
6
+ private static final float[][] PATCHES = {
7
+ {-80.00f, 0.00f, 30.00f, -80.00f, -44.80f, 30.00f, -44.80f,
8
+ -80.00f, 30.00f, 0.00f, -80.00f, 30.00f, -80.00f, 0.00f,
9
+ 12.00f, -80.00f, -44.80f, 12.00f, -44.80f, -80.00f, 12.00f,
10
+ 0.00f, -80.00f, 12.00f, -60.00f, 0.00f, 3.00f, -60.00f,
11
+ -33.60f, 3.00f, -33.60f, -60.00f, 3.00f, 0.00f, -60.00f,
12
+ 3.00f, -60.00f, 0.00f, 0.00f, -60.00f, -33.60f, 0.00f,
13
+ -33.60f, -60.00f, 0.00f, 0.00f, -60.00f, 0.00f,},
14
+ {0.00f, -80.00f, 30.00f, 44.80f, -80.00f, 30.00f, 80.00f, -44.80f,
15
+ 30.00f, 80.00f, 0.00f, 30.00f, 0.00f, -80.00f, 12.00f,
16
+ 44.80f, -80.00f, 12.00f, 80.00f, -44.80f, 12.00f, 80.00f,
17
+ 0.00f, 12.00f, 0.00f, -60.00f, 3.00f, 33.60f, -60.00f,
18
+ 3.00f, 60.00f, -33.60f, 3.00f, 60.00f, 0.00f, 3.00f, 0.00f,
19
+ -60.00f, 0.00f, 33.60f, -60.00f, 0.00f, 60.00f, -33.60f,
20
+ 0.00f, 60.00f, 0.00f, 0.00f,},
21
+ {-60.00f, 0.00f, 90.00f, -60.00f, -33.60f, 90.00f, -33.60f,
22
+ -60.00f, 90.00f, 0.00f, -60.00f, 90.00f, -70.00f, 0.00f,
23
+ 69.00f, -70.00f, -39.20f, 69.00f, -39.20f, -70.00f, 69.00f,
24
+ 0.00f, -70.00f, 69.00f, -80.00f, 0.00f, 48.00f, -80.00f,
25
+ -44.80f, 48.00f, -44.80f, -80.00f, 48.00f, 0.00f, -80.00f,
26
+ 48.00f, -80.00f, 0.00f, 30.00f, -80.00f, -44.80f, 30.00f,
27
+ -44.80f, -80.00f, 30.00f, 0.00f, -80.00f, 30.00f,},
28
+ {0.00f, -60.00f, 90.00f, 33.60f, -60.00f, 90.00f, 60.00f, -33.60f,
29
+ 90.00f, 60.00f, 0.00f, 90.00f, 0.00f, -70.00f, 69.00f,
30
+ 39.20f, -70.00f, 69.00f, 70.00f, -39.20f, 69.00f, 70.00f,
31
+ 0.00f, 69.00f, 0.00f, -80.00f, 48.00f, 44.80f, -80.00f,
32
+ 48.00f, 80.00f, -44.80f, 48.00f, 80.00f, 0.00f, 48.00f,
33
+ 0.00f, -80.00f, 30.00f, 44.80f, -80.00f, 30.00f, 80.00f,
34
+ -44.80f, 30.00f, 80.00f, 0.00f, 30.00f,},
35
+ {-56.00f, 0.00f, 90.00f, -56.00f, -31.36f, 90.00f, -31.36f,
36
+ -56.00f, 90.00f, 0.00f, -56.00f, 90.00f, -53.50f, 0.00f,
37
+ 95.25f, -53.50f, -29.96f, 95.25f, -29.96f, -53.50f, 95.25f,
38
+ 0.00f, -53.50f, 95.25f, -57.50f, 0.00f, 95.25f, -57.50f,
39
+ -32.20f, 95.25f, -32.20f, -57.50f, 95.25f, 0.00f, -57.50f,
40
+ 95.25f, -60.00f, 0.00f, 90.00f, -60.00f, -33.60f, 90.00f,
41
+ -33.60f, -60.00f, 90.00f, 0.00f, -60.00f, 90.00f,},
42
+ {0.00f, -56.00f, 90.00f, 31.36f, -56.00f, 90.00f, 56.00f, -31.36f,
43
+ 90.00f, 56.00f, 0.00f, 90.00f, 0.00f, -53.50f, 95.25f,
44
+ 29.96f, -53.50f, 95.25f, 53.50f, -29.96f, 95.25f, 53.50f,
45
+ 0.00f, 95.25f, 0.00f, -57.50f, 95.25f, 32.20f, -57.50f,
46
+ 95.25f, 57.50f, -32.20f, 95.25f, 57.50f, 0.00f, 95.25f,
47
+ 0.00f, -60.00f, 90.00f, 33.60f, -60.00f, 90.00f, 60.00f,
48
+ -33.60f, 90.00f, 60.00f, 0.00f, 90.00f,},
49
+ {80.00f, 0.00f, 30.00f, 80.00f, 44.80f, 30.00f, 44.80f, 80.00f,
50
+ 30.00f, 0.00f, 80.00f, 30.00f, 80.00f, 0.00f, 12.00f,
51
+ 80.00f, 44.80f, 12.00f, 44.80f, 80.00f, 12.00f, 0.00f,
52
+ 80.00f, 12.00f, 60.00f, 0.00f, 3.00f, 60.00f, 33.60f,
53
+ 3.00f, 33.60f, 60.00f, 3.00f, 0.00f, 60.00f, 3.00f, 60.00f,
54
+ 0.00f, 0.00f, 60.00f, 33.60f, 0.00f, 33.60f, 60.00f, 0.00f,
55
+ 0.00f, 60.00f, 0.00f,},
56
+ {0.00f, 80.00f, 30.00f, -44.80f, 80.00f, 30.00f, -80.00f, 44.80f,
57
+ 30.00f, -80.00f, 0.00f, 30.00f, 0.00f, 80.00f, 12.00f,
58
+ -44.80f, 80.00f, 12.00f, -80.00f, 44.80f, 12.00f, -80.00f,
59
+ 0.00f, 12.00f, 0.00f, 60.00f, 3.00f, -33.60f, 60.00f,
60
+ 3.00f, -60.00f, 33.60f, 3.00f, -60.00f, 0.00f, 3.00f,
61
+ 0.00f, 60.00f, 0.00f, -33.60f, 60.00f, 0.00f, -60.00f,
62
+ 33.60f, 0.00f, -60.00f, 0.00f, 0.00f,},
63
+ {60.00f, 0.00f, 90.00f, 60.00f, 33.60f, 90.00f, 33.60f, 60.00f,
64
+ 90.00f, 0.00f, 60.00f, 90.00f, 70.00f, 0.00f, 69.00f,
65
+ 70.00f, 39.20f, 69.00f, 39.20f, 70.00f, 69.00f, 0.00f,
66
+ 70.00f, 69.00f, 80.00f, 0.00f, 48.00f, 80.00f, 44.80f,
67
+ 48.00f, 44.80f, 80.00f, 48.00f, 0.00f, 80.00f, 48.00f,
68
+ 80.00f, 0.00f, 30.00f, 80.00f, 44.80f, 30.00f, 44.80f,
69
+ 80.00f, 30.00f, 0.00f, 80.00f, 30.00f,},
70
+ {0.00f, 60.00f, 90.00f, -33.60f, 60.00f, 90.00f, -60.00f, 33.60f,
71
+ 90.00f, -60.00f, 0.00f, 90.00f, 0.00f, 70.00f, 69.00f,
72
+ -39.20f, 70.00f, 69.00f, -70.00f, 39.20f, 69.00f, -70.00f,
73
+ 0.00f, 69.00f, 0.00f, 80.00f, 48.00f, -44.80f, 80.00f,
74
+ 48.00f, -80.00f, 44.80f, 48.00f, -80.00f, 0.00f, 48.00f,
75
+ 0.00f, 80.00f, 30.00f, -44.80f, 80.00f, 30.00f, -80.00f,
76
+ 44.80f, 30.00f, -80.00f, 0.00f, 30.00f,},
77
+ {56.00f, 0.00f, 90.00f, 56.00f, 31.36f, 90.00f, 31.36f, 56.00f,
78
+ 90.00f, 0.00f, 56.00f, 90.00f, 53.50f, 0.00f, 95.25f,
79
+ 53.50f, 29.96f, 95.25f, 29.96f, 53.50f, 95.25f, 0.00f,
80
+ 53.50f, 95.25f, 57.50f, 0.00f, 95.25f, 57.50f, 32.20f,
81
+ 95.25f, 32.20f, 57.50f, 95.25f, 0.00f, 57.50f, 95.25f,
82
+ 60.00f, 0.00f, 90.00f, 60.00f, 33.60f, 90.00f, 33.60f,
83
+ 60.00f, 90.00f, 0.00f, 60.00f, 90.00f,},
84
+ {0.00f, 56.00f, 90.00f, -31.36f, 56.00f, 90.00f, -56.00f, 31.36f,
85
+ 90.00f, -56.00f, 0.00f, 90.00f, 0.00f, 53.50f, 95.25f,
86
+ -29.96f, 53.50f, 95.25f, -53.50f, 29.96f, 95.25f, -53.50f,
87
+ 0.00f, 95.25f, 0.00f, 57.50f, 95.25f, -32.20f, 57.50f,
88
+ 95.25f, -57.50f, 32.20f, 95.25f, -57.50f, 0.00f, 95.25f,
89
+ 0.00f, 60.00f, 90.00f, -33.60f, 60.00f, 90.00f, -60.00f,
90
+ 33.60f, 90.00f, -60.00f, 0.00f, 90.00f,},
91
+ {-64.00f, 0.00f, 75.00f, -64.00f, 12.00f, 75.00f, -60.00f, 12.00f,
92
+ 84.00f, -60.00f, 0.00f, 84.00f, -92.00f, 0.00f, 75.00f,
93
+ -92.00f, 12.00f, 75.00f, -100.00f, 12.00f, 84.00f,
94
+ -100.00f, 0.00f, 84.00f, -108.00f, 0.00f, 75.00f, -108.00f,
95
+ 12.00f, 75.00f, -120.00f, 12.00f, 84.00f, -120.00f, 0.00f,
96
+ 84.00f, -108.00f, 0.00f, 66.00f, -108.00f, 12.00f, 66.00f,
97
+ -120.00f, 12.00f, 66.00f, -120.00f, 0.00f, 66.00f,},
98
+ {-60.00f, 0.00f, 84.00f, -60.00f, -12.00f, 84.00f, -64.00f,
99
+ -12.00f, 75.00f, -64.00f, 0.00f, 75.00f, -100.00f, 0.00f,
100
+ 84.00f, -100.00f, -12.00f, 84.00f, -92.00f, -12.00f,
101
+ 75.00f, -92.00f, 0.00f, 75.00f, -120.00f, 0.00f, 84.00f,
102
+ -120.00f, -12.00f, 84.00f, -108.00f, -12.00f, 75.00f,
103
+ -108.00f, 0.00f, 75.00f, -120.00f, 0.00f, 66.00f, -120.00f,
104
+ -12.00f, 66.00f, -108.00f, -12.00f, 66.00f, -108.00f,
105
+ 0.00f, 66.00f,},
106
+ {-108.00f, 0.00f, 66.00f, -108.00f, 12.00f, 66.00f, -120.00f,
107
+ 12.00f, 66.00f, -120.00f, 0.00f, 66.00f, -108.00f, 0.00f,
108
+ 57.00f, -108.00f, 12.00f, 57.00f, -120.00f, 12.00f, 48.00f,
109
+ -120.00f, 0.00f, 48.00f, -100.00f, 0.00f, 39.00f, -100.00f,
110
+ 12.00f, 39.00f, -106.00f, 12.00f, 31.50f, -106.00f, 0.00f,
111
+ 31.50f, -80.00f, 0.00f, 30.00f, -80.00f, 12.00f, 30.00f,
112
+ -76.00f, 12.00f, 18.00f, -76.00f, 0.00f, 18.00f,},
113
+ {-120.00f, 0.00f, 66.00f, -120.00f, -12.00f, 66.00f, -108.00f,
114
+ -12.00f, 66.00f, -108.00f, 0.00f, 66.00f, -120.00f, 0.00f,
115
+ 48.00f, -120.00f, -12.00f, 48.00f, -108.00f, -12.00f,
116
+ 57.00f, -108.00f, 0.00f, 57.00f, -106.00f, 0.00f, 31.50f,
117
+ -106.00f, -12.00f, 31.50f, -100.00f, -12.00f, 39.00f,
118
+ -100.00f, 0.00f, 39.00f, -76.00f, 0.00f, 18.00f, -76.00f,
119
+ -12.00f, 18.00f, -80.00f, -12.00f, 30.00f, -80.00f, 0.00f,
120
+ 30.00f,},
121
+ {68.00f, 0.00f, 51.00f, 68.00f, 26.40f, 51.00f, 68.00f, 26.40f,
122
+ 18.00f, 68.00f, 0.00f, 18.00f, 104.00f, 0.00f, 51.00f,
123
+ 104.00f, 26.40f, 51.00f, 124.00f, 26.40f, 27.00f, 124.00f,
124
+ 0.00f, 27.00f, 92.00f, 0.00f, 78.00f, 92.00f, 10.00f,
125
+ 78.00f, 96.00f, 10.00f, 75.00f, 96.00f, 0.00f, 75.00f,
126
+ 108.00f, 0.00f, 90.00f, 108.00f, 10.00f, 90.00f, 132.00f,
127
+ 10.00f, 90.00f, 132.00f, 0.00f, 90.00f,},
128
+ {68.00f, 0.00f, 18.00f, 68.00f, -26.40f, 18.00f, 68.00f, -26.40f,
129
+ 51.00f, 68.00f, 0.00f, 51.00f, 124.00f, 0.00f, 27.00f,
130
+ 124.00f, -26.40f, 27.00f, 104.00f, -26.40f, 51.00f,
131
+ 104.00f, 0.00f, 51.00f, 96.00f, 0.00f, 75.00f, 96.00f,
132
+ -10.00f, 75.00f, 92.00f, -10.00f, 78.00f, 92.00f, 0.00f,
133
+ 78.00f, 132.00f, 0.00f, 90.00f, 132.00f, -10.00f, 90.00f,
134
+ 108.00f, -10.00f, 90.00f, 108.00f, 0.00f, 90.00f,},
135
+ {108.00f, 0.00f, 90.00f, 108.00f, 10.00f, 90.00f, 132.00f, 10.00f,
136
+ 90.00f, 132.00f, 0.00f, 90.00f, 112.00f, 0.00f, 93.00f,
137
+ 112.00f, 10.00f, 93.00f, 141.00f, 10.00f, 93.75f, 141.00f,
138
+ 0.00f, 93.75f, 116.00f, 0.00f, 93.00f, 116.00f, 6.00f,
139
+ 93.00f, 138.00f, 6.00f, 94.50f, 138.00f, 0.00f, 94.50f,
140
+ 112.00f, 0.00f, 90.00f, 112.00f, 6.00f, 90.00f, 128.00f,
141
+ 6.00f, 90.00f, 128.00f, 0.00f, 90.00f,},
142
+ {132.00f, 0.00f, 90.00f, 132.00f, -10.00f, 90.00f, 108.00f,
143
+ -10.00f, 90.00f, 108.00f, 0.00f, 90.00f, 141.00f, 0.00f,
144
+ 93.75f, 141.00f, -10.00f, 93.75f, 112.00f, -10.00f, 93.00f,
145
+ 112.00f, 0.00f, 93.00f, 138.00f, 0.00f, 94.50f, 138.00f,
146
+ -6.00f, 94.50f, 116.00f, -6.00f, 93.00f, 116.00f, 0.00f,
147
+ 93.00f, 128.00f, 0.00f, 90.00f, 128.00f, -6.00f, 90.00f,
148
+ 112.00f, -6.00f, 90.00f, 112.00f, 0.00f, 90.00f,},
149
+ {50.00f, 0.00f, 90.00f, 50.00f, 28.00f, 90.00f, 28.00f, 50.00f,
150
+ 90.00f, 0.00f, 50.00f, 90.00f, 52.00f, 0.00f, 90.00f,
151
+ 52.00f, 29.12f, 90.00f, 29.12f, 52.00f, 90.00f, 0.00f,
152
+ 52.00f, 90.00f, 54.00f, 0.00f, 90.00f, 54.00f, 30.24f,
153
+ 90.00f, 30.24f, 54.00f, 90.00f, 0.00f, 54.00f, 90.00f,
154
+ 56.00f, 0.00f, 90.00f, 56.00f, 31.36f, 90.00f, 31.36f,
155
+ 56.00f, 90.00f, 0.00f, 56.00f, 90.00f,},
156
+ {0.00f, 50.00f, 90.00f, -28.00f, 50.00f, 90.00f, -50.00f, 28.00f,
157
+ 90.00f, -50.00f, 0.00f, 90.00f, 0.00f, 52.00f, 90.00f,
158
+ -29.12f, 52.00f, 90.00f, -52.00f, 29.12f, 90.00f, -52.00f,
159
+ 0.00f, 90.00f, 0.00f, 54.00f, 90.00f, -30.24f, 54.00f,
160
+ 90.00f, -54.00f, 30.24f, 90.00f, -54.00f, 0.00f, 90.00f,
161
+ 0.00f, 56.00f, 90.00f, -31.36f, 56.00f, 90.00f, -56.00f,
162
+ 31.36f, 90.00f, -56.00f, 0.00f, 90.00f,},
163
+ {-50.00f, 0.00f, 90.00f, -50.00f, -28.00f, 90.00f, -28.00f,
164
+ -50.00f, 90.00f, 0.00f, -50.00f, 90.00f, -52.00f, 0.00f,
165
+ 90.00f, -52.00f, -29.12f, 90.00f, -29.12f, -52.00f, 90.00f,
166
+ 0.00f, -52.00f, 90.00f, -54.00f, 0.00f, 90.00f, -54.00f,
167
+ -30.24f, 90.00f, -30.24f, -54.00f, 90.00f, 0.00f, -54.00f,
168
+ 90.00f, -56.00f, 0.00f, 90.00f, -56.00f, -31.36f, 90.00f,
169
+ -31.36f, -56.00f, 90.00f, 0.00f, -56.00f, 90.00f,},
170
+ {0.00f, -50.00f, 90.00f, 28.00f, -50.00f, 90.00f, 50.00f, -28.00f,
171
+ 90.00f, 50.00f, 0.00f, 90.00f, 0.00f, -52.00f, 90.00f,
172
+ 29.12f, -52.00f, 90.00f, 52.00f, -29.12f, 90.00f, 52.00f,
173
+ 0.00f, 90.00f, 0.00f, -54.00f, 90.00f, 30.24f, -54.00f,
174
+ 90.00f, 54.00f, -30.24f, 90.00f, 54.00f, 0.00f, 90.00f,
175
+ 0.00f, -56.00f, 90.00f, 31.36f, -56.00f, 90.00f, 56.00f,
176
+ -31.36f, 90.00f, 56.00f, 0.00f, 90.00f,},
177
+ {8.00f, 0.00f, 102.00f, 8.00f, 4.48f, 102.00f, 4.48f, 8.00f,
178
+ 102.00f, 0.00f, 8.00f, 102.00f, 16.00f, 0.00f, 96.00f,
179
+ 16.00f, 8.96f, 96.00f, 8.96f, 16.00f, 96.00f, 0.00f,
180
+ 16.00f, 96.00f, 52.00f, 0.00f, 96.00f, 52.00f, 29.12f,
181
+ 96.00f, 29.12f, 52.00f, 96.00f, 0.00f, 52.00f, 96.00f,
182
+ 52.00f, 0.00f, 90.00f, 52.00f, 29.12f, 90.00f, 29.12f,
183
+ 52.00f, 90.00f, 0.00f, 52.00f, 90.00f,},
184
+ {0.00f, 8.00f, 102.00f, -4.48f, 8.00f, 102.00f, -8.00f, 4.48f,
185
+ 102.00f, -8.00f, 0.00f, 102.00f, 0.00f, 16.00f, 96.00f,
186
+ -8.96f, 16.00f, 96.00f, -16.00f, 8.96f, 96.00f, -16.00f,
187
+ 0.00f, 96.00f, 0.00f, 52.00f, 96.00f, -29.12f, 52.00f,
188
+ 96.00f, -52.00f, 29.12f, 96.00f, -52.00f, 0.00f, 96.00f,
189
+ 0.00f, 52.00f, 90.00f, -29.12f, 52.00f, 90.00f, -52.00f,
190
+ 29.12f, 90.00f, -52.00f, 0.00f, 90.00f,},
191
+ {-8.00f, 0.00f, 102.00f, -8.00f, -4.48f, 102.00f, -4.48f, -8.00f,
192
+ 102.00f, 0.00f, -8.00f, 102.00f, -16.00f, 0.00f, 96.00f,
193
+ -16.00f, -8.96f, 96.00f, -8.96f, -16.00f, 96.00f, 0.00f,
194
+ -16.00f, 96.00f, -52.00f, 0.00f, 96.00f, -52.00f, -29.12f,
195
+ 96.00f, -29.12f, -52.00f, 96.00f, 0.00f, -52.00f, 96.00f,
196
+ -52.00f, 0.00f, 90.00f, -52.00f, -29.12f, 90.00f, -29.12f,
197
+ -52.00f, 90.00f, 0.00f, -52.00f, 90.00f,},
198
+ {0.00f, -8.00f, 102.00f, 4.48f, -8.00f, 102.00f, 8.00f, -4.48f,
199
+ 102.00f, 8.00f, 0.00f, 102.00f, 0.00f, -16.00f, 96.00f,
200
+ 8.96f, -16.00f, 96.00f, 16.00f, -8.96f, 96.00f, 16.00f,
201
+ 0.00f, 96.00f, 0.00f, -52.00f, 96.00f, 29.12f, -52.00f,
202
+ 96.00f, 52.00f, -29.12f, 96.00f, 52.00f, 0.00f, 96.00f,
203
+ 0.00f, -52.00f, 90.00f, 29.12f, -52.00f, 90.00f, 52.00f,
204
+ -29.12f, 90.00f, 52.00f, 0.00f, 90.00f,},
205
+ {0.00f, 0.00f, 120.00f, 0.00f, 0.00f, 120.00f, 0.00f, 0.00f,
206
+ 120.00f, 0.00f, 0.00f, 120.00f, 32.00f, 0.00f, 120.00f,
207
+ 32.00f, 18.00f, 120.00f, 18.00f, 32.00f, 120.00f, 0.00f,
208
+ 32.00f, 120.00f, 0.00f, 0.00f, 108.00f, 0.00f, 0.00f,
209
+ 108.00f, 0.00f, 0.00f, 108.00f, 0.00f, 0.00f, 108.00f,
210
+ 8.00f, 0.00f, 102.00f, 8.00f, 4.48f, 102.00f, 4.48f, 8.00f,
211
+ 102.00f, 0.00f, 8.00f, 102.00f,},
212
+ {0.00f, 0.00f, 120.00f, 0.00f, 0.00f, 120.00f, 0.00f, 0.00f,
213
+ 120.00f, 0.00f, 0.00f, 120.00f, 0.00f, 32.00f, 120.00f,
214
+ -18.00f, 32.00f, 120.00f, -32.00f, 18.00f, 120.00f,
215
+ -32.00f, 0.00f, 120.00f, 0.00f, 0.00f, 108.00f, 0.00f,
216
+ 0.00f, 108.00f, 0.00f, 0.00f, 108.00f, 0.00f, 0.00f,
217
+ 108.00f, 0.00f, 8.00f, 102.00f, -4.48f, 8.00f, 102.00f,
218
+ -8.00f, 4.48f, 102.00f, -8.00f, 0.00f, 102.00f,},
219
+ {0.00f, 0.00f, 120.00f, 0.00f, 0.00f, 120.00f, 0.00f, 0.00f,
220
+ 120.00f, 0.00f, 0.00f, 120.00f, -32.00f, 0.00f, 120.00f,
221
+ -32.00f, -18.00f, 120.00f, -18.00f, -32.00f, 120.00f,
222
+ 0.00f, -32.00f, 120.00f, 0.00f, 0.00f, 108.00f, 0.00f,
223
+ 0.00f, 108.00f, 0.00f, 0.00f, 108.00f, 0.00f, 0.00f,
224
+ 108.00f, -8.00f, 0.00f, 102.00f, -8.00f, -4.48f, 102.00f,
225
+ -4.48f, -8.00f, 102.00f, 0.00f, -8.00f, 102.00f,},
226
+ {0.00f, 0.00f, 120.00f, 0.00f, 0.00f, 120.00f, 0.00f, 0.00f,
227
+ 120.00f, 0.00f, 0.00f, 120.00f, 0.00f, -32.00f, 120.00f,
228
+ 18.00f, -32.00f, 120.00f, 32.00f, -18.00f, 120.00f, 32.00f,
229
+ 0.00f, 120.00f, 0.00f, 0.00f, 108.00f, 0.00f, 0.00f,
230
+ 108.00f, 0.00f, 0.00f, 108.00f, 0.00f, 0.00f, 108.00f,
231
+ 0.00f, -8.00f, 102.00f, 4.48f, -8.00f, 102.00f, 8.00f,
232
+ -4.48f, 102.00f, 8.00f, 0.00f, 102.00f,}};
233
+
234
+ public Teapot() {
235
+ super(PATCHES);
236
+ }
237
+ }
@@ -0,0 +1,15 @@
1
+ package org.sunflow.image;
2
+
3
+ public abstract class Bitmap {
4
+
5
+ protected static final float INV255 = 1.0f / 255;
6
+ protected static final float INV65535 = 1.0f / 65535;
7
+
8
+ public abstract int getWidth();
9
+
10
+ public abstract int getHeight();
11
+
12
+ public abstract Color readColor(int x, int y);
13
+
14
+ public abstract float readAlpha(int x, int y);
15
+ }
@@ -0,0 +1,39 @@
1
+ package org.sunflow.image;
2
+
3
+ import java.io.IOException;
4
+
5
+ /**
6
+ * This is a very simple interface, designed to handle loading of bitmap data.
7
+ */
8
+ public interface BitmapReader {
9
+
10
+ /**
11
+ * Load the specified filename. This method should throw exception if it
12
+ * encounters any errors. If the file is valid but its contents are not
13
+ * (invalid header for example), a {@link BitmapFormatException} may be
14
+ * thrown. It is an error for this method to return
15
+ * <code>null</code>.
16
+ *
17
+ * @param filename image filename to load
18
+ * @param isLinear if this is <code>true</code>, the bitmap is assumed to be
19
+ * already in linear space. This can be usefull when reading greyscale
20
+ * images for bump mapping for example. HDR formats can ignore this flag
21
+ * since they usually always store data in linear form.
22
+ * @return a new {@link Bitmap} object
23
+ * @throws java.io.IOException
24
+ * @throws org.sunflow.image.BitmapReader.BitmapFormatException
25
+ */
26
+ public Bitmap load(String filename, boolean isLinear) throws IOException, BitmapFormatException;
27
+
28
+ /**
29
+ * This exception can be used internally by bitmap readers to signal they
30
+ * have encountered a valid file but which contains invalid content.
31
+ */
32
+ @SuppressWarnings("serial")
33
+ public static final class BitmapFormatException extends Exception {
34
+
35
+ public BitmapFormatException(String message) {
36
+ super(message);
37
+ }
38
+ }
39
+ }
@@ -0,0 +1,79 @@
1
+ package org.sunflow.image;
2
+
3
+ import java.io.IOException;
4
+
5
+ /**
6
+ * This interface is used to represents an image output format. The methods are
7
+ * tile oriented so that tiled image formats may be optimally supported. Note
8
+ * that if the header is declared with a 0 tile size, the image will not be
9
+ * written with identical sized tiles. The image should either be buffered so it
10
+ * can be written all at once on close, or an eror should be thrown. The bitmap
11
+ * writer should be designed so that it is thread safe. Specifically, this means
12
+ * that the tile writing method can be called by several threads.
13
+ */
14
+ public interface BitmapWriter {
15
+
16
+ /**
17
+ * This method will be called before writing begins. It is used to set
18
+ * common attributes to file writers. Currently supported keywords include:
19
+ * <ul>
20
+ * <li>"compression"</li>
21
+ * <li>"channeltype": "byte", "short", "half", "float"</li>
22
+ * </ul>
23
+ * Note that this method should not fail if its input is not supported or
24
+ * invalid. It should gracefully ignore the error and keep its default
25
+ * state.
26
+ *
27
+ * @param option
28
+ * @param value
29
+ */
30
+ public abstract void configure(String option, String value);
31
+
32
+ /**
33
+ * Open a handle to the specified file for writing. If the writer buffers
34
+ * the image and writes it on close, then the filename should be stored.
35
+ *
36
+ * @param filename filename to write the bitmap to
37
+ * @throws IOException thrown if an I/O error occurs
38
+ */
39
+ public abstract void openFile(String filename) throws IOException;
40
+
41
+ /**
42
+ * Write the bitmap header. This may be defered if the image is buffered for
43
+ * writing all at once on close. Note that if tile size is positive, data
44
+ * sent to this class is guarenteed to arrive in tiles of that size (except
45
+ * at borders). Otherwise, it should be assumed that the data is random, and
46
+ * that it may overlap. The writer should then either throw an error or
47
+ * start buffering data manually.
48
+ *
49
+ * @param width image width
50
+ * @param height image height
51
+ * @param tileSize tile size or 0 if the image will not be sent in tiled
52
+ * form
53
+ * @throws IOException thrown if an I/O error occurs
54
+ * @throws UnsupportedOperationException thrown if this writer does not
55
+ * support writing the image with the supplied tile size
56
+ */
57
+ public abstract void writeHeader(int width, int height, int tileSize) throws IOException, UnsupportedOperationException;
58
+
59
+ /**
60
+ * Write a tile of data. Note that this method may be called by more than
61
+ * one thread, so it should be made thread-safe if possible.
62
+ *
63
+ * @param x tile x coordinate
64
+ * @param y tile y coordinate
65
+ * @param w tile width
66
+ * @param h tile height
67
+ * @param color color data
68
+ * @param alpha alpha data
69
+ * @throws IOException thrown if an I/O error occurs
70
+ */
71
+ public abstract void writeTile(int x, int y, int w, int h, Color[] color, float[] alpha) throws IOException;
72
+
73
+ /**
74
+ * Close the file, this completes the bitmap writing process.
75
+ *
76
+ * @throws IOException thrown if an I/O error occurs
77
+ */
78
+ public abstract void closeFile() throws IOException;
79
+ }
@@ -0,0 +1,16 @@
1
+ package org.sunflow.image;
2
+
3
+ public class BlackbodySpectrum extends SpectralCurve {
4
+
5
+ private final float temp;
6
+
7
+ public BlackbodySpectrum(float temp) {
8
+ this.temp = temp;
9
+ }
10
+
11
+ @Override
12
+ public float sample(float lambda) {
13
+ double wavelength = lambda * 1e-9;
14
+ return (float) ((3.74183e-16 * Math.pow(wavelength, -5.0)) / (Math.exp(1.4388e-2 / (wavelength * temp)) - 1.0));
15
+ }
16
+ }
@@ -0,0 +1,55 @@
1
+ package org.sunflow.image;
2
+
3
+ /**
4
+ * This spectral curve represents a given (x,y) chromaticity pair as explained
5
+ * in the sun/sky paper (section A.5)
6
+ */
7
+ public final class ChromaticitySpectrum extends SpectralCurve {
8
+
9
+ private static final float[] S0_AMPLITUDES = {0.04f, 6.0f, 29.6f, 55.3f,
10
+ 57.3f, 61.8f, 61.5f, 68.8f, 63.4f, 65.8f, 94.8f, 104.8f, 105.9f,
11
+ 96.8f, 113.9f, 125.6f, 125.5f, 121.3f, 121.3f, 113.5f, 113.1f,
12
+ 110.8f, 106.5f, 108.8f, 105.3f, 104.4f, 100.0f, 96.0f, 95.1f,
13
+ 89.1f, 90.5f, 90.3f, 88.4f, 84.0f, 85.1f, 81.9f, 82.6f, 84.9f,
14
+ 81.3f, 71.9f, 74.3f, 76.4f, 63.3f, 71.7f, 77.0f, 65.2f, 47.7f,
15
+ 68.6f, 65.0f, 66.0f, 61.0f, 53.3f, 58.9f, 61.9f};
16
+ private static final float[] S1_AMPLITUDES = {0.02f, 4.5f, 22.4f, 42.0f,
17
+ 40.6f, 41.6f, 38.0f, 42.4f, 38.5f, 35.0f, 43.4f, 46.3f, 43.9f,
18
+ 37.1f, 36.7f, 35.9f, 32.6f, 27.9f, 24.3f, 20.1f, 16.2f, 13.2f,
19
+ 8.6f, 6.1f, 4.2f, 1.9f, 0.0f, -1.6f, -3.5f, -3.5f, -5.8f, -7.2f,
20
+ -8.6f, -9.5f, -10.9f, -10.7f, -12.0f, -14.0f, -13.6f, -12.0f,
21
+ -13.3f, -12.9f, -10.6f, -11.6f, -12.2f, -10.2f, -7.8f, -11.2f,
22
+ -10.4f, -10.6f, -9.7f, -8.3f, -9.3f, -9.8f};
23
+ private static final float[] S2_AMPLITUDES = {0.0f, 2.0f, 4.0f, 8.5f, 7.8f,
24
+ 6.7f, 5.3f, 6.1f, 3.0f, 1.2f, -1.1f, -0.5f, -0.7f, -1.2f, -2.6f,
25
+ -2.9f, -2.8f, -2.6f, -2.6f, -1.8f, -1.5f, -1.3f, -1.2f, -1.0f,
26
+ -0.5f, -0.3f, 0.0f, 0.2f, 0.5f, 2.1f, 3.2f, 4.1f, 4.7f, 5.1f, 6.7f,
27
+ 7.3f, 8.6f, 9.8f, 10.2f, 8.3f, 9.6f, 8.5f, 7.0f, 7.6f, 8.0f, 6.7f,
28
+ 5.2f, 7.4f, 6.8f, 7.0f, 6.4f, 5.5f, 6.1f, 6.5f};
29
+ private static final RegularSpectralCurve KS0_SPECTRUM = new RegularSpectralCurve(S0_AMPLITUDES, 300, 830);
30
+ private static final RegularSpectralCurve KS1_SPECTRUM = new RegularSpectralCurve(S1_AMPLITUDES, 300, 830);
31
+ private static final RegularSpectralCurve KS2_SPECTRUM = new RegularSpectralCurve(S2_AMPLITUDES, 300, 830);
32
+ private static final XYZColor S0_XYZ = KS0_SPECTRUM.toXYZ();
33
+ private static final XYZColor S1_XYZ = KS1_SPECTRUM.toXYZ();
34
+ private static final XYZColor S2_XYZ = KS2_SPECTRUM.toXYZ();
35
+ private final float M1, M2;
36
+
37
+ public ChromaticitySpectrum(float x, float y) {
38
+ M1 = (-1.3515f - 1.7703f * x + 5.9114f * y) / (0.0241f + 0.2562f * x - 0.7341f * y);
39
+ M2 = (0.03f - 31.4424f * x + 30.0717f * y) / (0.0241f + 0.2562f * x - 0.7341f * y);
40
+ }
41
+
42
+ @Override
43
+ public float sample(float lambda) {
44
+ return KS0_SPECTRUM.sample(lambda) + M1 * KS1_SPECTRUM.sample(lambda) + M2 * KS2_SPECTRUM.sample(lambda);
45
+ }
46
+
47
+ public static final XYZColor get(float x, float y) {
48
+ float M1 = (-1.3515f - 1.7703f * x + 5.9114f * y) / (0.0241f + 0.2562f * x - 0.7341f * y);
49
+ float M2 = (0.03f - 31.4424f * x + 30.0717f * y) / (0.0241f + 0.2562f * x - 0.7341f * y);
50
+ float X = S0_XYZ.getX() + M1 * S1_XYZ.getX() + M2 * S2_XYZ.getX();
51
+ float Y = S0_XYZ.getY() + M1 * S1_XYZ.getY() + M2 * S2_XYZ.getY();
52
+ float Z = S0_XYZ.getZ() + M1 * S1_XYZ.getZ() + M2 * S2_XYZ.getZ();
53
+ return new XYZColor(X, Y, Z);
54
+ }
55
+ }
@@ -0,0 +1,374 @@
1
+ package org.sunflow.image;
2
+
3
+ import org.sunflow.math.MathUtils;
4
+
5
+ public final class Color {
6
+
7
+ private float r, g, b;
8
+ public static final RGBSpace NATIVE_SPACE = RGBSpace.SRGB;
9
+ public static final Color BLACK = new Color(0, 0, 0);
10
+ public static final Color WHITE = new Color(1, 1, 1);
11
+ public static final Color RED = new Color(1, 0, 0);
12
+ public static final Color GREEN = new Color(0, 1, 0);
13
+ public static final Color BLUE = new Color(0, 0, 1);
14
+ public static final Color YELLOW = new Color(1, 1, 0);
15
+ public static final Color CYAN = new Color(0, 1, 1);
16
+ public static final Color MAGENTA = new Color(1, 0, 1);
17
+ public static final Color GRAY = new Color(0.5f, 0.5f, 0.5f);
18
+
19
+ public static Color black() {
20
+ return new Color();
21
+ }
22
+
23
+ public static Color white() {
24
+ return new Color(1, 1, 1);
25
+ }
26
+ private static final float[] EXPONENT = new float[256];
27
+
28
+ static {
29
+ EXPONENT[0] = 0;
30
+ for (int i = 1; i < 256; i++) {
31
+ float f = 1.0f;
32
+ int e = i - (128 + 8);
33
+ if (e > 0) {
34
+ for (int j = 0; j < e; j++) {
35
+ f *= 2.0f;
36
+ }
37
+ } else {
38
+ for (int j = 0; j < -e; j++) {
39
+ f *= 0.5f;
40
+ }
41
+ }
42
+ EXPONENT[i] = f;
43
+ }
44
+ }
45
+
46
+ public Color() {
47
+ }
48
+
49
+ public Color(float gray) {
50
+ r = g = b = gray;
51
+ }
52
+
53
+ public Color(float r, float g, float b) {
54
+ this.r = r;
55
+ this.g = g;
56
+ this.b = b;
57
+ }
58
+
59
+ public Color toNonLinear() {
60
+ r = NATIVE_SPACE.gammaCorrect(r);
61
+ g = NATIVE_SPACE.gammaCorrect(g);
62
+ b = NATIVE_SPACE.gammaCorrect(b);
63
+ return this;
64
+ }
65
+
66
+ public Color toLinear() {
67
+ r = NATIVE_SPACE.ungammaCorrect(r);
68
+ g = NATIVE_SPACE.ungammaCorrect(g);
69
+ b = NATIVE_SPACE.ungammaCorrect(b);
70
+ return this;
71
+ }
72
+
73
+ public Color(Color c) {
74
+ r = c.r;
75
+ g = c.g;
76
+ b = c.b;
77
+ }
78
+
79
+ public Color(int rgb) {
80
+ r = ((rgb >> 16) & 0xFF) / 255.0f;
81
+ g = ((rgb >> 8) & 0xFF) / 255.0f;
82
+ b = (rgb & 0xFF) / 255.0f;
83
+ }
84
+
85
+ public Color copy() {
86
+ return new Color(this);
87
+ }
88
+
89
+ public final Color set(float r, float g, float b) {
90
+ this.r = r;
91
+ this.g = g;
92
+ this.b = b;
93
+ return this;
94
+ }
95
+
96
+ public final Color set(Color c) {
97
+ r = c.r;
98
+ g = c.g;
99
+ b = c.b;
100
+ return this;
101
+ }
102
+
103
+ public final Color setRGB(int rgb) {
104
+ r = ((rgb >> 16) & 0xFF) / 255.0f;
105
+ g = ((rgb >> 8) & 0xFF) / 255.0f;
106
+ b = (rgb & 0xFF) / 255.0f;
107
+ return this;
108
+ }
109
+
110
+ public final Color setRGBE(int rgbe) {
111
+ float f = EXPONENT[rgbe & 0xFF];
112
+ r = f * ((rgbe >>> 24) + 0.5f);
113
+ g = f * (((rgbe >> 16) & 0xFF) + 0.5f);
114
+ b = f * (((rgbe >> 8) & 0xFF) + 0.5f);
115
+ return this;
116
+ }
117
+
118
+ public final boolean isBlack() {
119
+ return r <= 0 && g <= 0 && b <= 0;
120
+ }
121
+
122
+ public final float getLuminance() {
123
+ return (0.2989f * r) + (0.5866f * g) + (0.1145f * b);
124
+ }
125
+
126
+ public final float getMin() {
127
+ return MathUtils.min(r, g, b);
128
+ }
129
+
130
+ public final float getMax() {
131
+ return MathUtils.max(r, g, b);
132
+ }
133
+
134
+ public final float getAverage() {
135
+ return (r + g + b) / 3.0f;
136
+ }
137
+
138
+ public final float[] getRGB() {
139
+ return new float[]{r, g, b};
140
+ }
141
+
142
+ public final int toRGB() {
143
+ int ir = (int) (r * 255 + 0.5);
144
+ int ig = (int) (g * 255 + 0.5);
145
+ int ib = (int) (b * 255 + 0.5);
146
+ ir = MathUtils.clamp(ir, 0, 255);
147
+ ig = MathUtils.clamp(ig, 0, 255);
148
+ ib = MathUtils.clamp(ib, 0, 255);
149
+ return (ir << 16) | (ig << 8) | ib;
150
+ }
151
+
152
+ public final int toRGBA(float a) {
153
+ int ir = (int) (r * 255 + 0.5);
154
+ int ig = (int) (g * 255 + 0.5);
155
+ int ib = (int) (b * 255 + 0.5);
156
+ int ia = (int) (a * 255 + 0.5);
157
+ ir = MathUtils.clamp(ir, 0, 255);
158
+ ig = MathUtils.clamp(ig, 0, 255);
159
+ ib = MathUtils.clamp(ib, 0, 255);
160
+ ia = MathUtils.clamp(ia, 0, 255);
161
+ return (ia << 24) | (ir << 16) | (ig << 8) | ib;
162
+ }
163
+
164
+ public final int toRGBE() {
165
+ // encode the color into 32bits while preserving HDR using Ward's RGBE
166
+ // technique
167
+ float v = MathUtils.max(r, g, b);
168
+ if (v < 1e-32f) {
169
+ return 0;
170
+ }
171
+
172
+ // get mantissa and exponent
173
+ float m = v;
174
+ int e = 0;
175
+ if (v > 1.0f) {
176
+ while (m > 1.0f) {
177
+ m *= 0.5f;
178
+ e++;
179
+ }
180
+ } else if (v <= 0.5f) {
181
+ while (m <= 0.5f) {
182
+ m *= 2.0f;
183
+ e--;
184
+ }
185
+ }
186
+ v = (m * 255.0f) / v;
187
+ int c = (e + 128);
188
+ c |= ((int) (r * v) << 24);
189
+ c |= ((int) (g * v) << 16);
190
+ c |= ((int) (b * v) << 8);
191
+ return c;
192
+ }
193
+
194
+ public final Color constrainRGB() {
195
+ // clamp the RGB value to a representable value
196
+ float w = -MathUtils.min(0, r, g, b);
197
+ if (w > 0) {
198
+ r += w;
199
+ g += w;
200
+ b += w;
201
+ }
202
+ return this;
203
+ }
204
+
205
+ public final boolean isNan() {
206
+ return Float.isNaN(r) || Float.isNaN(g) || Float.isNaN(b);
207
+ }
208
+
209
+ public final boolean isInf() {
210
+ return Float.isInfinite(r) || Float.isInfinite(g) || Float.isInfinite(b);
211
+ }
212
+
213
+ public final Color add(Color c) {
214
+ r += c.r;
215
+ g += c.g;
216
+ b += c.b;
217
+ return this;
218
+ }
219
+
220
+ public static final Color add(Color c1, Color c2) {
221
+ return Color.add(c1, c2, new Color());
222
+ }
223
+
224
+ public static final Color add(Color c1, Color c2, Color dest) {
225
+ dest.r = c1.r + c2.r;
226
+ dest.g = c1.g + c2.g;
227
+ dest.b = c1.b + c2.b;
228
+ return dest;
229
+ }
230
+
231
+ public final Color madd(float s, Color c) {
232
+ r += (s * c.r);
233
+ g += (s * c.g);
234
+ b += (s * c.b);
235
+ return this;
236
+ }
237
+
238
+ public final Color madd(Color s, Color c) {
239
+ r += s.r * c.r;
240
+ g += s.g * c.g;
241
+ b += s.b * c.b;
242
+ return this;
243
+ }
244
+
245
+ public final Color sub(Color c) {
246
+ r -= c.r;
247
+ g -= c.g;
248
+ b -= c.b;
249
+ return this;
250
+ }
251
+
252
+ public static final Color sub(Color c1, Color c2) {
253
+ return Color.sub(c1, c2, new Color());
254
+ }
255
+
256
+ public static final Color sub(Color c1, Color c2, Color dest) {
257
+ dest.r = c1.r - c2.r;
258
+ dest.g = c1.g - c2.g;
259
+ dest.b = c1.b - c2.b;
260
+ return dest;
261
+ }
262
+
263
+ public final Color mul(Color c) {
264
+ r *= c.r;
265
+ g *= c.g;
266
+ b *= c.b;
267
+ return this;
268
+ }
269
+
270
+ public static final Color mul(Color c1, Color c2) {
271
+ return Color.mul(c1, c2, new Color());
272
+ }
273
+
274
+ public static final Color mul(Color c1, Color c2, Color dest) {
275
+ dest.r = c1.r * c2.r;
276
+ dest.g = c1.g * c2.g;
277
+ dest.b = c1.b * c2.b;
278
+ return dest;
279
+ }
280
+
281
+ public final Color mul(float s) {
282
+ r *= s;
283
+ g *= s;
284
+ b *= s;
285
+ return this;
286
+ }
287
+
288
+ public static final Color mul(float s, Color c) {
289
+ return Color.mul(s, c, new Color());
290
+ }
291
+
292
+ public static final Color mul(float s, Color c, Color dest) {
293
+ dest.r = s * c.r;
294
+ dest.g = s * c.g;
295
+ dest.b = s * c.b;
296
+ return dest;
297
+ }
298
+
299
+ public final Color div(Color c) {
300
+ r /= c.r;
301
+ g /= c.g;
302
+ b /= c.b;
303
+ return this;
304
+ }
305
+
306
+ public static final Color div(Color c1, Color c2) {
307
+ return Color.div(c1, c2, new Color());
308
+ }
309
+
310
+ public static final Color div(Color c1, Color c2, Color dest) {
311
+ dest.r = c1.r / c2.r;
312
+ dest.g = c1.g / c2.g;
313
+ dest.b = c1.b / c2.b;
314
+ return dest;
315
+ }
316
+
317
+ public final Color exp() {
318
+ r = (float) Math.exp(r);
319
+ g = (float) Math.exp(g);
320
+ b = (float) Math.exp(b);
321
+ return this;
322
+ }
323
+
324
+ public final Color opposite() {
325
+ r = 1 - r;
326
+ g = 1 - g;
327
+ b = 1 - b;
328
+ return this;
329
+ }
330
+
331
+ public final Color clamp(float min, float max) {
332
+ r = MathUtils.clamp(r, min, max);
333
+ g = MathUtils.clamp(g, min, max);
334
+ b = MathUtils.clamp(b, min, max);
335
+ return this;
336
+ }
337
+
338
+ public static final Color blend(Color c1, Color c2, float b) {
339
+ return blend(c1, c2, b, new Color());
340
+ }
341
+
342
+ public static final Color blend(Color c1, Color c2, float b, Color dest) {
343
+ dest.r = (1.0f - b) * c1.r + b * c2.r;
344
+ dest.g = (1.0f - b) * c1.g + b * c2.g;
345
+ dest.b = (1.0f - b) * c1.b + b * c2.b;
346
+ return dest;
347
+ }
348
+
349
+ public static final Color blend(Color c1, Color c2, Color b) {
350
+ return blend(c1, c2, b, new Color());
351
+ }
352
+
353
+ public static final Color blend(Color c1, Color c2, Color b, Color dest) {
354
+ dest.r = (1.0f - b.r) * c1.r + b.r * c2.r;
355
+ dest.g = (1.0f - b.g) * c1.g + b.g * c2.g;
356
+ dest.b = (1.0f - b.b) * c1.b + b.b * c2.b;
357
+ return dest;
358
+ }
359
+
360
+ public static final boolean hasContrast(Color c1, Color c2, float thresh) {
361
+ if (Math.abs(c1.r - c2.r) / (c1.r + c2.r) > thresh) {
362
+ return true;
363
+ }
364
+ if (Math.abs(c1.g - c2.g) / (c1.g + c2.g) > thresh) {
365
+ return true;
366
+ }
367
+ return (Math.abs(c1.b - c2.b) / (c1.b + c2.b) > thresh);
368
+ }
369
+
370
+ @Override
371
+ public String toString() {
372
+ return String.format("(%.3f, %.3f, %.3f)", r, g, b);
373
+ }
374
+ }