Skip to content

Commit

Permalink
0.1.8 (Added Animations and new Bitmap Functions
Browse files Browse the repository at this point in the history
  • Loading branch information
wargio committed Sep 7, 2012
1 parent 4bb7b6e commit 4f5642e
Show file tree
Hide file tree
Showing 8 changed files with 306 additions and 6 deletions.
5 changes: 4 additions & 1 deletion README.md
Expand Up @@ -74,7 +74,10 @@ Changelog:
New Header. now to include NoRSX inside your code, you will need to add the new header <NoRSX.h> New Header. now to include NoRSX inside your code, you will need to add the new header <NoRSX.h>
Added EventHandler. it is included with <NoRSX.h> you don't need to use it. it's already configured by the lib. Added EventHandler. it is included with <NoRSX.h> you don't need to use it. it's already configured by the lib.
- 0.1.6 - - 0.1.6 -
added gradient for background color. Added gradient for background color.
- 0.1.8 -
Added Animation.cpp and Animation.h to create animations
New Bitmap Functions


Homebrews built with this lib: Homebrews built with this lib:
------------------------------ ------------------------------
Expand Down
183 changes: 183 additions & 0 deletions libNoRSX/Animation.cpp
@@ -0,0 +1,183 @@
#include "Animation.h"
#include <stdio.h>
#include <stdint.h>

void Animation::LoadAnimation (uint32_t Elem_num, uint32_t Elem_w, uint32_t Elem_h, uint32_t ChromaKey, pngData* PNG, NoRSX_Animation *anim){
if(PNG->bmp_out && anim->load != 0){
anim->load = 0;
anim->bitmap = new uint32_t[(const int)(PNG->height*PNG->width)];
anim->bitmap_height = PNG->height;
anim->bitmap_width = PNG->width;
anim->elem_num = Elem_num;
anim->elem_height = Elem_h;
anim->elem_width = Elem_w;
anim->elem_y=0;
anim->elem_x=0;
anim->chromakey = ChromaKey;

uint32_t *png = (uint32_t *)(void *)PNG->bmp_out;

for(uint32_t y=0, i=0; y<PNG->height; y+=Elem_h){
if(i>anim->elem_num)
break;

anim->elem_x=0;
for(uint32_t x=0; x<PNG->width;i++,x+=Elem_w){
if(i>anim->elem_num)
break;

anim->elem_x++;
}
anim->elem_y++;
}
for(u32 n=0, i=0;n < PNG->height;n++,i+=anim->bitmap_width){
for(u32 m=0;m < PNG->width;m++)
anim->bitmap[i+m]=png[m];
png+=PNG->pitch>>2;
}
}
}


void Animation::LoadAnimation (uint32_t Elem_num, uint32_t Elem_w, uint32_t Elem_h, pngData* PNG, NoRSX_Animation *anim){
if(PNG->bmp_out && anim->load != 0){
anim->load = 0;
anim->bitmap = new uint32_t[(const int)(PNG->height*PNG->width)];
anim->bitmap_height = PNG->height;
anim->bitmap_width = PNG->width;
anim->elem_num = Elem_num;
anim->elem_height = Elem_h;
anim->elem_width = Elem_w;
anim->elem_y=0;
anim->elem_x=0;
anim->chromakey = ANIMATION_ALPHA_CHROMAKEY;

uint32_t *png = (uint32_t *)(void *)PNG->bmp_out;

for(uint32_t y=0, i=0; y<PNG->height; y+=Elem_h){
if(i>anim->elem_num)
break;

anim->elem_x=0;
for(uint32_t x=0; x<PNG->width;i++,x+=Elem_w){
if(i>anim->elem_num)
break;

anim->elem_x++;
}
anim->elem_y++;
}
for(u32 n=0, i=0;n < PNG->height;n++,i+=anim->bitmap_width){
for(u32 m=0;m < PNG->width;m++)
anim->bitmap[i+m]=png[m];
png+=PNG->pitch>>2;
}
}
}

void Animation::LoadAnimation (uint32_t Elem_num, uint32_t Elem_w, uint32_t Elem_h, uint32_t ChromaKey, jpgData* JPG, NoRSX_Animation *anim){
if(JPG->bmp_out && anim->load != 0){
anim->load = 0;
anim->bitmap = new uint32_t[(const int)(JPG->height*JPG->width)];
anim->bitmap_height = JPG->height;
anim->bitmap_width = JPG->width;
anim->elem_num = Elem_num;
anim->elem_height = Elem_h;
anim->elem_width = Elem_w;
anim->elem_y=0;
anim->elem_x=0;
anim->chromakey = ChromaKey;
for(uint32_t y=0, i=0; y<JPG->height || i<=anim->elem_num; y+=Elem_h,i++){
for(uint32_t x=0; x<JPG->width || i<=anim->elem_num; x+=Elem_w,i++){
anim->elem_x++;
}
anim->elem_y++;
}
uint32_t *jpg = (uint32_t *)(void *)JPG->bmp_out;
for(u32 n=0;n < JPG->height;n++){
for(u32 m=0;m < JPG->width;m++)
anim->bitmap[m]=jpg[m];
jpg+=JPG->pitch>>2;
anim->bitmap+=anim->bitmap_width;
}
}
}

void Animation::CleanAnimation(NoRSX_Animation *anim){
if(anim->load){
anim->load = 1;
free(anim->bitmap);
delete [] anim->bitmap;
}
}

void Animation::DrawAnimation (uint32_t X, uint32_t Y, uint32_t frame, NoRSX_Animation *anim){
if(anim->load==0 && !(frame < 0)){
uint32_t size = G->height*G->width, scr = Y*G->height+X, y_pos = 0;
if(scr>=size)
scr = size;

if(frame > anim->elem_num)
frame = anim->elem_num;

while(frame >= anim->elem_x){
frame -=anim->elem_x;
y_pos++;
}

u32 *screen = (uint32_t *)G->buffers[G->currentBuffer].ptr;
u32 *bitmap = (uint32_t *)anim->bitmap;
uint32_t n, m,j, pos = 0;

screen += Y*G->width+X;
pos = (frame*anim->elem_width)+(y_pos*anim->bitmap_height*anim->elem_width);
for(n=0;n<anim->elem_height;n++){
for(m=0,j=0;m<anim->elem_width;m++,j++){
if(bitmap[pos+m]!=anim->chromakey)
screen[j]=bitmap[pos+m];
}
pos += anim->bitmap_width;
screen+=G->width;
}

}
}

void Animation::AlphaDrawAnimation (uint32_t X, uint32_t Y, uint32_t frame, NoRSX_Animation *anim){
if(anim->load==0 && !(frame < 0)){
uint32_t size = G->height*G->width, scr = Y*G->height+X, y_pos = 0;
if(scr>=size)
scr = size;

if(frame > anim->elem_num)
frame = anim->elem_num;

while(frame >= anim->elem_x){
frame -=anim->elem_x;
y_pos++;
}

u32 *screen = (uint32_t *)G->buffers[G->currentBuffer].ptr;
u32 *bitmap = (uint32_t *)anim->bitmap;
uint32_t n, m, j, pos = 0;

screen += Y*G->width+X;
pos = y_pos*(anim->bitmap_height*anim->elem_width)+(frame*anim->elem_width);
for(n=0;n<anim->elem_height;n++){
for(m=0,j=0;m<anim->elem_width;m++,j++){
unsigned int a = bitmap[pos+m] >> 24; // alpha
u32 OxFF_A = 0xff - a;
if (0 != a)
screen[j] = (bitmap[pos+m] & 0xff000000) | ((((((bitmap[pos+m] & 0x00ff00ff) * a) + ((screen[j] & 0x00ff00ff) *
(OxFF_A))) & 0xff00ff00) | ((((bitmap[pos+m] & 0x0000ff00) * a) + ((screen[j] & 0x0000ff00) *
(OxFF_A))) & 0x00ff0000)) >> 8);

}
pos += anim->bitmap_width;
screen+=G->width;
}

}
}


2 changes: 1 addition & 1 deletion libNoRSX/Background.cpp
Expand Up @@ -72,7 +72,7 @@ void Background::Gradient(u32 Color1, u32 Color2){ //G->buffers[G->currentBuffer
} }


void Background::GradientBitmap(u32 Color1, u32 Color2, NoRSX_Bitmap *a){ void Background::GradientBitmap(u32 Color1, u32 Color2, NoRSX_Bitmap *a){
s32 size = G->buffers[G->currentBuffer].height * G->buffers[G->currentBuffer].width; u32 size = G->height * G->width;
u8 Color_Red = R(Color2); u8 Color_Red = R(Color2);
u8 Color_Blue = B(Color2); u8 Color_Blue = B(Color2);
u8 Color_Green = G(Color2); u8 Color_Green = G(Color2);
Expand Down
42 changes: 40 additions & 2 deletions libNoRSX/Bitmap.cpp
@@ -1,8 +1,36 @@
#include <NoRSX/Bitmap.h>


/*
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>.
*/

#include <NoRSX/Bitmap.h>


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

void Bitmap::GenerateCustomBitmap(uint32_t width, uint32_t height, NoRSX_Bitmap *a){
a->bitmap = new uint32_t[width*height];

a->height = height;
a->width = width;

a->load = 1; a->load = 1;
} }


Expand Down Expand Up @@ -31,3 +59,13 @@ void Bitmap::DrawBitmap(NoRSX_Bitmap *a){
} }
} }
} }

void Bitmap::DrawCustomBitmap(uint32_t start_width, uint32_t start_height, uint32_t end_width, uint32_t end_height, NoRSX_Bitmap *a){
if(a->load==1){
s32 size = G->buffers[G->currentBuffer].height * G->buffers[G->currentBuffer].width;
u32 pos = start_height*a->width+start_width;
for(s32 i = 0; i < size; i++) {
G->buffers[G->currentBuffer].ptr[i] = a->bitmap[pos+i];
}
}
}
4 changes: 2 additions & 2 deletions libNoRSX/Makefile
Expand Up @@ -43,7 +43,7 @@ CXXFLAGS := $(CFLAGS)
VPATH := $(BASEDIR) VPATH := $(BASEDIR)


#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
OBJS := Background.o Font.o Min.o NoRSX.o NoRSXutil.o Bitmap.o Image.o Msg.o Objects.o EventHandler.o OBJS := Background.o Font.o Min.o NoRSX.o NoRSXutil.o Bitmap.o Image.o Msg.o Objects.o EventHandler.o Animation.o


#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
all: install-headers ppu install all: install-headers ppu install
Expand Down Expand Up @@ -86,7 +86,7 @@ lib: $(LIBRARY).a
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
clean: clean:
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
@echo clean ... @echo lib cleaned ...
@rm -rf ppu @rm -rf ppu
@rm -rf $(DEPS) @rm -rf $(DEPS)
@rm -rf $(LIBS) @rm -rf $(LIBS)
Expand Down
1 change: 1 addition & 0 deletions libNoRSX/NoRSX.h
Expand Up @@ -27,6 +27,7 @@
#include <NoRSX/Msg.h> #include <NoRSX/Msg.h>
#include <NoRSX/Bitmap.h> #include <NoRSX/Bitmap.h>
#include <NoRSX/EventHandler.h> #include <NoRSX/EventHandler.h>
#include <NoRSX/Animation.h>


#include <stdio.h> #include <stdio.h>
#include <malloc.h> #include <malloc.h>
Expand Down
70 changes: 70 additions & 0 deletions libNoRSX/NoRSX/Animation.h
@@ -0,0 +1,70 @@
/*
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_ANIMATION_H__
#define __NORSX_ANIMATION_H__

#include "Min.h"
#include "Image.h"

#define ANIMATION_ALPHA_CHROMAKEY 0x000000ff


typedef struct {
//ALL THESE VALUES ARE LOADED WHEN YOU WILL CALL LoadAnimation() FUNCTION

uint32_t elem_num; //the number of elements of the animation.
uint32_t elem_height; //the height of a single element
uint32_t elem_width; //the width of a single element


//DON'T CHANGE THE FOLLOWINGS VALUES IN YOUR CODE.

uint32_t chromakey; //Chroma Key. you don't need it if you will use AlphaDrawAnimation
uint32_t bitmap_height;//the height of the bitmap (DO NOT CHANGE IT) this element is loaded automatically
uint32_t bitmap_width; //the width of the bitmap (DO NOT CHANGE IT) this element is loaded automatically
int load; //check if something it's loaded
uint32_t elem_x; //it is needed to calculate the frame. DO NOT CHANGE IT
uint32_t elem_y; //it is needed to calculate the frame. DO NOT CHANGE IT
uint32_t *bitmap;
} NoRSX_Animation;


class Animation{
public:
Animation(Minimum *g){
G=g;
}
~Animation(){}
//use this only if you will use AlphaDrawAnimation
void LoadAnimation (uint32_t Elem_num, uint32_t Elem_w, uint32_t Elem_h, pngData* PNG, NoRSX_Animation *anim);

//use these for AlphaDrawAnimation and DrawAnimation
void LoadAnimation (uint32_t Elem_num, uint32_t Elem_w, uint32_t Elem_h, uint32_t ChromaKey, pngData* PNG, NoRSX_Animation *anim);
void LoadAnimation (uint32_t Elem_num, uint32_t Elem_w, uint32_t Elem_h, uint32_t ChromaKey, jpgData* JPG, NoRSX_Animation *anim);

//REMEMBER TO CLEAN THE NoRSX_Animation struct before the NoRSX_Exit() function.
void CleanAnimation(NoRSX_Animation *anim);

void DrawAnimation (uint32_t X, uint32_t Y, uint32_t frame, NoRSX_Animation *anim);
void AlphaDrawAnimation (uint32_t X, uint32_t Y, uint32_t frame, NoRSX_Animation *anim);

private:
Minimum *G;
};

#endif
5 changes: 5 additions & 0 deletions libNoRSX/NoRSX/Bitmap.h
Expand Up @@ -22,6 +22,9 @@


typedef struct { typedef struct {
uint32_t *bitmap; uint32_t *bitmap;
uint32_t width;
uint32_t height;

int load; int load;
} NoRSX_Bitmap; } NoRSX_Bitmap;


Expand All @@ -36,8 +39,10 @@ class Bitmap{
} }


void GenerateBitmap(NoRSX_Bitmap *a); void GenerateBitmap(NoRSX_Bitmap *a);
void GenerateCustomBitmap(uint32_t width, uint32_t height, NoRSX_Bitmap *a);
void ClearBitmap(NoRSX_Bitmap *a); void ClearBitmap(NoRSX_Bitmap *a);
void RegenBitmap(NoRSX_Bitmap *a); void RegenBitmap(NoRSX_Bitmap *a);
void DrawCustomBitmap(uint32_t start_width, uint32_t start_height, uint32_t end_width, uint32_t end_height, NoRSX_Bitmap *a);
void DrawBitmap(NoRSX_Bitmap *a); void DrawBitmap(NoRSX_Bitmap *a);




Expand Down

0 comments on commit 4f5642e

Please sign in to comment.