View unanswered posts | View active topics It is currently Tue Jan 22, 2019 8:58 am

Reply to topic  [ 1 post ] 
 Convert image to RGBA for libnx 
Author Message

Joined: Tue Feb 17, 2015 6:42 pm
Posts: 3

I want to convert a jpeg to rgba for libnx but i have a bug...

I'm on Windows 10 64bits, i have test with ImageMagick "magick convert image.jpg image.rgba", next step rename image.rgba to image.bin, but the display is bad...
I've test with imagemagick Q16-x64-dll & Q8-x64-dll but same result...

What is the good way for convert image for libnx ?

#include <string.h>
#include <stdio.h>
#include <switch.h>

#include "image_bin.h"//Your own raw RGB888 1280x720 image at "data/image.bin" is required.

//See also libnx gfx.h.

int main(int argc, char **argv)
   u32* framebuf;
   u32  cnt=0;
   u8*  imageptr = (u8*)image_bin;

   //Enable max-1080p support. Remove for 720p-only resolution.


   //Set current resolution automatically depending on current/changed OperationMode. Only use this when using gfxInitResolution*().

      //Scan all the inputs. This should be done once for each frame

      //hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame)
      u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO);

      if (kDown & KEY_PLUS) break; // break in order to return to hbmenu

      u32 width, height;
      u32 pos;
      framebuf = (u32*) gfxGetFramebuffer((u32*)&width, (u32*)&height);


      //Each pixel is 4-bytes due to RGBA8888.
      u32 x, y;
      for (y=0; y<height; y++)//Access the buffer linearly.
         for (x=0; x<width; x++)
            pos = y * width + x;
            framebuf[pos] = RGBA8_MAXALPHA(imageptr[pos*3+0], imageptr[pos*3+1], imageptr[pos*3+2]);


   return 0;

The code is same of example without #ifdef DISPLAY_IMAGE and Fade Grey.

Thank you.

result.jpg [192.88 KiB]
Not downloaded yet
image.jpg [81.66 KiB]
Not downloaded yet
Tue Mar 06, 2018 6:18 pm
Display posts from previous:  Sort by  
Reply to topic   [ 1 post ] 

Who is online

Users browsing this forum: No registered users and 3 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
  Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software.
Get devkitPro at Fast, secure and Free Open Source software downloads