Author Topic: Why is picture after comment DEST not full?  (Read 4250 times)

0 Members and 1 Guest are viewing this topic.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Why is picture after comment DEST not full?
« on: June 11, 2018, 11:59:24 am »
Hi. I write here program for filtering white color on image background, but... if is comment DEST on line 13, is then view half. Why? And one more ask: How is difference between new MEMNEW, where are copyed datas from IMAGE& created by NEWIMAGE?  I'm interested in it.

Code: QB64: [Select]
  1. L& = filter&(_SCREENIMAGE)
  2.  
  3.  
  4. FUNCTION filter& (image AS LONG)
  5.     DIM f AS _MEM
  6.     f = _MEMIMAGE(image&)
  7.     '   filter& = _MEMNEW(_WIDTH(image&) * _HEIGHT(image&) * _PIXELSIZE(image&)) ' Here is one bug for developers. Uncomment and give C++ compilation error. I know why, so just for info. :-D With love :-D
  8.     filter& = _NEWIMAGE(_WIDTH(image&), _HEIGHT(image&), 32)
  9.     DIM GG AS _MEM
  10.     GG = _MEMIMAGE(filter&)
  11.     _SOURCE image&
  12.     _DEST image& ' next ask for developers. Comment DEST on this line and start it. You give HALF picture. Why?
  13.     SELECT CASE _PIXELSIZE(image&)
  14.         CASE 4
  15.             DIM clr AS LONG
  16.             white& = _RGBA32(255, 255, 255, 255)
  17.             FOR y = 0 TO _HEIGHT(image&) - 4
  18.                 FOR x = 0 TO _WIDTH(image&) - 4
  19.                     _MEMGET f, f.OFFSET + IN&(x, y), clr&
  20.                     R = _RED32(clr&)
  21.                     G = _GREEN32(clr&)
  22.                     B = _BLUE32(clr&)
  23.                     A = _ALPHA32(clr&)
  24.                     IF R > 240 AND G > 240 AND B > 240 AND A > 250 THEN _MEMPUT GG, GG.OFFSET + IN&(x, y), white& ELSE _MEMPUT GG, GG.OFFSET + IN&(x, y), clr&
  25.     NEXT x, y: END SELECT
  26.  
  27.     _MEMFREE f
  28.     _MEMFREE GG
  29.     _FREEIMAGE image&
  30.  
  31.  
  32.     IN& = _PIXELSIZE(_SOURCE) * ((_WIDTH * y) + x)
  33.  
  34.  


i found SOURCE in IN& function maybe do something this. But then, if rewrite _SOURCE to 4 * in IN& function and comment _DEST in my program, become the same output.
« Last Edit: June 11, 2018, 12:08:43 pm by Petr »

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: Why is picture after comment DEST not full?
« Reply #1 on: June 12, 2018, 01:40:37 am »
Hi Petr!
if (Me.success) {Me.improve()} else {Me.tryAgain()}


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

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Why is picture after comment DEST not full?
« Reply #2 on: June 12, 2018, 10:34:52 am »
Hi Ashish, I did not realize that. Thank you for your help.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Why is picture after comment DEST not full?
« Reply #3 on: June 12, 2018, 11:26:34 am »
Hi Petr,

Is this code in connection to the collision detection thing you were showing us in that thread?

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Why is picture after comment DEST not full?
« Reply #4 on: June 12, 2018, 01:08:44 pm »
Hi Bplus, yes it is, BUT I am deeply dissatisfied with the processing speed and so I try to do it differently and much faster. I'm shaking my head with MEM commands.

(i think collision detection in move, not this one subprogram)
« Last Edit: June 12, 2018, 01:14:30 pm by Petr »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Why is picture after comment DEST not full?
« Reply #5 on: June 12, 2018, 01:20:06 pm »
Yes, mem, _gl and linked lists are adventures I look forward to here with QB64.

If you are checking every single pixel between two images, I can definitely see why it is so slow. I know there are great speed improvements with Mem but that much? And if you are checking border crossings... not sure how that might go. Can you tell I haven't studied the code yet? ;) 

I think I would like a summary in English of what is supposed to happen before seeing it done in code.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Why is picture after comment DEST not full?
« Reply #6 on: June 12, 2018, 02:08:58 pm »
I have no problem with it. So here is the thought:
The main prerequisite is that any images you create with a program like NEWIMAGE or uploaded through LOADIMAGE will have the same resolution on the screen. When it works in this ratio 1 to 1 then we can try sadomasochistic games with different ratios. But to the point. I originally thought that storing all points of the body circuit into the fields and comparing them would not be such a big problem for speed. It fugues for a small resolution, even for static pictures like snowfall on the body, but for games it will not be the right one. So now I want to take each picture, I will find out which RGB32 color is not used (I already have this feature) and I will paint the background with this color. Then, during the game, using the MEM command, I want to check the body penetration through this color. That should be faster. If you look closely, and this is perhaps one of the ways, you can make the body circumference so that only every N - rd point is written (because fire or enemy picture is not only one pixel big, you then need not every one pixel use in array) This significantly reduces the field and increases the speed. It occurred to me if I would introduce this array do  with the MEMNEW, if it would not be much faster than a common field created through DIM? I have to explore this. If it is in unemulted memory, it should be fast.
Collision detection, as I want to do it, as if you were putting two cut out pictures. If you venture at the same step in both, it should work. Another option is to modify the program so that it only reads outside boundaries and not internal ones.

In the program when it moves a picture, it has a size. I can expect a collision from the top or bottom, then I do not need to control collisions from the hips - I get smaller fields and higher speed. And so on. It's a lot of experiments and mistakes, but I'm working on it. Of course every suggestion how to do it better is very welcome.

This source code is not commented, because i think, that developers, that is something. That is big programmer, which look in it and know :-D Because this is one part from bigger program, is not commented. But in this source is it used and there it is commented: https://www.qb64.org/forum/index.php?topic=261.msg1500#msg1500
if you search how it works, goto lines 122, 131 for 256 colors and 147, 158 for 32 bit.


Maybe you ask - why coloring background? It is for use with SETALPHA, is unvisible so do not problems in use, image is loaded in memory, so then can be used for reading enemy coordinates for collision detection. Let say, picture conains body and eye. Eye use rgb255,255,255 but background also. if I leave it, the eye will take the program as a collision border. But for program and real cool detect i need borders, if i use none array, and reading image using MEM, that is 1D array, none pixel in picture can not use background color, because background color enable colision, other color disable collision - function return 1 = is collision.
« Last Edit: June 12, 2018, 02:37:34 pm by Petr »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Why is picture after comment DEST not full?
« Reply #7 on: June 12, 2018, 03:31:29 pm »
Thanks Petr now you have been thinking about borders crossing detection.

Each image has an outline, across each line cross section (for each y line across) there is a minX and a maxX between these two numbers is the interior of image.

so for collision detection align the two image arrays of min and max X's with y offsets for image positions in game, you have collision (overlapping images) when the x min or max is inside the x min / max of the 2nd image.

Oh rats, there could be a slew of min / max X's for one line on each image...

Heck, it's possible for an image to have several enclosed 'blobs" (for lack of a better term).

Your circle collision detection and Johnno's rectangular one is looking better and better!

Well for starters, I think I would be happy if I could get outlines expressed in terms of xin/xout pairings for each line cross section of an image.
« Last Edit: June 12, 2018, 03:38:41 pm by bplus »