Author Topic: SaveImage Library v1.5  (Read 5738 times)

0 Members and 1 Guest are viewing this topic.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
SaveImage Library v1.5
« on: November 02, 2018, 02:48:24 pm »
As of version 1.5, this basically merges the SaveImage and SaveBMP libraries.

NOTE: On Linux/Mac this will ONLY save BMP images.  The routine which does PNG images requires Zlib.dll or Zlib1.dll to be used for compression/decompression, which makes it Windows-only.



Format for the command looks like the following:

Result = SaveImage(exportimage1$, 0, 0, 0, _WIDTH, _HEIGHT)

The actual function is the following: FUNCTION SaveImage (file$, image&, x1%, y1%, x2%, y2%)

So, how is this different than before?

First, it saves both PNG and BMP files for us. Just specify the extension for which you want in the filename.

exportimage1$ = "testimage.png"
Result = SaveImage(exportimage1$, 0, 0, 0, _WIDTH, _HEIGHT)
exportimage2$ = "testimage.bmp"
Result = SaveImage(exportimage1$, 0, 0, 0, _WIDTH, _HEIGHT)

With the above, the first filename will export a PNG file, while the second will export a BMP file. Change the extension, change the output format. It's that simple.

Second, this now works in ALL the QB64 screen modes for both PNG and BMP export images. That's right: It can even export a screen capture of a SCREEN 0, TEXT screen for you!!

As a side note, the PNG side of things does a better job error-checking itself and all, since it also does file compression and all that stuff, so don't expect to get any error messages from saving a BMP file.

PNG files can return the following error messages for you:

'PNGExport results:
'-1 All is good. We think we exported a proper PNG file.
' 0 Compression failed. File is probably corrupt.
' 1 File Already Exists. As these are Binary files, we probably don't want to just overwrite the same file.
' 2 Incorrect Alpha settings. Check for Alpha mode, and Color mode, and look for conflicts.
' 3 Bad GrabMode
' 4 Bad x1 coordinate
' 5 Bad y1 coordinate
' 6 Bad x2 coordinate
' 7 Bad y2 coordinate
' 8 x2 < x1 -- correct this to proceed
' 9 y2 < y1 -- correct this to proceed
'10 Bad color mode. Either use 256 or 32 color mode.
'11 Attempted to export a text screen which will not work.

BMP files will always return a -1. If they fail, it'll be a standard QB64 error message of some sort which will pop up.

Grab the attachment below, extract to your QB64 folder, and give it a go and see how it works for you. From my testing, this works for all screen modes, in both SDL and GL versions, and hasn't died on me yet.

All code is free to use, alter, delete, edit, and annoy Clippy with. No credit expected, nor needed. If you can use it, use it. If you can sell it and make $$$ with it, do that too! Just be warned: If it somehow melts your computer or starts a zombie takeover, I take no responsibility for that either. Code is "As is -- As is, you use it however you want, but you're responsible for whatever happens when you do."  :D



Usage is:

'$Include:'SaveImage.BI' <--- Top of your code

Result = SaveImage(exportimage1$, 0, 0, 0, _WIDTH, _HEIGHT) <--- Inside the code somewhere

'$INCLUDE:'SaveImage.BM' <--- Bottom of your code
« Last Edit: February 13, 2019, 01:13:49 am by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: SaveImage Library v1.4
« Reply #1 on: November 02, 2018, 03:16:02 pm »
Thank You, Steve!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: SaveImage Library v1.4
« Reply #2 on: November 02, 2018, 03:20:34 pm »
Thank You, Steve!

Sorry Petr!  You'll need to redownload, or go in and change the paths in the BI file.  I accidently had the path hardcoded into them, and that's not going to work with the version you grabbed.  The issue should be corrected now.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: SaveImage Library v1.5
« Reply #3 on: November 03, 2018, 06:24:46 pm »
Updated this to version 1.5.

Changes:

1) It should now load and work for folks on Linux.  It, however, WON'T SAVE PNG IMAGES ON LINUX, but it should work just fine to save BMP files, without any errors.  The precompiler should strip out all the windows related stuff for you, and you'll basically have a copy of the SaveBMP library, as I discussed here: https://www.qb64.org/forum/index.php?topic=752.0   

This just helps me keep everything together and easier to maintain, for future releases -- it really doesn't add anything new for the non-windows folks who might've had the SaveBMP library instead.

2) This removes the FUNCTION TextScreenToImage&, which was in version 1.4, and instead gives us two variants which we can choose from instead:

FUNCTION TextScreenToImage256& (image&)
FUNCTION TextScreenToImage32& (image&)


No longer are we forced to save a text screen in 256 color mode; we can now save it in 32-bit color, if we so desire.

3) This adds one new variable/CONST which you can set, to change the behavior of the routines --SaveTextAs256Color:

Since QB64 currently doesn't load 256 color images, you may not want to save a text screen as a 256 color screen.  (Or, then again, you might, if you're going to use it for something externally and want to reduce overall size of the file.)  This variable lets you change the mode which SaveImage uses to convert a text screen into.

SaveTextAs256Color = 0   <-- Then you use 32-bit colors when converting and saving.
SaveTextAs256Color = (anything but 0)    <--   Then you use 256 colors when converting and saving.
« Last Edit: November 03, 2018, 06:29:13 pm by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: SaveImage Library v1.5
« Reply #4 on: November 04, 2018, 09:53:53 am »
Hi Steve
Quote
The routine which does PNG images requires Zlib.dll or Zlib1.dll to be used for compression/decompression,

1. Zlib.dll or Zlib1.dll?
https://zlib.net  and https://zlib.net/DLL_FAQ.txt at point 2. are not clear to me to choose.

2. Linux Unix have no version of Zlib?
I find interesting this info http://www.libpng.org/pub/png/book/sources.html, but I need more knowledge before to read these examples

Thanks for sharing your works!!!
Programming isn't difficult, only it's  consuming time and coffee

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: SaveImage Library v1.5
« Reply #5 on: November 04, 2018, 10:23:47 am »
Hi Steve
Quote
The routine which does PNG images requires Zlib.dll or Zlib1.dll to be used for compression/decompression,

1. Zlib.dll or Zlib1.dll?
https://zlib.net  and https://zlib.net/DLL_FAQ.txt at point 2. are not clear to me to choose.

2. Linux Unix have no version of Zlib?
I find interesting this info http://www.libpng.org/pub/png/book/sources.html, but I need more knowledge before to read these examples

Thanks for sharing your works!!!

The library chooses for you, automagically.

For 32-bit versions of QB64, it uses zlib1.dll; 64-bit versions use zlib.dll.

Linux uses zlib.so and zlib1.so files (instead of *.dll), and I've got a copy of both already.  The issue is trying to get DECLARE LIBRARY to find and use them.  No matter how much I try, I just can't get QB64 to work with the files on Linux, and looking at the wiki page for DECLARE DYNAMIC LIBRARY, it mentions, "support for *.so files will be added later"...

So, for now, saving images as PNG files is a Windows-only feature.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: SaveImage Library v1.5
« Reply #6 on: November 04, 2018, 12:58:14 pm »
So later. Hm.... :-D Wherever I've been reading this promise. In many cases...

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: SaveImage Library v1.5
« Reply #7 on: February 13, 2019, 01:17:25 am »
Library removed as v1.6 is now on the forums here in the original topic: https://www.qb64.org/forum/index.php?topic=47.msg102645#msg102645

Why I even started a new topic for v1.5, I have no idea.  I blame it, like most things, on a lack of coffee.  If Odin wants to delete this topic (or merge the two), that’s fine with me.  It’s much easier to address any concerns or glitches if all the reports/feedback are in the same topic.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!