Hacking Getting the RGBA value for a pixel?

  • Thread starter Thread starter GalladeGuy
  • Start date Start date
  • Views Views 1,172
  • Replies Replies 5
  • Likes Likes 1

GalladeGuy

Cool and Epic
Member
Joined
Oct 28, 2015
Messages
2,686
Reaction score
2,795
Trophies
2
XP
3,376
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.
 
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
 
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
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,
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
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