B4J Code Snippet Geometrize in B4J

Full Geometrize source attached — and yes, it actually works! 🎉
Just a heads-up: if you’re using BIG source images, grab a good movie, a large coffee, and maybe a backup coffee… it’s gonna be a while. ☕🎬

As for the GUI — let’s just say it’s technically functional. Not exactly “production-ready,” but hey, it does the job. 😅

have fun

gui.png
flower_sm.jpg
ezgif.com-optimize.gif
 

Attachments

  • geometric.zip
    12.5 KB · Views: 13

William Lancee

Well-Known Member
Licensed User
Longtime User
Last edited:

madru

Active Member
Licensed User
Longtime User
put this in, will give you a little speed bump on Windows

VirtualMachineArgs Windows:
#VirtualMachineArgs: -Dprism.order=d3d,es2,sw -Dprism.forceGPU=true -Dprism.vsync=false -Dprism.verbose=true --add-exports javafx.graphics/com.sun.prism=ALL-UNNAMED --add-exports javafx.graphics/com.sun.javafx.sg.prism=ALL-UNNAMED

VirtualMachineArgs OSX:
#VirtualMachineArgs: -Dprism.order=es2,sw -Dprism.forceGPU=True -Dprism.vsync=False -Dprism.verbose=True
does not work on OSX (no idea why), but does work if using using this:

B4X:
java -Dprism.order=es2,sw \
     -Dprism.forceGPU=True \
     -Dprism.vsync=False \
     -Dprism.verbose=True \
     -jar file.jar

here some code to test if the GPU is enabled

B4X:
Sub CheckGPU
    ' Check if arguments are loaded
    Dim jo As JavaObject
    jo.InitializeStatic("java.lang.System")
    Dim prismOrder As String = jo.RunMethod("getProperty", Array("prism.order", "NOT_SET"))
   
    Log($"Prism Order: ${prismOrder}"$)
   
    If prismOrder = "NOT_SET" Then
        Log("VM arguments NOT loaded!")
        Log("Fix: Put all args on ONE line")
    Else
        Log("VM arguments loaded correctly")
    End If
   
    ' Check actual pipeline at runtime
    Try
        Dim pipeline As JavaObject
        pipeline.InitializeStatic("com.sun.prism.GraphicsPipeline")
        Dim currentPipeline As Object = pipeline.RunMethod("getPipeline", Null)
        Log($"Active Pipeline: ${currentPipeline}"$)
       
        Dim pipelineName As String = currentPipeline
        If pipelineName.Contains("D3D") Then
            Log("Using Direct3D (GPU)")
        Else If pipelineName.Contains("ES2") Then
            Log("Using OpenGL ES2 (GPU)")
        Else
            Log("Using Software Rendering")
        End If
    Catch
        Log($"Pipeline detection error: ${LastException}"$)
    End Try
End Sub
 

madru

Active Member
Licensed User
Longtime User
First and Last Update

Additions:
  • Antialiasing
  • Rotated Rectangle
  • Rotated Ellipse
  • Polyline
  • Quadratic Bézier
  • GPU Detection
Performance:
  • Highly optimized math now


 

Attachments

  • geometric.zip
    14.9 KB · Views: 13
Last edited:

madru

Active Member
Licensed User
Longtime User
This is a lovely way to "artify" an image.

I noticed that colors are retained but small details get absorbed by the shapes.
What happens if you superimpose a word say "happy" on the flower? Will it disappear?

It reminds me of a B4X project I did some years ago where I needed to obscure details on a Google satellite image.
https://www.b4x.com/android/forum/t...ge-creating-an-impressionistic-effect.143149/
try it

geometrized_final_22445shapes.png


this one uses only 3000 shapes (lines)...already quite detailed
 

William Lancee

Well-Known Member
Licensed User
Longtime User
What happened to the smiling snail?

The algorithm creates a mosaic of overlapping random shapes. The color of each defined by some formula based on the color of the corresponding pixels in the original contained by the shape. Since the snail's outline color is thin, most overlapping shapes will only see a small part of and it will be drowned out by the other colors contained in the shape. @madru correct me if I'm wrong.
 
Top