draw image pixel_by_pixel (Solved)

Previous topic - Next topic

onugl

I'm tryng to draw an image pixel by pixel, but I don't know how to do it  :whistle:

This is my ugly code
Code (glbasic) Select
// --------------------------------- //
// Project: pic_pixelTopixel
// Start: Sunday, July 20, 2008
// IDE Version: 5.322


SETSCREEN 640, 480, 0   // MODO GRAFICO
LIMITFPS 60

SCREEN_PIXEL("d:/test.png", 640, 480)


FUNCTION SCREEN_PIXEL:image$, zwidth, zheight

LOCAL  gx, gy,  pixel, INCR, c, graphseg = 0;

LOADSPRITE image$, 1

CREATESCREEN 0, 13, zwidth, zheight

USESCREEN 0
DRAWSPRITE 1,0,0

FOR gy = 0 TO zheight - 1
FOR gx = 0 TO zwidth - 1
USESCREEN 0
pixel= GETPIXEL(gx, gy)
USESCREEN -1
USEASBMP
SETPIXEL gx, gy, pixel
SHOWSCREEN
NEXT
NEXT

ENDFUNCTION


Thank you in advance

PeeJay

There's no such thing as a stupid question (but there are stupid answers, usually given by me :D)

The easiest way to do this is using the POLYVECTOR command, where you can display part of an image - saves all the messy screen bits.

Hope that helps ....
www.peejays-remakes.co.uk
For games, remakes, and GL Basic Tutorials
Artificial Intelligence is no match for Natural Stupidity

onugl

 =D Thank you PeeJay, I'll see POLYVECTOR command.

I need to convert pixels to black&white before to put in the screen

I have now this code, but while it is putting pixels, the screen is degradated

Code (glbasic) Select
// this code will put an image pixel by pixel
// but the image is being degradated while pixels is putting in screen

SETSCREEN 640, 480, 0   // MODO GRAFICO
LIMITFPS 60


ZX_SCREEN("d:/test.png", 640, 480, 0,0, 2)
MOUSEWAIT

FUNCTION ZX_SCREEN:grafico$, zwidth, zheight, x, y, velocidad
LOCAL  gx, gy,  pixel

        BLACKSCREEN
GRABSPRITE 2, 0,0, zwidth, zheight  // create a black sprite

LOADSPRITE grafico$, 1


FOR gy = 0 TO zheight - 1

FOR gx = 0 TO zwidth - 1

DRAWSPRITE 1, 0,0  // draw original image

pixel = GETPIXEL(gx, gy)

IF pixel > RGB(255,255,255)/2
pixel = RGB(255,255,255)   // white
ELSE
pixel = RGB(0,0,0)            // black
ENDIF

DRAWSPRITE 2, 0,0

SETPIXEL gx, gy, pixel

GRABSPRITE 2, 0,0, zwidth, zheight  // update black sprite

SHOWSCREEN

NEXT

NEXT

ENDFUNCTION


Sorry for my bad english :D

Kitty Hello

IF pixel > RGB(255,255,255)/2
You can't simply compare it this way.
Check, if the "green" component is bigger than 128:

IF bAND(pixel, 0x00ff00) > 0x008000 ...

PeeJay

If you need it deadly accurate, you will need to compare red, green, and blue components of course, which you could do like this:-

Code (glbasic) Select

pixel = GETPIXEL (x,y)
red = bAND(pixel,255)
green = bAND(pixel/256,255)
blue = bAND(pixel/65536,255)
mono = INTEGER(((red+green+blue)/3)/128)


Where mono would then by 0 for a black pixel, or 1 for a white pixel.

However, be aware that pixel by pixel operations are slow, since it is not really what the language was designed for ;)
www.peejays-remakes.co.uk
For games, remakes, and GL Basic Tutorials
Artificial Intelligence is no match for Natural Stupidity

onugl

Nice! thank you to both. I'll post my code this night :D

Kitty Hello

To make it gray like in TV, use 30% of the red value, 59% of the green value, and 11% of the blue value mixed up. Our eye is more sensual to green and less to blue.

gray = (red*.3+green*.59+blue*.11)
mono = INTEGER(gray/128)

onugl

IN 5-6 hours you can see what I'm tryng to do ;) (retrogaming :D)

PeeJay

I think I already know what you're trying to do, which is recreate a speccy loading screen from the finished image. How are my guessing skills? ;)
www.peejays-remakes.co.uk
For games, remakes, and GL Basic Tutorials
Artificial Intelligence is no match for Natural Stupidity

onugl

#9
 :good: I did it in FENIX/DIV, and now I have it in GLBasic  =)

And I discover my real(nick) name.

I already remaked Mad Mix Game (or Pepsi Challenge), Solomon's Key and Go Bear Go and now I'm working in a new project to learn GLBasic

Ian Price

Ooh! Solomon's Key. I love that game. Download link please :)
I came. I saw. I played.

onugl

Quote from: Ian Price on 2008-Jul-22
Ooh! Solomon's Key. I love that game. Download link please :)
Yeees, It's my favourite 'bar game' (with Tiger Heli)

http://zikitrake.com/ (in FREEWARE-REMAKES zone)


onugl

#12
And this is my solution  ;/

Please modify it to make a better version :nw:

http://zikitrake.com/tmp/ZX_LOAD.RAR

Regards

Kitty Hello

GETPIXEL and USEASBMP in a loop.. well, it looks really really "real", so I hope you're not hoping for a speedup?
Very nice effect.

onugl

#14
 ;/ this is faster than the speed generation of a ZX loading screen :D (I need the current speed because I don't want bored players  :bed:)

See a sample: http://youtube.com/watch?v=FdfJhTle8fg