Hacking Getting the RGBA value for a pixel?

GalladeGuy

Cool and Epic
OP
Member
Joined
Oct 28, 2015
Messages
2,686
Trophies
1
XP
3,105
Country
United States
So for something I'm working on, I need to be able to get the RGBA value for a given pixel on either of the screens. Is there a way to do this? I just want a simple function that takes in an X and Y position and a buffer number and returns the RGBA value. Thanks.
 

jc5504

Well-Known Member
Newcomer
Joined
Jan 14, 2015
Messages
60
Trophies
0
Age
27
XP
130
Country
United States
I can't answer your question, but I thought I'd let you know that the gamepad screen has a low resolution, and would have different rgba values than the tv. It has 854x480 resolution, compared to 1920x1080 in most situations. But you may have already known that, haha
 
Joined
Apr 19, 2015
Messages
1,023
Trophies
1
Location
Stuck in the PowerPC
Website
heyquark.com
XP
3,909
Country
Australia
It depends where you're trying to get the pixel from. If it's an OSScreen-enabled homebrew it's really easy (brienj even wrote a routine to take full screenshots for UPaint). GX2 homebrew and retail software takes a bit more work afaik, however there is a bit of homebrew around here somewhere that allows you to open a game (including stuff injected into Mii Maker) then switch into the browser and take a screenshot of the game.

Most OSScreen stuff stores the framebuffer at 0xF4000000 in RGBA8888 format (lucky you!) so some quick multiplication should be able to get something working for you. Try (unsigned int*)(0xF4000000 + (X * 4) + ((Y * X) * 4) or ask brienj.
 
  • Like
Reactions: GalladeGuy

brienj

Trying to avoid getting cancer
Member
Joined
Jan 3, 2016
Messages
1,232
Trophies
0
Website
twitter.com
XP
2,142
Country
United States
For OSScreen framebuffer only -
Code:
// Code to get pointer to either framebuffer

int buf0_size = OSScreenGetBufferSizeEx(0);
char *screenTV = (void *)0xF4000000;
char *screenDRC = (void *)0xF4000000 + buf0_size;
Code:
//  Given x and y for the pixel we want on the TV
// TV Framebuffer is 1280 x 720 (actually 1280 x 1024 I think, but doesn't matter in this case, and doesn't change the formula)

uint32_t pixel = (x + y * 1280) * 4;
char TVr = screenTV[pixel];
char TVg = screenTV[pixel + 1];
char TVb = screenTV[pixel + 2];
char TVa = screenTV[pixel + 3];
Code:
// Given x and y for the pixel we want on the DRC
// DRC Framebuffer is 896 x 480

uint32_t pixel = (x + y * 896) * 4;
char DRCr = screenDRC[pixel];
char DRCg = screenDRC[pixel + 1];
char DRCb = screenDRC[pixel + 2];
char DRCa = screenDRC[pixel + 3];

You can also rewrite the code to return a uint_32t RGBA value as well. I can give that code if you need it as well.
 
Last edited by brienj,

GalladeGuy

Cool and Epic
OP
Member
Joined
Oct 28, 2015
Messages
2,686
Trophies
1
XP
3,105
Country
United States
For OSScreen framebuffer only -
Code:
// Code to get pointer to either framebuffer

int buf0_size = OSScreenGetBufferSizeEx(0);
char *screenTV = (void *)0xF4000000;
char *screenDRC = (void *)0xF4000000 + buf0_size;
Code:
//  Given x and y for the pixel we want on the TV
// TV Framebuffer is 1280 x 720 (actually 1280 x 1024 I think, but doesn't matter in this case, and doesn't change the formula)

uint32_t pixel = (x + y * 1280) * 4;
char TVr = screenTV[pixel];
char TVg = screenTV[pixel + 1];
char TVb = screenTV[pixel + 2];
char TVa = screenTV[pixel + 3];
Code:
// Given x and y for the pixel we want on the DRC
// DRC Framebuffer is 896 x 480

uint32_t pixel = (x + y * 896) * 4;
char DRCr = screenDRC[pixel];
char DRCg = screenDRC[pixel + 1];
char DRCb = screenDRC[pixel + 2];
char DRCa = screenDRC[pixel + 3];

You can also rewrite the code to return a uint_32t RGBA value as well. I can give that code if you need it as well.
Can I have the code to return a uint32_t? Thanks! :)

EDIT: Never mind, I figured it out.
 
Last edited by GalladeGuy,
  • Like
Reactions: brienj

brienj

Trying to avoid getting cancer
Member
Joined
Jan 3, 2016
Messages
1,232
Trophies
0
Website
twitter.com
XP
2,142
Country
United States
Can I have the code to return a uint32_t? Thanks! :)

EDIT: Never mind, I figured it out.
Yeah, the code for that is pretty easy to convert. I was wondering if you might be able to say what this is for, or even PM me if you want it secret. :D

I was just curious what other work is being done.
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • No one is chatting at the moment.
    SylverReZ @ SylverReZ: @OctoAori20, Thank you. Hope you're in good spirits today like I am. :)