Author Topic: SaveImage v2.1 Bugfix  (Read 3835 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 v2.1 Bugfix
« on: June 06, 2020, 06:47:43 am »
SaveImage is a library which I shared ages ago for people to make use of with QB64 which gives us the ability to export and save images from our programs. 

AND, for the longest time, PNG files have generated a glitch when one attempted to use them in various external applications...

BUT...  I think I have that corrected finally!

Issue was so simple that it almost makes me cry to say, "WTH didn't I notice this glitch before?!!"  My only real consultation is just the fact of, "WTH didn't anyone else, either??"

If you take a moment to look down inside SaveImage.BM, you'll find two glitches:

First, in the SUB PNGExport, we see the following typo: 
Code: QB64: [Select]
  1.         l = ConvertUL(l = ConvertUL(PNGCRCStringCheck("IEND", "")))  

If you look at any of the other calls to the CRC check routines, you'll see that the above is just a complete glitch which should look like:
Code: QB64: [Select]
  1.         l = ConvertUL(PNGCRCStringCheck("IEND", ""))  

BUT....  It's a glitch that doesn't matter, honestly, because of our second glitch:
Code: QB64: [Select]
  1.     FUNCTION PNGCRCStringCheck~& (id AS STRING * 4, dta$)
  2.         DIM m AS _MEM
  3.         DIM temp(0 TO 3) AS _UNSIGNED _BYTE
  4.         DIM text(0 TO LEN(dta$) - 1) AS _UNSIGNED _BYTE
  5.         PNGCRC = -1
  6.         FOR z = 1 TO 4: temp(z - 1) = ASC(id, z): NEXT
  7.         FOR z = 1 TO LEN(dta$): text(z - 1) = ASC(dta$, z): NEXT
  8.  
  9.         m = _MEM(temp()): Update_PNGCRC PNGCRC, m: _MEMFREE m
  10.         m = _MEM(text()): Update_PNGCRC PNGCRC, m: _MEMFREE m
  11.         PNGCRCcheck~& = NOT PNGCRC

If you look at our actual function which generates our CRC values, you'll notice something glaringly obvious once I ask one rather pungent question:  Where do we calculate a return value in this function??  Exactly what does this function do??

The answers are: We don't, and this function does absolutely nothing.  CHEERS TO USELESS CODING!!

Change      PNGCRCcheck~& = NOT PNGCRC  to      PNGCRCStringCheck~& = NOT PNGCRC and PRESTO!!  You now have a return value coming back from the end of that FUNCTION call!



And those two glitches should now have PNG exports corrected and glitch free, so you can now use and test them in any other program that you desire without issue.

I've made the corrections to the code, and am sharing it here for folks to test out and kick around a bit, before I go for an official v2.2 release, which I want to alt to use the new _DEFLATE routines with, so the routines will start to work for folks on Linux (and possibly not need any DLL files included with it, for future versions).

Test it out, make certain I packaged up the code with the proper changes into the archive, and let me know if it works as it should without tossing CRC errors as it was doing before for you guys.  (Bplus and _vince did a lot of testing before and helped point me to the issue being in the IEND data chunk CRC value, so everyone take a moment to say, "Thanks guys," to them.  Without their help in narrowing down the issue, I probably would've never micro-focused on those typos and found them!)

If all looks and works well, I'll swap in _DEFLATE, swap out the zlib.dll files, and repackage a smaller, friendlier  version for everyone to enjoy and make use of sometime later next week.   ;)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: SaveImage v2.1 Bugfix
« Reply #1 on: June 06, 2020, 10:46:30 am »
Thanks @SMcNeill

Did you get your computer back, working with new one or still with ipad???

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: SaveImage v2.1 Bugfix
« Reply #2 on: June 06, 2020, 12:41:39 pm »
Thanks @SMcNeill

Did you get your computer back, working with new one or still with ipad???

Got a new one, which finally arrived a few days ago.  Now that everything's been transfered from the old to the new, SaveImage was one of the first things I wanted to dig into and enhance.  I've been enhancing it and maintaining it for years and years, so it's an excellent place for me to start and test my system's setup on.   ;D
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Bert22306

  • Forum Regular
  • Posts: 206
    • View Profile
Re: SaveImage v2.1 Bugfix
« Reply #3 on: June 06, 2020, 08:40:30 pm »
From the department of pedantry. Two words with different meanings:

To consult, verb, consultation, noun. Means providing an opinion or advice on some subject matter.

To console, verb, consolation, noun. To provide solace to someone in grief.

Just sayin'.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: SaveImage v2.1 Bugfix
« Reply #4 on: June 06, 2020, 10:20:19 pm »
From the department of pedantry. Two words with different meanings:

To consult, verb, consultation, noun. Means providing an opinion or advice on some subject matter.

To console, verb, consolation, noun. To provide solace to someone in grief.

Just sayin'.

Well, since the whole glitch here is all because of a few silly typos, what can I say besides, "I must like consistency in my work!"  :P
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: SaveImage v2.1 Bugfix
« Reply #5 on: June 07, 2020, 01:25:35 am »
Thanks for this! :D
if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials