Author Topic: draw image pixel_by_pixel (Solved)  (Read 1365 times)

onugl

  • Guest
draw image pixel_by_pixel (Solved)
« on: 2008-Jul-20 »
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
« Last Edit: 2008-Jul-23 by zikitrake »

Offline PeeJay

  • Mr. Polyvector
  • ***
  • Posts: 244
    • View Profile
    • PeeJays Remakes
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

  • Guest
 =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
« Last Edit: 2008-Jul-21 by onugl »

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *****
  • Posts: 10294
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
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 ...

Offline PeeJay

  • Mr. Polyvector
  • ***
  • Posts: 244
    • View Profile
    • PeeJays Remakes
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

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

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *****
  • Posts: 10294
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
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

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

Offline PeeJay

  • Mr. Polyvector
  • ***
  • Posts: 244
    • View Profile
    • PeeJays Remakes
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

  • Guest
 :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
« Last Edit: 2008-Jul-22 by zikitrake »

Offline Ian Price

  • Global Moderator
  • Prof. Inline
  • ****
  • Posts: 3122
  • On the shoulders of giants.
    • View Profile
    • My Apps
Ooh! Solomon's Key. I love that game. Download link please :)
I came. I saw. I played.

onugl

  • Guest
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

  • Guest
And this is my solution  ;/

Please modify it to make a better version :nw:

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

Regards
« Last Edit: 2008-Jul-22 by zikitrake »

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *****
  • Posts: 10294
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
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

  • Guest
 ;/ 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
« Last Edit: 2008-Jul-22 by zikitrake »