Skip to content

Commit

Permalink
0.1.0 Added Bitmap
Browse files Browse the repository at this point in the history
  • Loading branch information
wargio committed Jun 10, 2012
1 parent 5e94efa commit 1eab797
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -40,6 +40,8 @@ Changelog:
Removed old font support.
- 0.0.9b -
Added a few options!.
- 0.1.0 -
Added Bitmap!.


Homebrews built with this lib:
Expand Down
5 changes: 5 additions & 0 deletions include/Background.h
Expand Up @@ -19,6 +19,7 @@
#define __NORSX_BACKGROUND_H__
#include "Min.h"
#include "Colors.h"
#include "Bitmap.h"

class Background{
public:
Expand All @@ -28,6 +29,10 @@ class Background{
void Mono(s32 Color);
// void DoubleGradient(s32 Color1, s32 Color2);


void MonoBitmap(s32 Color, NoRSX_Bitmap *a);


protected:
int frame;
Minimum *G;
Expand Down
48 changes: 48 additions & 0 deletions include/Bitmap.h
@@ -0,0 +1,48 @@
/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
This program was created by Grazioli Giovanni Dante <wargio@libero.it>.
*/

#ifndef __NORSX_BITMAP_H__
#define __NORSX_BITMAP_H__

#include "Min.h"

typedef struct {
uint32_t *bitmap;
} NoRSX_Bitmap;

class Bitmap{
public:
Bitmap(Minimum *g){
G=g;
}

Bitmap(){

}

void GenerateBitmap(NoRSX_Bitmap *a);
void ClearBitmap(NoRSX_Bitmap *a);
void RigenBitmap(NoRSX_Bitmap *a);
void DrawBitmap(NoRSX_Bitmap *a);



private:
Minimum *G;
};

#endif
4 changes: 4 additions & 0 deletions include/Image.h
Expand Up @@ -23,6 +23,7 @@
#include <sysutil/sysutil.h>
#include <sysmodule/sysmodule.h>
#include "Min.h"
#include "Bitmap.h"

//#define CROMAKEY 0xffbcbc222

Expand All @@ -48,6 +49,9 @@ class Image{
void DrawIMG(int x, int y, jpgData *jpg1);
void AlphaDrawIMG(int x, int y, pngData *png1);

void DrawIMGtoBitmap(int x, int y, pngData *png1, NoRSX_Bitmap *a);
void AlphaDrawIMGtoBitmap(int x, int y, pngData *png1, NoRSX_Bitmap *a);

protected:
Minimum *G;
void DrawPartialImage(int x, int y, unsigned int s_width, unsigned int s_height, unsigned int e_width, unsigned int e_height, unsigned int bg, unsigned int color, pngData *png1);
Expand Down
1 change: 1 addition & 0 deletions include/NoRSX.h
Expand Up @@ -27,6 +27,7 @@
#include "Objects.h"
#include "Font.h"
#include "Msg.h"
#include "Bitmap.h"

#include <stdio.h>
#include <malloc.h>
Expand Down
10 changes: 10 additions & 0 deletions source/Background.cpp
Expand Up @@ -12,6 +12,16 @@ void Background::Mono(s32 Color){
G->buffers[G->currentBuffer].ptr[i* G->buffers[G->currentBuffer].width + j] = Color;
}
}

void Background::MonoBitmap(s32 Color, NoRSX_Bitmap *a){
s32 i, j;
for(i = 0; i < G->buffers[G->currentBuffer].height; i++) {
for(j = 0; j < G->buffers[G->currentBuffer].width; j++)
a->bitmap[i* G->buffers[G->currentBuffer].width + j] = Color;
}
}


/*
void Background::DoubleGradient(s32 Color1, s32 Color2){
s32 i, j;
Expand Down
23 changes: 23 additions & 0 deletions source/Bitmap.cpp
@@ -0,0 +1,23 @@
#include "Bitmap.h"


void Bitmap::GenerateBitmap(NoRSX_Bitmap *a){
a->bitmap = new uint32_t[(sizeof(u32) * G->width * G->height)];
}

void Bitmap::ClearBitmap(NoRSX_Bitmap *a){
delete [] a;
}

void Bitmap::RigenBitmap(NoRSX_Bitmap *a){
delete [] a;
a->bitmap = new uint32_t[(sizeof(u32) * G->width * G->height)];
}

void Bitmap::DrawBitmap(NoRSX_Bitmap *a){
s32 i, j;
for(i = 0; i < G->buffers[G->currentBuffer].height; i++) {
for(j = 0; j < G->buffers[G->currentBuffer].width; j++)
G->buffers[G->currentBuffer].ptr[i* G->buffers[G->currentBuffer].width + j] = a->bitmap[i* G->buffers[G->currentBuffer].width + j];
}
}
45 changes: 45 additions & 0 deletions source/Image.cpp
Expand Up @@ -117,3 +117,48 @@ void Image::DrawPartialImage(int x, int y, unsigned int s_width, unsigned int s_
}
}

void Image::DrawIMGtoBitmap(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;
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;
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::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;
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;
unsigned int a = png[m] >> 24; // alpha
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);
}
png+=png1->pitch>>2;
scr+=G->buffers[G->currentBuffer].width;
}
}
}

0 comments on commit 1eab797

Please sign in to comment.