Author Topic: sprite editor  (Read 51483 times)

0 Members and 1 Guest are viewing this topic.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
sprite editor
« on: July 03, 2018, 04:03:49 am »
I decided to 'dust off' my old incomplete sdlbasic sprite editor in the hope of getting it to work. Conversion is going slow but I have come up against an interesting 'random feature'.

When a sprite is loaded, it is placed into a 'preview' box. The image is scanned, using the point() command, then places the colour into an array whilst, at the same time, translating the image to the main display. All of this function works just fine... except... the colours are different. See the screen dump. Nothing is done to the pixels. Point picks up the colour and places it in the main display.

Has anyone had this kind of problem before?

J
spredit.png
* spredit.png (Filesize: 18.26 KB, Dimensions: 1026x794, Views: 675)
Logic is the beginning of wisdom.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: sprite editor
« Reply #1 on: July 03, 2018, 07:00:59 am »
Here is a simple test. I cannot understand why the colours are different.

J

ps: Change the path...
* test.zip (Filesize: 1.56 KB, Downloads: 445)
Logic is the beginning of wisdom.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: sprite editor
« Reply #2 on: July 03, 2018, 07:48:10 am »
Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(640, 480, 32)
  2. ' >>>>>>>>>>>>>>>>> path$ = "/home/john/Desktop/spriteditor/"
  3. patch = _LOADIMAGE("colourpatch.png")
  4. _PUTIMAGE (10, 10), patch
  5.  
  6. DIM current AS LONG '<<<<<<<<<<<<<<<<< simple type problem, colors need big integers _UNSIGNED LONG better for alpha range
  7.  
  8.  
  9.     mx = _MOUSEX
  10.     my = _MOUSEY
  11.     mb = _MOUSEBUTTON(1)
  12.  
  13.     LINE (120, 220)-(152, 252), _RGB32(90, 90, 90), B
  14.  
  15.     IF mx > 10 AND mx < 284 AND my > 10 AND my < 200 AND POINT(mx, my) <> _RGB32(90, 90, 90) AND mb THEN
  16.         current = POINT(mx, my)
  17.         LINE (121, 221)-(151, 251), current, BF
  18.     END IF

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: sprite editor
« Reply #3 on: July 03, 2018, 08:10:35 am »
Ah, ya blood's worth bottling! Worked for 'testing.bas' and for the editor. Very cool... :D

Many thanks...

J
Logic is the beginning of wisdom.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: sprite editor
« Reply #4 on: July 03, 2018, 08:37:51 am »
The same effect is, if you use &, because & = LONG:

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(640, 480, 32)
  2. path$ = "/home/john/Desktop/spriteditor/"
  3. patch = _LOADIMAGE("colourpatch.png")
  4. _PUTIMAGE (10, 10), patch
  5.  
  6.  
  7.  
  8.     mx = _MOUSEX
  9.     my = _MOUSEY
  10.     mb = _MOUSEBUTTON(1)
  11.  
  12.     LINE (120, 220)-(152, 252), _RGB32(90, 90, 90), B
  13.  
  14.     IF mx > 10 AND mx < 284 AND my > 10 AND my < 200 AND POINT(mx, my) <> _RGB32(90, 90, 90) AND mb THEN
  15.         current& = POINT(mx, my)
  16.         LINE (121, 221)-(151, 251), current&, BF
  17.     END IF
  18.  


Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: sprite editor
« Reply #5 on: July 03, 2018, 11:26:54 am »
Thanks Petr. One character! Saved some sore fingers there... lol

J
Logic is the beginning of wisdom.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: sprite editor
« Reply #6 on: July 03, 2018, 09:57:43 pm »
This is the editor so far... VERY limited functionality. Again, change the file path to your taste...

This is my first attempt at converting my 'non completed' editor from sdlbasic to qb64. I know, before you say anything, the coding is terribly sloppy.

What works... hmm... interesting...

Colour selection works..
Drawing on the main grid works...
"New" works...
"Load" works but is limited to a specific file...
"Save"... not yet..
"Quit" works... The only part that functioned flawlessly from the start! Who woulda thought?

BIG thanks to bplus and petr for their tips with my colour problem...

Still LOTS to do!! There are FAR too many 'If.. Then's for my liking but it seems to work ok...

As usual, any 'constructive' criticism is welcomed as is any reasonable suggestion (my skills are quite limited... lol)

Let me know what you think?

J
* test2.zip (Filesize: 6.02 KB, Downloads: 447)
Logic is the beginning of wisdom.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: sprite editor
« Reply #7 on: July 04, 2018, 08:34:34 am »
Johnno, is this along the same lines of what we did in Naalaa?

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: sprite editor
« Reply #8 on: July 04, 2018, 09:25:51 am »
Oh nuts! The secret is out! nah kidding...

Yeah, basically (no pun intended)... Trying my hand at converting to QB64. The program is far from finished... crumbs, never got very far with sdl. I know and editor has been 'done to death' and I know that there are other editors 'out there' but I'm not going to learn anything if I don't to it myself.... lol  I may never finish it, but that's not the point, is it?

Yeah, I think someone else is trying their hand, using Naalaa. I think I wrote sprEdit in late 2014 and it ended up migrating to Naalaa earlier this year and has been gathering dust ever since... *sigh*  Maybe I'll have better luck here... crossed fingers...

Have you tried it yet? I have spent more time on since posting, cosmetics mainly, but slowly plugging away at it... I still need to check out how to save and load to and from the file system... What's the point of writing this beastie if you can't save your work? lol  Once that bit is done then I can start looking at how to implement other drawing tools. eg: circles (ellipses); boxes; lines; fill (the dreaded fill - my aching back...) Perhaps different modes? ie: 8x8, 16x16 etc. (my very early version had these... but I think I lost it in a drive crash... Just simple 'buttons' containing "8" and "16" and the main grid would change accordingly (handy for retro sprites)... anyway, just some ideas... Saving to files.... hmmm...
Logic is the beginning of wisdom.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: sprite editor
« Reply #9 on: July 04, 2018, 09:40:01 am »
Yes, I just tried it and had to cut path in line 306 so the file loads from same folder as source.

I'd say work on saving a file to same folder as source, use a time stamped name so you don't have to worry about getting input about file name from user or loosing your title 01 sample file. Let Windows or your OS do the work of renaming the file if you really want to save the file with a real name.

Too much concern for color names for my taste, but not my app! ;-))

Naalaa was nice little editor, we had gone a long way with it. I will see if I can dig it up. ;)
« Last Edit: July 04, 2018, 09:41:59 am by bplus »

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: sprite editor
« Reply #10 on: July 04, 2018, 10:12:46 am »
I tried having the just the file in the same directory, but for some reason and I think it maybe Linux related, qb64 would alway kick up a fuss unless the full path was given. It's no big deal for me as I'm used to it... lol

My very first version was tedious. I had a colour patch with way more colours than a bag of Skittles and each colour square had it's rgb code and paint command... sore fingers THAT day!! You're right about the names. They are only there for my benefit. It's simple enough just to leave out.

I'm still toying with the idea to change the colour patch... the current one seem to be all over the place.

Hey. I went looking for the first version on another disc and found it... Horrible code. Simply horrible. I don't know what I was thinking. But it DID have two main grid sizes 10 an 20 pixels (for 16x16 and 32x32)

Well. It's just gone midnight and my eyes are struggling to stay open...  I've started tidying up the listing a little by using subs and comments. Since the last version I had put all the colour names and rgb codes into an external file. Made for a slightly smaller listing... I'll do some more in the morning, and if I remember, I may post an update. But, it's only cosmetic, no real advancement... lol

My mug of coffee has finally worn off... Goodnight.

J
Logic is the beginning of wisdom.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: sprite editor
« Reply #11 on: July 04, 2018, 10:23:44 am »
Now I have a question, how do you save a file with say, a .png format?

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: sprite editor
« Reply #12 on: July 04, 2018, 11:00:26 am »
Hi Johnno56. I'm interested in this topic, but unfortunately I'm just on the way away. I'll add some suggestions to you later. I made my video editor (it was an experiment, so it only knows two colors), the output can be seen for example at Voleyball game. Did you see her? I add it here and I also add a Galleon program that lets you save your images to BMP format.

GalleonĀ“s save utility:
Code: QB64: [Select]
  1. 'program create file CIRCLE.BMP on your harddrive (tested in windows)
  2.  
  3. circleimage& = _NEWIMAGE(320, 240, 32) '                                     create virtual screen
  4. _DEST circleimage&
  5. CIRCLE (160, 120), 120, _RGB32(255, 0, 0)
  6. PAINT (160, 120), _RGB32(255, 0, 0), _RGB32(255, 0, 0)
  7. SaveImage circleimage&, "CIRCLE.BMP"
  8. _FREEIMAGE circleimage&
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21. SUB SaveImage (image AS LONG, filename AS STRING)
  22.     bytesperpixel& = _PIXELSIZE(image&)
  23.     IF bytesperpixel& = 0 THEN PRINT "Text modes unsupported!": END
  24.     IF bytesperpixel& = 1 THEN bpp& = 8 ELSE bpp& = 24
  25.     x& = _WIDTH(image&)
  26.     y& = _HEIGHT(image&)
  27.     b$ = "BM????QB64????" + MKL$(40) + MKL$(x&) + MKL$(y&) + MKI$(1) + MKI$(bpp&) + MKL$(0) + "????" + STRING$(16, 0) 'partial BMP header info(???? to be filled later)
  28.     IF bytesperpixel& = 1 THEN
  29.         FOR c& = 0 TO 255 ' read BGR color settings from JPG image + 1 byte spacer(CHR$(0))
  30.             cv& = _PALETTECOLOR(c&, image&) ' color attribute to read.
  31.             b$ = b$ + CHR$(_BLUE32(cv&)) + CHR$(_GREEN32(cv&)) + CHR$(_RED32(cv&)) + CHR$(0) 'spacer byte
  32.         NEXT
  33.     END IF
  34.     MID$(b$, 11, 4) = MKL$(LEN(b$)) ' image pixel data offset(BMP header)
  35.     lastsource& = _SOURCE
  36.     _SOURCE image&
  37.     IF ((x& * 3) MOD 4) THEN padder$ = STRING$(4 - ((x& * 3) MOD 4), 0)
  38.     FOR py& = y& - 1 TO 0 STEP -1 ' read JPG image pixel color data
  39.         r$ = ""
  40.         FOR px& = 0 TO x& - 1
  41.             c& = POINT(px&, py&) 'POINT 32 bit values are large LONG values
  42.             IF bytesperpixel& = 1 THEN r$ = r$ + CHR$(c&) ELSE r$ = r$ + LEFT$(MKL$(c&), 3)
  43.         NEXT px&
  44.         d$ = d$ + r$ + padder$
  45.     NEXT py&
  46.     _SOURCE lastsource&
  47.     MID$(b$, 35, 4) = MKL$(LEN(d$)) ' image size(BMP header)
  48.     b$ = b$ + d$ ' total file data bytes to create file
  49.     MID$(b$, 3, 4) = MKL$(LEN(b$)) ' size of data file(BMP header)
  50.     IF LCASE$(RIGHT$(filename$, 4)) <> ".bmp" THEN ext$ = ".bmp"
  51.     f& = FREEFILE
  52.     OPEN filename$ + ext$ FOR OUTPUT AS #f&: CLOSE #f& ' erases an existing file
  53.     OPEN filename$ + ext$ FOR BINARY AS #f&
  54.     PUT #f&, , b$
  55.     CLOSE #f&
  56.  

* voll.zip (Filesize: 572.98 KB, Downloads: 493)

FellippeHeitor

  • Guest
Re: sprite editor
« Reply #13 on: July 04, 2018, 12:08:05 pm »
Steve has a library somewhere to export images to PNG format too.

FellippeHeitor

  • Guest
Re: sprite editor
« Reply #14 on: July 04, 2018, 12:22:31 pm »