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,30 @@
1
+ package org.sunflow.image;
2
+
3
+ public class RegularSpectralCurve extends SpectralCurve {
4
+
5
+ private final float[] spectrum;
6
+ private final float lambdaMin, lambdaMax;
7
+ private final float delta, invDelta;
8
+
9
+ public RegularSpectralCurve(float[] spectrum, float lambdaMin, float lambdaMax) {
10
+ this.lambdaMin = lambdaMin;
11
+ this.lambdaMax = lambdaMax;
12
+ this.spectrum = spectrum;
13
+ delta = (lambdaMax - lambdaMin) / (spectrum.length - 1);
14
+ invDelta = 1 / delta;
15
+ }
16
+
17
+ @Override
18
+ public float sample(float lambda) {
19
+ // reject wavelengths outside the valid range
20
+ if (lambda < lambdaMin || lambda > lambdaMax) {
21
+ return 0;
22
+ }
23
+ // interpolate the two closest samples linearly
24
+ float x = (lambda - lambdaMin) * invDelta;
25
+ int b0 = (int) x;
26
+ int b1 = Math.min(b0 + 1, spectrum.length - 1);
27
+ float dx = x - b0;
28
+ return (1 - dx) * spectrum[b0] + dx * spectrum[b1];
29
+ }
30
+ }
@@ -0,0 +1,118 @@
1
+ package org.sunflow.image;
2
+
3
+ /**
4
+ * This class is an abstract interface to sampled or analytic spectral data.
5
+ */
6
+ public abstract class SpectralCurve {
7
+
8
+ /**
9
+ * This function determines the actual spectral curve data. Note that the
10
+ * lambda parameter is assumed to be in nanometers.
11
+ *
12
+ * @param lambda wavelength to sample in nanometers
13
+ * @return the value of the spectral curve at this point
14
+ */
15
+ public abstract float sample(float lambda);
16
+ private static final int WAVELENGTH_MIN = 360;
17
+ private static final int WAVELENGTH_MAX = 830;
18
+ private static final double[] CIE_XBAR = {0.000129900000, 0.000232100000,
19
+ 0.000414900000, 0.000741600000, 0.001368000000, 0.002236000000,
20
+ 0.004243000000, 0.007650000000, 0.014310000000, 0.023190000000,
21
+ 0.043510000000, 0.077630000000, 0.134380000000, 0.214770000000,
22
+ 0.283900000000, 0.328500000000, 0.348280000000, 0.348060000000,
23
+ 0.336200000000, 0.318700000000, 0.290800000000, 0.251100000000,
24
+ 0.195360000000, 0.142100000000, 0.095640000000, 0.057950010000,
25
+ 0.032010000000, 0.014700000000, 0.004900000000, 0.002400000000,
26
+ 0.009300000000, 0.029100000000, 0.063270000000, 0.109600000000,
27
+ 0.165500000000, 0.225749900000, 0.290400000000, 0.359700000000,
28
+ 0.433449900000, 0.512050100000, 0.594500000000, 0.678400000000,
29
+ 0.762100000000, 0.842500000000, 0.916300000000, 0.978600000000,
30
+ 1.026300000000, 1.056700000000, 1.062200000000, 1.045600000000,
31
+ 1.002600000000, 0.938400000000, 0.854449900000, 0.751400000000,
32
+ 0.642400000000, 0.541900000000, 0.447900000000, 0.360800000000,
33
+ 0.283500000000, 0.218700000000, 0.164900000000, 0.121200000000,
34
+ 0.087400000000, 0.063600000000, 0.046770000000, 0.032900000000,
35
+ 0.022700000000, 0.015840000000, 0.011359160000, 0.008110916000,
36
+ 0.005790346000, 0.004106457000, 0.002899327000, 0.002049190000,
37
+ 0.001439971000, 0.000999949300, 0.000690078600, 0.000476021300,
38
+ 0.000332301100, 0.000234826100, 0.000166150500, 0.000117413000,
39
+ 0.000083075270, 0.000058706520, 0.000041509940, 0.000029353260,
40
+ 0.000020673830, 0.000014559770, 0.000010253980, 0.000007221456,
41
+ 0.000005085868, 0.000003581652, 0.000002522525, 0.000001776509,
42
+ 0.000001251141,};
43
+ private static final double[] CIE_YBAR = {0.000003917000, 0.000006965000,
44
+ 0.000012390000, 0.000022020000, 0.000039000000, 0.000064000000,
45
+ 0.000120000000, 0.000217000000, 0.000396000000, 0.000640000000,
46
+ 0.001210000000, 0.002180000000, 0.004000000000, 0.007300000000,
47
+ 0.011600000000, 0.016840000000, 0.023000000000, 0.029800000000,
48
+ 0.038000000000, 0.048000000000, 0.060000000000, 0.073900000000,
49
+ 0.090980000000, 0.112600000000, 0.139020000000, 0.169300000000,
50
+ 0.208020000000, 0.258600000000, 0.323000000000, 0.407300000000,
51
+ 0.503000000000, 0.608200000000, 0.710000000000, 0.793200000000,
52
+ 0.862000000000, 0.914850100000, 0.954000000000, 0.980300000000,
53
+ 0.994950100000, 1.000000000000, 0.995000000000, 0.978600000000,
54
+ 0.952000000000, 0.915400000000, 0.870000000000, 0.816300000000,
55
+ 0.757000000000, 0.694900000000, 0.631000000000, 0.566800000000,
56
+ 0.503000000000, 0.441200000000, 0.381000000000, 0.321000000000,
57
+ 0.265000000000, 0.217000000000, 0.175000000000, 0.138200000000,
58
+ 0.107000000000, 0.081600000000, 0.061000000000, 0.044580000000,
59
+ 0.032000000000, 0.023200000000, 0.017000000000, 0.011920000000,
60
+ 0.008210000000, 0.005723000000, 0.004102000000, 0.002929000000,
61
+ 0.002091000000, 0.001484000000, 0.001047000000, 0.000740000000,
62
+ 0.000520000000, 0.000361100000, 0.000249200000, 0.000171900000,
63
+ 0.000120000000, 0.000084800000, 0.000060000000, 0.000042400000,
64
+ 0.000030000000, 0.000021200000, 0.000014990000, 0.000010600000,
65
+ 0.000007465700, 0.000005257800, 0.000003702900, 0.000002607800,
66
+ 0.000001836600, 0.000001293400, 0.000000910930, 0.000000641530,
67
+ 0.000000451810,};
68
+ private static final double[] CIE_ZBAR = {0.000606100000, 0.001086000000,
69
+ 0.001946000000, 0.003486000000, 0.006450001000, 0.010549990000,
70
+ 0.020050010000, 0.036210000000, 0.067850010000, 0.110200000000,
71
+ 0.207400000000, 0.371300000000, 0.645600000000, 1.039050100000,
72
+ 1.385600000000, 1.622960000000, 1.747060000000, 1.782600000000,
73
+ 1.772110000000, 1.744100000000, 1.669200000000, 1.528100000000,
74
+ 1.287640000000, 1.041900000000, 0.812950100000, 0.616200000000,
75
+ 0.465180000000, 0.353300000000, 0.272000000000, 0.212300000000,
76
+ 0.158200000000, 0.111700000000, 0.078249990000, 0.057250010000,
77
+ 0.042160000000, 0.029840000000, 0.020300000000, 0.013400000000,
78
+ 0.008749999000, 0.005749999000, 0.003900000000, 0.002749999000,
79
+ 0.002100000000, 0.001800000000, 0.001650001000, 0.001400000000,
80
+ 0.001100000000, 0.001000000000, 0.000800000000, 0.000600000000,
81
+ 0.000340000000, 0.000240000000, 0.000190000000, 0.000100000000,
82
+ 0.000049999990, 0.000030000000, 0.000020000000, 0.000010000000,
83
+ 0.000000000000, 0.000000000000, 0.000000000000, 0.000000000000,
84
+ 0.000000000000, 0.000000000000, 0.000000000000, 0.000000000000,
85
+ 0.000000000000, 0.000000000000, 0.000000000000, 0.000000000000,
86
+ 0.000000000000, 0.000000000000, 0.000000000000, 0.000000000000,
87
+ 0.000000000000, 0.000000000000, 0.000000000000, 0.000000000000,
88
+ 0.000000000000, 0.000000000000, 0.000000000000, 0.000000000000,
89
+ 0.000000000000, 0.000000000000, 0.000000000000, 0.000000000000,
90
+ 0.000000000000, 0.000000000000, 0.000000000000, 0.000000000000,
91
+ 0.000000000000, 0.000000000000, 0.000000000000, 0.000000000000,
92
+ 0.000000000000,};
93
+ private static final int WAVELENGTH_STEP = (WAVELENGTH_MAX - WAVELENGTH_MIN) / (CIE_XBAR.length - 1);
94
+
95
+ static {
96
+ if (WAVELENGTH_STEP * (CIE_XBAR.length - 1) != WAVELENGTH_MAX - WAVELENGTH_MIN) {
97
+ String err = String.format("Internal error - spectrum static data is inconsistent!\n * min = %d\n * max = %d\n * step = %d\n * num = %d", WAVELENGTH_MIN, WAVELENGTH_MAX, WAVELENGTH_STEP, CIE_XBAR.length);
98
+ throw new RuntimeException(err);
99
+ }
100
+ }
101
+
102
+ /**
103
+ * Convert this curve to a tristimulus CIE XYZ color by integrating against
104
+ * the CIE color matching functions.
105
+ *
106
+ * @return XYZColor that represents this spectra
107
+ */
108
+ public final XYZColor toXYZ() {
109
+ float X = 0, Y = 0, Z = 0;
110
+ for (int i = 0, w = WAVELENGTH_MIN; i < CIE_XBAR.length; i++, w += WAVELENGTH_STEP) {
111
+ float s = sample(w);
112
+ X += s * CIE_XBAR[i];
113
+ Y += s * CIE_YBAR[i];
114
+ Z += s * CIE_ZBAR[i];
115
+ }
116
+ return new XYZColor(X, Y, Z).mul(WAVELENGTH_STEP);
117
+ }
118
+ }
@@ -0,0 +1,50 @@
1
+ package org.sunflow.image;
2
+
3
+ public final class XYZColor {
4
+
5
+ private float X, Y, Z;
6
+
7
+ public XYZColor() {
8
+ }
9
+
10
+ public XYZColor(float X, float Y, float Z) {
11
+ this.X = X;
12
+ this.Y = Y;
13
+ this.Z = Z;
14
+ }
15
+
16
+ public final float getX() {
17
+ return X;
18
+ }
19
+
20
+ public final float getY() {
21
+ return Y;
22
+ }
23
+
24
+ public final float getZ() {
25
+ return Z;
26
+ }
27
+
28
+ public final XYZColor mul(float s) {
29
+ X *= s;
30
+ Y *= s;
31
+ Z *= s;
32
+ return this;
33
+ }
34
+
35
+ public final void normalize() {
36
+ float XYZ = X + Y + Z;
37
+ if (XYZ < 1e-6f) {
38
+ return;
39
+ }
40
+ float s = 1 / XYZ;
41
+ X *= s;
42
+ Y *= s;
43
+ Z *= s;
44
+ }
45
+
46
+ @Override
47
+ public final String toString() {
48
+ return String.format("(%.3f, %.3f, %.3f)", X, Y, Z);
49
+ }
50
+ }
@@ -0,0 +1,27 @@
1
+ package org.sunflow.image.formats;
2
+
3
+ import org.sunflow.image.Bitmap;
4
+ import org.sunflow.image.Color;
5
+
6
+ public class BitmapBlack extends Bitmap {
7
+
8
+ @Override
9
+ public int getWidth() {
10
+ return 1;
11
+ }
12
+
13
+ @Override
14
+ public int getHeight() {
15
+ return 1;
16
+ }
17
+
18
+ @Override
19
+ public Color readColor(int x, int y) {
20
+ return Color.BLACK;
21
+ }
22
+
23
+ @Override
24
+ public float readAlpha(int x, int y) {
25
+ return 0;
26
+ }
27
+ }
@@ -0,0 +1,36 @@
1
+ package org.sunflow.image.formats;
2
+
3
+ import org.sunflow.image.Bitmap;
4
+ import org.sunflow.image.Color;
5
+
6
+ public class BitmapG8 extends Bitmap {
7
+
8
+ private int w, h;
9
+ private byte[] data;
10
+
11
+ public BitmapG8(int w, int h, byte[] data) {
12
+ this.w = w;
13
+ this.h = h;
14
+ this.data = data;
15
+ }
16
+
17
+ @Override
18
+ public int getWidth() {
19
+ return w;
20
+ }
21
+
22
+ @Override
23
+ public int getHeight() {
24
+ return h;
25
+ }
26
+
27
+ @Override
28
+ public Color readColor(int x, int y) {
29
+ return new Color((data[x + y * w] & 0xFF) * INV255);
30
+ }
31
+
32
+ @Override
33
+ public float readAlpha(int x, int y) {
34
+ return 1;
35
+ }
36
+ }
@@ -0,0 +1,30 @@
1
+ package org.sunflow.image.formats;
2
+
3
+ import org.sunflow.image.Bitmap;
4
+ import org.sunflow.image.Color;
5
+
6
+ public class BitmapGA8 extends Bitmap {
7
+
8
+ private int w, h;
9
+ private byte[] data;
10
+
11
+ @Override
12
+ public int getWidth() {
13
+ return w;
14
+ }
15
+
16
+ @Override
17
+ public int getHeight() {
18
+ return h;
19
+ }
20
+
21
+ @Override
22
+ public Color readColor(int x, int y) {
23
+ return new Color((data[2 * (x + y * w) + 0] & 0xFF) * INV255);
24
+ }
25
+
26
+ @Override
27
+ public float readAlpha(int x, int y) {
28
+ return (data[2 * (x + y * w) + 1] & 0xFF) * INV255;
29
+ }
30
+ }
@@ -0,0 +1,40 @@
1
+ package org.sunflow.image.formats;
2
+
3
+ import org.sunflow.image.Bitmap;
4
+ import org.sunflow.image.Color;
5
+
6
+ public class BitmapRGB8 extends Bitmap {
7
+
8
+ private int w, h;
9
+ private byte[] data;
10
+
11
+ public BitmapRGB8(int w, int h, byte[] data) {
12
+ this.w = w;
13
+ this.h = h;
14
+ this.data = data;
15
+ }
16
+
17
+ @Override
18
+ public int getWidth() {
19
+ return w;
20
+ }
21
+
22
+ @Override
23
+ public int getHeight() {
24
+ return h;
25
+ }
26
+
27
+ @Override
28
+ public Color readColor(int x, int y) {
29
+ int index = 3 * (x + y * w);
30
+ float r = (data[index + 0] & 0xFF) * INV255;
31
+ float g = (data[index + 1] & 0xFF) * INV255;
32
+ float b = (data[index + 2] & 0xFF) * INV255;
33
+ return new Color(r, g, b);
34
+ }
35
+
36
+ @Override
37
+ public float readAlpha(int x, int y) {
38
+ return 1;
39
+ }
40
+ }
@@ -0,0 +1,40 @@
1
+ package org.sunflow.image.formats;
2
+
3
+ import org.sunflow.image.Bitmap;
4
+ import org.sunflow.image.Color;
5
+
6
+ public class BitmapRGBA8 extends Bitmap {
7
+
8
+ private int w, h;
9
+ private byte[] data;
10
+
11
+ public BitmapRGBA8(int w, int h, byte[] data) {
12
+ this.w = w;
13
+ this.h = h;
14
+ this.data = data;
15
+ }
16
+
17
+ @Override
18
+ public int getWidth() {
19
+ return w;
20
+ }
21
+
22
+ @Override
23
+ public int getHeight() {
24
+ return h;
25
+ }
26
+
27
+ @Override
28
+ public Color readColor(int x, int y) {
29
+ int index = 4 * (x + y * w);
30
+ float r = (data[index + 0] & 0xFF) * INV255;
31
+ float g = (data[index + 1] & 0xFF) * INV255;
32
+ float b = (data[index + 2] & 0xFF) * INV255;
33
+ return new Color(r, g, b);
34
+ }
35
+
36
+ @Override
37
+ public float readAlpha(int x, int y) {
38
+ return (data[4 * (x + y * w) + 3] & 0xFF) * INV255;
39
+ }
40
+ }
@@ -0,0 +1,60 @@
1
+ package org.sunflow.image.formats;
2
+
3
+ import org.sunflow.image.Bitmap;
4
+ import org.sunflow.image.Color;
5
+
6
+ public class BitmapRGBE extends Bitmap {
7
+
8
+ private int w, h;
9
+ private int[] data;
10
+ private static final float[] EXPONENT = new float[256];
11
+
12
+ static {
13
+ EXPONENT[0] = 0;
14
+ for (int i = 1; i < 256; i++) {
15
+ float f = 1.0f;
16
+ int e = i - (128 + 8);
17
+ if (e > 0) {
18
+ for (int j = 0; j < e; j++) {
19
+ f *= 2.0f;
20
+ }
21
+ } else {
22
+ for (int j = 0; j < -e; j++) {
23
+ f *= 0.5f;
24
+ }
25
+ }
26
+ EXPONENT[i] = f;
27
+ }
28
+ }
29
+
30
+ public BitmapRGBE(int w, int h, int[] data) {
31
+ this.w = w;
32
+ this.h = h;
33
+ this.data = data;
34
+ }
35
+
36
+ @Override
37
+ public int getWidth() {
38
+ return w;
39
+ }
40
+
41
+ @Override
42
+ public int getHeight() {
43
+ return h;
44
+ }
45
+
46
+ @Override
47
+ public Color readColor(int x, int y) {
48
+ int rgbe = data[x + y * w];
49
+ float f = EXPONENT[rgbe & 0xFF];
50
+ float r = f * ((rgbe >>> 24) + 0.5f);
51
+ float g = f * (((rgbe >> 16) & 0xFF) + 0.5f);
52
+ float b = f * (((rgbe >> 8) & 0xFF) + 0.5f);
53
+ return new Color(r, g, b);
54
+ }
55
+
56
+ @Override
57
+ public float readAlpha(int x, int y) {
58
+ return 1;
59
+ }
60
+ }
@@ -0,0 +1,38 @@
1
+ package org.sunflow.image.formats;
2
+
3
+ import org.sunflow.image.Bitmap;
4
+ import org.sunflow.image.Color;
5
+ import org.sunflow.image.XYZColor;
6
+
7
+ public class BitmapXYZ extends Bitmap {
8
+
9
+ private int w, h;
10
+ private float[] data;
11
+
12
+ public BitmapXYZ(int w, int h, float[] data) {
13
+ this.w = w;
14
+ this.h = h;
15
+ this.data = data;
16
+ }
17
+
18
+ @Override
19
+ public int getWidth() {
20
+ return w;
21
+ }
22
+
23
+ @Override
24
+ public int getHeight() {
25
+ return h;
26
+ }
27
+
28
+ @Override
29
+ public Color readColor(int x, int y) {
30
+ int index = 3 * (x + y * w);
31
+ return Color.NATIVE_SPACE.convertXYZtoRGB(new XYZColor(data[index], data[index + 1], data[index + 2])).mul(0.1f);
32
+ }
33
+
34
+ @Override
35
+ public float readAlpha(int x, int y) {
36
+ return 1;
37
+ }
38
+ }