1
0
Fork 0
mirror of https://github.com/ctruLua/ctruLua.git synced 2025-10-27 16:39:29 +00:00

Added missing dependicies

This commit is contained in:
Reuh 2015-08-17 21:10:54 +02:00
parent 03baa21c10
commit ebcd9f00ed
47 changed files with 18405 additions and 0 deletions

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,145 @@
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
endif
include $(DEVKITARM)/3ds_rules
#---------------------------------------------------------------------------------
# TARGET is the name of the output
# BUILD is the directory where object files & intermediate files will be placed
# SOURCES is a list of directories containing source code
# DATA is a list of directories containing data files
# INCLUDES is a list of directories containing header files
#---------------------------------------------------------------------------------
TARGET := sfil
BUILD := build
SOURCES := source
DATA := data
INCLUDES := include
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard
CFLAGS := -g -Wall -O2\
$(ARCH)
CFLAGS += $(INCLUDE) -DARM11 -D_3DS
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
ASFLAGS := -g $(ARCH)
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS := $(CTRULIB) $(PORTLIBS) \
$(CURDIR)/../../3ds_portlibs/build \
$(CURDIR)/../../sf2dlib/libsf2d
#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
# rules for different file extensions
#---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------
export OUTPUT := $(CURDIR)/lib/lib$(TARGET).a
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
export DEPSDIR := $(CURDIR)/$(BUILD)
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
#---------------------------------------------------------------------------------
export LD := $(CC)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
export LD := $(CXX)
#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------
export OFILES := $(addsuffix .o,$(BINFILES)) \
$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
$(foreach dir,$(PORTLIBS),-I$(dir)/include/freetype2) \
-I$(CURDIR)/$(BUILD)
.PHONY: $(BUILD) clean all
#---------------------------------------------------------------------------------
all: $(BUILD)
lib:
@[ -d $@ ] || mkdir -p $@
$(BUILD): lib
@[ -d $@ ] || mkdir -p $@
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
#---------------------------------------------------------------------------------
clean:
@echo clean ...
@rm -fr $(BUILD) lib latex html
#---------------------------------------------------------------------------------
install: $(BUILD)
@cp $(OUTPUT) $(CTRULIB)/lib
@cp include/sfil.h $(CTRULIB)/include
@echo "Installed!"
#---------------------------------------------------------------------------------
docs:
@doxygen Doxyfile
#---------------------------------------------------------------------------------
else
DEPENDS := $(OFILES:.o=.d)
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
$(OUTPUT) : $(OFILES)
#---------------------------------------------------------------------------------
%.bin.o : %.bin
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@$(bin2o)
# WARNING: This is not the right way to do this! TODO: Do it right!
#---------------------------------------------------------------------------------
%_vsh.h %.vsh.o : %.vsh
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@python $(AEMSTRO)/aemstro_as.py $< ../$(notdir $<).shbin
@bin2s ../$(notdir $<).shbin | $(PREFIX)as -o $@
@echo "extern const u8" `(echo $(notdir $<).shbin | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"_end[];" > `(echo $(notdir $<).shbin | tr . _)`.h
@echo "extern const u8" `(echo $(notdir $<).shbin | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"[];" >> `(echo $(notdir $<).shbin | tr . _)`.h
@echo "extern const u32" `(echo $(notdir $<).shbin | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`_size";" >> `(echo $(notdir $<).shbin | tr . _)`.h
@rm ../$(notdir $<).shbin
-include $(DEPENDS)
#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------

View file

@ -0,0 +1,71 @@
/**
* @file sfil.h
* @author Sergi Granell (xerpi)
* @date 2 April 2015
* @brief sfillib header
*/
#ifndef SFIL_H
#define SFIL_H
#include <3ds.h>
#include <sf2d.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Loads a PNG image from the SD card
* @param filename the path of the image to load
* @param place where to allocate the texture
* @return a pointer to the newly created texture/image
*/
sf2d_texture *sfil_load_PNG_file(const char *filename, sf2d_place place);
/**
* @brief Loads a PNG image from a memory buffer
* @param buffer the pointer of the memory buffer to load the image from
* @param place where to allocate the texture
* @return a pointer to the newly created texture/image
*/
sf2d_texture *sfil_load_PNG_buffer(const void *buffer, sf2d_place place);
/**
* @brief Loads a JPG/JPEG image from the SD card
* @param filename the path of the image to load
* @param place where to allocate the texture
* @return a pointer to the newly created texture/image
*/
sf2d_texture *sfil_load_JPEG_file(const char *filename, sf2d_place place);
/**
* @brief Loads a JPG/JPEG image from a memory buffer
* @param buffer the pointer of the memory buffer to load the image from
* @param buffer_size the size of the memory buffer
* @param place where to allocate the texture
* @return a pointer to the newly created texture/image
*/
sf2d_texture *sfil_load_JPEG_buffer(const void *buffer, unsigned long buffer_size, sf2d_place place);
/**
* @brief Loads a BMP image from the SD card
* @param filename the path of the image to load
* @param place where to allocate the texture
* @return a pointer to the newly created texture/image
*/
sf2d_texture *sfil_load_BMP_file(const char *filename, sf2d_place place);
/**
* @brief Loads a BMP image from a memory buffer
* @param buffer the pointer of the memory buffer to load the image from
* @param place where to allocate the texture
* @return a pointer to the newly created texture/image
*/
sf2d_texture *sfil_load_BMP_buffer(const void *buffer, sf2d_place place);
#ifdef __cplusplus
}
#endif
#endif

View file

@ -0,0 +1,171 @@
#include "sfil.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define BMP_SIGNATURE (0x4D42)
typedef struct {
unsigned short bfType;
unsigned int bfSize;
unsigned short bfReserved1;
unsigned short bfReserved2;
unsigned int bfOffBits;
}__attribute__((packed)) BITMAPFILEHEADER;
typedef struct {
unsigned int biSize;
unsigned int biWidth;
unsigned int biHeight;
unsigned short biPlanes;
unsigned short biBitCount;
unsigned int biCompression;
unsigned int biSizeImage;
unsigned int biXPelsPerMeter;
unsigned int biYPelsPerMeter;
unsigned int biClrUsed;
unsigned int biClrImportant;
}__attribute__((packed)) BITMAPINFOHEADER;
static sf2d_texture *_sfil_load_BMP_generic(
BITMAPFILEHEADER *bmp_fh,
BITMAPINFOHEADER *bmp_ih,
void *user_data,
void (*seek_fn)(void *user_data, unsigned int offset),
void (*read_fn)(void *user_data, void *buffer, unsigned int length),
sf2d_place place)
{
unsigned int row_size = bmp_ih->biWidth * (bmp_ih->biBitCount/8);
if (row_size%4 != 0) {
row_size += 4-(row_size%4);
}
sf2d_texture *texture = sf2d_create_texture(bmp_ih->biWidth, bmp_ih->biHeight,
GPU_RGBA8, place);
seek_fn(user_data, bmp_fh->bfOffBits);
int stride = texture->pow2_w * 4;
void *buffer = malloc(row_size);
unsigned int *tex_ptr;
unsigned int color;
int i, x, y;
for (i = 0; i < bmp_ih->biHeight; i++) {
read_fn(user_data, buffer, row_size);
y = bmp_ih->biHeight - 1 - i;
tex_ptr = (unsigned int *)(texture->data + y*stride);
for (x = 0; x < bmp_ih->biWidth; x++) {
if (bmp_ih->biBitCount == 32) { //ABGR8888
color = *(unsigned int *)(buffer + x*4);
*tex_ptr = (color&0xFF)<<24 | ((color>>8)&0xFF)<<16 |
((color>>16)&0xFF)<<8 | (color>>24);
} else if (bmp_ih->biBitCount == 24) { //BGR888
unsigned char *address = buffer + x*3;
*tex_ptr = (*address)<<16 | (*(address+1))<<8 |
(*(address+2)) | (0xFF<<24);
} else if (bmp_ih->biBitCount == 16) { //BGR565
color = *(unsigned short *)(buffer + x*2);
unsigned char r = (color & 0x1F) *((float)255/31);
unsigned char g = ((color>>5) & 0x3F) *((float)255/63);
unsigned char b = ((color>>11) & 0x1F) *((float)255/31);
*tex_ptr = ((r<<16) | (g<<8) | b | (0xFF<<24));
}
tex_ptr++;
}
}
free(buffer);
sf2d_texture_tile32(texture);
return texture;
}
static void _sfil_read_bmp_file_seek_fn(void *user_data, unsigned int offset)
{
fseek((FILE *)user_data, offset, SEEK_SET);
}
static void _sfil_read_bmp_file_read_fn(void *user_data, void *buffer, unsigned int length)
{
fread(buffer, 1, length, (FILE *)user_data);
}
static void _sfil_read_bmp_buffer_seek_fn(void *user_data, unsigned int offset)
{
*(unsigned int *)user_data += offset;
}
static void _sfil_read_bmp_buffer_read_fn(void *user_data, void *buffer, unsigned int length)
{
memcpy(buffer, (void *)*(unsigned int *)user_data, length);
*(unsigned int *)user_data += length;
}
sf2d_texture *sfil_load_BMP_file(const char *filename, sf2d_place place)
{
FILE *fp;
if ((fp = fopen(filename, "rb")) == NULL) {
goto exit_error;
}
BITMAPFILEHEADER bmp_fh;
fread((void *)&bmp_fh, 1, sizeof(BITMAPFILEHEADER), fp);
if (bmp_fh.bfType != BMP_SIGNATURE) {
goto exit_close;
}
BITMAPINFOHEADER bmp_ih;
fread((void *)&bmp_ih, 1, sizeof(BITMAPINFOHEADER), fp);
sf2d_texture *texture = _sfil_load_BMP_generic(&bmp_fh,
&bmp_ih,
(void *)&fp,
_sfil_read_bmp_file_seek_fn,
_sfil_read_bmp_file_read_fn,
place);
fclose(fp);
return texture;
exit_close:
fclose(fp);
exit_error:
return NULL;
}
sf2d_texture *sfil_load_BMP_buffer(const void *buffer, sf2d_place place)
{
BITMAPFILEHEADER bmp_fh;
memcpy(&bmp_fh, buffer, sizeof(BITMAPFILEHEADER));
if (bmp_fh.bfType != BMP_SIGNATURE) {
goto exit_error;
}
BITMAPINFOHEADER bmp_ih;
memcpy(&bmp_ih, buffer + sizeof(BITMAPFILEHEADER), sizeof(BITMAPINFOHEADER));
unsigned int buffer_address = (unsigned int)buffer;
sf2d_texture *texture = _sfil_load_BMP_generic(&bmp_fh,
&bmp_ih,
(void *)&buffer_address,
_sfil_read_bmp_buffer_seek_fn,
_sfil_read_bmp_buffer_read_fn,
place);
return texture;
exit_error:
return NULL;
}

View file

@ -0,0 +1,97 @@
#include "sfil.h"
#include <stdio.h>
#include <string.h>
#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)
{
int row_bytes;
switch (jinfo->out_color_space) {
case JCS_RGB:
row_bytes = jinfo->image_width * 3;
break;
default:
goto exit_error;
}
sf2d_texture *texture = sf2d_create_texture(jinfo->image_width,
jinfo->image_height,
GPU_RGBA8, place);
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);
int stride = texture->pow2_w * 4;
while (jinfo->output_scanline < jinfo->output_height) {
jpeg_read_scanlines(jinfo, buffer, 1);
tex_ptr = (row_ptr += stride);
for (i = 0, jpeg_ptr = buffer[0]; i < jinfo->output_width; i++) {
color = *(jpeg_ptr++);
color |= *(jpeg_ptr++)<<8;
color |= *(jpeg_ptr++)<<16;
*(tex_ptr++) = color | 0xFF000000;
}
}
free(buffer[0]);
free(buffer);
sf2d_texture_tile32(texture);
return texture;
exit_error:
return NULL;
}
sf2d_texture *sfil_load_JPEG_file(const char *filename, sf2d_place place)
{
FILE *fp;
if ((fp = fopen(filename, "rb")) < 0) {
return NULL;
}
struct jpeg_decompress_struct jinfo;
struct jpeg_error_mgr jerr;
jinfo.err = jpeg_std_error(&jerr);
jpeg_create_decompress(&jinfo);
jpeg_stdio_src(&jinfo, fp);
jpeg_read_header(&jinfo, 1);
sf2d_texture *texture = _sfil_load_JPEG_generic(&jinfo, &jerr, place);
jpeg_finish_decompress(&jinfo);
jpeg_destroy_decompress(&jinfo);
fclose(fp);
return texture;
}
sf2d_texture *sfil_load_JPEG_buffer(const void *buffer, unsigned long buffer_size, sf2d_place place)
{
struct jpeg_decompress_struct jinfo;
struct jpeg_error_mgr jerr;
jinfo.err = jpeg_std_error(&jerr);
jpeg_create_decompress(&jinfo);
jpeg_mem_src(&jinfo, (void *)buffer, buffer_size);
jpeg_read_header(&jinfo, 1);
sf2d_texture *texture = _sfil_load_JPEG_generic(&jinfo, &jerr, place);
jpeg_finish_decompress(&jinfo);
jpeg_destroy_decompress(&jinfo);
return texture;
}

View file

@ -0,0 +1,139 @@
#include "sfil.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <png.h>
#define PNG_SIGSIZE (8)
static void _sfil_read_png_file_fn(png_structp png_ptr, png_bytep data, png_size_t length)
{
FILE *fp = (FILE *)png_get_io_ptr(png_ptr);
fread(data, 1, length, fp);
}
static void _sfil_read_png_buffer_fn(png_structp png_ptr, png_bytep data, png_size_t length)
{
unsigned int *address = png_get_io_ptr(png_ptr);
memcpy(data, (void *)*address, length);
*address += length;
}
static sf2d_texture *_sfil_load_PNG_generic(const void *io_ptr, png_rw_ptr read_data_fn, sf2d_place place)
{
png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (png_ptr == NULL) {
goto exit_error;
}
png_infop info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL) {
goto exit_destroy_read;
}
png_bytep *row_ptrs = NULL;
if (setjmp(png_jmpbuf(png_ptr))) {
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)0);
if (row_ptrs != NULL)
free(row_ptrs);
goto exit_error;
}
png_set_read_fn(png_ptr, (png_voidp)io_ptr, read_data_fn);
png_set_sig_bytes(png_ptr, PNG_SIGSIZE);
png_read_info(png_ptr, info_ptr);
unsigned int width, height;
int bit_depth, color_type;
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth,
&color_type, NULL, NULL, NULL);
if ((color_type == PNG_COLOR_TYPE_PALETTE && bit_depth <= 8)
|| (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
|| png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)
|| (bit_depth == 16)) {
png_set_expand(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_PALETTE) {
png_set_palette_to_rgb(png_ptr);
png_set_filler(png_ptr, 0xFF, PNG_FILLER_AFTER);
}
if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
png_set_expand_gray_1_2_4_to_8(png_ptr);
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
png_set_tRNS_to_alpha(png_ptr);
if (bit_depth < 8)
png_set_packing(png_ptr);
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);
int stride = texture->pow2_w * 4;
int i;
for (i = 0; i < height; i++) {
row_ptrs[i] = (png_bytep)(texture->data + i*stride);
}
png_read_image(png_ptr, row_ptrs);
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)0);
free(row_ptrs);
sf2d_texture_tile32(texture);
return texture;
exit_destroy_read:
png_destroy_read_struct(&png_ptr, (png_infopp)0, (png_infopp)0);
exit_error:
return NULL;
}
sf2d_texture *sfil_load_PNG_file(const char *filename, sf2d_place place)
{
png_byte pngsig[PNG_SIGSIZE];
FILE *fp;
if ((fp = fopen(filename, "rb")) == NULL) {
goto exit_error;
}
if (fread(pngsig, 1, PNG_SIGSIZE, fp) != PNG_SIGSIZE) {
goto exit_close;
}
if (png_sig_cmp(pngsig, 0, PNG_SIGSIZE) != 0) {
goto exit_close;
}
sf2d_texture *texture = _sfil_load_PNG_generic((void *)fp, _sfil_read_png_file_fn, place);
fclose(fp);
return texture;
exit_close:
fclose(fp);
exit_error:
return NULL;
}
sf2d_texture *sfil_load_PNG_buffer(const void *buffer, sf2d_place place)
{
if (png_sig_cmp((png_byte *) buffer, 0, PNG_SIGSIZE) != 0) {
return NULL;
}
unsigned int buffer_address = (unsigned int)buffer + PNG_SIGSIZE;
return _sfil_load_PNG_generic((void *)&buffer_address, _sfil_read_png_buffer_fn, place);
}