Author Topic: Question about reading pixels from high resolution pictures  (Read 2833 times)

Offline DaCarSoft

  • Community Developer
  • Mr. Polyvector
  • ******
  • Posts: 182
    • View Profile
Hi all!

I have a question rounding my mind  :S, related to a new project that I have to do, and I'm trying to suppose if it is possible to do directly from GLBasic or I need to use some other programming language:

I would like to open a high resolution picture (a JPEG of 1,3 megapixels, for example) from GLBasic and read every pixel from the picture to found where are located the pixels of a specific color (the red ones or RGB = #FF0000 for example).

I know, for example, that in Visual Basic you can do this by loading a picture in a control object like "image box" and read every individual pixel as you need, it does not matter if the image does not fit into screen, you can read pixels wich are not showed just on screen, these pixels may be hidden behind the limits of the control that could have scrolling bars.

But...   Is this possible in GLBasic??   Can I open in any way a full 1,3 Mpx JPEG at full resolution and read the colour from some pixels in a X,Y coordinate??

May be that I need a back buffer??

I was thinking about a possible way: To convert from JPEG to BMP and try to read pixels from the file directly as text...   Is that possible from GLBasic??  O_O

All suggestions will be highly appreciated...  :giveup:

Thanks in advance.


EDIT:   I will test with LOADSPRITE and GETPIXEL using high resolution pictures to know wich are the resolution limits for GLBasic, but I suppose these limits are low...    ??   I read in this forums some comments related to this limits some time ago, almost for iPhone/iPad...   I would like my solution could be cross platform.

??
« Last Edit: 2013-Oct-21 by DaCarSoft »
"Si quieres resultados distintos... no hagas siempre lo mismo" - Albert Einstein.

Offline msx

  • Prof. Inline
  • *****
  • Posts: 773
    • View Profile
Personally I would try to understand the structure of each type of image file and read the data directly from this.

Offline DaCarSoft

  • Community Developer
  • Mr. Polyvector
  • ******
  • Posts: 182
    • View Profile
Pufff, in JPEGs this is complex.   JPEGs are compressed...
"Si quieres resultados distintos... no hagas siempre lo mismo" - Albert Einstein.

Offline mentalthink

  • Prof. Inline
  • *****
  • Posts: 3375
  • Integrated Brain
    • View Profile
Doing a virtual screen, with window or usescreen can works?¿... or perhaps if you put the texture into a 3d plane?¿ then read with readpixel?¿.

Offline fuzzy70

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 828
  • Look left, Look right, LOOK OUT!!
    • View Profile
I would use LOADSPRITE then SPRITE2MEM() (LOADSPRITEMEM() is only useful if you know the size of the image thats being loaded. Once the data is in the array you can then scan it for what you need using bitwise operations for the individual colours. Using READPIXEL is possible but extremely slow.

Lee
"Why don't you just make ten louder and make ten be the top number and make that a little louder?"
- "These go to eleven."

This Is Spinal Tap (1984)

Offline kanonet

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1137
    • View Profile
    • My GLBasic code archiv
Fuzzy is right: LOADSPRITEMEM etc. is the way to go, but
Fuzzy is wrong: you dont need to know width and hight to use it, so its the perfect function for you!
 :D

What you want to do can easily be done with GLB - but in case you want to do it at real time, every frame - im not sure if it would be fast enough, but you should try.
« Last Edit: 2013-Oct-22 by kanonet »
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

Offline r0ber7

  • Prof. Inline
  • *****
  • Posts: 552
    • View Profile
LOADSPRITEMEM can do amazing things. I use it to detect the solid parts of my level tiles. It checks the pixels for each tile. Based on the color of the pixels, I get an array of x&y coordinates to use in my collision detection. :-)

Offline fuzzy70

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 828
  • Look left, Look right, LOOK OUT!!
    • View Profile
Fuzzy is right: LOADSPRITEMEM etc. is the way to go, but
Fuzzy is wrong: you dont need to know width and hight to use it, so its the perfect function for you!
 :D

What you want to do can easily be done with GLB - but in case you want to do it at real time, every frame - im not sure if it would be fast enough, but you should try.

Thanks Kanonet for correcting me  :good: . I have not had a use for that command yet & just saw the w% & h% in the parameters without actually realising that those variables must be filled in by GLB when the image is loaded, rather than required to load an image.

I may use it more now though thanks to you pointing out my errror  :booze:

Lee
"Why don't you just make ten louder and make ten be the top number and make that a little louder?"
- "These go to eleven."

This Is Spinal Tap (1984)

Offline DaCarSoft

  • Community Developer
  • Mr. Polyvector
  • ******
  • Posts: 182
    • View Profile
Wow!

Thanks so much for all people...

Now, I have enough information to start my testing in the correct way...   I didn't have very clear the use and limits of LOADSPRITEMEM...

I do not need to do calculations in real time, so, speed is not a priority...


Thanks so so so much to all!!!!
"Si quieres resultados distintos... no hagas siempre lo mismo" - Albert Einstein.

Offline msx

  • Prof. Inline
  • *****
  • Posts: 773
    • View Profile
Suerte