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,27 @@
1
+ package org.sunflow.system;
2
+
3
+ import java.io.File;
4
+ import java.util.Locale;
5
+
6
+ public final class FileUtils {
7
+
8
+ /**
9
+ * Extract the file extension from the specified filename.
10
+ *
11
+ * @param filename filename to get the extension of
12
+ * @return a string representing the file extension, or <code>null</code> if
13
+ * the filename doesn't have any extension, or is not a file
14
+ */
15
+ public static String getExtension(String filename) {
16
+ if (filename == null) {
17
+ return null;
18
+ }
19
+ File f = new File(filename);
20
+ if (f.isDirectory()) {
21
+ return null;
22
+ }
23
+ String name = new File(filename).getName();
24
+ int idx = name.lastIndexOf('.');
25
+ return idx == -1 ? null : name.substring(idx + 1).toLowerCase(Locale.ENGLISH);
26
+ }
27
+ }
@@ -0,0 +1,282 @@
1
+ package org.sunflow.system;
2
+
3
+ import java.awt.Dimension;
4
+ import java.awt.Graphics;
5
+ import java.awt.event.InputEvent;
6
+ import java.awt.event.MouseEvent;
7
+ import java.awt.event.MouseWheelEvent;
8
+ import java.awt.image.BufferedImage;
9
+ import java.io.File;
10
+ import java.io.IOException;
11
+ import java.util.logging.Level;
12
+ import java.util.logging.Logger;
13
+
14
+ import javax.imageio.ImageIO;
15
+ import javax.swing.JPanel;
16
+ import javax.swing.event.MouseInputAdapter;
17
+
18
+ import org.sunflow.core.Display;
19
+ import org.sunflow.image.Color;
20
+
21
+ @SuppressWarnings("serial")
22
+ public class ImagePanel extends JPanel implements Display {
23
+
24
+ private static final int[] BORDERS = {Color.RED.toRGB(),
25
+ Color.GREEN.toRGB(), Color.BLUE.toRGB(), Color.YELLOW.toRGB(),
26
+ Color.CYAN.toRGB(), Color.MAGENTA.toRGB()};
27
+ private BufferedImage image;
28
+ private float xo, yo;
29
+ private float w, h;
30
+ private long repaintCounter;
31
+
32
+ private class ScrollZoomListener extends MouseInputAdapter {
33
+
34
+ int mx;
35
+ int my;
36
+ boolean dragging;
37
+ boolean zooming;
38
+
39
+ @Override
40
+ public void mousePressed(MouseEvent e) {
41
+ mx = e.getX();
42
+ my = e.getY();
43
+ switch (e.getButton()) {
44
+ case MouseEvent.BUTTON1:
45
+ dragging = true;
46
+ zooming = false;
47
+ break;
48
+ case MouseEvent.BUTTON2: {
49
+ dragging = zooming = false;
50
+ // if CTRL is pressed
51
+ if ((e.getModifiersEx() & InputEvent.CTRL_DOWN_MASK) == InputEvent.CTRL_DOWN_MASK) {
52
+ fit();
53
+ } else {
54
+ reset();
55
+ }
56
+ break;
57
+ }
58
+ case MouseEvent.BUTTON3:
59
+ zooming = true;
60
+ dragging = false;
61
+ break;
62
+ default:
63
+ return;
64
+ }
65
+ repaint();
66
+ }
67
+
68
+ @Override
69
+ public void mouseDragged(MouseEvent e) {
70
+ int mx2 = e.getX();
71
+ int my2 = e.getY();
72
+ if (dragging) {
73
+ drag(mx2 - mx, my2 - my);
74
+ }
75
+ if (zooming) {
76
+ zoom(mx2 - mx, my2 - my);
77
+ }
78
+ mx = mx2;
79
+ my = my2;
80
+ }
81
+
82
+ @Override
83
+ public void mouseReleased(MouseEvent e) {
84
+ // same behaviour
85
+ mouseDragged(e);
86
+ }
87
+
88
+ @Override
89
+ public void mouseWheelMoved(MouseWheelEvent e) {
90
+ zoom(-20 * e.getWheelRotation(), 0);
91
+ }
92
+ }
93
+
94
+ public ImagePanel() {
95
+ setPreferredSize(new Dimension(640, 480));
96
+ image = null;
97
+ xo = yo = 0;
98
+ w = h = 0;
99
+ ScrollZoomListener listener = new ScrollZoomListener();
100
+ addMouseListener(listener);
101
+ addMouseMotionListener(listener);
102
+ addMouseWheelListener(listener);
103
+ }
104
+
105
+ public void save(String filename) {
106
+ try {
107
+ ImageIO.write(image, "png", new File(filename));
108
+ } catch (IOException ex) {
109
+ Logger.getLogger(ImagePanel.class.getName()).log(Level.SEVERE, null, ex);
110
+ }
111
+ }
112
+
113
+ private synchronized void drag(int dx, int dy) {
114
+ xo += dx;
115
+ yo += dy;
116
+ repaint();
117
+ }
118
+
119
+ private synchronized void zoom(int dx, int dy) {
120
+ int a = Math.max(dx, dy);
121
+ int b = Math.min(dx, dy);
122
+ if (Math.abs(b) > Math.abs(a)) {
123
+ a = b;
124
+ }
125
+ if (a == 0) {
126
+ return;
127
+ }
128
+ // window center
129
+ float cx = getWidth() * 0.5f;
130
+ float cy = getHeight() * 0.5f;
131
+
132
+ // origin of the image in window space
133
+ float x = xo + (getWidth() - w) * 0.5f;
134
+ float y = yo + (getHeight() - h) * 0.5f;
135
+
136
+ // coordinates of the pixel we are over
137
+ float sx = cx - x;
138
+ float sy = cy - y;
139
+
140
+ // scale
141
+ if (w + a > 100) {
142
+ h = (w + a) * h / w;
143
+ sx = (w + a) * sx / w;
144
+ sy = (w + a) * sy / w;
145
+ w = (w + a);
146
+ }
147
+
148
+ // restore center pixel
149
+
150
+ float x2 = cx - sx;
151
+ float y2 = cy - sy;
152
+
153
+ xo = (x2 - (getWidth() - w) * 0.5f);
154
+ yo = (y2 - (getHeight() - h) * 0.5f);
155
+
156
+ repaint();
157
+ }
158
+
159
+ public synchronized void reset() {
160
+ xo = yo = 0;
161
+ if (image != null) {
162
+ w = image.getWidth();
163
+ h = image.getHeight();
164
+ }
165
+ repaint();
166
+ }
167
+
168
+ public synchronized void fit() {
169
+ xo = yo = 0;
170
+ if (image != null) {
171
+ float wx = Math.max(getWidth() - 10, 100);
172
+ float hx = wx * image.getHeight() / image.getWidth();
173
+ float hy = Math.max(getHeight() - 10, 100);
174
+ float wy = hy * image.getWidth() / image.getHeight();
175
+ if (hx > hy) {
176
+ w = wy;
177
+ h = hy;
178
+ } else {
179
+ w = wx;
180
+ h = hx;
181
+ }
182
+ repaint();
183
+ }
184
+ }
185
+
186
+ @Override
187
+ public synchronized void imageBegin(int w, int h, int bucketSize) {
188
+ if (image != null && w == image.getWidth() && h == image.getHeight()) {
189
+ // dull image if it has same resolution (75%)
190
+ for (int y = 0; y < h; y++) {
191
+ for (int x = 0; x < w; x++) {
192
+ int rgba = image.getRGB(x, y);
193
+ image.setRGB(x, y, ((rgba & 0xFEFEFEFE) >>> 1) + ((rgba & 0xFCFCFCFC) >>> 2));
194
+ }
195
+ }
196
+ } else {
197
+ // allocate new framebuffer
198
+ image = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
199
+ // center
200
+ this.w = w;
201
+ this.h = h;
202
+ xo = yo = 0;
203
+ }
204
+ repaintCounter = System.nanoTime();
205
+ repaint();
206
+ }
207
+
208
+ @Override
209
+ public synchronized void imagePrepare(int x, int y, int w, int h, int id) {
210
+ int border = BORDERS[id % BORDERS.length] | 0xFF000000;
211
+ for (int by = 0; by < h; by++) {
212
+ for (int bx = 0; bx < w; bx++) {
213
+ if (bx == 0 || bx == w - 1) {
214
+ if (5 * by < h || 5 * (h - by - 1) < h) {
215
+ image.setRGB(x + bx, y + by, border);
216
+ }
217
+ } else if (by == 0 || by == h - 1) {
218
+ if (5 * bx < w || 5 * (w - bx - 1) < w) {
219
+ image.setRGB(x + bx, y + by, border);
220
+ }
221
+ }
222
+ }
223
+ }
224
+ repaint();
225
+ }
226
+
227
+ @Override
228
+ public synchronized void imageUpdate(int x, int y, int w, int h, Color[] data, float[] alpha) {
229
+ for (int j = 0, index = 0; j < h; j++) {
230
+ for (int i = 0; i < w; i++, index++) {
231
+ image.setRGB(x + i, y + j, data[index].copy().mul(1.0f / alpha[index]).toNonLinear().toRGBA(alpha[index]));
232
+ }
233
+ }
234
+ repaint();
235
+ }
236
+
237
+ @Override
238
+ public synchronized void imageFill(int x, int y, int w, int h, Color c, float alpha) {
239
+ int rgba = c.copy().mul(1.0f / alpha).toNonLinear().toRGBA(alpha);
240
+ for (int j = 0, index = 0; j < h; j++) {
241
+ for (int i = 0; i < w; i++, index++) {
242
+ image.setRGB(x + i, y + j, rgba);
243
+ }
244
+ }
245
+ fastRepaint();
246
+ }
247
+
248
+ @Override
249
+ public void imageEnd() {
250
+ repaint();
251
+ }
252
+
253
+ private void fastRepaint() {
254
+ long t = System.nanoTime();
255
+ if (repaintCounter + 125000000 < t) {
256
+ repaintCounter = t;
257
+ repaint();
258
+ }
259
+ }
260
+
261
+ @Override
262
+ public synchronized void paintComponent(Graphics g) {
263
+ super.paintComponent(g);
264
+ if (image == null) {
265
+ return;
266
+ }
267
+ int x = Math.round(xo + (getWidth() - w) * 0.5f);
268
+ int y = Math.round(yo + (getHeight() - h) * 0.5f);
269
+ int iw = Math.round(w);
270
+ int ih = Math.round(h);
271
+ int x0 = x - 1;
272
+ int y0 = y - 1;
273
+ int x1 = x + iw + 1;
274
+ int y1 = y + ih + 1;
275
+ g.setColor(java.awt.Color.WHITE);
276
+ g.drawLine(x0, y0, x1, y0);
277
+ g.drawLine(x1, y0, x1, y1);
278
+ g.drawLine(x1, y1, x0, y1);
279
+ g.drawLine(x0, y1, x0, y0);
280
+ g.drawImage(image, x, y, iw, ih, java.awt.Color.BLACK, this);
281
+ }
282
+ }
@@ -0,0 +1,18 @@
1
+ package org.sunflow.system;
2
+
3
+ public final class Memory {
4
+
5
+ public static String sizeof(int[] array) {
6
+ return bytesToString(array == null ? 0 : 4 * array.length);
7
+ }
8
+
9
+ public static String bytesToString(long bytes) {
10
+ if (bytes < 1024) {
11
+ return String.format("%db", bytes);
12
+ }
13
+ if (bytes < 1024 * 1024) {
14
+ return String.format("%dKb", (bytes + 512) >>> 10);
15
+ }
16
+ return String.format("%dMb", (bytes + 512 * 1024) >>> 20);
17
+ }
18
+ }
@@ -0,0 +1,162 @@
1
+ package org.sunflow.system;
2
+
3
+ import java.io.BufferedReader;
4
+ import java.io.FileNotFoundException;
5
+ import java.io.FileReader;
6
+ import java.io.IOException;
7
+ import java.util.ArrayList;
8
+
9
+ public class Parser {
10
+
11
+ private final FileReader file;
12
+ private BufferedReader bf;
13
+ private String[] lineTokens;
14
+ private int index;
15
+
16
+ public Parser(String filename) throws FileNotFoundException {
17
+ file = new FileReader(filename);
18
+ bf = new BufferedReader(file);
19
+ lineTokens = new String[0];
20
+ index = 0;
21
+ }
22
+
23
+ public void close() throws IOException {
24
+ if (file != null) {
25
+ file.close();
26
+ }
27
+ bf = null;
28
+ }
29
+
30
+ public String getNextToken() throws IOException {
31
+ while (true) {
32
+ String tok = fetchNextToken();
33
+ if (tok == null) {
34
+ return null;
35
+ }
36
+ if (tok.equals("/*")) {
37
+ do {
38
+ tok = fetchNextToken();
39
+ if (tok == null) {
40
+ return null;
41
+ }
42
+ } while (!tok.equals("*/"));
43
+ } else {
44
+ return tok;
45
+ }
46
+ }
47
+ }
48
+
49
+ public boolean peekNextToken(String tok) throws IOException {
50
+ while (true) {
51
+ String t = fetchNextToken();
52
+ if (t == null) {
53
+ return false; // nothing left
54
+ }
55
+ if (t.equals("/*")) {
56
+ do {
57
+ t = fetchNextToken();
58
+ if (t == null) {
59
+ return false; // nothing left
60
+ }
61
+ } while (!t.equals("*/"));
62
+ } else if (t.equals(tok)) {
63
+ // we found the right token, keep parsing
64
+ return true;
65
+ } else {
66
+ // rewind the token so we can try again
67
+ index--;
68
+ return false;
69
+ }
70
+ }
71
+ }
72
+
73
+ private String fetchNextToken() throws IOException {
74
+ if (bf == null) {
75
+ return null;
76
+ }
77
+ while (true) {
78
+ if (index < lineTokens.length) {
79
+ return lineTokens[index++];
80
+ } else if (!getNextLine()) {
81
+ return null;
82
+ }
83
+ }
84
+ }
85
+
86
+ private boolean getNextLine() throws IOException {
87
+ String line = bf.readLine();
88
+
89
+ if (line == null) {
90
+ return false;
91
+ }
92
+
93
+ ArrayList<String> tokenList = new ArrayList<>();
94
+ StringBuilder current = new StringBuilder(80);
95
+ boolean inQuotes = false;
96
+
97
+ for (int i = 0; i < line.length(); i++) {
98
+ char c = line.charAt(i);
99
+ if (current.length() == 0 && (c == '%' || c == '#')) {
100
+ break;
101
+ }
102
+
103
+ boolean quote = c == '\"';
104
+ inQuotes = inQuotes ^ quote;
105
+
106
+ if (!quote && (inQuotes || !Character.isWhitespace(c))) {
107
+ current.append(c);
108
+ } else if (current.length() > 0) {
109
+ tokenList.add(current.toString());
110
+ current = new StringBuilder(80);
111
+ }
112
+ }
113
+
114
+ if (current.length() > 0) {
115
+ tokenList.add(current.toString());
116
+ }
117
+ lineTokens = tokenList.toArray(new String[0]);
118
+ index = 0;
119
+ return true;
120
+ }
121
+
122
+ public String getNextCodeBlock() throws ParserException, IOException {
123
+ // read a java code block
124
+ StringBuilder code = new StringBuilder(80);
125
+ checkNextToken("<code>");
126
+ while (true) {
127
+ String line = bf.readLine();
128
+ if (line.trim().equals("</code>")) {
129
+ return code.toString();
130
+ }
131
+ code.append(line).append("\n");
132
+ }
133
+ }
134
+
135
+ public boolean getNextBoolean() throws IOException {
136
+ return Boolean.parseBoolean(getNextToken());
137
+ }
138
+
139
+ public int getNextInt() throws IOException {
140
+ return Integer.parseInt(getNextToken());
141
+ }
142
+
143
+ public float getNextFloat() throws IOException {
144
+ return Float.parseFloat(getNextToken());
145
+ }
146
+
147
+ public void checkNextToken(String token) throws ParserException, IOException {
148
+ String found = getNextToken();
149
+ if (!token.equals(found)) {
150
+ close();
151
+ throw new ParserException(token, found);
152
+ }
153
+ }
154
+
155
+ @SuppressWarnings("serial")
156
+ public static class ParserException extends Exception {
157
+
158
+ private ParserException(String token, String found) {
159
+ super(String.format("Expecting %s found %s", token, found));
160
+ }
161
+ }
162
+ }