Welcome! Log In Create A New Profile

Advanced

how do you read a few pixels from an image..

Posted by filfat 
how do you read a few pixels from an image..
October 30, 2012 04:09PM
how to read one singel block in this image?
Re: how do you read a few pixels from an image..
November 19, 2012 02:19PM
Re: how do you read a few pixels from an image..
November 21, 2012 09:50AM
This particular image is a 32bit png, so you need to decode it in your application first.

After that you have an array of 256*256*4 bytes. There are 16x16 blocks in this image. You get the start address of a block like that:

    unsigned char* pImage = DecodePNG(...whatever arguments needed...);

    // get block in row 12, column 13
    int xb = 13;
    int yb = 12;

    unsigned char* pBlock = GetBlockAt(xb, yb, pImage);
    ...

unsigned char* GetBlockAt(int xb, int yb, unsigned char* pImage)
{
    const int imageSizeX = 256;
    const int blockSizeX = 16;
    const int blockSizeY = 16;
    return pImage + ((blockSizeY * yb * imageSizeX) + (blockSizeX * xb) * 4;
}

Is that what you want? You need to be more specific when posting a question, otherwise people will not bother to figure out what you want in the first place.
Re: how do you read a few pixels from an image..
November 23, 2012 10:24PM
ok, GRRlib takes in an X and an Y int. so i need to get the X and Y variabels for exemple the stone block. or if you can help me to code an function i can send you the source of the app

EDIT: I arent god in Codinaters XD

EDIT2: I realy dont get the GX part!!! any easy 3D/2D libs with Doc best was if it has a video tut. for I realy sucks at GX part -_-



Edited 3 time(s). Last edit at 11/23/2012 10:48PM by filfat.
Re: how do you read a few pixels from an image..
November 23, 2012 11:00PM
GRRlib draw an img like this:
GRRLIB_DrawImg(250, 48, terrain, 0, 1/*X*/, 1/*Y*/, 0xffffffff);
//Scale x multiplies the width by x, same for y. 1 for scale leaves the image at original size.
So i want's to change the 1, 1 codinaters to show only one block not the whole terrain.png file.
and sory for the bad explanation. the best would be if you want's to help me on Wiicraft/Minecraft Wii Edition Link:HERE
Re: how do you read a few pixels from an image..
November 24, 2012 11:09AM
Quote
filfat
EDIT2: I realy dont get the GX part!!! any easy 3D/2D libs with Doc best was if it has a video tut. for I realy sucks at GX part -_-

If you want a video tutorial, you could use SDL instead of GRRLIB. SDL is a widely used media library so there are tons of tutorials out there. Also, SDL is for PC which might be more convenient when you want experiment a bit with it. A quick googling for "sdl video tutorial" will take you here: [www.sdltutorials.com].

Happy "coading"! :)



Edited 1 time(s). Last edit at 11/24/2012 11:09AM by profetylen.
Re: how do you read a few pixels from an image..
November 24, 2012 12:13PM
I have try sdl but i only got an error -_- so i will try to use an fresh libogc thanks for the tips =)
Re: how do you read a few pixels from an image..
November 24, 2012 12:51PM
can i use both GRRlib and SDL? for i use GRRlib por the pointers XD
Re: how do you read a few pixels from an image..
November 24, 2012 01:03PM
here is the error:
> "make" 
main.cpp
c:/Users/Filiph/wiicraft-code/source/main.cpp: In function 'int SDL_main()':
c:/Users/Filiph/wiicraft-code/source/main.cpp:179:9: warning: unused variable 'version' [-Wunused-variable]
c:/Users/Filiph/wiicraft-code/source/main.cpp:180:6: warning: unused variable 'xb' [-Wunused-variable]
c:/Users/Filiph/wiicraft-code/source/main.cpp:181:9: warning: unused variable 'yb' [-Wunused-variable]
linking ... wiicraft-code.elf
c:/devkitPro/libogc/lib/wii\libgrrlib.a(GRRLIB_core.o):(.sbss.xfb+0x0): multiple definition of `xfb'
c:/devkitPro/libogc/lib/wii\libSDL.a(SDL_wiivideo.o):c:\Users\Daryl\Desktop\Projects\sdl-wii\SDL/src/video/wii/SDL_wiivideo.c:279: first defined here
c:/devkitPro/libogc/lib/wii\libSDL.a(SDL_wii_main.o): In function `main':
c:\Users\Daryl\Desktop\Projects\sdl-wii\SDL/src/main/wii/SDL_wii_main.c:78: undefined reference to `SDL_main'
c:/devkitPro/libogc/lib/wii\libSDL.a(SDL_wiivideo.o): In function `WII_InitVideoSystem':
SDL_wiivideo.c:(.text.WII_InitVideoSystem+0x42): undefined reference to `TVPal574IntDfScale'
SDL_wiivideo.c:(.text.WII_InitVideoSystem+0x4a): undefined reference to `TVPal574IntDfScale'
collect2: ld returned 1 exit status
make[1]: *** [/c/Users/Filiph/wiicraft-code/wiicraft-code.elf] Error 1
"make": *** [build] Error 2

> Process Exit Code: 2
> Time Taken: 00:03
Re: how do you read a few pixels from an image..
November 24, 2012 05:25PM
I'd imagine using both GRRLIB and SDL would be a very complex thing to do, and also quite pointless. I *think* you are getting this error; "multiple definition of `xfb'" because you are using both of them and both try to connect with libogcs framebuffer. I also *think* you are getting this error; "undefined reference to `SDL_main'" and the other two below it because you are not linking with SDL. (Which would be done in the makefile with the -lsdl option (or something similar to that).

Not to discourage you or anything, but I think you are throwing yourself into very complex stuff without konwing the basics particularily well. I still suggest getting SDL to work on PC first and switching to the Wii. SDL is well documented and, there's really a lot of good tutorials out there.



Edited 1 time(s). Last edit at 11/24/2012 05:26PM by profetylen.
Re: how do you read a few pixels from an image..
December 06, 2012 09:07AM
Quote
filfat
how to read one singel block in this image?
That's a perfectly nice 16 by 16 texture palette, just draw quads (or two triangles) with the right texture coordinates.
See GRRLIB_DrawTileQuad for the math (or just call it directly if you are using GRRLIB). Pseudocode:
texture = GRRLIB_LoadTextureFromFile (filename);
GRRLIB_InitTileSet (texture, 16, 16, 0);
GRRLIB_DrawTileQuad (theQuad, texture, color, frame);
I wonder why GRRLIB doesn't load textures in the Wii's native format as produced by gxtexconv. (There's no reason to convert from PNG to GX native texture format on every load instead of once when building)
Re: how do you read a few pixels from an image..
December 06, 2012 12:04PM
Filfat is using this for his Minecraft clone, meaning he is applying the texture to 3D objects. GRRLIB_DrawTileQuad is only for 2D objects.

I would recommend handling textures yourself instead of GRRLIB, because GRRLIB does not handle mipmaps and texture filtering (which causes flickering/aliasing for distant objects).
Re: how do you read a few pixels from an image..
December 07, 2012 10:55PM
for now i get it work by have one image for every block. but i will look into the problem later =)
Sorry, only registered users may post in this forum.

Click here to login