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,73 @@
1
+ package org.sunflow.image.formats;
2
+
3
+ import java.io.IOException;
4
+
5
+ import org.sunflow.PluginRegistry;
6
+ import org.sunflow.image.Bitmap;
7
+ import org.sunflow.image.BitmapWriter;
8
+ import org.sunflow.image.Color;
9
+ import org.sunflow.system.FileUtils;
10
+ import org.sunflow.system.UI;
11
+ import org.sunflow.system.UI.Module;
12
+
13
+ /**
14
+ * This is a generic and inefficient bitmap format which may be used for
15
+ * debugging purposes (dumping small images), when memory usage is not a
16
+ * concern.
17
+ */
18
+ public class GenericBitmap extends Bitmap {
19
+
20
+ private final int w;
21
+ private final int h;
22
+ private final Color[] color;
23
+ private final float[] alpha;
24
+
25
+ public GenericBitmap(int w, int h) {
26
+ this.w = w;
27
+ this.h = h;
28
+ color = new Color[w * h];
29
+ alpha = new float[w * h];
30
+ }
31
+
32
+ @Override
33
+ public int getWidth() {
34
+ return w;
35
+ }
36
+
37
+ @Override
38
+ public int getHeight() {
39
+ return h;
40
+ }
41
+
42
+ @Override
43
+ public Color readColor(int x, int y) {
44
+ return color[x + y * w];
45
+ }
46
+
47
+ @Override
48
+ public float readAlpha(int x, int y) {
49
+ return alpha[x + y * w];
50
+ }
51
+
52
+ public void writePixel(int x, int y, Color c, float a) {
53
+ color[x + y * w] = c;
54
+ alpha[x + y * w] = a;
55
+ }
56
+
57
+ public void save(String filename) {
58
+ String extension = FileUtils.getExtension(filename);
59
+ BitmapWriter writer = PluginRegistry.BITMAP_WRITER_PLUGINS.createObject(extension);
60
+ if (writer == null) {
61
+ UI.printError(Module.IMG, "Unable to save file \"%s\" - unknown file format: %s", filename, extension);
62
+ return;
63
+ }
64
+ try {
65
+ writer.openFile(filename);
66
+ writer.writeHeader(w, h, Math.max(w, h));
67
+ writer.writeTile(0, 0, w, h, color, alpha);
68
+ writer.closeFile();
69
+ } catch (IOException e) {
70
+ UI.printError(Module.IMG, "Unable to save file \"%s\" - %s", filename, e.getLocalizedMessage());
71
+ }
72
+ }
73
+ }
@@ -0,0 +1,39 @@
1
+ package org.sunflow.image.readers;
2
+
3
+ import java.awt.image.BufferedImage;
4
+ import java.io.File;
5
+ import java.io.IOException;
6
+
7
+ import javax.imageio.ImageIO;
8
+
9
+ import org.sunflow.image.Bitmap;
10
+ import org.sunflow.image.BitmapReader;
11
+ import org.sunflow.image.Color;
12
+ import org.sunflow.image.formats.BitmapRGB8;
13
+
14
+ public class BMPBitmapReader implements BitmapReader {
15
+
16
+ public Bitmap load(String filename, boolean isLinear) throws IOException, BitmapFormatException {
17
+ // regular image, load using Java api - ignore alpha channel
18
+ BufferedImage bi = ImageIO.read(new File(filename));
19
+ int width = bi.getWidth();
20
+ int height = bi.getHeight();
21
+ byte[] pixels = new byte[3 * width * height];
22
+ for (int y = 0, index = 0; y < height; y++) {
23
+ for (int x = 0; x < width; x++, index += 3) {
24
+ int argb = bi.getRGB(x, height - 1 - y);
25
+ pixels[index + 0] = (byte) (argb >> 16);
26
+ pixels[index + 1] = (byte) (argb >> 8);
27
+ pixels[index + 2] = (byte) argb;
28
+ }
29
+ }
30
+ if (!isLinear) {
31
+ for (int index = 0; index < pixels.length; index += 3) {
32
+ pixels[index + 0] = Color.NATIVE_SPACE.rgbToLinear(pixels[index + 0]);
33
+ pixels[index + 1] = Color.NATIVE_SPACE.rgbToLinear(pixels[index + 1]);
34
+ pixels[index + 2] = Color.NATIVE_SPACE.rgbToLinear(pixels[index + 2]);
35
+ }
36
+ }
37
+ return new BitmapRGB8(width, height, pixels);
38
+ }
39
+ }
@@ -0,0 +1,155 @@
1
+ package org.sunflow.image.readers;
2
+
3
+ import java.io.BufferedInputStream;
4
+ import java.io.FileInputStream;
5
+ import java.io.IOException;
6
+ import java.io.InputStream;
7
+
8
+ import org.sunflow.image.Bitmap;
9
+ import org.sunflow.image.BitmapReader;
10
+ import org.sunflow.image.formats.BitmapRGBE;
11
+
12
+ public class HDRBitmapReader implements BitmapReader {
13
+
14
+ public Bitmap load(String filename, boolean isLinear) throws IOException, BitmapFormatException {
15
+ // load radiance rgbe file
16
+ InputStream f = new BufferedInputStream(new FileInputStream(filename));
17
+ // parse header
18
+ boolean parseWidth = false, parseHeight = false;
19
+ int width = 0, height = 0;
20
+ int last = 0;
21
+ while (width == 0 || height == 0 || last != '\n') {
22
+ int n = f.read();
23
+ switch (n) {
24
+ case 'Y':
25
+ parseHeight = last == '-';
26
+ parseWidth = false;
27
+ break;
28
+ case 'X':
29
+ parseHeight = false;
30
+ parseWidth = last == '+';
31
+ break;
32
+ case ' ':
33
+ parseWidth &= width == 0;
34
+ parseHeight &= height == 0;
35
+ break;
36
+ case '0':
37
+ case '1':
38
+ case '2':
39
+ case '3':
40
+ case '4':
41
+ case '5':
42
+ case '6':
43
+ case '7':
44
+ case '8':
45
+ case '9':
46
+ if (parseHeight) {
47
+ height = 10 * height + (n - '0');
48
+ } else if (parseWidth) {
49
+ width = 10 * width + (n - '0');
50
+ }
51
+ break;
52
+ default:
53
+ parseWidth = parseHeight = false;
54
+ break;
55
+ }
56
+ last = n;
57
+ }
58
+ // allocate image
59
+ int[] pixels = new int[width * height];
60
+ if ((width < 8) || (width > 0x7fff)) {
61
+ // run length encoding is not allowed so read flat
62
+ readFlatRGBE(f, 0, width * height, pixels);
63
+ } else {
64
+ int rasterPos = 0;
65
+ int numScanlines = height;
66
+ int[] scanlineBuffer = new int[4 * width];
67
+ while (numScanlines > 0) {
68
+ int r = f.read();
69
+ int g = f.read();
70
+ int b = f.read();
71
+ int e = f.read();
72
+ if ((r != 2) || (g != 2) || ((b & 0x80) != 0)) {
73
+ // this file is not run length encoded
74
+ pixels[rasterPos] = (r << 24) | (g << 16) | (b << 8) | e;
75
+ readFlatRGBE(f, rasterPos + 1, width * numScanlines - 1, pixels);
76
+ break;
77
+ }
78
+
79
+ if (((b << 8) | e) != width) {
80
+ throw new BitmapFormatException("Invalid scanline width");
81
+ }
82
+ int p = 0;
83
+ // read each of the four channels for the scanline into
84
+ // the buffer
85
+ for (int i = 0; i < 4; i++) {
86
+ if (p % width != 0) {
87
+ throw new BitmapFormatException("Unaligned access to scanline data");
88
+ }
89
+ int end = (i + 1) * width;
90
+ while (p < end) {
91
+ int b0 = f.read();
92
+ int b1 = f.read();
93
+ if (b0 > 128) {
94
+ // a run of the same value
95
+ int count = b0 - 128;
96
+ if ((count == 0) || (count > (end - p))) {
97
+ throw new BitmapFormatException("Bad scanline data - invalid RLE run");
98
+ }
99
+
100
+ while (count-- > 0) {
101
+ scanlineBuffer[p] = b1;
102
+ p++;
103
+ }
104
+ } else {
105
+ // a non-run
106
+ int count = b0;
107
+ if ((count == 0) || (count > (end - p))) {
108
+ throw new BitmapFormatException("Bad scanline data - invalid count");
109
+ }
110
+ scanlineBuffer[p] = b1;
111
+ p++;
112
+ if (--count > 0) {
113
+ for (int x = 0; x < count; x++) {
114
+ scanlineBuffer[p + x] = f.read();
115
+ }
116
+ p += count;
117
+ }
118
+ }
119
+ }
120
+ }
121
+ // now convert data from buffer into floats
122
+ for (int i = 0; i < width; i++) {
123
+ r = scanlineBuffer[i];
124
+ g = scanlineBuffer[i + width];
125
+ b = scanlineBuffer[i + 2 * width];
126
+ e = scanlineBuffer[i + 3 * width];
127
+ pixels[rasterPos] = (r << 24) | (g << 16) | (b << 8) | e;
128
+ rasterPos++;
129
+ }
130
+ numScanlines--;
131
+ }
132
+ }
133
+ f.close();
134
+ // flip image
135
+ for (int y = 0, i = 0, ir = (height - 1) * width; y < height / 2; y++, ir -= width) {
136
+ for (int x = 0, i2 = ir; x < width; x++, i++, i2++) {
137
+ int t = pixels[i];
138
+ pixels[i] = pixels[i2];
139
+ pixels[i2] = t;
140
+ }
141
+ }
142
+ return new BitmapRGBE(width, height, pixels);
143
+ }
144
+
145
+ private void readFlatRGBE(InputStream f, int rasterPos, int numPixels, int[] pixels) throws IOException {
146
+ while (numPixels-- > 0) {
147
+ int r = f.read();
148
+ int g = f.read();
149
+ int b = f.read();
150
+ int e = f.read();
151
+ pixels[rasterPos] = (r << 24) | (g << 16) | (b << 8) | e;
152
+ rasterPos++;
153
+ }
154
+ }
155
+ }
@@ -0,0 +1,104 @@
1
+ package org.sunflow.image.readers;
2
+
3
+ import java.io.BufferedInputStream;
4
+ import java.io.FileInputStream;
5
+ import java.io.IOException;
6
+ import java.io.InputStream;
7
+
8
+ import org.sunflow.image.Bitmap;
9
+ import org.sunflow.image.BitmapReader;
10
+ import org.sunflow.image.formats.BitmapXYZ;
11
+
12
+ /**
13
+ * Reads images in Indigo's native XYZ format.
14
+ * http://www2.indigorenderer.com/joomla/forum/viewtopic.php?p=11430
15
+ */
16
+ public class IGIBitmapReader implements BitmapReader {
17
+
18
+ public Bitmap load(String filename, boolean isLinear) throws IOException, BitmapFormatException {
19
+ InputStream stream = new BufferedInputStream(new FileInputStream(filename));
20
+ // read header
21
+ int magic = read32i(stream);
22
+ int version = read32i(stream);
23
+ stream.skip(8); // skip number of samples (double value)
24
+ int width = read32i(stream);
25
+ int height = read32i(stream);
26
+ int superSample = read32i(stream); // super sample factor
27
+ int compression = read32i(stream);
28
+ int dataSize = read32i(stream);
29
+ int colorSpace = read32i(stream);
30
+ stream.skip(5000); // skip the rest of the header (unused for now)
31
+ // error checking
32
+ if (magic != 66613373) {
33
+ throw new BitmapFormatException("wrong magic: " + magic);
34
+ }
35
+ if (version != 1) {
36
+ throw new BitmapFormatException("unsupported version: " + version);
37
+ }
38
+ if (compression != 0) {
39
+ throw new BitmapFormatException("unsupported compression: " + compression);
40
+ }
41
+ if (colorSpace != 0) {
42
+ throw new BitmapFormatException("unsupported color space: " + colorSpace);
43
+ }
44
+ if (dataSize != (width * height * 12)) {
45
+ throw new BitmapFormatException("invalid data block size: " + dataSize);
46
+ }
47
+ if (width <= 0 || height <= 0) {
48
+ throw new BitmapFormatException("invalid image size: " + width + "x" + height);
49
+ }
50
+ if (superSample <= 0) {
51
+ throw new BitmapFormatException("invalid super sample factor: " + superSample);
52
+ }
53
+ if ((width % superSample) != 0 || (height % superSample) != 0) {
54
+ throw new BitmapFormatException("invalid image size: " + width + "x" + height);
55
+ }
56
+ float[] xyz = new float[width * height * 3];
57
+ for (int y = 0, i = 3 * (height - 1) * width; y < height; y++, i -= 6 * width) {
58
+ for (int x = 0; x < width; x++, i += 3) {
59
+ xyz[i + 0] = read32f(stream);
60
+ xyz[i + 1] = read32f(stream);
61
+ xyz[i + 2] = read32f(stream);
62
+ }
63
+ }
64
+ stream.close();
65
+ if (superSample > 1) {
66
+ // rescale image (basic box filtering)
67
+ float[] rescaled = new float[xyz.length / (superSample * superSample)];
68
+ float inv = 1.0f / (superSample * superSample);
69
+ for (int y = 0, i = 0; y < height; y += superSample) {
70
+ for (int x = 0; x < width; x += superSample, i += 3) {
71
+ float X = 0;
72
+ float Y = 0;
73
+ float Z = 0;
74
+ for (int sy = 0; sy < superSample; sy++) {
75
+ for (int sx = 0; sx < superSample; sx++) {
76
+ int offset = 3 * ((x + sx + (y + sy) * width));
77
+ X += xyz[offset + 0];
78
+ Y += xyz[offset + 1];
79
+ Z += xyz[offset + 2];
80
+ }
81
+ }
82
+ rescaled[i + 0] = X * inv;
83
+ rescaled[i + 1] = Y * inv;
84
+ rescaled[i + 2] = Z * inv;
85
+ }
86
+ }
87
+ return new BitmapXYZ(width / superSample, height / superSample, rescaled);
88
+ } else {
89
+ return new BitmapXYZ(width, height, xyz);
90
+ }
91
+ }
92
+
93
+ private static final int read32i(InputStream stream) throws IOException {
94
+ int i = stream.read();
95
+ i |= stream.read() << 8;
96
+ i |= stream.read() << 16;
97
+ i |= stream.read() << 24;
98
+ return i;
99
+ }
100
+
101
+ private static final float read32f(InputStream stream) throws IOException {
102
+ return Float.intBitsToFloat(read32i(stream));
103
+ }
104
+ }
@@ -0,0 +1,39 @@
1
+ package org.sunflow.image.readers;
2
+
3
+ import java.awt.image.BufferedImage;
4
+ import java.io.File;
5
+ import java.io.IOException;
6
+
7
+ import javax.imageio.ImageIO;
8
+
9
+ import org.sunflow.image.Bitmap;
10
+ import org.sunflow.image.BitmapReader;
11
+ import org.sunflow.image.Color;
12
+ import org.sunflow.image.formats.BitmapRGB8;
13
+
14
+ public class JPGBitmapReader implements BitmapReader {
15
+
16
+ public Bitmap load(String filename, boolean isLinear) throws IOException, BitmapFormatException {
17
+ // regular image, load using Java api - ignore alpha channel
18
+ BufferedImage bi = ImageIO.read(new File(filename));
19
+ int width = bi.getWidth();
20
+ int height = bi.getHeight();
21
+ byte[] pixels = new byte[3 * width * height];
22
+ for (int y = 0, index = 0; y < height; y++) {
23
+ for (int x = 0; x < width; x++, index += 3) {
24
+ int argb = bi.getRGB(x, height - 1 - y);
25
+ pixels[index + 0] = (byte) (argb >> 16);
26
+ pixels[index + 1] = (byte) (argb >> 8);
27
+ pixels[index + 2] = (byte) argb;
28
+ }
29
+ }
30
+ if (!isLinear) {
31
+ for (int index = 0; index < pixels.length; index += 3) {
32
+ pixels[index + 0] = Color.NATIVE_SPACE.rgbToLinear(pixels[index + 0]);
33
+ pixels[index + 1] = Color.NATIVE_SPACE.rgbToLinear(pixels[index + 1]);
34
+ pixels[index + 2] = Color.NATIVE_SPACE.rgbToLinear(pixels[index + 2]);
35
+ }
36
+ }
37
+ return new BitmapRGB8(width, height, pixels);
38
+ }
39
+ }
@@ -0,0 +1,40 @@
1
+ package org.sunflow.image.readers;
2
+
3
+ import java.awt.image.BufferedImage;
4
+ import java.io.File;
5
+ import java.io.IOException;
6
+
7
+ import javax.imageio.ImageIO;
8
+
9
+ import org.sunflow.image.Bitmap;
10
+ import org.sunflow.image.BitmapReader;
11
+ import org.sunflow.image.Color;
12
+ import org.sunflow.image.formats.BitmapRGBA8;
13
+
14
+ public class PNGBitmapReader implements BitmapReader {
15
+
16
+ public Bitmap load(String filename, boolean isLinear) throws IOException, BitmapFormatException {
17
+ // regular image, load using Java api
18
+ BufferedImage bi = ImageIO.read(new File(filename));
19
+ int width = bi.getWidth();
20
+ int height = bi.getHeight();
21
+ byte[] pixels = new byte[4 * width * height];
22
+ for (int y = 0, index = 0; y < height; y++) {
23
+ for (int x = 0; x < width; x++, index += 4) {
24
+ int argb = bi.getRGB(x, height - 1 - y);
25
+ pixels[index + 0] = (byte) (argb >> 16);
26
+ pixels[index + 1] = (byte) (argb >> 8);
27
+ pixels[index + 2] = (byte) argb;
28
+ pixels[index + 3] = (byte) (argb >> 24);
29
+ }
30
+ }
31
+ if (!isLinear) {
32
+ for (int index = 0; index < pixels.length; index += 4) {
33
+ pixels[index + 0] = Color.NATIVE_SPACE.rgbToLinear(pixels[index + 0]);
34
+ pixels[index + 1] = Color.NATIVE_SPACE.rgbToLinear(pixels[index + 1]);
35
+ pixels[index + 2] = Color.NATIVE_SPACE.rgbToLinear(pixels[index + 2]);
36
+ }
37
+ }
38
+ return new BitmapRGBA8(width, height, pixels);
39
+ }
40
+ }