Author Topic: Re: PopImage  (Read 872 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
Re: PopImage
« on: February 22, 2019, 03:05:41 am »
Why not just use _CopyImage?  http://qb64.org/wiki/COPYIMAGE

Copy image.
Put image.
Free copy.

Done.



It’s basically the process I was going to use to allow _PUTIMAGE to work with the same source and destination, but folks felt the command was confusing enough already and vetoed the alteration.
« Last Edit: February 22, 2019, 03:07:54 am by SMcNeill »
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: PopImage
« Reply #1 on: February 22, 2019, 11:02:07 am »
Why not just use _CopyImage?  http://qb64.org/wiki/COPYIMAGE

Copy image.
Put image.
Free copy.

Done.

I think it's basically that some inhabitants of this planet purposely find some degree of satisfaction in performing various tasks in such a manner that requires several extra procedural processes to complete the given task at hand.

Steved down = "You mean some people like doing things the hard way?"

[banned user]: Copying part looks useful in making a photo-editing function like crop. Nice!

Pete :D

- I wouldn't spend so much time reinventing the wheel, if I could just find a way to get around it.
« Last Edit: February 22, 2019, 11:04:08 am by 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: PopImage
« Reply #2 on: February 22, 2019, 11:15:34 am »
Why not just use _CopyImage?  http://qb64.org/wiki/COPYIMAGE

Copy image.
Put image.
Free copy.
Done.

It’s basically the process I was going to use to allow _PUTIMAGE to work with the same source and destination, but folks felt the command was confusing enough already and vetoed the alteration.

_CopyImage  will copy the entire image.

That’s the entire point.  ;)

Say I want to copy and put an area from (100,100)-(200,200) to (400,400)-(500,500) inside the same image.  IF _PUTIMAGE worked with the same source and destination, one command would do the trick:

_PUTIMAGE (400,400)-(500,500), source, dest, (100,100)-(200,200)

Since source and dest can’t be the same, without an error, we simply:

temphandle = _COPYIMAGE(dest)
PUTIMAGE (400,400)-(500,500), temphandle, dest, (100,100)-(200,200)
_FREEIMAGE temphandle

Make a copy of the screen with exact same coordinates, image, and all.  Simply use the copy as the source and then put what we want from it, back to the original.  Then free the copy.
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: PopImage
« Reply #3 on: February 22, 2019, 11:49:36 am »
Steve, do you have editing ability in the Wiki? If so, I think your example would be a welcome addition. As is the wiki contains...

 _PUTIMAGE can be used without any handle parameters if the _SOURCE and/or _DEST are already defined.
The sourceHandle& and destHandle& cannot be the same or an Illegal Function Call error will occur.

And so forth...

After that second statement, an exception could be added to use your method to get around that limitation. An example code could also be added and referenced in that new statement.

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: PopImage
« Reply #4 on: February 22, 2019, 12:32:43 pm »
Steve, do you have editing ability in the Wiki? If so, I think your example would be a welcome addition. As is the wiki contains...

 _PUTIMAGE can be used without any handle parameters if the _SOURCE and/or _DEST are already defined.
The sourceHandle& and destHandle& cannot be the same or an Illegal Function Call error will occur.

And so forth...

After that second statement, an exception could be added to use your method to get around that limitation. An example code could also be added and referenced in that new statement.

Pete

No editing privileges here, I’m afraid.   

If folks don’t object to _PUTIMAGE being able to work with the same source and destination, QB64 could be easily modified to allow it.  Just alter sub_putimage inside libqb to make a copy and use it as indicated, instead of tossing the error code...

I was going to make the changes once before in the past, but people somehow objected saying it’d make the command even more complicated to understand/implement, so the idea was dropped.  If the current user base doesn’t have the issues with the change that the folks over at [abandoned, outdated and now likely malicious qb64 dot net website - don’t go there] had, it’d be a simple process to completely remove that restriction from the command.  ;)
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: PopImage
« Reply #5 on: February 22, 2019, 02:19:09 pm »
Well count me as in favor of removing that restriction... provided we don't have to drag Clippy back here to update that change in the Wiki. :D

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: PopImage
« Reply #6 on: February 23, 2019, 01:40:31 am »
Well count me as in favor of removing that restriction... provided we don't have to drag Clippy back here to update that change in the Wiki. :D

Pete

Instructions to make the change for yourself:

1) Open your local QB64 folder.  Head to internal\c and open libqb.cpp.  That's the file we're going to edit.
2) Do a search for void sub__putimage(
3) Scroll down to the line which reads:     if (s==d){error(5); return;}//cannot put source onto itself!
3a) The line is down at line number 3481 in my version of libqb.cpp, if the development branch hasn't altered it any since I last cloned the repo.

4) Change that line to the following:
Code: QB64: [Select]
  1.     if (s==d){
  2.         //error(5); return;}//cannot put source onto itself!
  3.         int32 temphandle=func__copyimage( 0 ,NULL,0);
  4.         passed=passed|8; //make certain we set the flag to let QB64 know we're passing a handle to the temp image
  5.         sub__putimage( f_dx1 , f_dy1 , f_dx2 , f_dy2 ,temphandle , dst , f_sx1 , f_sy1 , f_sx2 , f_sy2 , passed);
  6.         sub__freeimage(temphandle,1);
  7.         return;
  8.     }

5) Save the changes.  Close libqb.cpp. 

6) You're not quite done yet.  Inside the folder where libqb.cpp is found, scroll down and find the batch file called, "purge_libqb_only.bat".

7) Run that batch file.

8) Break open a bottle of campaign and celebrate!  You can now write programs which use the same source and destination to write to themselves!  The restriction is now lifted!  :P
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!