Skip to content
Browse files

0.1.1c - Performance Patch + DrawIMGtoBitmap function for JPG

  • Loading branch information...
1 parent 8f2a71f commit adf7ed877bdbed1f9e0fd0010cc8d6eaf5a9686d @wargio committed
Showing with 105 additions and 28 deletions.
  1. +3 −0 README.md
  2. +1 −0 include/Image.h
  3. +94 −25 source/Image.cpp
  4. +7 −3 source/main.cpp
View
3 README.md
@@ -59,6 +59,9 @@ Changelog:
They needs to be initialized as this Example: NoRSX GFX(RESOLUTION_1280x720);
- 0.1.1b -
Fixed Screen Size bugs.
+ - 0.1.1c -
+ Performance Patch by KDSBest (Just for Images).
+ Added DrawIMGtoBitmap function for JPG (I forgot this one!)
Homebrews built with this lib:
View
1 include/Image.h
@@ -50,6 +50,7 @@ class Image{
void AlphaDrawIMG(int x, int y, pngData *png1);
void DrawIMGtoBitmap(int x, int y, pngData *png1, NoRSX_Bitmap *a);
+ void DrawIMGtoBitmap(int x, int y, jpgData *jpg1, NoRSX_Bitmap *a);
void AlphaDrawIMGtoBitmap(int x, int y, pngData *png1, NoRSX_Bitmap *a);
protected:
View
119 source/Image.cpp
@@ -17,18 +17,24 @@ void Image::LoadJPG_Buf(const void* name, u32 name_size, jpgData *jpg){
}
void Image::DrawIMG(int x, int y, pngData *png1){
+
if(png1->bmp_out){
u32 *scr = (u32 *)G->buffers[G->currentBuffer].ptr;
u32 *png= (u32 *)(void *)png1->bmp_out;
unsigned int n, m;
scr += y*G->buffers[G->currentBuffer].width+x;
- for(n=0;n<png1->height;n++){
- if((y+n)>=G->buffers[G->currentBuffer].height) break;
- for(m=0;m<png1->width;m++){
- if((x+m)>=G->buffers[G->currentBuffer].width) break;
+ u32 height = png1->height;
+ if((y+height) >= G->buffers[G->currentBuffer].height)
+ height = G->buffers[G->currentBuffer].height;
+
+ u32 width = png1->width;
+ if((x+width) >=G->buffers[G->currentBuffer].width)
+ width = G->buffers[G->currentBuffer].width;
+
+ for(n=0;n < height;n++){
+ for(m=0;m < width;m++)
scr[m]=png[m];
- }
png+=png1->pitch>>2;
scr+=G->buffers[G->currentBuffer].width;
}
@@ -42,12 +48,17 @@ void Image::DrawIMG(int x, int y, jpgData *jpg1){
unsigned int n, m;
scr += y*G->buffers[G->currentBuffer].width+x;
- for(n=0;n<jpg1->height;n++){
- if((y+n)>=G->buffers[G->currentBuffer].height) break;
- for(m=0;m<jpg1->width;m++){
- if((x+m)>=G->buffers[G->currentBuffer].width) break;
+ u32 height = jpg1->height;
+ if((y+height) >= G->buffers[G->currentBuffer].height)
+ height = G->buffers[G->currentBuffer].height;
+
+ u32 width = jpg1->width;
+ if((x+width) >=G->buffers[G->currentBuffer].width)
+ width = G->buffers[G->currentBuffer].width;
+
+ for(n=0;n < height;n++){
+ for(m=0;m < width;m++)
scr[m]=jpg[m];
- }
jpg+=jpg1->pitch>>2;
scr+=G->buffers[G->currentBuffer].width;
}
@@ -61,6 +72,28 @@ void Image::AlphaDrawIMG(int x, int y, pngData *png1){
unsigned int n, m;
scr += y*G->buffers[G->currentBuffer].width+x;
+ u32 height = png1->height;
+ if((y+height) >= G->buffers[G->currentBuffer].height)
+ height = G->buffers[G->currentBuffer].height;
+
+ u32 width = png1->width;
+ if((x+width) >=G->buffers[G->currentBuffer].width)
+ width = G->buffers[G->currentBuffer].width;
+
+ for(n=0;n < height;n++){
+ for(m=0;m < width;m++){
+ unsigned int a = png[m] >> 24; // alpha
+ u32 OxFF_A = 0xff - a;
+ if (0 != a)
+ scr[m] = (png[m] & 0xff000000) | ( (((((png[m] & 0x00ff00ff) * a) + ((scr[m] & 0x00ff00ff) *
+ (OxFF_A))) & 0xff00ff00) | ((((png[m] & 0x0000ff00) * a) + ((scr[m] & 0x0000ff00) *
+ (OxFF_A))) & 0x00ff0000)) >> 8);
+ }
+ png+=png1->pitch>>2;
+ scr+=G->buffers[G->currentBuffer].width;
+ }
+/*
+ scr += y*G->buffers[G->currentBuffer].width+x;
for(n=0;n<png1->height;n++){
if((y+n)>=G->buffers[G->currentBuffer].height) break;
for(m=0;m<png1->width;m++){
@@ -75,6 +108,7 @@ void Image::AlphaDrawIMG(int x, int y, pngData *png1){
png+=png1->pitch>>2;
scr+=G->buffers[G->currentBuffer].width;
}
+*/
}
}
@@ -125,37 +159,72 @@ void Image::DrawIMGtoBitmap(int x, int y, pngData *png1, NoRSX_Bitmap *a){
unsigned int n, m;
scr += y*G->buffers[G->currentBuffer].width+x;
- for(n=0;n<png1->height;n++){
- if((y+n)>=G->buffers[G->currentBuffer].height) break;
- for(m=0;m<png1->width;m+=4){
- if((x+m)>=G->buffers[G->currentBuffer].width) break;
+ u32 height = png1->height;
+ if((y+height) >= G->buffers[G->currentBuffer].height)
+ height = G->buffers[G->currentBuffer].height;
+
+ u32 width = png1->width;
+ if((x+width) >=G->buffers[G->currentBuffer].width)
+ width = G->buffers[G->currentBuffer].width;
+
+ for(n=0;n < height;n++){
+ for(m=0;m < width;m++)
scr[m]=png[m];
- scr[m+1]=png[m+1];
- scr[m+2]=png[m+2];
- scr[m+3]=png[m+3];
- }
png+=png1->pitch>>2;
scr+=G->buffers[G->currentBuffer].width;
}
}
}
+
+void Image::DrawIMGtoBitmap(int x, int y, jpgData *jpg1, NoRSX_Bitmap *a){
+ if(jpg1->bmp_out){
+ u32 *scr = (u32 *)a->bitmap;
+ u32 *jpg= (u32 *)(void *)jpg1->bmp_out;
+ unsigned int n, m;
+
+ scr += y*G->buffers[G->currentBuffer].width+x;
+ u32 height = jpg1->height;
+ if((y+height) >= G->buffers[G->currentBuffer].height)
+ height = G->buffers[G->currentBuffer].height;
+
+ u32 width = jpg1->width;
+ if((x+width) >=G->buffers[G->currentBuffer].width)
+ width = G->buffers[G->currentBuffer].width;
+
+ for(n=0;n < height;n++){
+ for(m=0;m < width;m++)
+ scr[m]=jpg[m];
+ jpg+=jpg1->pitch>>2;
+ scr+=G->buffers[G->currentBuffer].width;
+ }
+ }
+}
+
+
void Image::AlphaDrawIMGtoBitmap(int x, int y, pngData *png1, NoRSX_Bitmap *a){
if(png1->bmp_out){
u32 *scr = (u32 *)a->bitmap;
- u32 *png = (u32 *)(void *)png1->bmp_out;
+ u32 *png= (u32 *)(void *)png1->bmp_out;
unsigned int n, m;
scr += y*G->buffers[G->currentBuffer].width+x;
- for(n=0;n<png1->height;n++){
- if((y+n)>=G->buffers[G->currentBuffer].height) break;
- for(m=0;m<png1->width;m++){
- if((x+m)>=G->buffers[G->currentBuffer].width) break;
+ u32 height = png1->height;
+ if((y+height) >= G->buffers[G->currentBuffer].height)
+ height = G->buffers[G->currentBuffer].height;
+
+ u32 width = png1->width;
+ if((x+width) >=G->buffers[G->currentBuffer].width)
+ width = G->buffers[G->currentBuffer].width;
+
+ for(n=0;n < height;n++){
+ for(m=0;m < width;m++){
unsigned int a = png[m] >> 24; // alpha
+ u32 OxFF_A = 0xff - a;
if (0 != a)
scr[m] = (png[m] & 0xff000000) | ( (((((png[m] & 0x00ff00ff) * a) + ((scr[m] & 0x00ff00ff) *
- (0xff - a))) & 0xff00ff00) | ((((png[m] & 0x0000ff00) * a) + ((scr[m] & 0x0000ff00) *
- (0xff - a))) & 0x00ff0000)) >> 8);
+ (OxFF_A))) & 0xff00ff00) | ((((png[m] & 0x0000ff00) * a) + ((scr[m] & 0x0000ff00) *
+ (OxFF_A))) & 0x00ff0000)) >> 8);
}
png+=png1->pitch>>2;
scr+=G->buffers[G->currentBuffer].width;
View
10 source/main.cpp
@@ -39,7 +39,7 @@ static inline void eventHandler(u64 status, u64 param, void * userdata)
}
}
-msgType MSG_OK = (msgType)(MSG_DIALOG_NORMAL | MSG_DIALOG_BTN_TYPE_OK | MSG_DIALOG_DISABLE_CANCEL_ON);
+//msgType MSG_OK = (msgType)(MSG_DIALOG_NORMAL | MSG_DIALOG_BTN_TYPE_OK | MSG_DIALOG_DISABLE_CANCEL_ON);
s32 main(s32 argc, const char* argv[])
{
@@ -51,7 +51,7 @@ s32 main(s32 argc, const char* argv[])
pngData png;
- NoRSX *GFX = new NoRSX(RESOLUTION_1280x720); //set defined screen resolution
+ NoRSX *GFX = new NoRSX(RESOLUTION_1280x720); //set defined screen resolution You can change it to: RESOLUTION_720x480 | RESOLUTION_720x576 | RESOLUTION_1280x720 | RESOLUTION_1920x1080
Image IMG(GFX);
Background BG(GFX);
Object OBJ(GFX);
@@ -59,7 +59,7 @@ s32 main(s32 argc, const char* argv[])
NoRSX_Bitmap Precalculated_Layer;
- BMap.GenerateBitmap(&Precalculated_Layer);
+ BMap.GenerateBitmap(&Precalculated_Layer); //Initialize the Bitmap
Font F1(Sans_ttf,Sans_ttf_size ,GFX); //Loaded from Memory
Font F2("/dev_hdd0/game/NORSX0000/GOODTIME.ttf" ,GFX); //Loaded from File!
@@ -69,8 +69,12 @@ s32 main(s32 argc, const char* argv[])
u32 imgX =(GFX->width/2)-(png.width/2), imgY = (GFX->height/2)-(png.height/2);
BG.MonoBitmap(0xb4e83a,&Precalculated_Layer); //a green hex color (you can use hex colors insted of COLOR_XXXXXXX)
+
IMG.DrawIMGtoBitmap(imgX,imgY,&png,&Precalculated_Layer);
+
OBJ.CircleToBitmap(500,500,50,COLOR_YELLOW,&Precalculated_Layer);
+
+
F1.PrintfToBitmap(150,200,&Precalculated_Layer,COLOR_RED,"Screen %d x %d",GFX->width,GFX->height);
F1.PrintfToBitmap(150,250,&Precalculated_Layer,COLOR_BLUE, 35,"Press X to exit!");
F2.PrintfToBitmap(150,300,&Precalculated_Layer,COLOR_GREEN,20,"FreeType2 with TTF support :)");

0 comments on commit adf7ed8

Please sign in to comment.
Something went wrong with that request. Please try again.