BASIC

Author Topic: C64-ize graphics  (Read 14054 times)

Offline AndyH

  • Dr. Type
  • ****
  • Posts: 383
    • View Profile
    • http://www.ovine.net/
C64-ize graphics
« Reply #15 on: 2008-Apr-04 »
Vista, yes my drivers are the latest.  I don't really get any problems here - everything runs great (DirectX and OpenGL).

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10714
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
C64-ize graphics
« Reply #16 on: 2008-Apr-04 »
Updated the file. Working now?

Offline Ian Price

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 4147
  • On the shoulders of giants.
    • View Profile
    • My Apps
C64-ize graphics
« Reply #17 on: 2008-Apr-04 »
It works now, but it takes an age (it says "LOADING" for a good few seconds) and the square no longer rotates (in fact the program appears to cease after it has displayed the image).
I came. I saw. I played.

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10714
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
C64-ize graphics
« Reply #18 on: 2008-Apr-08 »
Update. Should work on more cards now.

Offline Ian Price

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 4147
  • On the shoulders of giants.
    • View Profile
    • My Apps
C64-ize graphics
« Reply #19 on: 2008-Apr-08 »
Nope. It dies now before any image is displayed, after a long "Loading" screen. :(
I came. I saw. I played.

Offline Albert

  • Dr. Type
  • ****
  • Posts: 257
    • View Profile
    • Blog
C64-ize graphics
« Reply #20 on: 2008-Apr-08 »
Working fine on Radeon HD2600 pro

Offline PeeJay

  • Mr. Polyvector
  • ***
  • Posts: 244
    • View Profile
    • PeeJays Remakes
C64-ize graphics
« Reply #21 on: 2008-Apr-08 »
Works great on my dinosaur too! :)
www.peejays-remakes.co.uk
For games, remakes, and GL Basic Tutorials
Artificial Intelligence is no match for Natural Stupidity

Offline Qedo

  • Mr. Polyvector
  • ***
  • Posts: 167
  • UNUS SED LEO
    • View Profile
Re: C64-ize graphics
« Reply #22 on: 2019-Feb-10 »
I enjoyed optimizing the no shader version.
On my pc 20 ms with standard programming

Code: GLBasic [Select]
SETFONT 0,2
GLOBAL pixels%[],id%=0
IF DOESFILEEXIST("test.png")
        LOADSPRITE "test.png",id
ENDIF
SPRITE2MEM (pixels[],id)
GETSPRITESIZE id, sx%, sy%
dtime% = GETTIMERALL()
C64ize()
MEM2SPRITE(pixels[],id,sx,sy)
dtime% = GETTIMERALL()-dtime%
DRAWSPRITE id,0,0
SAVESPRITE "test.bmp", id
PRINT dtime%,10,300
SHOWSCREEN
MOUSEWAIT
END

FUNCTION C64ize:
        // weighting of color components
LOCAL x%,y%,c%, r%,g%,b%, dr%,dg%,db%
LOCAL mindist, dist, ibest, i
LOCAL c64_pal[]
        DIMDATA c64_pal[], _
                        0x00    , 0x00  , 0x00, 0, _
                        0xff    , 0xff  , 0xff, 0, _
                        0x88    , 0x00  , 0x00, 0, _
                        0xaa    , 0xff  , 0xee, 0, _
                        0xcc    , 0x44  , 0xcc, 0, _
                        0x00    , 0xcc  , 0x55, 0, _
                        0x00    , 0x00  , 0xaa, 0, _
                        0xee    , 0xee  , 0x77, 0, _
                        0xdd    , 0x88  , 0x55, 0, _
                        0x66    , 0x44  , 0x00, 0, _
                        0xff    , 0x77  , 0x77, 0, _
                        0x33    , 0x33  , 0x33, 0, _
                        0x77    , 0x77  , 0x77, 0, _
                        0xaa    , 0xff  , 0x66, 0, _
                        0x00    , 0x88  , 0xff, 0, _
                        0xbb    , 0xbb  , 0xbb, 0

        FOR i=0 TO 15
                c64_pal[i*4+3] = RGB(c64_pal[i*4], c64_pal[i*4+1], c64_pal[i*4+2])
        NEXT

        FOR x=0 TO 319 STEP 2
                FOR y=0 TO 239
                                                ind=x+y*320
                        c = pixels[ind]
                                                c = BAND(c, 0xffffff)
                                            r=BAND(c, 0xff)/2
                                                g=BAND(ASR(c,8), 0xff)/2
                                                b=BAND(ASR(c,16), 0xff)/2
                        mindist=0
                        c = pixels[ind+1]
                                                c = BAND(c, 0xffffff)
                                            INC r,BAND(c, 0xff)/2
                                                INC g,BAND(ASR(c,8), 0xff)/2
                                                INC b,BAND(ASR(c,16), 0xff)/2
                        ibest=0
                        FOR i=0 TO 15
                                                                db=b - c64_pal[i*4+2]
                                                                dg=g - c64_pal[i*4+1]
                                                                dr=r - c64_pal[i*4  ]
                                dist=dr*dr+dg*dg+db*db
                                IF i=0 OR dist<mindist
                                        mindist=dist
                                        ibest=i
                                ENDIF
                        NEXT
                        fillcolour=BOR(c64_pal[ibest*4+3], ASL(255, 24))
                        pixels[ind]=fillcolour
                        pixels[ind+1]=fillcolour
                NEXT
        NEXT
ENDFUNCTION

 

Offline dreamerman

  • Global Moderator
  • Dr. Type
  • *******
  • Posts: 288
    • View Profile
    • my personal website
Re: C64-ize graphics
« Reply #23 on: 2019-Feb-10 »
Am I missing something? As both pure in-code effects doesn't work for me :/ bitmap remains unchanged (24bit bmp GLB logo). Or maybe there is something more to this code as not all variables were declared, probably I'm blind :D
On other hand, change 'c64_pal' array from floats to integers -> "LOCAL c64_pal%[]" as this should fast it up to 15ms..
Check my source code editor for GLBasic - link

Offline Qedo

  • Mr. Polyvector
  • ***
  • Posts: 167
  • UNUS SED LEO
    • View Profile
Re: C64-ize graphics
« Reply #24 on: 2019-Feb-10 »
 Yes the file test.bmp is 24bit but inside there are only 16 colours.
Change the array to integer don't improve on my pc.

Offline dreamerman

  • Global Moderator
  • Dr. Type
  • *******
  • Posts: 288
    • View Profile
    • my personal website
Re: C64-ize graphics
« Reply #25 on: 2019-Feb-10 »
I mean input bitmap that I'm using is 24bit bmp GLB logo, and the result/output bitmap 'test.bmp' is also 24bit with full color range, checked with gimp - same as result drawn on screen when running this code. hm.. probably some mismatch from pasting code but can't find it :>
Strange, because changing to integers should give speed up around 25%-30%, double checked on my pc, and btw. didn't noticed that also some other variables are floats, at least in this code on forum..
Code: GLBasic [Select]
LOCAL mindist%, dist%, ibest%, i%
LOCAL c64_pal%[]
that gives speed bump from 22ms to 11ms, on my i5.
Check my source code editor for GLBasic - link

Offline Qedo

  • Mr. Polyvector
  • ***
  • Posts: 167
  • UNUS SED LEO
    • View Profile
Re: C64-ize graphics
« Reply #26 on: 2019-Feb-11 »
Try with this file.

Offline dreamerman

  • Global Moderator
  • Dr. Type
  • *******
  • Posts: 288
    • View Profile
    • my personal website
Re: C64-ize graphics
« Reply #27 on: 2019-Feb-12 »
Yep this file works, and now I see what was the issue :)
Both FOR loops in main function are fixed to this image dimensions - 320x240px, despite checking sprite size with GETSPRITESIZE. How could I miss that :/
Easy to fix and now works great :-) And now I know where to use this with combination of Your FastMem2Sprite - or that Shader version by Gernot :D Thanks!
« Last Edit: 2019-Feb-12 by dreamerman »
Check my source code editor for GLBasic - link