Author Topic: Sprite Editor question(s)  (Read 7709 times)

0 Members and 1 Guest are viewing this topic.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Sprite Editor question(s)
« on: September 05, 2020, 12:33:59 am »
I am trying to rewrite my old sprite editor....

Loading and saving questions:

I know how to load an image using _loadimage(). When the editor "puts" it into the "preview" box, the image is scanned, then displayed on the main grid... Well it will when its finished... lol  My problem is, if I click the "LOAD" button, how do I get QB64 to display a directory of "png" files?
My other question pertains to saving. In the same manner, if the "SAVE" button is clicked, how do I get QB64 to save a "png" image?

It's just that, if a sprite editor cannot load or save an image, then there is no point really, right?  I figured that I would ask now before I get too far into the project....

Many thanks.

J
Logic is the beginning of wisdom.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Sprite Editor question(s)
« Reply #1 on: September 05, 2020, 02:22:43 am »
SaveImage 2.3 Steve McNeill's work
https://www.qb64.org/forum/index.php?topic=1651.msg108777#msg108777

Also Steve's
GetLists - Directorys and Files that is suppose to work with Linux:
https://www.qb64.org/forum/index.php?topic=1511.msg122368#msg122368

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Sprite Editor question(s)
« Reply #2 on: September 05, 2020, 03:35:51 am »
Tested the 'saveimage', using a 64x64 test image, and it produced various file formats as it was designed to do.... one slight itty bitty problem though... all images were stretched out to 1280x720... lol

I'm running on caffeine fumes at the moment and the brain refuses to co-operate with my keyboard... I think a good nap will serve me well...
Logic is the beginning of wisdom.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Sprite Editor question(s)
« Reply #3 on: September 05, 2020, 10:23:18 am »
Tested the 'saveimage', using a 64x64 test image, and it produced various file formats as it was designed to do.... one slight itty bitty problem though... all images were stretched out to 1280x720... lol

I'm running on caffeine fumes at the moment and the brain refuses to co-operate with my keyboard... I think a good nap will serve me well...

Did you _PUTIMAGE your 64x64 onto a 1280x720 screen?  SaveImage doesn’t do any scaling; it simply saves the images in the same size and color palette as what you point it at.
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: Sprite Editor question(s)
« Reply #4 on: September 05, 2020, 01:25:12 pm »
@johnno56  I am really curious about GetLists for Directories and Files on Linux.

I could do this just fine without Steve's thing on Windows but that couldn't port to Linux so since you posted Sprite Editor years ago I've been looking for method that would work both in Linux and Windows for you and all the Linux deviants ;-)) whom I am secretly jealous because Windows gets cruddier and cruddier. I have something like 92 processes running in background when I boot up WTH? all that dang delay for what?

I recall this:
https://www.qb64.org/forum/index.php?topic=313.msg2115#msg2115
« Last Edit: September 05, 2020, 01:52:18 pm by bplus »

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Sprite Editor question(s)
« Reply #5 on: September 05, 2020, 06:08:59 pm »
Steve,

I didn't 'put' the image on the screen... Hard coded the file name in place of the volcano...
Logic is the beginning of wisdom.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Sprite Editor question(s)
« Reply #6 on: September 05, 2020, 06:33:39 pm »
Bplus...

Yep. Two years since I "shelved" this beastie... With the lockdown, and the enforced free time, I figured,"Why not?"... Then I remembered the save/load issue I had last time... I must be a glutton for punishment... *sigh*

Re-coded from scratch... as you do... while giving the 'help file' a real work out...

I have a 'kind of' working version... All it can do is... well... not much actually. "Load" is using a sample image. Pencil and Mirror/Symmetry works. RMB will erase. Quit, New and Clear work. Colour selection works. On the subject of colour... Remember the horrible colour problem I had with the image to text program? Same thing happened when loading the sample file... then I remember your suggestion of 'unsigned long'... Worked like a charm.

There is still a LOT of things to fix and or add...

I can post it you like but it's FAR from 'alpha'.... Can alphabets go into the negative?

I still haven't tried Steve's directory program yet... I would be curious to know as well...

Serious caffeine withdrawal .... must caffinate... memory fading... fadi... Who are you?
Logic is the beginning of wisdom.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Sprite Editor question(s)
« Reply #7 on: September 05, 2020, 06:39:56 pm »
Steve,

I didn't 'put' the image on the screen... Hard coded the file name in place of the volcano...

Post me the relvant code, and any required files, and I’ll sort out what’s wrong with it for you.  ;)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Sprite Editor question(s)
« Reply #8 on: September 05, 2020, 07:09:47 pm »
The code used was 'saveimage 2.3' and I used the attached image.
Logic is the beginning of wisdom.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Sprite Editor question(s)
« Reply #9 on: September 05, 2020, 07:15:49 pm »
Steve,

I changed the '_newimage' to 64x64x32 - it made it a bit hard to 'read' the text output, but the upside is, all images created were 64x64.
Logic is the beginning of wisdom.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Sprite Editor question(s)
« Reply #10 on: September 06, 2020, 01:34:36 pm »
Hi johnno56
I find your project very interesting, I have always thought that a Sprite editor and an Image editor written in QB64 were cool to demonstrate the power of the language, also if you can use different free tool very powerful like Gimp, Allegro Sprite Editor, Icoxp, Piskel, Krita, Slate, Pixiliart, GrafX2.

So the project of this sprite editor is to make sprites at 32 bit colors or is  it possible to use different resolutions?
And is it possible to set the alphachannel color?
Please gimme many details if you want share your ideas about your project.

Good Programming

Programming isn't difficult, only it's  consuming time and coffee

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Sprite Editor question(s)
« Reply #11 on: September 06, 2020, 04:15:25 pm »
Steve,

I changed the '_newimage' to 64x64x32 - it made it a bit hard to 'read' the text output, but the upside is, all images created were 64x64.

It's this little demo code which you're looking at, I assume:

Code: QB64: [Select]
  1. '$INCLUDE:'SaveImage.BI'
  2.  
  3. CONST SaveTextAs256Color = 0 'Flag to Save as 256 color file or 32-bit color file, when converting SCREEN 0 to an image
  4. '                             Set to TRUE (any non-zero value) to save text screens in 256 color mode.
  5. '                             Set to FALSE (zero) to save text screens in 32-bit color mode.
  6.  
  7.  
  8. 'CONST ConvertToStandard256Palette = 0
  9. '                             Set the value to 0 (FALSE) to preseve the color information perfectly, using its default palette.
  10. '                             If the CONST is set (TRUE), then we convert our colors to as close of a match as possible, while
  11. '                             preserving the standard QB64 256-color palette.
  12. '                             Commented here, simply to help folks know that it exists for use when converting a 32 bit image
  13. '                             down to 256 colors, such as what the GIF routine has to do for us (GIFs are limited to 256 color images)
  14.  
  15. SCREEN _NEWIMAGE(1280, 720, 32)
  16. DIM exportimage(4) AS STRING
  17. InitialImage$ = "Volcano Logo.jpg"
  18. exportimage(1) = "testimage.png": exportimage(2) = "testimage.bmp"
  19. exportimage(3) = "testimage.jpg": exportimage(4) = "testimage.gif"
  20.  
  21. 'If you want to test the demo with a screen 0 image, then...
  22. l& = _LOADIMAGE(InitialImage$) 'Remark out this line
  23. '_PUTIMAGE , l& 'And remark the _PUTIMAGE line down below as well
  24.  
  25. 'And unremark the following
  26. 'SCREEN 0
  27. 'FOR i = 0 TO 15
  28. '    COLOR i
  29. '    PRINT "COLOR i"
  30. 'NEXT
  31. 'Then you can watch as we prove that we can save images while in Screen 0 TEXT mode.
  32. FOR i = 1 TO 4
  33.     _PUTIMAGE , l& 'Remark out this line, if you want to see the SCREEN 0 demo
  34.     LOCATE 1, 1
  35.     Result = SaveImage(exportimage(i), 0, 0, 0, _WIDTH - 1, _HEIGHT - 1)
  36.     IF Result = 1 THEN 'file already found on drive
  37.         KILL exportimage(i) 'delete the old file
  38.         Result = SaveImage(exportimage(i), 0, 0, 0, _WIDTH - 1, _HEIGHT - 1) 'save the new one again
  39.     END IF
  40.     PRINT Result
  41.     IF Result < 0 THEN PRINT "Successful " + exportimage(i) + " export" ELSE PRINT ext$ + " Export failed with Error Code:"; Result: ' END
  42.     SLEEP
  43.  
  44. FOR i = 1 TO 4
  45.     zz& = _LOADIMAGE(exportimage(i), 32)
  46.     IF zz& <> -1 THEN
  47.         SCREEN zz&
  48.         PRINT "Image Handle: "; zz&, exportimage(i)
  49.         PRINT "Successful Import using _LOADIMAGE"
  50.     ELSE
  51.         PRINT "ERROR - Not Loading the new image (" + exportimage(i) + ") with _LOADIMAGE."
  52.     END IF
  53.     SLEEP
  54.  
  55.  
  56. '$INCLUDE:'SaveImage.BM'
  57.  

If you notice, there's 3 particular lines of interest going on here, which affect your resolution:

SCREEN _NEWIMAGE(1280, 720, 32)  -- This sets the screen image to 1280x720.

l& = _LOADIMAGE(InitialImage$) -- This loads an image into the demo.

    _PUTIMAGE , l& 'Remark out this line, if you want to see the SCREEN 0 demo  -- This line puts the image to the main screen, making it a 1280x720 picture

And, once those 3 things are taken into consideration, we call the SaveImage routine with:

    Result = SaveImage(exportimage(i), 0, 0, 0, _WIDTH - 1, _HEIGHT - 1)



Now, to break down that Function, let's take a look at the BM file and view the syntax:

FUNCTION SaveImage (file$, image&, x1%, y1%, x2%, y2%)

So, now you can make sense of what all those 0's and such we're sending the function does:

exportimage(i)  -- this is the name of the file which we want to save to, on the disk.  In this case, it's in a loop with 4 different names, so we save in all 4 available formats.

, 0 -- this is the screen/image handle which we're exporting from.  A 0 designates, "use the visisble display screen", so that's the 1280x720 screen we put the image on -- NOT the original image itself.


, 0, 0, _WIDTH - 1, _HEIGHT - 1  -- and this is the screen dimensions which we want to capture and save.  From (0,0) to (_WIDTH -1, _HEIGHT -1) - basically, the whole 1280x720 screen image.





Now, if you wanted to simply load and convert your original image, you could make a simple change to that export line:

    Result = SaveImage(exportimage(i), l&, 0, 0, _WIDTH(l&) - 1, _HEIGHT(l&) - 1)

With the above, you can see that I'm now pointing the command to work with the image handle that we'd loaded, and not the visible display screen (l& instead of that first 0).  I've also changed it so that it's getting the width and height of the image, and not the display with _WIDTH(l&) and _HEIGHT(l&).

Point it at the right image, and you'll get the right resolutions.  By putting the image to an enlarged screen, and then saving that enlarged screen, you get the enlarged images on saving -- which isn't exactly what you're wanting to do at all, in this case. 

There's no bug in there: it's all working as it should, from what I can tell.  ;)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Sprite Editor question(s)
« Reply #12 on: September 06, 2020, 07:29:33 pm »
Steve,

Many thanks for explaining the function. Much appreciated.

I have a crazy idea... When I used to tinker with QB4.5 it used two commands, BLOAD and BSAVE, to load and save a binary image file... I also noticed that QB64 has retained these commands. I am not totally familiar with how these commands work. I just know that they do.... I am curious. QB64 now implements the '_LOADIMAGE() command... You know where I'm going with this... Can a _SAVEIMAGE() command be added to QB64? This would save me at least one headache... lol... At the moment it's just me and to grab a quote out of context, "The needs of the many out weigh the needs of the few... or the one."

Just an idea...
Logic is the beginning of wisdom.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Sprite Editor question(s)
« Reply #13 on: September 06, 2020, 08:49:06 pm »
TempodiBasic,

Primarily, I wanted to make a basic (no pun intended) sprite editor, to do pixel art for games. I do not have the knowledge or skill to add a bunch of functions. At the moment I have a working 'pencil' and the ability to 'mirror' pixels. The current resolution is 64x64 but my very early version had the ability to change the main grid size to 8x8, 16x16, 32x32 and64x64. If I can find it I will try to modify my current version. Gimp if my preferred editor and has been for a long time... There are MANY functions, some of which I have never used, but I'm still learning. All I need for my project to do is create a sprite with pixels. To be able to load and or save an image. No "bells or whistles". Just the ability to draw and erase pixels. Hmm... A poor man's version of MSPaint... lol

This is my current version... It works but it's FAR from complete... I am always open for 'constructive' criticism and suggestions.

Instructions: Select a colour and a tool. Left mouse button to draw. Right mouse button to erase.

'New", "Clear", "Quit", "Pencil" and "Mirror" work. "Load" will use a sample image. The ability to load and save images, to and from the hard drive, is still a "work in progress".

It's taken me 5 years, on and off - mainly off - to get it to this stage. Please do not laugh at it or I will remove you from my Christmas list... Nah. Kidding. I have no Christmas list... There may be one among us who has seen a version of this editor before... I will mention no names... Clue: A popular vitamin...

Note: I use Linux Mint. If you are using Windows then you may have to change the file paths... I think...
Logic is the beginning of wisdom.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Sprite Editor question(s)
« Reply #14 on: September 06, 2020, 10:53:59 pm »
Quote
There may be one among us who has seen a version of this editor before... I will mention no names... Clue: A popular vitamin...

Yeah I remember showing it how to draw circles and lines in Naalaa.

I just got done practicing using Steves SaveImage v2.3b to grab images with mouse rectangle selections. I think I can do a fixed point save to file quite easily.