Getting the RGBA value for a pixel?

Discussion in 'Wii U - Hacking & Backup Loaders' started by GalladeGuy, Jun 12, 2016.

  1. GalladeGuy
    OP

    GalladeGuy Freeze Kirby :3

    Member
    2,536
    2,497
    Oct 28, 2015
    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.
     
    imthe666st likes this.
  2. jc5504

    jc5504 Advanced Member

    Newcomer
    60
    38
    Jan 14, 2015
    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
     
  3. QuarkTheAwesome

    QuarkTheAwesome Working for Hugs

    Member
    761
    1,852
    Apr 19, 2015
    Australia
    Stuck in the PowerPC
    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.
     
    GalladeGuy likes this.
  4. brienj

    brienj Trying to avoid getting cancer

    Member
    1,232
    1,701
    Jan 3, 2016
    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, Jun 12, 2016
    vgmoose and GalladeGuy like this.
  5. GalladeGuy
    OP

    GalladeGuy Freeze Kirby :3

    Member
    2,536
    2,497
    Oct 28, 2015
    United States
    Can I have the code to return a uint32_t? Thanks! :)

    EDIT: Never mind, I figured it out.
     
    Last edited by GalladeGuy, Jun 12, 2016
    brienj likes this.
  6. brienj

    brienj Trying to avoid getting cancer

    Member
    1,232
    1,701
    Jan 3, 2016
    United States
    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.