Author Topic: sprite editor  (Read 338 times)

Offline johnno56

  • Live long and prosper.
sprite editor
« on: July 03, 2018, 05: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
Logic is the beginning of wisdom.

Offline johnno56

  • Live long and prosper.
Re: sprite editor
« Reply #1 on: July 03, 2018, 08:00:59 AM »
Here is a simple test. I cannot understand why the colours are different.

J

ps: Change the path...
Logic is the beginning of wisdom.

Offline bplus

  • B = B + geberation
Re: sprite editor
« Reply #2 on: July 03, 2018, 08:48:10 AM »
Code: [Select]
SCREEN _NEWIMAGE(640, 480, 32)
' >>>>>>>>>>>>>>>>> path$ = "/home/john/Desktop/spriteditor/"
patch = _LOADIMAGE("colourpatch.png")
_PUTIMAGE (10, 10), patch

DIM current AS LONG '<<<<<<<<<<<<<<<<< simple type problem, colors need big integers _UNSIGNED LONG better for alpha range
WHILE INKEY$ <> CHR$(27)

    DO WHILE _MOUSEINPUT: LOOP

    mx = _MOUSEX
    my = _MOUSEY
    mb = _MOUSEBUTTON(1)

    LINE (120, 220)-(152, 252), _RGB32(90, 90, 90), B

    IF mx > 10 AND mx < 284 AND my > 10 AND my < 200 AND POINT(mx, my) <> _RGB32(90, 90, 90) AND mb THEN
        current = POINT(mx, my)
        LINE (121, 221)-(151, 251), current, BF
    END IF
WEND
B = B + ...

Offline johnno56

  • Live long and prosper.
Re: sprite editor
« Reply #3 on: July 03, 2018, 09: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.

Re: sprite editor
« Reply #4 on: July 03, 2018, 09:37:51 AM »
The same effect is, if you use &, because & = LONG:

Code: [Select]
SCREEN _NEWIMAGE(640, 480, 32)
path$ = "/home/john/Desktop/spriteditor/"
patch = _LOADIMAGE("colourpatch.png")
_PUTIMAGE (10, 10), patch

WHILE INKEY$ <> CHR$(27)

    WHILE _MOUSEINPUT: WEND

    mx = _MOUSEX
    my = _MOUSEY
    mb = _MOUSEBUTTON(1)

    LINE (120, 220)-(152, 252), _RGB32(90, 90, 90), B

    IF mx > 10 AND mx < 284 AND my > 10 AND my < 200 AND POINT(mx, my) <> _RGB32(90, 90, 90) AND mb THEN
        current& = POINT(mx, my)
        LINE (121, 221)-(151, 251), current&, BF
    END IF
WEND

Coding is relax (At least sometimes)

Offline johnno56

  • Live long and prosper.
Re: sprite editor
« Reply #5 on: July 03, 2018, 12:26:54 PM »
Thanks Petr. One character! Saved some sore fingers there... lol

J
Logic is the beginning of wisdom.

Offline johnno56

  • Live long and prosper.
Re: sprite editor
« Reply #6 on: July 03, 2018, 10: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
Logic is the beginning of wisdom.

Offline bplus

  • B = B + geberation
Re: sprite editor
« Reply #7 on: July 04, 2018, 09:34:34 AM »
Johnno, is this along the same lines of what we did in Naalaa?
B = B + ...

Offline johnno56

  • Live long and prosper.
Re: sprite editor
« Reply #8 on: July 04, 2018, 10: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

  • B = B + geberation
Re: sprite editor
« Reply #9 on: July 04, 2018, 10: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, 10:41:59 AM by bplus »
B = B + ...

Offline johnno56

  • Live long and prosper.
Re: sprite editor
« Reply #10 on: July 04, 2018, 11: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

  • B = B + geberation
Re: sprite editor
« Reply #11 on: July 04, 2018, 11:23:44 AM »
Now I have a question, how do you save a file with say, a .png format?
B = B + ...

Re: sprite editor
« Reply #12 on: July 04, 2018, 12:00:26 PM »
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: [Select]
'program create file CIRCLE.BMP on your harddrive (tested in windows)

circleimage& = _NEWIMAGE(320, 240, 32) '                                     create virtual screen
_DEST circleimage&
CIRCLE (160, 120), 120, _RGB32(255, 0, 0)
PAINT (160, 120), _RGB32(255, 0, 0), _RGB32(255, 0, 0)
SaveImage circleimage&, "CIRCLE.BMP"
_FREEIMAGE circleimage&












SUB SaveImage (image AS LONG, filename AS STRING)
    bytesperpixel& = _PIXELSIZE(image&)
    IF bytesperpixel& = 0 THEN PRINT "Text modes unsupported!": END
    IF bytesperpixel& = 1 THEN bpp& = 8 ELSE bpp& = 24
    x& = _WIDTH(image&)
    y& = _HEIGHT(image&)
    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)
    IF bytesperpixel& = 1 THEN
        FOR c& = 0 TO 255 ' read BGR color settings from JPG image + 1 byte spacer(CHR$(0))
            cv& = _PALETTECOLOR(c&, image&) ' color attribute to read.
            b$ = b$ + CHR$(_BLUE32(cv&)) + CHR$(_GREEN32(cv&)) + CHR$(_RED32(cv&)) + CHR$(0) 'spacer byte
        NEXT
    END IF
    MID$(b$, 11, 4) = MKL$(LEN(b$)) ' image pixel data offset(BMP header)
    lastsource& = _SOURCE
    _SOURCE image&
    IF ((x& * 3) MOD 4) THEN padder$ = STRING$(4 - ((x& * 3) MOD 4), 0)
    FOR py& = y& - 1 TO 0 STEP -1 ' read JPG image pixel color data
        r$ = ""
        FOR px& = 0 TO x& - 1
            c& = POINT(px&, py&) 'POINT 32 bit values are large LONG values
            IF bytesperpixel& = 1 THEN r$ = r$ + CHR$(c&) ELSE r$ = r$ + LEFT$(MKL$(c&), 3)
        NEXT px&
        d$ = d$ + r$ + padder$
    NEXT py&
    _SOURCE lastsource&
    MID$(b$, 35, 4) = MKL$(LEN(d$)) ' image size(BMP header)
    b$ = b$ + d$ ' total file data bytes to create file
    MID$(b$, 3, 4) = MKL$(LEN(b$)) ' size of data file(BMP header)
    IF LCASE$(RIGHT$(filename$, 4)) <> ".bmp" THEN ext$ = ".bmp"
    f& = FREEFILE
    OPEN filename$ + ext$ FOR OUTPUT AS #f&: CLOSE #f& ' erases an existing file
    OPEN filename$ + ext$ FOR BINARY AS #f&
    PUT #f&, , b$
    CLOSE #f&
END SUB

Coding is relax (At least sometimes)

Online FellippeHeitor

  • QB64 Developer
  • LET IT = BE
    • QB64.org
Re: sprite editor
« Reply #13 on: July 04, 2018, 01:08:05 PM »
Steve has a library somewhere to export images to PNG format too.

Online FellippeHeitor

  • QB64 Developer
  • LET IT = BE
    • QB64.org
Re: sprite editor
« Reply #14 on: July 04, 2018, 01:22:31 PM »