Commit 30d522cc authored by Libretro-Admin's avatar Libretro-Admin
Browse files

Indenting changes

parent 5f0d1260
Pipeline #58003 passed with stages
in 9 minutes and 27 seconds
...@@ -24,192 +24,182 @@ static const char *gme_allowed_exts[] = { ...@@ -24,192 +24,182 @@ static const char *gme_allowed_exts[] = {
static bool is_gme_allowed_ext(char *ext) static bool is_gme_allowed_ext(char *ext)
{ {
int i; int i;
int arr_length; int arr_length;
arr_length = sizeof(gme_allowed_exts) / sizeof(char*); arr_length = sizeof(gme_allowed_exts) / sizeof(char*);
for(i=0;i<arr_length;i++) for(i=0;i<arr_length;i++)
{ {
if(strcmp(ext,gme_allowed_exts[i])==0) if(strcmp(ext,gme_allowed_exts[i])==0)
{ return true;
return true; }
} return false;
}
return false;
} }
static bool uncompress_file_data(file_data** fd) static bool uncompress_file_data(file_data** fd)
{ {
int srcLen,dstLen; int srcLen,dstLen;
int err = -1; int err = -1;
z_stream strm = {0}; z_stream strm = {0};
file_data* src_fd = *fd; file_data* src_fd = *fd;
file_data* dest_fd = NULL; file_data* dest_fd = NULL;
srcLen = src_fd->length; srcLen = src_fd->length;
memcpy(&dstLen,&(src_fd->data[src_fd->length-4]),4); memcpy(&dstLen,&(src_fd->data[src_fd->length-4]),4);
dest_fd = malloc(sizeof(file_data)); dest_fd = malloc(sizeof(file_data));
dest_fd->length = dstLen; dest_fd->length = dstLen;
dest_fd->name = calloc(strlen(src_fd->name)+1,sizeof(char)); dest_fd->name = calloc(strlen(src_fd->name)+1,sizeof(char));
strcpy(dest_fd->name,src_fd->name); strcpy(dest_fd->name,src_fd->name);
dest_fd->data = malloc(dstLen * sizeof(char)); dest_fd->data = malloc(dstLen * sizeof(char));
strm.total_in = strm.avail_in = srcLen; strm.total_in = strm.avail_in = srcLen;
strm.total_out = strm.avail_out = dstLen; strm.total_out = strm.avail_out = dstLen;
strm.next_in = (Bytef *) src_fd->data; strm.next_in = (Bytef *) src_fd->data;
strm.next_out = (Bytef *) dest_fd->data; strm.next_out = (Bytef *) dest_fd->data;
strm.zalloc = Z_NULL; strm.zalloc = Z_NULL;
strm.zfree = Z_NULL; strm.zfree = Z_NULL;
strm.opaque = Z_NULL; strm.opaque = Z_NULL;
err = inflateInit2(&strm, (15 + 32)); //15 window bits, and the +32 tells zlib to to detect if using gzip or zlib err = inflateInit2(&strm, (15 + 32)); //15 window bits, and the +32 tells zlib to to detect if using gzip or zlib
if (err == Z_OK) if (err == Z_OK)
{ {
err = inflate(&strm, Z_FINISH); err = inflate(&strm, Z_FINISH);
if (err != Z_STREAM_END) if (err != Z_STREAM_END)
{ {
inflateEnd(&strm); inflateEnd(&strm);
return false; return false;
} }
} }
else else
{ {
inflateEnd(&strm); inflateEnd(&strm);
return false; return false;
} }
inflateEnd(&strm); inflateEnd(&strm);
free(src_fd->data); free(src_fd->data);
free(src_fd->name); free(src_fd->name);
free(src_fd); free(src_fd);
*fd = dest_fd; *fd = dest_fd;
return true; return true;
} }
static bool get_files_from_zip(const char *path, file_data ***dest_files, int *dest_numfiles) static bool get_files_from_zip(const char *path, file_data ***dest_files, int *dest_numfiles)
{ {
unzFile uf = NULL; unzFile uf = NULL;
unz_global_info64 gi; unz_global_info64 gi;
unz_file_info64 file_info; unz_file_info64 file_info;
int i; int i;
char filename_inzip[256]; char filename_inzip[256];
char *ext; char *ext;
file_data **files; file_data **files;
int numfiles,position; int numfiles,position;
//load zip content //load zip content
uf = unzOpen64(path); uf = unzOpen64(path);
unzGetGlobalInfo64(uf,&gi); unzGetGlobalInfo64(uf,&gi);
numfiles = (int)gi.number_entry; numfiles = (int)gi.number_entry;
files = malloc(sizeof(file_data*) * numfiles); files = malloc(sizeof(file_data*) * numfiles);
position = 0; position = 0;
for(i=0;i<gi.number_entry;i++) for(i=0;i<gi.number_entry;i++)
{ {
void* buf; void* buf;
int err; int err;
int bytes_read; int bytes_read;
uInt size_buf = 8192; uInt size_buf = 8192;
//read compressed file info //read compressed file info
err = unzGetCurrentFileInfo64(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0); err = unzGetCurrentFileInfo64(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0);
if(err!=UNZ_OK) if(err!=UNZ_OK)
{ {
return false;
}
if(filename_inzip[file_info.size_filename -1]=='/')
ext = strrchr(filename_inzip,'/');
else
ext = strrchr(filename_inzip,'.') + 1;
if(is_gme_allowed_ext(ext))
{
//get file name in zip
files[position] = malloc(sizeof(file_data));
files[position]->name = calloc(strlen(filename_inzip)+1,sizeof(char));
strcpy(files[position]->name,filename_inzip);
//allocate uncompressed data buffer
files[position]->length= sizeof(char) * file_info.uncompressed_size;
files[position]->data = (char*)malloc(files[position]->length);
//setup buffer
bytes_read = 0;
buf = (void*)malloc(size_buf);
if (buf==NULL)
return false; return false;
} //read file from zip
if(filename_inzip[file_info.size_filename -1]=='/') err = unzOpenCurrentFilePassword(uf,NULL);
ext = strrchr(filename_inzip,'/'); if (err!=UNZ_OK)
else return false;
ext = strrchr(filename_inzip,'.') + 1; //get data from zip
if(is_gme_allowed_ext(ext)) do
{ {
//get file name in zip err = unzReadCurrentFile(uf,buf,size_buf);
files[position] = malloc(sizeof(file_data)); if(err<0)
files[position]->name = calloc(strlen(filename_inzip)+1,sizeof(char)); return false;
strcpy(files[position]->name,filename_inzip); if(err>0)
//allocate uncompressed data buffer
files[position]->length= sizeof(char) * file_info.uncompressed_size;
files[position]->data = (char*)malloc(files[position]->length);
//setup buffer
bytes_read = 0;
buf = (void*)malloc(size_buf);
if (buf==NULL)
return false;
//read file from zip
err = unzOpenCurrentFilePassword(uf,NULL);
if (err!=UNZ_OK)
return false;
//get data from zip
do
{ {
err = unzReadCurrentFile(uf,buf,size_buf); memcpy(files[position]->data + bytes_read,buf,err * sizeof(char));
if(err<0) bytes_read += err;
return false; }
if(err>0) } while (err>0);
{ if(buf!=NULL)
memcpy(files[position]->data + bytes_read,buf,err * sizeof(char)); free(buf);
bytes_read += err;
}
} while (err>0);
if(buf!=NULL)
free(buf);
if(strcmp(ext,"vgz")==0) if(strcmp(ext,"vgz")==0)
if(!uncompress_file_data(&(files[position]))) if(!uncompress_file_data(&(files[position])))
return false; return false;
position++; position++;
} }
else else
{ {
numfiles--; numfiles--;
} }
if ((i+1)<gi.number_entry) if ((i+1)<gi.number_entry)
unzGoToNextFile(uf); unzGoToNextFile(uf);
} }
files = realloc(files,sizeof(file_data*) * numfiles); files = realloc(files,sizeof(file_data*) * numfiles);
*dest_files = files; *dest_files = files;
*dest_numfiles = numfiles; *dest_numfiles = numfiles;
return true; return true;
} }
bool get_file_data(const char *path,file_data ***dest_files, int *dest_numfiles) bool get_file_data(const char *path,file_data ***dest_files, int *dest_numfiles)
{ {
//local variables //local variables
FILE *fp; FILE *fp;
const char *bname; file_data *fd;
char *ext; file_data **files;
file_data **files; //get file name and extension
//get file name and extension const char *bname = path_basename(path);
bname = path_basename(path); char *ext = strrchr(path,'.') +1;
ext = strrchr(path,'.') +1; //get file data
//get file data if(strcmp(ext,"zip")==0)
if(strcmp(ext,"zip")==0) return get_files_from_zip(path,dest_files,dest_numfiles);
{ if (!(fp = fopen(path,"rb")))
return get_files_from_zip(path,dest_files,dest_numfiles); return false;
} files = malloc(sizeof(file_data*));
else fd = malloc(sizeof(file_data));
{ //get file length
file_data *fd; fseek (fp,0,SEEK_END);
fp = fopen(path,"rb"); fd->length = ftell(fp);
if (!fp) rewind(fp);
return false; //get file data
files = malloc(sizeof(file_data*)); fd->data = malloc(sizeof(char)*fd->length);
fd = malloc(sizeof(file_data)); fread(fd->data,1,fd->length,fp);
//get file length fclose(fp);
fseek (fp,0,SEEK_END); fd->name = calloc(strlen(bname)+1,sizeof(char));
fd->length = ftell(fp); strcpy(fd->name,bname);
rewind(fp); if(strcmp(ext,"vgz")==0)
//get file data {
fd->data = malloc(sizeof(char)*fd->length); if(!uncompress_file_data(&fd))
fread(fd->data,1,fd->length,fp); return false;
fclose(fp); }
fd->name = calloc(strlen(bname)+1,sizeof(char)); files[0] = fd;
strcpy(fd->name,bname); *dest_files = files;
if(strcmp(ext,"vgz")==0) *dest_numfiles = 1;
{ return true;
if(!uncompress_file_data(&fd))
return false;
}
files[0] = fd;
*dest_files = files;
*dest_numfiles = 1;
return true;
}
} }
#ifndef GME_LIBRETRO_FILEFORMAT_H__ #ifndef GME_LIBRETRO_FILEFORMAT_H__
#define GME_LIBRETRO_FILEFORMAT_H__ #define GME_LIBRETRO_FILEFORMAT_H__
typedef struct { typedef struct
char* name; {
char* data; char* name;
int length; char* data;
int length;
} file_data; } file_data;
bool get_file_data(const char *path,file_data ***files, int *dest_numfiles); bool get_file_data(const char *path,file_data ***files, int *dest_numfiles);
#endif #endif
\ No newline at end of file
...@@ -6,34 +6,37 @@ ...@@ -6,34 +6,37 @@
unsigned short get_color(char r, char g, char b) unsigned short get_color(char r, char g, char b)
{ {
unsigned short color= (r << 11) | (g << 5) | b; unsigned short color= (r << 11) | (g << 5) | b;
return color; return color;
} }
surface *create_surface(unsigned int width, unsigned int height, unsigned int bpp) surface *create_surface(unsigned int width, unsigned int height, unsigned int bpp)
{ {
surface *newsurf = malloc(sizeof(surface)); surface *newsurf = malloc(sizeof(surface));
if(newsurf==NULL) if (!newsurf)
return NULL; return NULL;
newsurf->pixel_data = malloc(width*height*bpp); newsurf->pixel_data = malloc(width*height*bpp);
if(newsurf->pixel_data==NULL)
if (!newsurf->pixel_data)
{ {
free(newsurf); free(newsurf);
return NULL; return NULL;
} }
memset(newsurf->pixel_data,0,width*height*bpp);
newsurf->width = width; memset(newsurf->pixel_data,0,width*height*bpp);
newsurf->height = height; newsurf->width = width;
newsurf->bytes_per_pixel = bpp; newsurf->height = height;
return newsurf; newsurf->bytes_per_pixel = bpp;
return newsurf;
} }
void free_surface(surface *surf) void free_surface(surface *surf)
{ {
if(surf != NULL) { if (surf)
free(surf->pixel_data); {
free(surf); free(surf->pixel_data);
} free(surf);
}
} }
surface *clip_surface(surface *src_surf, int x_src, int y_src, int x0, int y0, int x1, int y1) surface *clip_surface(surface *src_surf, int x_src, int y_src, int x0, int y0, int x1, int y1)
...@@ -42,16 +45,19 @@ surface *clip_surface(surface *src_surf, int x_src, int y_src, int x0, int y0, i ...@@ -42,16 +45,19 @@ surface *clip_surface(surface *src_surf, int x_src, int y_src, int x0, int y0, i
int lx,ly,lw,lh; //local coord int lx,ly,lw,lh; //local coord
surface *clipped_surf = NULL; surface *clipped_surf = NULL;
//check if completely out of bounds //check if completely out of bounds
if( (x_src+src_surf->width) <x0 || x_src > x1 || (y_src+src_surf->height) < y0 || y_src > y1) if( (x_src+src_surf->width) <x0
|| (x_src > x1)
|| (y_src+src_surf->height) < y0
|| (y_src > y1))
return clipped_surf; return clipped_surf;
wx0 = MAX(x_src,x0); wx0 = MAX(x_src,x0);
wy0 = MAX(y_src,y0); wy0 = MAX(y_src,y0);
wx1 = MIN(x_src+src_surf->width,x1); wx1 = MIN(x_src+src_surf->width,x1);
wy1 = MIN(y_src+src_surf->height,y1); wy1 = MIN(y_src+src_surf->height,y1);
lx = wx0 - x_src; lx = wx0 - x_src;
ly = wy0 - y_src; ly = wy0 - y_src;
lw = wx1 - wx0; lw = wx1 - wx0;
lh = wy1 - wy0; lh = wy1 - wy0;
clipped_surf = create_surface(lw, lh,2); clipped_surf = create_surface(lw, lh,2);
copy_surface(src_surf,clipped_surf,lx,ly,0,0,lw,lh); copy_surface(src_surf,clipped_surf,lx,ly,0,0,lw,lh);
return clipped_surf; return clipped_surf;
...@@ -73,34 +79,35 @@ void copy_surface(surface *src_surf, surface *dst_surf, int x_src, int y_src, in ...@@ -73,34 +79,35 @@ void copy_surface(surface *src_surf, surface *dst_surf, int x_src, int y_src, in
void draw_line(surface *surf, unsigned short color, int start_x, int start_y, int end_x, int end_y) void draw_line(surface *surf, unsigned short color, int start_x, int start_y, int end_x, int end_y)
{ {
if(start_x==end_x) //vertical line if(start_x==end_x) //vertical line
{ {
int y; int y;
for(y=start_y;y<=end_y;y++) for(y=start_y;y<=end_y;y++)
set_pixel(surf,start_x,y,color); set_pixel(surf,start_x,y,color);
} }
else if(start_y==end_y) // horizontal line else if(start_y==end_y) // horizontal line
{ {
int x; int x;
for(x=start_x;x<=end_x;x++) for(x=start_x;x<=end_x;x++)
set_pixel(surf,x,start_y,color) = color; set_pixel(surf,x,start_y,color) = color;
} }
else else
{ {
// Bresenham line algorithm, copied from https://rosettacode.org/wiki/Bitmap/Bresenham%27s_line_algorithm#C // Bresenham line algorithm, copied from https://rosettacode.org/wiki/Bitmap/Bresenham%27s_line_algorithm#C
int x = start_x, y = start_y; int x = start_x, y = start_y;
int dx = abs(end_x-start_x), sx = start_x<end_x ? 1 : -1; int dx = abs(end_x-start_x), sx = start_x<end_x ? 1 : -1;
int dy = abs(end_y-start_y), sy = start_y<end_y ? 1 : -1; int dy = abs(end_y-start_y), sy = start_y<end_y ? 1 : -1;
int err = (dx>dy ? dx : -dy)/2, e2; int err = (dx>dy ? dx : -dy)/2, e2;
for(;;) for(;;)
{ {
set_pixel(surf,x,y,color); set_pixel(surf,x,y,color);
if (x==end_x && y==end_y) break; if (x==end_x && y==end_y)
break;
e2 = err; e2 = err;
if (e2 >-dx) { err -= dy; x += sx; } if (e2 >-dx) { err -= dy; x += sx; }
if (e2 < dy) { err += dx; y += sy; } if (e2 < dy) { err += dx; y += sy; }
} }
} }
} }
void draw_box(surface *surf, unsigned short color, int x0, int y0, int x1, int y1) void draw_box(surface *surf, unsigned short color, int x0, int y0, int x1, int y1)
...@@ -124,13 +131,10 @@ void draw_shape(surface *surf, unsigned short color, int pos_x, int pos_y, int w ...@@ -124,13 +131,10 @@ void draw_shape(surface *surf, unsigned short color, int pos_x, int pos_y, int w
void draw_letter(surface *surf, unsigned short color, char letter, int pos_x, int pos_y) void draw_letter(surface *surf, unsigned short color, char letter, int pos_x, int pos_y)
{ {
int y, x; int y, x;
int charx = 0;
int chary = 0;
//calculate letter offset //calculate letter offset
charx = (letter % 16); int charx = (letter % 16) * 8;
chary = (letter >> 4); int chary = (letter >> 4) * 8;
charx *= 8;
chary *= 8;
for(y=0;y<8;y++) for(y=0;y<8;y++)
{ {
for(x=0;x<8;x++) for(x=0;x<8;x++)
...@@ -158,15 +162,16 @@ void draw_string(surface *surf, unsigned short color, char* text, int pos_x, int ...@@ -158,15 +162,16 @@ void draw_string(surface *surf, unsigned short color, char* text, int pos_x, int
if((msglen*8)>280) if((msglen*8)>280)
{ {
delta = (msglen*8) -280; delta = (msglen*8) -280;
modulo = delta + (delay * 2); modulo = delta + (delay * 2);
x_offset = (modulo - abs(framecounter/frame_delay % (2*modulo) - modulo)) - delay; // triangle function x_offset = (modulo - abs(framecounter/frame_delay % (2*modulo) - modulo)) - delay; // triangle function
x_offset = MAX(x_offset,0); //clamp left to add delay x_offset = MAX(x_offset,0); //clamp left to add delay
x_offset = MIN(x_offset,delta); //clamp right to add delay x_offset = MIN(x_offset,delta); //clamp right to add delay
} }
clipped_surface = clip_surface(temp_surface,pos_x-x_offset,pos_y,21,21,299,219); clipped_surface = clip_surface(temp_surface,pos_x-x_offset,pos_y,21,21,299,219);
if(clipped_surface !=NULL)
if (clipped_surface)
{ {
copy_surface(clipped_surface,surf,0,0,pos_x,pos_y,clipped_surface->width,clipped_surface->height); copy_surface(clipped_surface,surf,0,0,pos_x,pos_y,clipped_surface->width,clipped_surface->height);
free_surface(clipped_surface); free_surface(clipped_surface);
......
...@@ -8,11 +8,12 @@ ...@@ -8,11 +8,12 @@
#define get_pixel(surf,x,y) ((unsigned short *)surf->pixel_data)[(x)+((y)*surf->width)] #define get_pixel(surf,x,y) ((unsigned short *)surf->pixel_data)[(x)+((y)*surf->width)]
#define is_font_pixel(x,y) (((unsigned short *)font.pixel_data)[(x)+((y)*font.width)] == 0 ? 1 : 0) #define is_font_pixel(x,y) (((unsigned short *)font.pixel_data)[(x)+((y)*font.width)] == 0 ? 1 : 0)
typedef struct { typedef struct
unsigned int width; {
unsigned int height; unsigned int width;
unsigned int bytes_per_pixel; /* 2:RGB16, 3:RGB, 4:RGBA */ unsigned int height;
char *pixel_data; unsigned int bytes_per_pixel; /* 2:RGB16, 3:RGB, 4:RGBA */
char *pixel_data;
} surface; } surface;
unsigned short get_color(char r, char g, char b); unsigned short get_color(char r, char g, char b);
...@@ -26,8 +27,6 @@ void draw_letter(surface *surf, unsigned short color, char letter, int pos_x, in ...@@ -26,8 +27,6 @@ void draw_letter(surface *surf, unsigned short color, char letter, int pos_x, in
void draw_string(surface *surf, unsigned short color, char* text, int pos_x, int pos_y, unsigned int framecounter); void draw_string(surface *surf, unsigned short color, char* text, int pos_x, int pos_y, unsigned int framecounter);
int get_string_length(char* text); int get_string_length(char* text);