Author Topic: _CLEARCOLOR() Usage  (Read 6176 times)

0 Members and 1 Guest are viewing this topic.

Offline TerryRitchie

  • Seasoned Forum Regular
  • Posts: 495
  • Semper Fidelis
    • View Profile
_CLEARCOLOR() Usage
« on: September 08, 2018, 05:05:45 pm »
I swear years ago I could load a 32bit PNG file in that already had an alpha channel defined and then use _CLEARCOLOR to identify the alpha channel color.

_CLEARCOLOR is always returning 0 for me when polling a loaded 32bit PNG image.

Am I correct, or is my age showing again?

There's got to be another way than scanning each pixel in the image and comparing it to _ALPHA32() for a value of zero to find the transparent layer.
In order to understand recursion, one must first understand recursion.

FellippeHeitor

  • Guest
Re: _CLEARCOLOR() Usage
« Reply #1 on: September 08, 2018, 05:14:21 pm »
Clearcolor always returns 0 in 32bit mode.

Offline TerryRitchie

  • Seasoned Forum Regular
  • Posts: 495
  • Semper Fidelis
    • View Profile
Re: _CLEARCOLOR() Usage
« Reply #2 on: September 08, 2018, 05:22:53 pm »
Well poo .. ok then, scanning the image it is.

It would be really awesome if _CLEARCOLOR returned the alpha channel of a loaded PNG that already has an alpha channel included. :))))
In order to understand recursion, one must first understand recursion.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: _CLEARCOLOR() Usage
« Reply #3 on: September 08, 2018, 05:56:45 pm »
It makes me wonder where in the png file that info is stored, and how it is stored. It would be cool if it were straight forward enough and you could just open the png, read that data, find the transparency coding, and convert it to use in your program.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline RhoSigma

  • QB64 Developer
  • Forum Resident
  • Posts: 565
    • View Profile
Re: _CLEARCOLOR() Usage
« Reply #4 on: September 08, 2018, 06:27:13 pm »
Here are the specs: https://www.w3.org/TR/2003/REC-PNG-20031110/

Happy reading...
My Projects:   https://qb64forum.alephc.xyz/index.php?topic=809
GuiTools - A graphic UI framework (can do multiple UI forms/windows in one program)
Libraries - ImageProcess, StringBuffers (virt. files), MD5/SHA2-Hash, LZW etc.
Bonus - Blankers, QB64/Notepad++ setup pack

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: _CLEARCOLOR() Usage
« Reply #5 on: September 08, 2018, 07:00:54 pm »
It makes me wonder where in the png file that info is stored, and how it is stored. It would be cool if it were straight forward enough and you could just open the png, read that data, find the transparency coding, and convert it to use in your program.

Pete

Easy peasy for PNG files! 

First, you need to understand that PNG files write data in CHUNKS.  Basically, you have the file header (one chunk of info with size, color mode, ect stored), and then other chunks come later (perhaps palette, or author info, or the actual pixel data...)

Each of these chunks has a 4 byte identifier to them.  "IHDR" is the image header.  "PLTE" is the color palette, if one is used (say for 256 color images).  "IDAT" is the pixel data and "IEND" is the end of data.

Read a chunk identifier, if it's not the one you're interested in, skip its data and read the next chunk header until you find the one you're looking for -- they can be in ANY order (more or less), so don't assume the 4th chunk is what you need just because you found the info there once, for one image.

The one you'd want is "bKGB".

The bKGD chunk specifies a default background colour to present the image against. If there is any other preferred background, either user-specified or part of a larger page (as in a browser), the bKGD chunk should be ignored. The bKGD chunk contains:

For Color types 2 and 6 (RGB32 and RGBA32 images:
Red   2 bytes
Green   2 bytes
Blue   2 bytes

For colour types 2 and 6 (truecolour, truecolour with alpha), the values are the colour to be used as background, given as RGB samples in the range 0 to (2bitdepth)-1.

**********************

So basically, open the file for binary.  Read a chunk to get the identifier.  When you find "kBGD", you've found the color used for the image background.

And, to make it even easier, if you look in my SaveImage library, there's already a basic LoadPNG routine which reads and displays chunk headers and info for us.  It could be easily modified to find the "kBGD" chunk and then retrieve the data afterwards. 

https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: _CLEARCOLOR() Usage
« Reply #6 on: September 08, 2018, 07:07:35 pm »
Well that's pretty cool! I had a hunch it was possible, but some things are encoded or present other difficulties. Glad to learn pngs are more straight forward.

Hope you are recovering well. Take it easy, drink plenty of fluids and try to make sure most of those fluids cannot be used to fuel single-engine aircraft.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: _CLEARCOLOR() Usage
« Reply #7 on: September 08, 2018, 07:28:01 pm »
Well that's pretty cool! I had a hunch it was possible, but some things are encoded or present other difficulties. Glad to learn pngs are more straight forward.

Hope you are recovering well. Take it easy, drink plenty of fluids and try to make sure most of those fluids cannot be used to fuel single-engine aircraft.

Pete

Well, the data is compressed for the image (which is why my library includes ZLIB for Windows users and won't work on Linux), but it doesn't seem like the background info is.  (After all, what are you going to save, compressing 6 bytes?). It should be a straightforward go in, fetch, and use routine.  ;)

As for recovery, that's got to wait.  The surgeon said I didn't need to have my gallbladder removed (YAY!  No surgery!), and then with the same breath asked me, "What do you want to do about the ascending aortic aneurism?  (BAM!  Good news isn't popped like a bubble in a cactus farm...)

Sept 20th is now my first appointment with the heart surgeon so he can review the case, and then surgery will be scheduled soon to follow.  At 4cm, they begin to watch and monitor an aneurism on the artery.  At 5cm, they recommend surgery.  My CT scan showed mine being 5.8cm... 

Basically a bulge on the main artery coming directly from the heart, which if it pops *IS* fatal.  You bleed out in minutes, when the nearest hospital is half an hour away...

So, the trick is to replace that part before it pops, and then replace the replacement every 10-12 years...  Needless to say, it's a lot to take in all at once, and it's dampened my enthusiasm for writing/coding/or other hobbies.  I've always been blessed with a great imagination; unfortunately, it's now working on overdrive with, "What if?"

'Tis a curse sometimes to have our woes illuminated and brought to the light of day, for us.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: _CLEARCOLOR() Usage
« Reply #8 on: September 08, 2018, 08:29:12 pm »
I have heard patient's who were misdiagnosed for gallbladder disease, and it turned out to be some type of heart disorder, although I think you stated they found stones present in the gallbladder. That, and aortic aneurysms are usually asymptomatic but can produce back pain or digestive type pain if large or leaking. That's not an absolute rule, though. Actually I would have thought a chest x-ray would have caught one of that size but MRI are the most conclusive, better for soft tissue than CT exams. Echo ultrasounds are also sometimes used.  You may have had it for quite sometime but I know, when someone brings it to attention people get overly obsessed with the situation. Anxiety is no friend to the heart so maybe count yourself fortunate you have been fine with it and will be even better off after it is repaired. I'd be happy to save you some money and pop a pipe clamp on it. I think Obamacare covers that. Well, probably the heart surgeon is a better way to go. I'm not too wild about the medical profession but I do respect the advances in medicine when it comes to both orthopedics and heart conditions. They are still lagging behind chiropractors when it comes to disc conditions but far better than years ago. In most cardiovascular conditions what they can do is downright amazing.

I do have to bring up one long shot, just in case. Are yo absolutely sure the MRI is yours? I ask because I went with my wife when she had a mammogram before we started our family. The radiologists actually mixed up the name markers on the studies. I was present in the room to read the films, I saw the lesion, it appeared to be highly suspect that it was a malignant tumor but I also realized the breast tissue presentation seemed wrong I asked them to investigate my concerns and sure enough, there was a mix up in the developing room. In your situation, the bulge should show up on some previous chest x-ray or other markers on the MRI should be identifiable against other studies.

Second opinions are also a good thing. That saved me from an over-eager resident who wanted to put a stint in one of my arteries. It turned out I didn't need one.

Pete



Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

FellippeHeitor

  • Guest
Re: _CLEARCOLOR() Usage
« Reply #9 on: September 08, 2018, 09:22:42 pm »
Well that's pretty cool! I had a hunch it was possible, but some things are encoded or present other difficulties. Glad to learn pngs are more straight forward.

Hope you are recovering well. Take it easy, drink plenty of fluids and try to make sure most of those fluids cannot be used to fuel single-engine aircraft.

Pete

Well, the data is compressed for the image (which is why my library includes ZLIB for Windows users and won't work on Linux), but it doesn't seem like the background info is.  (After all, what are you going to save, compressing 6 bytes?). It should be a straightforward go in, fetch, and use routine.  ;)

As for recovery, that's got to wait.  The surgeon said I didn't need to have my gallbladder removed (YAY!  No surgery!), and then with the same breath asked me, "What do you want to do about the ascending aortic aneurism?  (BAM!  Good news isn't popped like a bubble in a cactus farm...)

Sept 20th is now my first appointment with the heart surgeon so he can review the case, and then surgery will be scheduled soon to follow.  At 4cm, they begin to watch and monitor an aneurism on the artery.  At 5cm, they recommend surgery.  My CT scan showed mine being 5.8cm... 

Basically a bulge on the main artery coming directly from the heart, which if it pops *IS* fatal.  You bleed out in minutes, when the nearest hospital is half an hour away...

So, the trick is to replace that part before it pops, and then replace the replacement every 10-12 years...  Needless to say, it's a lot to take in all at once, and it's dampened my enthusiasm for writing/coding/or other hobbies.  I've always been blessed with a great imagination; unfortunately, it's now working on overdrive with, "What if?"

'Tis a curse sometimes to have our woes illuminated and brought to the light of day, for us.

We're all hoping for the best, Steve.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: _CLEARCOLOR() Usage
« Reply #10 on: September 09, 2018, 12:44:42 am »
Going back and checking my notes, here's all you'd need to do to get background for a PNG file....

Open file as binary
DO
   GET #1, , DataLength (unsigned long)
   GET #1, , code$ (4 byte string with code as described above in previous post.)
   IF code$ = "bKBD" THEN
       GET #1, , Red (INTEGER, NOT BYTE value)
       GET #1, , Blue
       GET #1, , Green
   ELSE
        Junk$ = SPACE$(DataLength)
        GET #1, , junk$
    END IF
LOOP UNTIL Code$ = "IEND"


***************

Simple enough, with one caveat: PNG stores values backwards from QB64.  It uses big-endian values, we use small-endian...  (Or vice-versa, whichever it is.) In my SaveImage library, there's a FUNCTION ConvertUL which does the trick for us.  Just copy/paste it into your code and convert the value it gives you, before using it.  :)

GET #1, , DataLength: DataLenth = ConvertUL(DataLength)    <---- Like so.

Code: QB64: [Select]
  1. FUNCTION ConvertUL~& (x AS _UNSIGNED LONG)
  2.     ConvertUL = x \ 2 ^ 24 OR x * 2 ^ 24 OR (x AND &HFF0000) \ 2 ^ 8 OR (x AND &HFF00~&) * 2 ^ 8
« Last Edit: September 09, 2018, 12:54:18 am by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: _CLEARCOLOR() Usage
« Reply #11 on: September 09, 2018, 06:34:16 am »
Hey Steve

don't stay down, I agree very much with Pete's opinion
Quote
Second opinions are also a good thing.
Why? Because IMHO medicine is yet at middle between art and science. To be clearer for the same situation you get so different qualified opinions and the solutions are different.
Take these two story for examples:
1.  one of my neighbor, while was following his routines of check up for hearth and vessels by making an ultrasuond imaging of great vessel of abdomen , he got a diagnosis of an aneurism of descendent aorta artery in abdomen.
Following this issue he goes to vascular surgeon to discuss the case and surgeon suggested to do a doppler ultrasound imaging and a arterography with contrast medium (angioTC of abdomen). While the first procedure (ultrasound doppler) was not clear in confirming/disconfirming diagnosis, the second (more invasive) shows up an aneurism of left renal artery.
So he have embolization and bypass for this aneurism. He continues to do his previous life. Sometimes he needs to make examinations suggested by his vascular surgeon.

2. one of my friend made an ultrasound of abdomen for liver and abdominal internal organs because it has iperlypidemia.
This first examination showed a unspecified mass in the pancreatic area. in the crude prospect of the hypotheses 80% was a cancer. He was sent by the oncologist surgeon who prescribed a CT with contrast. This subsequent examination showed that the lesion was a retropancreatic descending aortic aneurysm. He did an embolization surgery with patches and has a normal life.

this is the reason because I say you
Good Luck

@Pete

what do you think about my dislexya?

and
Quote
I have heard patient's who were misdiagnosed for gallbladder disease, and it turned out to be some type of heart disorder
if you want to hear Chinese Medicine (acupunture and the 5 movements theory) you can see that heart's energy depends from gallbladder energy  :-)
see this
Programming isn't difficult, only it's  consuming time and coffee