• Dear Cerberus X User!

    As we prepare to transition the forum ownership from Mike to Phil (TripleHead GmbH), we need your explicit consent to transfer your user data in accordance with our amended Terms and Rules in order to be compliant with data protection laws.

    Important: If you accept the amended Terms and Rules, you agree to the transfer of your user data to the future forum owner!

    Please read the new Terms and Rules below, check the box to agree, and click "Accept" to continue enjoying your Cerberus X Forum experience. The deadline for consent is April 5, 2024.

    Do not accept the amended Terms and Rules if you do not wish your personal data to be transferred to the future forum owner!

    Accepting ensures:

    - Continued access to your account with a short break for the actual transfer.

    - Retention of your data under the same terms.

    Without consent:

    - You don't have further access to your forum user account.

    - Your account and personal data will be deleted after April 5, 2024.

    - Public posts remain, but usernames indicating real identity will be anonymized. If you disagree with a fictitious name you have the option to contact us so we can find a name that is acceptable to you.

    We hope to keep you in our community and see you on the forum soon!

    All the best

    Your Cerberus X Team

SaveImage module (mojo2)

Status
Not open for further replies.

MikeHart

Administrator
Joined
Jun 19, 2017
Messages
3,597
This little module will let you save the content of a canvas to either a PNG, JPG or BMP file.
A little test programm is basically self explaining. About its usage. The relevant part is this:

Cerberus:
Import saveImage

'...

Local file := RequestFile("Save file....", "Image Files:png,jpg,bmp;All Files:*", True)
Local ext:=filepath.ExtractExt(file).ToLower()
Select ext
    Case "png"
        SavePNG(file, canvas)
    Case "bmp"
        SaveBMP(file,canvas)
    Case "jpg"              ' SaveJPG needs a quality value with a range of 1-100
        SaveJPG(file,canvas,50)
End

Just copy the content into your mojo2 powered game.

If you find any issues, please let me know in this thread.

Disclaimer: Tested only on Windows.
 

Attachments

  • SaveImage.zip
    535.1 KB · Views: 233
Thanks Mike! :D

I'll test it later/tomorrow on Linux.
 
Am I right in thinking saveImage.cxs and /native should be in /modules_ext? If so, I'm getting this error:

Cerberus:
g++ -O0 -Wno-int-to-pointer-cast -Wno-free-nonheap-object -Wno-unused-result -I../glfw3/include -I../openal/include -I../stb -I../glfw3/deps -I../glfw3/deps/vulkan -D_GLFW_HAS_GLXGETPROCADDRESS -pthread  -c -o build/Debug/main.o ../main.cpp
../main.cpp: In function ‘void _savejpg(String, int, int, BBDataBuffer*, int)’:
../main.cpp:5312:5: error: ‘stbi_write_jpg’ was not declared in this scope
     stbi_write_jpg(C_STR(filename), w, h, 4, &colorBuffer[0],q);
     ^~~~~~~~~~~~~~
../main.cpp:5312:5: note: suggested alternative: ‘stbi_write_png’
     stbi_write_jpg(C_STR(filename), w, h, 4, &colorBuffer[0],q);
     ^~~~~~~~~~~~~~
     stbi_write_png
Makefile:62: recipe for target 'build/Debug/main.o' failed
TRANS FAILED: Error executing 'make CCOPTS="  -O0" LDOPTS=" " LIBOPTS=" -lopenal" OUT="Debug/CerberusGame"', return code=512
make: *** [build/Debug/main.o] Error 1
Done.
 
Turns out my "later" was several days later but happy to report is works perfectly - at least PNG does, I haven't tried other formats yet.

One thing I can't figure out though is what if the path to the save file is not explicitly defined, eg if code is:
Code:
SavePNG("test.png", imageCanvas)
rather than:
Code:
SavePNG("/home/paul/test.png", imageCanvas)

Where does the image get saved (if at all) in the first case? I can't seem to find it LOL!

Can I suggest renaming module to saveimage.cxs so the import is lower case, the same as all other default modules? :D
 
ive not played with this module yet, Im still on the temporary savepng that @MikeHart gave me in the early days of FontDu
In that version, if there is no path, then the image is saved in the root of the compiled app, where the exe is.
 
...if there is no path, then the image is saved in the root of the compiled app, where the exe is.
Yup, seems to be working now, maybe did something silly earlier - not an unusual occurrence!
 
I know this is set up for Mojo2, but I need to save from a different data structure altogether (doing procedural generation).

What pixel format is this expecting, if I call _savepng directly? BGRA?
 
Status
Not open for further replies.
Back
Top Bottom