1
0
Fork 0
mirror of https://github.com/ctruLua/ctruLua.git synced 2025-10-28 16:59:30 +00:00

Updated all the libs, added citro3d, added ctr.swkbd (WIP, untested)

This commit is contained in:
Firew0lf 2016-08-05 17:30:24 +02:00
parent 68a44645f7
commit 49c87e5526
97 changed files with 7341 additions and 944 deletions

View file

@ -45,11 +45,19 @@ static sf2d_texture *_sfil_load_BMP_generic(
sf2d_texture *texture = sf2d_create_texture(bmp_ih->biWidth, bmp_ih->biHeight,
GPU_RGBA8, place);
if (!texture)
return NULL;
seek_fn(user_data, bmp_fh->bfOffBits);
int stride = texture->pow2_w * 4;
int stride = texture->tex.width * 4;
void *buffer = malloc(row_size);
if (!buffer) {
sf2d_free_texture(texture);
return NULL;
}
unsigned int *tex_ptr;
unsigned int color;
int i, x, y;
@ -59,7 +67,7 @@ static sf2d_texture *_sfil_load_BMP_generic(
read_fn(user_data, buffer, row_size);
y = bmp_ih->biHeight - 1 - i;
tex_ptr = (unsigned int *)(texture->data + y*stride);
tex_ptr = (unsigned int *)(texture->tex.data + y*stride);
for (x = 0; x < bmp_ih->biWidth; x++) {

View file

@ -4,9 +4,10 @@
#include <stdlib.h>
#include <jpeglib.h>
static sf2d_texture *_sfil_load_JPEG_generic(struct jpeg_decompress_struct *jinfo, struct jpeg_error_mgr *jerr, sf2d_place place)
{
jpeg_start_decompress(jinfo);
int row_bytes;
switch (jinfo->out_color_space) {
case JCS_RGB:
@ -17,18 +18,19 @@ static sf2d_texture *_sfil_load_JPEG_generic(struct jpeg_decompress_struct *jinf
}
sf2d_texture *texture = sf2d_create_texture(jinfo->image_width,
jinfo->image_height,
GPU_RGBA8, place);
jinfo->image_height, GPU_RGBA8, place);
if (!texture)
goto exit_error;
JSAMPARRAY buffer = (JSAMPARRAY)malloc(sizeof(JSAMPROW));
buffer[0] = (JSAMPROW)malloc(sizeof(JSAMPLE) * row_bytes);
unsigned int i, color, *tex_ptr;
unsigned char *jpeg_ptr;
void *row_ptr = texture->data;
jpeg_start_decompress(jinfo);
void *row_ptr = texture->tex.data;
int stride = texture->pow2_w * 4;
int stride = texture->tex.width * 4;
while (jinfo->output_scanline < jinfo->output_height) {
jpeg_read_scanlines(jinfo, buffer, 1);
@ -41,6 +43,8 @@ static sf2d_texture *_sfil_load_JPEG_generic(struct jpeg_decompress_struct *jinf
}
}
jpeg_finish_decompress(jinfo);
free(buffer[0]);
free(buffer);
@ -48,6 +52,7 @@ static sf2d_texture *_sfil_load_JPEG_generic(struct jpeg_decompress_struct *jinf
return texture;
exit_error:
jpeg_abort_decompress(jinfo);
return NULL;
}
@ -69,7 +74,6 @@ sf2d_texture *sfil_load_JPEG_file(const char *filename, sf2d_place place)
sf2d_texture *texture = _sfil_load_JPEG_generic(&jinfo, &jerr, place);
jpeg_finish_decompress(&jinfo);
jpeg_destroy_decompress(&jinfo);
fclose(fp);
@ -90,7 +94,6 @@ sf2d_texture *sfil_load_JPEG_buffer(const void *buffer, unsigned long buffer_siz
sf2d_texture *texture = _sfil_load_JPEG_generic(&jinfo, &jerr, place);
jpeg_finish_decompress(&jinfo);
jpeg_destroy_decompress(&jinfo);
return texture;

View file

@ -23,12 +23,12 @@ static sf2d_texture *_sfil_load_PNG_generic(const void *io_ptr, png_rw_ptr read_
{
png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (png_ptr == NULL) {
goto exit_error;
goto error_create_read;
}
png_infop info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL) {
goto exit_destroy_read;
goto error_create_info;
}
png_bytep *row_ptrs = NULL;
@ -37,7 +37,7 @@ static sf2d_texture *_sfil_load_PNG_generic(const void *io_ptr, png_rw_ptr read_
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)0);
if (row_ptrs != NULL)
free(row_ptrs);
goto exit_error;
return NULL;
}
png_set_read_fn(png_ptr, (png_voidp)io_ptr, read_data_fn);
@ -57,9 +57,17 @@ static sf2d_texture *_sfil_load_PNG_generic(const void *io_ptr, png_rw_ptr read_
png_set_expand(png_ptr);
}
if (bit_depth == 16)
png_set_scale_16(png_ptr);
if (bit_depth == 8 && color_type == PNG_COLOR_TYPE_RGB)
png_set_filler(png_ptr, 0xFF, PNG_FILLER_AFTER);
if (color_type == PNG_COLOR_TYPE_GRAY ||
color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
png_set_gray_to_rgb(png_ptr);
if (color_type == PNG_COLOR_TYPE_PALETTE) {
png_set_palette_to_rgb(png_ptr);
png_set_filler(png_ptr, 0xFF, PNG_FILLER_AFTER);
@ -77,12 +85,18 @@ static sf2d_texture *_sfil_load_PNG_generic(const void *io_ptr, png_rw_ptr read_
png_read_update_info(png_ptr, info_ptr);
row_ptrs = (png_bytep *)malloc(sizeof(png_bytep) * height);
sf2d_texture *texture = sf2d_create_texture(width, height, GPU_RGBA8, place);
if (!row_ptrs)
goto error_alloc_rows;
sf2d_texture *texture = sf2d_create_texture(width, height, GPU_RGBA8, place);
if (!texture)
goto error_create_tex;
int stride = texture->tex.width * 4;
int stride = texture->pow2_w * 4;
int i;
for (i = 0; i < height; i++) {
row_ptrs[i] = (png_bytep)(texture->data + i*stride);
row_ptrs[i] = (png_bytep)(texture->tex.data + i*stride);
}
png_read_image(png_ptr, row_ptrs);
@ -93,9 +107,13 @@ static sf2d_texture *_sfil_load_PNG_generic(const void *io_ptr, png_rw_ptr read_
sf2d_texture_tile32(texture);
return texture;
exit_destroy_read:
error_create_tex:
free(row_ptrs);
error_alloc_rows:
png_destroy_info_struct(png_ptr, &info_ptr);
error_create_info:
png_destroy_read_struct(&png_ptr, (png_infopp)0, (png_infopp)0);
exit_error:
error_create_read:
return NULL;
}