QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: johnno56 on September 05, 2020, 12:33:59 am

Title: Sprite Editor question(s)
Post by: johnno56 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
Title: Re: Sprite Editor question(s)
Post by: bplus 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
Title: Re: Sprite Editor question(s)
Post by: johnno56 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...
Title: Re: Sprite Editor question(s)
Post by: SMcNeill 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.
Title: Re: Sprite Editor question(s)
Post by: bplus 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
Title: Re: Sprite Editor question(s)
Post by: johnno56 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...
Title: Re: Sprite Editor question(s)
Post by: johnno56 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?
Title: Re: Sprite Editor question(s)
Post by: SMcNeill 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.  ;)
Title: Re: Sprite Editor question(s)
Post by: johnno56 on September 05, 2020, 07:09:47 pm
The code used was 'saveimage 2.3' and I used the attached image.
Title: Re: Sprite Editor question(s)
Post by: johnno56 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.
Title: Re: Sprite Editor question(s)
Post by: TempodiBasic 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

Title: Re: Sprite Editor question(s)
Post by: SMcNeill 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.  ;)
Title: Re: Sprite Editor question(s)
Post by: johnno56 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...
Title: Re: Sprite Editor question(s)
Post by: johnno56 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...
Title: Re: Sprite Editor question(s)
Post by: bplus 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.
Title: Re: Sprite Editor question(s)
Post by: johnno56 on September 07, 2020, 12:14:14 am
Waa... Circles and lines? Tell me you can remember how? Hmm..
Title: Re: Sprite Editor question(s)
Post by: bplus on September 07, 2020, 01:17:55 am
Waa... Circles and lines? Tell me you can remember how? Hmm..

I can figure out how again. Close enough? Lines turned out to be tricky, you had to spread out the jumps evenly over the length of line. I could do paint fills like for Ken's paint program. We could even try aliasing.
Title: Re: Sprite Editor question(s)
Post by: johnno56 on September 07, 2020, 03:54:59 am
I wish that I could have held onto those earlier versions... Combination of lack of foresight, system crashes and hard drive deaths...
I still have only one copy of version 2.3 from about 2016... It looks horrible, compared to the current version, but it may hold some clues to resolutions etc... I'm thinking of including all 4 resolutions (8,16,32 and 64)... but... not without caffeine... Moo Ha Ha....
Title: Re: Sprite Editor question(s)
Post by: johnno56 on September 07, 2020, 04:21:43 am
Just remembered that my early versions were using sdlbasic... I actually found the very first version... 16x16, New, Load and Quit (Save not working) using 16 colours... Man, that version put the "ug" in ugly... Also found an 8x8 version (made after the 16x16)
Title: Re: Sprite Editor question(s)
Post by: bplus on September 07, 2020, 04:52:06 am
Just remembered that my early versions were using sdlbasic... I actually found the very first version... 16x16, New, Load and Quit (Save not working) using 16 colours... Man, that version put the "ug" in ugly... Also found an 8x8 version (made after the 16x16)

Did some digging myself, June 28, 2015 code for what I called GE for Graphics Editor v1.0, complete with drawLine and drawCircle:

Do you think it would still work?
Title: Re: Sprite Editor question(s)
Post by: johnno56 on September 07, 2020, 06:22:53 am
I will attempt to convert it to QB64... Cool.
Title: Re: Sprite Editor question(s)
Post by: bplus on September 07, 2020, 01:08:15 pm
I will attempt to convert it to QB64... Cool.

Yes, I am particularly curious comparing draw line (with pixel/boxes) to other line drawing methods I've come up with since this 5 year old code. Man 5 years! actually 6 this September 14th, since I started up with Basics again.

@johnno56
Do you have a best QB64 version to post in Programs Board so we can start developing a work in progress or would you like to work this out yourself? Of course, would like confirmation that the GetLists method does work in Linux to get a list of files and directories. Probably have to build a File Dialog.

Update: well I couldn't wait! I bumped the old project with some mods to your v03:
https://www.qb64.org/forum/index.php?topic=313.msg122523#msg122523

Looks like we are ready to test a saveImage bi and massive bm addition to the code. I can put that together with my recent practice session fresh in mind.
Title: Re: Sprite Editor question(s)
Post by: TempodiBasic on September 07, 2020, 06:36:19 pm
@johnno56

1. in Windows10 it runs ok. No path adjustment required

2. Fine sound feedback on clicking on buttons....

3. No criticism, yes definition of goals to know if you are in the right direction or not while you're working on your SpriteEditor
Quote
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.

4. for now your goal is to manage sprites with dimensions ranging from 8X8 to 64X64...
 other my questions to know more about your project (ignore them if you're busy)

  -will it manage also rectangulare sprite (for example 8x4, 16x8, 32x64)?     
  - Or a sprite with very costumable dimensions?
  - also as spritesheet?
  -how many colors do you like to manage in the sprite editor?

  -do you think that MsPaint is a good tool for sprite creation?
  https://images.sftcdn.net/images/t_app-cover-l,f_auto/p/ad1de8c1-a23d-4e96-9b21-0ce5aec78b2d/3911303564/ms-paint-screenshot.png  (https://images.sftcdn.net/images/t_app-cover-l,f_auto/p/ad1de8c1-a23d-4e96-9b21-0ce5aec78b2d/3911303564/ms-paint-screenshot.png)

 a personal version of MsPaint that let save sprite image both as file image of inner Qbasic format by BSAVE/BLOAD, both as file image jpeg/png by Steve's image library, both as block of DATA value to insert in source code it would be very cool!

Thanks to talk of your project.
Title: Re: Sprite Editor question(s)
Post by: johnno56 on September 07, 2020, 07:58:24 pm
Wow. That's a lot of feedback, thank you.  ... and no, I'm not too busy... lol

At the moment, my intention is to keep the sprites 'square'. I'm still trying to figure out how to code for 8x8, 16x16 and 32x32. As I was planning on simple square sprites, rectangular or other shapes, wasn't even thought of... Most of the larger editors can define the size of the image when "New" is selected. Unfortunately, my current skill level, cannot reproduce that function. I'm not saying that it cannot be done... I'm saying that it cannot be done by "me"... *sigh*

Oh boy. Sprite-sheets... I have always wanted to be able to create and or separate sprites from a sprite-sheet. At the moment I use Gimp to extract sprites. I have no idea as to how to do that with QB64 (or any other basic)...

How many colours? Oh man, that is such a loaded question. If you are creating 'old school' games that use 8x8 or 16x16 then use a simple collection of colours. Have a close look at Mario. Usually between 3 to 6 colours were enough for Mario. 32x32 plus sprites obviously can contain more colours. My editor has only 117 colours. But not all of them are used. Selecting a palette of colours (just like an artist) is the most important thing to consider when using colour. It's not how "many" it's more about how the colours are "used". For example, Let's say that you use 20 colours to make level one of a game, be consistent, use the same colours for the other levels. Too much variation can be a distraction.... That being said... Standard RGB will number 16,777,216 colours...

Is MSPaint a good tool for sprite creation? I am a Linux user and have not used mspaint for more than 15 years. There are 'many' choices out there for graphics editing... From the simple (like mspaint) all the way up to Photoshop and beyond. All of those editors are good tools. The question might be better: Which editor is good for "you"? My suggestion: Start small. Not sprite size but complexity of the editor. If you are comfortable using mspaint, then stick with it. Piskel is a free online editor. There are many to choose from. Here is a 10 minute youtube that will cover free and non-free editors. I hope this helps.


These are only a few but it should give you a good place to start...

Saving and loading images to and from my program is still an ongoing issue. There are people, smarter than I, who are assisting with the problem...

I hope I haven't confused you... I tend to "waffle" on like that if I haven't had my coffee... NO! It's almost 10am and no coffee!!
Title: Re: Sprite Editor question(s)
Post by: TempodiBasic on September 14, 2020, 05:08:46 pm
Well
it seems that you are developing with more details your goal and so your project.
With no clear ideas I think that noone can make a good program.
I'll wait your development. in the while if you like to talk about some aspects to have a mirror to reflect and choose your goal I think this community is the good place to do it.
Title: Re: Sprite Editor question(s)
Post by: johnno56 on September 16, 2020, 05:51:19 pm
I had to erase my response because I read your comment the wrong way... My response was not very kind. My apologies.
Title: Re: Sprite Editor question(s)
Post by: TempodiBasic on September 16, 2020, 06:46:24 pm
@johnno56

Hi

1.
it seems that it is raised up an issue using a bad translation of my native ideas into foreign language.
the affirmation
Quote
With no clear ideas I think that noone can make a good program.
  comes out from this kind of knowledge and it is not a product of my mind http://aroma.vn/web/wp-content/uploads/2016/11/code-complete-2nd-edition-v413hav.pdf (http://aroma.vn/web/wp-content/uploads/2016/11/code-complete-2nd-edition-v413hav.pdf) see Chapter 3  titled
Quote
Chapter 3
Measure Twice, Cut Once:
Upstream Prerequisites
as you can read there you can see how much work is done before to type a single character of source code!
So I have said you that you're facing all these kind of issues to transform your idea into a real program . To solve these issues often you must define and observe (also talking with other persons ) your idea from many different points of view.

2.
about
Quote
How can I plan a project that I have never done before?!?!
  I think that an human ability very widespread is imagination. A man can imagine something, then he can specify how that something can be, interact and act. Subsequentially he can specify what to do to get that something or what he needs to know to go on with his specific idea. We can call this process creativity.

3.
I apology with anyone has understood what johnno56 has understood reading this sentence
Quote
With no clear ideas I think that noone can make a good program.
also if my message is quite far from his conclusions.

4.
Quote
You really know how to suck the joy right out of programming
, sorry if I miss a bit your message, my english ability is not so good to understand the level of irony of this sentence, nevertheless I say you Good Coding and Happy Life
Title: Re: Sprite Editor question(s)
Post by: johnno56 on September 16, 2020, 07:04:31 pm
Again. My apologies. I was erasing my post at the same time you were replying. When you said that "With no clear ideas I think that noone can make a good program", I assumed that, you meant all of us on the forum... My wife pointed out that your statement was "general"... Meaning that, unless a programmer has a clear Idea of how to program, the resulting program will not be good. It was my fault for assuming the worst... My responses were not very kind and I spoke before putting my brain into gear...
Title: Re: Sprite Editor question(s)
Post by: bplus on September 16, 2020, 07:34:05 pm
This is good from your dialogue

Quote
How can I plan a project that I have never done before?!?!

Quote
  I think that an human ability very widespread is imagination. A man can imagine something, then he can specify how that something can be, interact and act. Subsequentially he can specify what to do to get that something or what he needs to know to go on with his specific idea. We can call this process creativity.
Title: Re: Sprite Editor question(s)
Post by: bplus on September 16, 2020, 07:49:34 pm
But when I started this project up again it was immediately obvious after loading an image into the grid that you would want a tool to get a color from the image to use in the other cells, no pre-planning nor imagination needed.

Turns out that is very common tool with eyedropper image.

Form follows function?
Title: Re: Sprite Editor question(s)
Post by: TempodiBasic on September 16, 2020, 08:20:09 pm
@johnno56
I am very happy that my good intention behind the words is clear to you. I'm sorry about the misunderstandment, but the linguists say the words are not perfect but they are the only thing we can use to speak. So it is possible to talk without communicate the wanted message but somethingelse. It is part of the game of communication.
Good Coding
Title: Re: Sprite Editor question(s)
Post by: johnno56 on September 16, 2020, 09:38:39 pm
Thank you for being so understanding... Much appreciated.