FastColor/RemoveFPSCheat/LLVM-Style

This commit is contained in:
2023-03-07 18:09:48 +01:00
parent 2f7a266dc5
commit 66a35f28e6
22 changed files with 18350 additions and 15235 deletions
+10 -1
View File
@@ -88,6 +88,15 @@
"xtree": "cpp", "xtree": "cpp",
"xutility": "cpp", "xutility": "cpp",
"queue": "cpp", "queue": "cpp",
"semaphore": "cpp" "semaphore": "cpp",
"hash_map": "cpp",
"set": "cpp",
"unordered_set": "cpp",
"source_location": "cpp",
"future": "cpp",
"cfenv": "cpp",
"cinttypes": "cpp",
"typeindex": "cpp",
"variant": "cpp"
} }
} }
Executable
+7
View File
@@ -0,0 +1,7 @@
find . -type f \( -name '*.h' -o -name '*.hpp' -o -name '*.hh' -o -name '*.ino' -o -name '*.cpp' -o -name '*.c' -o -name '*.cxx' -o -name '*.inl' \) -and -not -path './build/*' -not -path './base/external/*' -not -path './DPP/*' | while read file; do
if [[ "$file" != *"json.hpp" ]]; then
echo "Formatting $file..."
clang-format -i --style=LLVM $file
fi
done
+60 -117
View File
@@ -25,17 +25,17 @@
#include <assert.h> #include <assert.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <renderd7/external/libnsbmp/libnsbmp.h> #include <renderd7/external/libnsbmp/libnsbmp.h>
#include <renderd7/external/libnsbmp/log.h> #include <renderd7/external/libnsbmp/log.h>
/* squashes unused variable compiler warnings */ /* squashes unused variable compiler warnings */
#define UNUSED(x) ((x)=(x)) #define UNUSED(x) ((x) = (x))
/* BMP entry sizes */ /* BMP entry sizes */
#define BMP_FILE_HEADER_SIZE 14 #define BMP_FILE_HEADER_SIZE 14
@@ -47,42 +47,38 @@
#ifdef WE_NEED_INT8_READING_NOW #ifdef WE_NEED_INT8_READING_NOW
static inline int8_t read_int8(uint8_t *data, unsigned int o) { static inline int8_t read_int8(uint8_t *data, unsigned int o) {
return (int8_t) data[o]; return (int8_t)data[o];
} }
#endif #endif
static inline uint8_t read_uint8(uint8_t *data, unsigned int o) { static inline uint8_t read_uint8(uint8_t *data, unsigned int o) {
return (uint8_t) data[o]; return (uint8_t)data[o];
} }
static inline int16_t read_int16(uint8_t *data, unsigned int o) { static inline int16_t read_int16(uint8_t *data, unsigned int o) {
return (int16_t) (data[o] | (data[o+1] << 8)); return (int16_t)(data[o] | (data[o + 1] << 8));
} }
static inline uint16_t read_uint16(uint8_t *data, unsigned int o) { static inline uint16_t read_uint16(uint8_t *data, unsigned int o) {
return (uint16_t) (data[o] | (data[o+1] << 8)); return (uint16_t)(data[o] | (data[o + 1] << 8));
} }
static inline int32_t read_int32(uint8_t *data, unsigned int o) { static inline int32_t read_int32(uint8_t *data, unsigned int o) {
return (int32_t) ((unsigned)data[o] | return (int32_t)((unsigned)data[o] | ((unsigned)data[o + 1] << 8) |
((unsigned)data[o+1] << 8) | ((unsigned)data[o + 2] << 16) |
((unsigned)data[o+2] << 16) | ((unsigned)data[o + 3] << 24));
((unsigned)data[o+3] << 24));
} }
static inline uint32_t read_uint32(uint8_t *data, unsigned int o) { static inline uint32_t read_uint32(uint8_t *data, unsigned int o) {
return (uint32_t) ((unsigned)data[o] | return (uint32_t)((unsigned)data[o] | ((unsigned)data[o + 1] << 8) |
((unsigned)data[o+1] << 8) | ((unsigned)data[o + 2] << 16) |
((unsigned)data[o+2] << 16) | ((unsigned)data[o + 3] << 24));
((unsigned)data[o+3] << 24));
} }
/** /**
* Parse the bitmap info header * Parse the bitmap info header
*/ */
static bmp_result bmp_info_header_parse(bmp_image *bmp, uint8_t *data) static bmp_result bmp_info_header_parse(bmp_image *bmp, uint8_t *data) {
{
uint32_t header_size; uint32_t header_size;
uint32_t i; uint32_t i;
uint8_t j; uint8_t j;
@@ -147,11 +143,8 @@ static bmp_result bmp_info_header_parse(bmp_image *bmp, uint8_t *data)
* values considered legal are: * values considered legal are:
* RGB ENCODING: 1, 4, 8, 16, 24 and 32 * RGB ENCODING: 1, 4, 8, 16, 24 and 32
*/ */
if ((bmp->bpp != 1) && (bmp->bpp != 4) && if ((bmp->bpp != 1) && (bmp->bpp != 4) && (bmp->bpp != 8) &&
(bmp->bpp != 8) && (bmp->bpp != 16) && (bmp->bpp != 24) && (bmp->bpp != 32))
(bmp->bpp != 16) &&
(bmp->bpp != 24) &&
(bmp->bpp != 32))
return BMP_DATA_ERROR; return BMP_DATA_ERROR;
if (bmp->bpp < 16) if (bmp->bpp < 16)
bmp->colours = (1 << bmp->bpp); bmp->colours = (1 << bmp->bpp);
@@ -236,11 +229,8 @@ static bmp_result bmp_info_header_parse(bmp_image *bmp, uint8_t *data)
*/ */
switch (bmp->encoding) { switch (bmp->encoding) {
case BMP_ENCODING_RGB: case BMP_ENCODING_RGB:
if ((bmp->bpp != 1) && (bmp->bpp != 4) && if ((bmp->bpp != 1) && (bmp->bpp != 4) && (bmp->bpp != 8) &&
(bmp->bpp != 8) && (bmp->bpp != 16) && (bmp->bpp != 24) && (bmp->bpp != 32))
(bmp->bpp != 16) &&
(bmp->bpp != 24) &&
(bmp->bpp != 32))
return BMP_DATA_ERROR; return BMP_DATA_ERROR;
break; break;
case BMP_ENCODING_RLE8: case BMP_ENCODING_RLE8:
@@ -329,7 +319,7 @@ static bmp_result bmp_info_header_parse(bmp_image *bmp, uint8_t *data)
if (bmp->opaque) if (bmp->opaque)
colour |= ((uint32_t)0xff << 24); colour |= ((uint32_t)0xff << 24);
data += palette_size; data += palette_size;
bmp->colour_table[i] = read_uint32((uint8_t *)&colour,0); bmp->colour_table[i] = read_uint32((uint8_t *)&colour, 0);
} }
/* some bitmaps have a bad offset if there is a pallete, work /* some bitmaps have a bad offset if there is a pallete, work
@@ -345,7 +335,8 @@ static bmp_result bmp_info_header_parse(bmp_image *bmp, uint8_t *data)
/* create our bitmap */ /* create our bitmap */
flags |= BMP_NEW | BMP_CLEAR_MEMORY; flags |= BMP_NEW | BMP_CLEAR_MEMORY;
bmp->bitmap = bmp->bitmap_callbacks.bitmap_create(bmp->width, bmp->height, flags); bmp->bitmap =
bmp->bitmap_callbacks.bitmap_create(bmp->width, bmp->height, flags);
if (!bmp->bitmap) { if (!bmp->bitmap) {
if (bmp->colour_table) if (bmp->colour_table)
free(bmp->colour_table); free(bmp->colour_table);
@@ -360,7 +351,6 @@ static bmp_result bmp_info_header_parse(bmp_image *bmp, uint8_t *data)
return BMP_OK; return BMP_OK;
} }
/** /**
* Parse the bitmap file header * Parse the bitmap file header
* *
@@ -368,8 +358,7 @@ static bmp_result bmp_info_header_parse(bmp_image *bmp, uint8_t *data)
* \param data The data for the file header * \param data The data for the file header
* \return BMP_OK on success or error code on faliure * \return BMP_OK on success or error code on faliure
*/ */
static bmp_result bmp_file_header_parse(bmp_image *bmp, uint8_t *data) static bmp_result bmp_file_header_parse(bmp_image *bmp, uint8_t *data) {
{
/* standard 14-byte BMP file header is: /* standard 14-byte BMP file header is:
* *
* +0 UINT16 File Type ('BM') * +0 UINT16 File Type ('BM')
@@ -394,7 +383,6 @@ static bmp_result bmp_file_header_parse(bmp_image *bmp, uint8_t *data)
return BMP_OK; return BMP_OK;
} }
/** /**
* Allocates memory for the next BMP in an ICO collection * Allocates memory for the next BMP in an ICO collection
* *
@@ -410,7 +398,6 @@ static bmp_result next_ico_image(ico_collection *ico, ico_image *image) {
return BMP_OK; return BMP_OK;
} }
/** /**
* Parse the icon file header * Parse the icon file header
* *
@@ -418,8 +405,7 @@ static bmp_result next_ico_image(ico_collection *ico, ico_image *image) {
* \param data The header data to parse. * \param data The header data to parse.
* \return BMP_OK on successful parse else error code * \return BMP_OK on successful parse else error code
*/ */
static bmp_result ico_header_parse(ico_collection *ico, uint8_t *data) static bmp_result ico_header_parse(ico_collection *ico, uint8_t *data) {
{
uint16_t count, i; uint16_t count, i;
bmp_result result; bmp_result result;
int area, max_area = 0; int area, max_area = 0;
@@ -442,7 +428,8 @@ static bmp_result ico_header_parse(ico_collection *ico, uint8_t *data)
data += ICO_FILE_HEADER_SIZE; data += ICO_FILE_HEADER_SIZE;
/* check if we have enough data for the directory */ /* check if we have enough data for the directory */
if (ico->buffer_size < (uint32_t)(ICO_FILE_HEADER_SIZE + (ICO_DIR_ENTRY_SIZE * count))) if (ico->buffer_size <
(uint32_t)(ICO_FILE_HEADER_SIZE + (ICO_DIR_ENTRY_SIZE * count)))
return BMP_INSUFFICIENT_DATA; return BMP_INSUFFICIENT_DATA;
/* Decode the BMP files. /* Decode the BMP files.
@@ -456,7 +443,8 @@ static bmp_result ico_header_parse(ico_collection *ico, uint8_t *data)
* +4 UINT16 Colour Planes (should be 0 or 1) * +4 UINT16 Colour Planes (should be 0 or 1)
* +6 UINT16 Bits Per Pixel * +6 UINT16 Bits Per Pixel
* +8 UINT32 Size of BMP info header + bitmap data in bytes * +8 UINT32 Size of BMP info header + bitmap data in bytes
* +12 UINT32 Offset (points to the BMP info header, not the bitmap data) * +12 UINT32 Offset (points to the BMP info header, not the bitmap
*data)
*/ */
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
ico_image *image; ico_image *image;
@@ -482,8 +470,7 @@ static bmp_result ico_header_parse(ico_collection *ico, uint8_t *data)
/* Ensure that the bitmap data resides in the buffer */ /* Ensure that the bitmap data resides in the buffer */
if (image->bmp.bmp_data - ico->ico_data >= 0 && if (image->bmp.bmp_data - ico->ico_data >= 0 &&
(uint32_t)(image->bmp.bmp_data - (uint32_t)(image->bmp.bmp_data - ico->ico_data) >= ico->buffer_size)
ico->ico_data) >= ico->buffer_size)
return BMP_DATA_ERROR; return BMP_DATA_ERROR;
/* Ensure that we have sufficient data to read the bitmap */ /* Ensure that we have sufficient data to read the bitmap */
@@ -491,8 +478,7 @@ static bmp_result ico_header_parse(ico_collection *ico, uint8_t *data)
ico->buffer_size - (ico->ico_data - data)) ico->buffer_size - (ico->ico_data - data))
return BMP_INSUFFICIENT_DATA; return BMP_INSUFFICIENT_DATA;
result = bmp_info_header_parse(&image->bmp, result = bmp_info_header_parse(&image->bmp, image->bmp.bmp_data);
image->bmp.bmp_data);
if (result != BMP_OK) if (result != BMP_OK)
return result; return result;
@@ -507,7 +493,6 @@ static bmp_result ico_header_parse(ico_collection *ico, uint8_t *data)
return BMP_OK; return BMP_OK;
} }
/** /**
* Decode BMP data stored in 32bpp colour. * Decode BMP data stored in 32bpp colour.
* *
@@ -518,8 +503,7 @@ static bmp_result ico_header_parse(ico_collection *ico, uint8_t *data)
* BMP_INSUFFICIENT_DATA if the bitmap data ends unexpectedly; * BMP_INSUFFICIENT_DATA if the bitmap data ends unexpectedly;
* in this case, the image may be partially viewable * in this case, the image may be partially viewable
*/ */
static bmp_result bmp_decode_rgb32(bmp_image *bmp, uint8_t **start, int bytes) static bmp_result bmp_decode_rgb32(bmp_image *bmp, uint8_t **start, int bytes) {
{
uint8_t *top, *bottom, *end, *data; uint8_t *top, *bottom, *end, *data;
uint32_t *scanline; uint32_t *scanline;
uint32_t x, y; uint32_t x, y;
@@ -567,7 +551,7 @@ static bmp_result bmp_decode_rgb32(bmp_image *bmp, uint8_t **start, int bytes)
if (bmp->opaque) if (bmp->opaque)
scanline[x] |= ((unsigned)0xff << 24); scanline[x] |= ((unsigned)0xff << 24);
data += 4; data += 4;
scanline[x] = read_uint32((uint8_t *)&scanline[x],0); scanline[x] = read_uint32((uint8_t *)&scanline[x], 0);
} }
} else { } else {
for (x = 0; x < bmp->width; x++) { for (x = 0; x < bmp->width; x++) {
@@ -581,7 +565,7 @@ static bmp_result bmp_decode_rgb32(bmp_image *bmp, uint8_t **start, int bytes)
scanline[x] |= (unsigned)data[3] << 24; scanline[x] |= (unsigned)data[3] << 24;
} }
data += 4; data += 4;
scanline[x] = read_uint32((uint8_t *)&scanline[x],0); scanline[x] = read_uint32((uint8_t *)&scanline[x], 0);
} }
} }
} }
@@ -589,7 +573,6 @@ static bmp_result bmp_decode_rgb32(bmp_image *bmp, uint8_t **start, int bytes)
return BMP_OK; return BMP_OK;
} }
/** /**
* Decode BMP data stored in 24bpp colour. * Decode BMP data stored in 24bpp colour.
* *
@@ -600,8 +583,7 @@ static bmp_result bmp_decode_rgb32(bmp_image *bmp, uint8_t **start, int bytes)
* BMP_INSUFFICIENT_DATA if the bitmap data ends unexpectedly; * BMP_INSUFFICIENT_DATA if the bitmap data ends unexpectedly;
* in this case, the image may be partially viewable * in this case, the image may be partially viewable
*/ */
static bmp_result bmp_decode_rgb24(bmp_image *bmp, uint8_t **start, int bytes) static bmp_result bmp_decode_rgb24(bmp_image *bmp, uint8_t **start, int bytes) {
{
uint8_t *top, *bottom, *end, *data; uint8_t *top, *bottom, *end, *data;
uint32_t *scanline; uint32_t *scanline;
uint32_t x, y; uint32_t x, y;
@@ -651,7 +633,7 @@ static bmp_result bmp_decode_rgb24(bmp_image *bmp, uint8_t **start, int bytes)
scanline[x] |= ((uint32_t)0xff << 24); scanline[x] |= ((uint32_t)0xff << 24);
} }
data += 3; data += 3;
scanline[x] = read_uint32((uint8_t *)&scanline[x],0); scanline[x] = read_uint32((uint8_t *)&scanline[x], 0);
} }
while (addr != (((intptr_t)data) & 3)) { while (addr != (((intptr_t)data) & 3)) {
@@ -662,7 +644,6 @@ static bmp_result bmp_decode_rgb24(bmp_image *bmp, uint8_t **start, int bytes)
return BMP_OK; return BMP_OK;
} }
/** /**
* Decode BMP data stored in 16bpp colour. * Decode BMP data stored in 16bpp colour.
* *
@@ -673,8 +654,7 @@ static bmp_result bmp_decode_rgb24(bmp_image *bmp, uint8_t **start, int bytes)
* BMP_INSUFFICIENT_DATA if the bitmap data ends unexpectedly; * BMP_INSUFFICIENT_DATA if the bitmap data ends unexpectedly;
* in this case, the image may be partially viewable * in this case, the image may be partially viewable
*/ */
static bmp_result bmp_decode_rgb16(bmp_image *bmp, uint8_t **start, int bytes) static bmp_result bmp_decode_rgb16(bmp_image *bmp, uint8_t **start, int bytes) {
{
uint8_t *top, *bottom, *end, *data; uint8_t *top, *bottom, *end, *data;
uint32_t *scanline; uint32_t *scanline;
uint32_t x, y, swidth; uint32_t x, y, swidth;
@@ -722,7 +702,7 @@ static bmp_result bmp_decode_rgb16(bmp_image *bmp, uint8_t **start, int bytes)
scanline[x] |= ((unsigned)0xff << 24); scanline[x] |= ((unsigned)0xff << 24);
} }
data += 2; data += 2;
scanline[x] = read_uint32((uint8_t *)&scanline[x],0); scanline[x] = read_uint32((uint8_t *)&scanline[x], 0);
} }
} else { } else {
for (x = 0; x < bmp->width; x++) { for (x = 0; x < bmp->width; x++) {
@@ -731,14 +711,13 @@ static bmp_result bmp_decode_rgb16(bmp_image *bmp, uint8_t **start, int bytes)
scanline[x] = bmp->trans_colour; scanline[x] = bmp->trans_colour;
else { else {
/* 16-bit RGB defaults to RGB555 */ /* 16-bit RGB defaults to RGB555 */
scanline[x] = ((word & (31 << 0)) << 19) | scanline[x] = ((word & (31 << 0)) << 19) | ((word & (31 << 5)) << 6) |
((word & (31 << 5)) << 6) |
((word & (31 << 10)) >> 7); ((word & (31 << 10)) >> 7);
} }
if (bmp->opaque) if (bmp->opaque)
scanline[x] |= ((unsigned)0xff << 24); scanline[x] |= ((unsigned)0xff << 24);
data += 2; data += 2;
scanline[x] = read_uint32((uint8_t *)&scanline[x],0); scanline[x] = read_uint32((uint8_t *)&scanline[x], 0);
} }
} }
while (addr != (((intptr_t)data) & 3)) while (addr != (((intptr_t)data) & 3))
@@ -748,7 +727,6 @@ static bmp_result bmp_decode_rgb16(bmp_image *bmp, uint8_t **start, int bytes)
return BMP_OK; return BMP_OK;
} }
/** /**
* Decode BMP data stored with a palette and in 8bpp colour or less. * Decode BMP data stored with a palette and in 8bpp colour or less.
* *
@@ -759,8 +737,7 @@ static bmp_result bmp_decode_rgb16(bmp_image *bmp, uint8_t **start, int bytes)
* BMP_INSUFFICIENT_DATA if the bitmap data ends unexpectedly; * BMP_INSUFFICIENT_DATA if the bitmap data ends unexpectedly;
* in this case, the image may be partially viewable * in this case, the image may be partially viewable
*/ */
static bmp_result bmp_decode_rgb(bmp_image *bmp, uint8_t **start, int bytes) static bmp_result bmp_decode_rgb(bmp_image *bmp, uint8_t **start, int bytes) {
{
uint8_t *top, *bottom, *end, *data; uint8_t *top, *bottom, *end, *data;
uint32_t *scanline; uint32_t *scanline;
intptr_t addr; intptr_t addr;
@@ -812,8 +789,7 @@ static bmp_result bmp_decode_rgb(bmp_image *bmp, uint8_t **start, int bytes)
if (idx < bmp->colours) { if (idx < bmp->colours) {
/* ensure colour table index is in bounds */ /* ensure colour table index is in bounds */
scanline[x] = bmp->colour_table[idx]; scanline[x] = bmp->colour_table[idx];
if ((bmp->limited_trans) && if ((bmp->limited_trans) && (scanline[x] == bmp->transparent_index)) {
(scanline[x] == bmp->transparent_index)) {
scanline[x] = bmp->trans_colour; scanline[x] = bmp->trans_colour;
} }
} }
@@ -825,7 +801,6 @@ static bmp_result bmp_decode_rgb(bmp_image *bmp, uint8_t **start, int bytes)
return BMP_OK; return BMP_OK;
} }
/** /**
* Decode a 1bpp mask for an ICO * Decode a 1bpp mask for an ICO
* *
@@ -834,8 +809,7 @@ static bmp_result bmp_decode_rgb(bmp_image *bmp, uint8_t **start, int bytes)
* \param bytes the number of bytes of data available * \param bytes the number of bytes of data available
* \return BMP_OK on success * \return BMP_OK on success
*/ */
static bmp_result bmp_decode_mask(bmp_image *bmp, uint8_t *data, int bytes) static bmp_result bmp_decode_mask(bmp_image *bmp, uint8_t *data, int bytes) {
{
uint8_t *top, *bottom, *end; uint8_t *top, *bottom, *end;
uint32_t *scanline; uint32_t *scanline;
intptr_t addr; intptr_t addr;
@@ -873,7 +847,6 @@ static bmp_result bmp_decode_mask(bmp_image *bmp, uint8_t *data, int bytes)
return BMP_OK; return BMP_OK;
} }
/** /**
* Decode BMP data stored encoded in RLE8. * Decode BMP data stored encoded in RLE8.
* *
@@ -884,9 +857,7 @@ static bmp_result bmp_decode_mask(bmp_image *bmp, uint8_t *data, int bytes)
* BMP_INSUFFICIENT_DATA if the bitmap data ends unexpectedly; * BMP_INSUFFICIENT_DATA if the bitmap data ends unexpectedly;
* in this case, the image may be partially viewable * in this case, the image may be partially viewable
*/ */
static bmp_result static bmp_result bmp_decode_rle8(bmp_image *bmp, uint8_t *data, int bytes) {
bmp_decode_rle8(bmp_image *bmp, uint8_t *data, int bytes)
{
uint8_t *top, *bottom, *end; uint8_t *top, *bottom, *end;
uint32_t *scanline; uint32_t *scanline;
uint32_t swidth; uint32_t swidth;
@@ -958,7 +929,7 @@ bmp_decode_rle8(bmp_image *bmp, uint8_t *data, int bytes)
* using some simple copying routines if so * using some simple copying routines if so
*/ */
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
uint32_t idx = (uint32_t) *data++; uint32_t idx = (uint32_t)*data++;
if (x >= bmp->width) { if (x >= bmp->width) {
x = 0; x = 0;
y++; y++;
@@ -1002,7 +973,7 @@ bmp_decode_rle8(bmp_image *bmp, uint8_t *data, int bytes)
* simply checking the bounds on entry and using some * simply checking the bounds on entry and using some
* simply copying routines if so * simply copying routines if so
*/ */
idx = (uint32_t) *data++; idx = (uint32_t)*data++;
if (idx >= bmp->colours) if (idx >= bmp->colours)
return BMP_DATA_ERROR; return BMP_DATA_ERROR;
@@ -1027,7 +998,6 @@ bmp_decode_rle8(bmp_image *bmp, uint8_t *data, int bytes)
return BMP_OK; return BMP_OK;
} }
/** /**
* Decode BMP data stored encoded in RLE4. * Decode BMP data stored encoded in RLE4.
* *
@@ -1038,9 +1008,7 @@ bmp_decode_rle8(bmp_image *bmp, uint8_t *data, int bytes)
* BMP_INSUFFICIENT_DATA if the bitmap data ends unexpectedly; * BMP_INSUFFICIENT_DATA if the bitmap data ends unexpectedly;
* in this case, the image may be partially viewable * in this case, the image may be partially viewable
*/ */
static bmp_result static bmp_result bmp_decode_rle4(bmp_image *bmp, uint8_t *data, int bytes) {
bmp_decode_rle4(bmp_image *bmp, uint8_t *data, int bytes)
{
uint8_t *top, *bottom, *end; uint8_t *top, *bottom, *end;
uint32_t *scanline; uint32_t *scanline;
uint32_t swidth; uint32_t swidth;
@@ -1123,19 +1091,16 @@ bmp_decode_rle4(bmp_image *bmp, uint8_t *data, int bytes)
} else { } else {
scanline -= bmp->width; scanline -= bmp->width;
} }
} }
if ((i & 1) == 0) { if ((i & 1) == 0) {
pixel = *data++; pixel = *data++;
if ((pixel >> 4) >= bmp->colours) if ((pixel >> 4) >= bmp->colours)
return BMP_DATA_ERROR; return BMP_DATA_ERROR;
scanline[x++] = bmp->colour_table scanline[x++] = bmp->colour_table[pixel >> 4];
[pixel >> 4];
} else { } else {
if ((pixel & 0xf) >= bmp->colours) if ((pixel & 0xf) >= bmp->colours)
return BMP_DATA_ERROR; return BMP_DATA_ERROR;
scanline[x++] = bmp->colour_table scanline[x++] = bmp->colour_table[pixel & 0xf];
[pixel & 0xf];
} }
} }
length = (length + 1) >> 1; length = (length + 1) >> 1;
@@ -1167,8 +1132,7 @@ bmp_decode_rle4(bmp_image *bmp, uint8_t *data, int bytes)
*/ */
pixel2 = *data++; pixel2 = *data++;
if ((pixel2 >> 4) >= bmp->colours || if ((pixel2 >> 4) >= bmp->colours || (pixel2 & 0xf) >= bmp->colours)
(pixel2 & 0xf) >= bmp->colours)
return BMP_DATA_ERROR; return BMP_DATA_ERROR;
pixel = bmp->colour_table[pixel2 >> 4]; pixel = bmp->colour_table[pixel2 >> 4];
pixel2 = bmp->colour_table[pixel2 & 0xf]; pixel2 = bmp->colour_table[pixel2 & 0xf];
@@ -1189,31 +1153,24 @@ bmp_decode_rle4(bmp_image *bmp, uint8_t *data, int bytes)
else else
scanline[x++] = pixel2; scanline[x++] = pixel2;
} }
} }
} while (data < end); } while (data < end);
return BMP_OK; return BMP_OK;
} }
/* exported interface documented in libnsbmp.h */ /* exported interface documented in libnsbmp.h */
bmp_result bmp_result bmp_create(bmp_image *bmp,
bmp_create(bmp_image *bmp, bmp_bitmap_callback_vt *bitmap_callbacks) {
bmp_bitmap_callback_vt *bitmap_callbacks)
{
memset(bmp, 0, sizeof(bmp_image)); memset(bmp, 0, sizeof(bmp_image));
bmp->bitmap_callbacks = *bitmap_callbacks; bmp->bitmap_callbacks = *bitmap_callbacks;
return BMP_OK; return BMP_OK;
} }
/* exported interface documented in libnsbmp.h */ /* exported interface documented in libnsbmp.h */
bmp_result bmp_result ico_collection_create(ico_collection *ico,
ico_collection_create(ico_collection *ico, bmp_bitmap_callback_vt *bitmap_callbacks) {
bmp_bitmap_callback_vt *bitmap_callbacks)
{
memset(ico, 0, sizeof(ico_collection)); memset(ico, 0, sizeof(ico_collection));
ico->bitmap_callbacks = *bitmap_callbacks; ico->bitmap_callbacks = *bitmap_callbacks;
@@ -1221,10 +1178,8 @@ ico_collection_create(ico_collection *ico,
return BMP_OK; return BMP_OK;
} }
/* exported interface documented in libnsbmp.h */ /* exported interface documented in libnsbmp.h */
bmp_result bmp_analyse(bmp_image *bmp, size_t size, uint8_t *data) bmp_result bmp_analyse(bmp_image *bmp, size_t size, uint8_t *data) {
{
bmp_result res; bmp_result res;
/* ensure we aren't already initialised */ /* ensure we aren't already initialised */
@@ -1243,10 +1198,8 @@ bmp_result bmp_analyse(bmp_image *bmp, size_t size, uint8_t *data)
return res; return res;
} }
/* exported interface documented in libnsbmp.h */ /* exported interface documented in libnsbmp.h */
bmp_result ico_analyse(ico_collection *ico, size_t size, uint8_t *data) bmp_result ico_analyse(ico_collection *ico, size_t size, uint8_t *data) {
{
/* ensure we aren't already initialised */ /* ensure we aren't already initialised */
if (ico->first) if (ico->first)
return BMP_OK; return BMP_OK;
@@ -1258,10 +1211,8 @@ bmp_result ico_analyse(ico_collection *ico, size_t size, uint8_t *data)
return ico_header_parse(ico, data); return ico_header_parse(ico, data);
} }
/* exported interface documented in libnsbmp.h */ /* exported interface documented in libnsbmp.h */
bmp_result bmp_decode(bmp_image *bmp) bmp_result bmp_decode(bmp_image *bmp) {
{
uint8_t *data; uint8_t *data;
uint32_t bytes; uint32_t bytes;
bmp_result result = BMP_OK; bmp_result result = BMP_OK;
@@ -1325,19 +1276,15 @@ bmp_result bmp_decode(bmp_image *bmp)
return result; return result;
} }
/* exported interface documented in libnsbmp.h */ /* exported interface documented in libnsbmp.h */
bmp_result bmp_decode_trans(bmp_image *bmp, uint32_t colour) bmp_result bmp_decode_trans(bmp_image *bmp, uint32_t colour) {
{
bmp->limited_trans = true; bmp->limited_trans = true;
bmp->trans_colour = colour; bmp->trans_colour = colour;
return bmp_decode(bmp); return bmp_decode(bmp);
} }
/* exported interface documented in libnsbmp.h */ /* exported interface documented in libnsbmp.h */
bmp_image *ico_find(ico_collection *ico, uint16_t width, uint16_t height) bmp_image *ico_find(ico_collection *ico, uint16_t width, uint16_t height) {
{
bmp_image *bmp = NULL; bmp_image *bmp = NULL;
ico_image *image; ico_image *image;
int x, y, cur, distance = (1 << 24); int x, y, cur, distance = (1 << 24);
@@ -1360,10 +1307,8 @@ bmp_image *ico_find(ico_collection *ico, uint16_t width, uint16_t height)
return bmp; return bmp;
} }
/* exported interface documented in libnsbmp.h */ /* exported interface documented in libnsbmp.h */
void bmp_finalise(bmp_image *bmp) void bmp_finalise(bmp_image *bmp) {
{
if (bmp->bitmap) if (bmp->bitmap)
bmp->bitmap_callbacks.bitmap_destroy(bmp->bitmap); bmp->bitmap_callbacks.bitmap_destroy(bmp->bitmap);
bmp->bitmap = NULL; bmp->bitmap = NULL;
@@ -1372,10 +1317,8 @@ void bmp_finalise(bmp_image *bmp)
bmp->colour_table = NULL; bmp->colour_table = NULL;
} }
/* exported interface documented in libnsbmp.h */ /* exported interface documented in libnsbmp.h */
void ico_finalise(ico_collection *ico) void ico_finalise(ico_collection *ico) {
{
ico_image *image; ico_image *image;
for (image = ico->first; image; image = image->next) for (image = ico->first; image; image = image->next)
+78 -41
View File
@@ -3,9 +3,9 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdlib.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/statvfs.h> #include <sys/statvfs.h>
#include <stdlib.h>
#define WORKING_DIR "/" #define WORKING_DIR "/"
@@ -23,7 +23,8 @@ FS_Archive archive, sdmc_archive, nand_archive;
Result FS_OpenArchive(FS_Archive *archive, FS_ArchiveID archiveID) { Result FS_OpenArchive(FS_Archive *archive, FS_ArchiveID archiveID) {
Result ret = 0; Result ret = 0;
if (R_FAILED(ret = FSUSER_OpenArchive(archive, archiveID, fsMakePath(PATH_EMPTY, "")))) if (R_FAILED(ret = FSUSER_OpenArchive(archive, archiveID,
fsMakePath(PATH_EMPTY, ""))))
return ret; return ret;
return 0; return 0;
@@ -44,19 +45,23 @@ Result FS_OpenDir(Handle *handle, FS_Archive archive, const char *path) {
u16 path_u16[strlen(path) + 1]; u16 path_u16[strlen(path) + 1];
Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1); Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1);
if (R_FAILED(ret = FSUSER_OpenDirectory(handle, archive, fsMakePath(PATH_UTF16, path_u16)))) if (R_FAILED(ret = FSUSER_OpenDirectory(handle, archive,
fsMakePath(PATH_UTF16, path_u16))))
return ret; return ret;
return 0; return 0;
} }
Result FS_OpenFile(Handle *handle, FS_Archive archive, const char *path, u32 flags, u32 attributes) { Result FS_OpenFile(Handle *handle, FS_Archive archive, const char *path,
u32 flags, u32 attributes) {
Result ret = 0; Result ret = 0;
u16 path_u16[strlen(path) + 1]; u16 path_u16[strlen(path) + 1];
Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1); Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1);
if (R_FAILED(ret = FSUSER_OpenFile(handle, archive, fsMakePath(PATH_UTF16, path_u16), flags, attributes))) if (R_FAILED(ret = FSUSER_OpenFile(handle, archive,
fsMakePath(PATH_UTF16, path_u16), flags,
attributes)))
return ret; return ret;
return 0; return 0;
@@ -68,7 +73,8 @@ Result FS_MakeDir(FS_Archive archive, const char *path) {
u16 path_u16[strlen(path) + 1]; u16 path_u16[strlen(path) + 1];
Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1); Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1);
if (R_FAILED(ret = FSUSER_CreateDirectory(archive, fsMakePath(PATH_UTF16, path_u16), 0))) if (R_FAILED(ret = FSUSER_CreateDirectory(
archive, fsMakePath(PATH_UTF16, path_u16), 0)))
return ret; return ret;
return 0; return 0;
@@ -80,7 +86,8 @@ Result FS_CreateFile(FS_Archive archive, const char *path, u64 size) {
u16 path_u16[strlen(path) + 1]; u16 path_u16[strlen(path) + 1];
Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1); Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1);
if (R_FAILED(ret = FSUSER_CreateFile(archive, fsMakePath(PATH_UTF16, path_u16), 0, size))) if (R_FAILED(ret = FSUSER_CreateFile(
archive, fsMakePath(PATH_UTF16, path_u16), 0, size)))
return ret; return ret;
return 0; return 0;
@@ -121,7 +128,8 @@ bool FS_FileExists(FS_Archive archive, const char *path) {
u16 path_u16[strlen(path) + 1]; u16 path_u16[strlen(path) + 1];
Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1); Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1);
if (R_FAILED(FSUSER_OpenFile(&handle, archive, fsMakePath(PATH_UTF16, path_u16), FS_OPEN_READ, 0))) if (R_FAILED(FSUSER_OpenFile(
&handle, archive, fsMakePath(PATH_UTF16, path_u16), FS_OPEN_READ, 0)))
return false; return false;
if (R_FAILED(FSFILE_Close(handle))) if (R_FAILED(FSFILE_Close(handle)))
@@ -136,7 +144,8 @@ bool FS_DirExists(FS_Archive archive, const char *path) {
u16 path_u16[strlen(path) + 1]; u16 path_u16[strlen(path) + 1];
Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1); Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1);
if (R_FAILED(FSUSER_OpenDirectory(&handle, archive, fsMakePath(PATH_UTF16, path_u16)))) if (R_FAILED(FSUSER_OpenDirectory(&handle, archive,
fsMakePath(PATH_UTF16, path_u16))))
return false; return false;
if (R_FAILED(FSDIR_Close(handle))) if (R_FAILED(FSDIR_Close(handle)))
@@ -152,7 +161,9 @@ Result FS_GetFileSize(FS_Archive archive, const char *path, u64 *size) {
u16 path_u16[strlen(path) + 1]; u16 path_u16[strlen(path) + 1];
Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1); Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1);
if (R_FAILED(ret = FSUSER_OpenFile(&handle, archive, fsMakePath(PATH_UTF16, path_u16), FS_OPEN_READ, 0))) if (R_FAILED(ret = FSUSER_OpenFile(&handle, archive,
fsMakePath(PATH_UTF16, path_u16),
FS_OPEN_READ, 0)))
return ret; return ret;
if (R_FAILED(ret = FSFILE_GetSize(handle, size))) { if (R_FAILED(ret = FSFILE_GetSize(handle, size))) {
@@ -185,7 +196,7 @@ u64 FS_GetTotalStorage(FS_SystemMediaType media_type) {
} }
u64 FS_GetUsedStorage(FS_SystemMediaType media_type) { u64 FS_GetUsedStorage(FS_SystemMediaType media_type) {
return 0;//(FS_GetTotalStorage(media_type) - FS_GetUsedStorage(media_type)); return 0; //(FS_GetTotalStorage(media_type) - FS_GetUsedStorage(media_type));
} }
Result FS_RemoveFile(FS_Archive archive, const char *path) { Result FS_RemoveFile(FS_Archive archive, const char *path) {
@@ -194,7 +205,8 @@ Result FS_RemoveFile(FS_Archive archive, const char *path) {
u16 path_u16[strlen(path) + 1]; u16 path_u16[strlen(path) + 1];
Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1); Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1);
if (R_FAILED(ret = FSUSER_DeleteFile(archive, fsMakePath(PATH_UTF16, path_u16)))) if (R_FAILED(
ret = FSUSER_DeleteFile(archive, fsMakePath(PATH_UTF16, path_u16))))
return ret; return ret;
return 0; return 0;
@@ -206,7 +218,8 @@ Result FS_RemoveDir(FS_Archive archive, const char *path) {
u16 path_u16[strlen(path) + 1]; u16 path_u16[strlen(path) + 1];
Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1); Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1);
if (R_FAILED(ret = FSUSER_DeleteDirectory(archive, fsMakePath(PATH_UTF16, path_u16)))) if (R_FAILED(ret = FSUSER_DeleteDirectory(archive,
fsMakePath(PATH_UTF16, path_u16))))
return ret; return ret;
return 0; return 0;
@@ -218,37 +231,48 @@ Result FS_RemoveDirRecursive(FS_Archive archive, const char *path) {
u16 path_u16[strlen(path) + 1]; u16 path_u16[strlen(path) + 1];
Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1); Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1);
if (R_FAILED(ret = FSUSER_DeleteDirectoryRecursively(archive, fsMakePath(PATH_UTF16, path_u16)))) if (R_FAILED(ret = FSUSER_DeleteDirectoryRecursively(
archive, fsMakePath(PATH_UTF16, path_u16))))
return ret; return ret;
return 0; return 0;
} }
Result FS_RenameFile(FS_Archive archive, const char *old_filename, const char *new_filename) { Result FS_RenameFile(FS_Archive archive, const char *old_filename,
const char *new_filename) {
Result ret = 0; Result ret = 0;
u16 old_filename_u16[strlen(old_filename) + 1]; u16 old_filename_u16[strlen(old_filename) + 1];
Utils_U8_To_U16(old_filename_u16, (const u8 *)old_filename, strlen(old_filename) + 1); Utils_U8_To_U16(old_filename_u16, (const u8 *)old_filename,
strlen(old_filename) + 1);
u16 new_filename_u16[strlen(new_filename) + 1]; u16 new_filename_u16[strlen(new_filename) + 1];
Utils_U8_To_U16(new_filename_u16, (const u8 *)new_filename, strlen(new_filename) + 1); Utils_U8_To_U16(new_filename_u16, (const u8 *)new_filename,
strlen(new_filename) + 1);
if (R_FAILED(ret = FSUSER_RenameFile(archive, fsMakePath(PATH_UTF16, old_filename_u16), archive, fsMakePath(PATH_UTF16, new_filename_u16)))) if (R_FAILED(ret = FSUSER_RenameFile(
archive, fsMakePath(PATH_UTF16, old_filename_u16), archive,
fsMakePath(PATH_UTF16, new_filename_u16))))
return ret; return ret;
return 0; return 0;
} }
Result FS_RenameDir(FS_Archive archive, const char *old_dirname, const char *new_dirname) { Result FS_RenameDir(FS_Archive archive, const char *old_dirname,
const char *new_dirname) {
Result ret = 0; Result ret = 0;
u16 old_dirname_u16[strlen(old_dirname) + 1]; u16 old_dirname_u16[strlen(old_dirname) + 1];
Utils_U8_To_U16(old_dirname_u16, (const u8 *)old_dirname, strlen(old_dirname) + 1); Utils_U8_To_U16(old_dirname_u16, (const u8 *)old_dirname,
strlen(old_dirname) + 1);
u16 new_dirname_u16[strlen(new_dirname) + 1]; u16 new_dirname_u16[strlen(new_dirname) + 1];
Utils_U8_To_U16(new_dirname_u16, (const u8 *)new_dirname, strlen(new_dirname) + 1); Utils_U8_To_U16(new_dirname_u16, (const u8 *)new_dirname,
strlen(new_dirname) + 1);
if (R_FAILED(ret = FSUSER_RenameDirectory(archive, fsMakePath(PATH_UTF16, old_dirname_u16), archive, fsMakePath(PATH_UTF16, new_dirname_u16)))) if (R_FAILED(ret = FSUSER_RenameDirectory(
archive, fsMakePath(PATH_UTF16, old_dirname_u16), archive,
fsMakePath(PATH_UTF16, new_dirname_u16))))
return ret; return ret;
return 0; return 0;
@@ -274,7 +298,8 @@ Result FS_Read(FS_Archive archive, const char *path, u64 size, void *buf) {
return 0; return 0;
} }
Result FS_Write(FS_Archive archive, const char *path, const void *buf, u32 size) { Result FS_Write(FS_Archive archive, const char *path, const void *buf,
u32 size) {
Result ret = 0; Result ret = 0;
Handle handle; Handle handle;
u32 bytes_written = 0; u32 bytes_written = 0;
@@ -285,13 +310,17 @@ Result FS_Write(FS_Archive archive, const char *path, const void *buf, u32 size)
u16 path_u16[strlen(path) + 1]; u16 path_u16[strlen(path) + 1];
Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1); Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1);
if (R_FAILED(ret = FSUSER_CreateFile(archive, fsMakePath(PATH_UTF16, path_u16), 0, size))) if (R_FAILED(ret = FSUSER_CreateFile(
archive, fsMakePath(PATH_UTF16, path_u16), 0, size)))
return ret; return ret;
if (R_FAILED(ret = FSUSER_OpenFile(&handle, archive, fsMakePath(PATH_UTF16, path_u16), FS_OPEN_WRITE, 0))) if (R_FAILED(ret = FSUSER_OpenFile(&handle, archive,
fsMakePath(PATH_UTF16, path_u16),
FS_OPEN_WRITE, 0)))
return ret; return ret;
if (R_FAILED(ret = FSFILE_Write(handle, &bytes_written, 0, buf, size, FS_WRITE_FLUSH))) { if (R_FAILED(ret = FSFILE_Write(handle, &bytes_written, 0, buf, size,
FS_WRITE_FLUSH))) {
FSFILE_Close(handle); FSFILE_Close(handle);
return ret; return ret;
} }
@@ -317,15 +346,15 @@ char *FS_GetFileTimestamp(const char *path) {
int month = timeStruct->tm_mon + 1; // January being 0 int month = timeStruct->tm_mon + 1; // January being 0
int year = timeStruct->tm_year + 1900; int year = timeStruct->tm_year + 1900;
snprintf(timeStr, 60, "%d/%d/%d %2i:%02i", year, month, day, hours, minutes); snprintf(timeStr, 60, "%d/%d/%d %2i:%02i", year, month, day, hours,
} minutes);
else } else
return NULL; return NULL;
return timeStr; return timeStr;
} }
FS_Path getPathInfo(const char * path, FS_ArchiveID * archive) { FS_Path getPathInfo(const char *path, FS_ArchiveID *archive) {
*archive = ARCHIVE_SDMC; *archive = ARCHIVE_SDMC;
FS_Path filePath = {0}; FS_Path filePath = {0};
unsigned int prefixlen = 0; unsigned int prefixlen = 0;
@@ -333,21 +362,22 @@ FS_Path getPathInfo(const char * path, FS_ArchiveID * archive) {
if (!strncmp(path, "sdmc:/", 6)) { if (!strncmp(path, "sdmc:/", 6)) {
prefixlen = 5; prefixlen = 5;
} else if (*path != '/') { } else if (*path != '/') {
//if the path is local (doesnt start with a slash), it needs to be appended to the working dir to be valid // if the path is local (doesnt start with a slash), it needs to be appended
char * actualPath = NULL; // to the working dir to be valid
char *actualPath = NULL;
asprintf(&actualPath, "%s%s", WORKING_DIR, path); asprintf(&actualPath, "%s%s", WORKING_DIR, path);
filePath = fsMakePath(PATH_ASCII, actualPath); filePath = fsMakePath(PATH_ASCII, actualPath);
free(actualPath); free(actualPath);
} }
//if the filePath wasnt set above, set it // if the filePath wasnt set above, set it
if (filePath.size == 0) { if (filePath.size == 0) {
filePath = fsMakePath(PATH_ASCII, path+prefixlen); filePath = fsMakePath(PATH_ASCII, path + prefixlen);
} }
return filePath; return filePath;
} }
Result makeDirs(const char * path) { Result makeDirs(const char *path) {
Result ret = 0; Result ret = 0;
FS_ArchiveID archiveID; FS_ArchiveID archiveID;
FS_Path filePath = getPathInfo(path, &archiveID); FS_Path filePath = getPathInfo(path, &archiveID);
@@ -355,14 +385,17 @@ Result makeDirs(const char * path) {
ret = FSUSER_OpenArchive(&archive, archiveID, fsMakePath(PATH_EMPTY, "")); ret = FSUSER_OpenArchive(&archive, archiveID, fsMakePath(PATH_EMPTY, ""));
for (char * slashpos = strchr(path+1, '/'); slashpos != NULL; slashpos = strchr(slashpos+1, '/')) { for (char *slashpos = strchr(path + 1, '/'); slashpos != NULL;
slashpos = strchr(slashpos + 1, '/')) {
char bak = *(slashpos); char bak = *(slashpos);
*(slashpos) = '\0'; *(slashpos) = '\0';
Handle dirHandle; Handle dirHandle;
ret = FSUSER_OpenDirectory(&dirHandle, archive, filePath); ret = FSUSER_OpenDirectory(&dirHandle, archive, filePath);
if (R_SUCCEEDED(ret)) FSDIR_Close(dirHandle); if (R_SUCCEEDED(ret))
else ret = FSUSER_CreateDirectory(archive, filePath, FS_ATTRIBUTE_DIRECTORY); FSDIR_Close(dirHandle);
else
ret = FSUSER_CreateDirectory(archive, filePath, FS_ATTRIBUTE_DIRECTORY);
*(slashpos) = bak; *(slashpos) = bak;
} }
@@ -372,15 +405,19 @@ Result makeDirs(const char * path) {
return ret; return ret;
} }
Result openFile(Handle* fileHandle, const char * path, bool write) { Result openFile(Handle *fileHandle, const char *path, bool write) {
FS_ArchiveID archive; FS_ArchiveID archive;
FS_Path filePath = getPathInfo(path, &archive); FS_Path filePath = getPathInfo(path, &archive);
u32 flags = (write ? (FS_OPEN_CREATE | FS_OPEN_WRITE) : FS_OPEN_READ); u32 flags = (write ? (FS_OPEN_CREATE | FS_OPEN_WRITE) : FS_OPEN_READ);
Result ret = 0; Result ret = 0;
ret = makeDirs(strdup(path)); ret = makeDirs(strdup(path));
ret = FSUSER_OpenFileDirectly(fileHandle, archive, fsMakePath(PATH_EMPTY, ""), filePath, flags, 0); ret = FSUSER_OpenFileDirectly(fileHandle, archive, fsMakePath(PATH_EMPTY, ""),
if (write) ret = FSFILE_SetSize(*fileHandle, 0); //truncate the file to remove previous contents before writing filePath, flags, 0);
if (write)
ret = FSFILE_SetSize(
*fileHandle,
0); // truncate the file to remove previous contents before writing
return ret; return ret;
} }
+3563 -2290
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -1,5 +1,5 @@
#pragma once #pragma once
#include <renderd7/StealConsole.hpp>
#include <renderd7/bmp.hpp> #include <renderd7/bmp.hpp>
#include <renderd7/renderd7.hpp> #include <renderd7/renderd7.hpp>
#include <renderd7/StealConsole.hpp>
+1 -1
View File
@@ -26,6 +26,6 @@ public:
uint8_t m_r, m_g, m_b, m_a; uint8_t m_r, m_g, m_b, m_a;
}; };
std::string RGB2Hex(int r, int g, int b); std::string RGB2Hex(int r, int g, int b);
uint32_t Hex(const std::string color, uint8_t a = 255); uint32_t Hex(const std::string &color, uint8_t a = 255);
} // namespace Color } // namespace Color
} // namespace RenderD7 } // namespace RenderD7
+9 -11
View File
@@ -1,14 +1,12 @@
#pragma once #pragma once
#include <string>
#include <3ds.h> #include <3ds.h>
#include <string>
namespace RenderD7 namespace RenderD7 {
{ class ResultDecoder {
class ResultDecoder public:
{ ResultDecoder() {}
public: ~ResultDecoder() {}
ResultDecoder(){}
~ResultDecoder(){}
void Load(Result rescode); void Load(Result rescode);
void Load(std::string rescode); void Load(std::string rescode);
std::string GetCode(); std::string GetCode();
@@ -21,7 +19,7 @@ namespace RenderD7
std::string GetSummary(); std::string GetSummary();
int GetSummaryInt(); int GetSummaryInt();
private: private:
Result m_rescode; Result m_rescode;
}; };
} } // namespace RenderD7
-1
View File
@@ -2,7 +2,6 @@
#include <sstream> #include <sstream>
#include <string> #include <string>
namespace RenderD7 { namespace RenderD7 {
class StealConsole { class StealConsole {
public: public:
+10 -6
View File
@@ -7,7 +7,8 @@ extern FS_Archive archive, sdmc_archive, nand_archive;
Result FS_OpenArchive(FS_Archive *archive, FS_ArchiveID id); Result FS_OpenArchive(FS_Archive *archive, FS_ArchiveID id);
Result FS_CloseArchive(FS_Archive archive); Result FS_CloseArchive(FS_Archive archive);
Result FS_OpenDir(Handle *handle, FS_Archive archive, const char *path); Result FS_OpenDir(Handle *handle, FS_Archive archive, const char *path);
Result FS_OpenFile(Handle *handle, FS_Archive archive, const char *path, u32 flags, u32 attributes); Result FS_OpenFile(Handle *handle, FS_Archive archive, const char *path,
u32 flags, u32 attributes);
Result FS_MakeDir(FS_Archive archive, const char *path); Result FS_MakeDir(FS_Archive archive, const char *path);
Result FS_CreateFile(FS_Archive archive, const char *path, u64 size); Result FS_CreateFile(FS_Archive archive, const char *path, u64 size);
Result FS_RecursiveMakeDir(FS_Archive archive, const char *path); Result FS_RecursiveMakeDir(FS_Archive archive, const char *path);
@@ -20,10 +21,13 @@ u64 FS_GetUsedStorage(FS_SystemMediaType media_type);
Result FS_RemoveFile(FS_Archive archive, const char *path); Result FS_RemoveFile(FS_Archive archive, const char *path);
Result FS_RemoveDir(FS_Archive archive, const char *path); Result FS_RemoveDir(FS_Archive archive, const char *path);
Result FS_RemoveDirRecursive(FS_Archive archive, const char *path); Result FS_RemoveDirRecursive(FS_Archive archive, const char *path);
Result FS_RenameFile(FS_Archive archive, const char *old_filename, const char *new_filename); Result FS_RenameFile(FS_Archive archive, const char *old_filename,
Result FS_RenameDir(FS_Archive archive, const char *old_dirname, const char *new_dirname); const char *new_filename);
Result FS_RenameDir(FS_Archive archive, const char *old_dirname,
const char *new_dirname);
Result FS_Read(FS_Archive archive, const char *path, u64 size, void *buf); Result FS_Read(FS_Archive archive, const char *path, u64 size, void *buf);
Result FS_Write(FS_Archive archive, const char *path, const void *buf, u32 size); Result FS_Write(FS_Archive archive, const char *path, const void *buf,
u32 size);
char *FS_GetFileTimestamp(const char *path); char *FS_GetFileTimestamp(const char *path);
Result makeDirs(const char * path); Result makeDirs(const char *path);
Result openFile(Handle* fileHandle, const char * path, bool write); Result openFile(Handle *fileHandle, const char *path, bool write);
+4 -3
View File
@@ -16,8 +16,8 @@
#define libnsbmp_h_ #define libnsbmp_h_
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h>
#include <stddef.h> #include <stddef.h>
#include <stdint.h>
/* bmp flags */ /* bmp flags */
#define BMP_NEW 0 #define BMP_NEW 0
@@ -47,9 +47,10 @@ typedef enum {
} bmp_encoding; } bmp_encoding;
/* API for Bitmap callbacks */ /* API for Bitmap callbacks */
typedef void* (*bmp_bitmap_cb_create)(int width, int height, unsigned int state); typedef void *(*bmp_bitmap_cb_create)(int width, int height,
unsigned int state);
typedef void (*bmp_bitmap_cb_destroy)(void *bitmap); typedef void (*bmp_bitmap_cb_destroy)(void *bitmap);
typedef unsigned char* (*bmp_bitmap_cb_get_buffer)(void *bitmap); typedef unsigned char *(*bmp_bitmap_cb_get_buffer)(void *bitmap);
typedef size_t (*bmp_bitmap_cb_get_bpp)(void *bitmap); typedef size_t (*bmp_bitmap_cb_get_bpp)(void *bitmap);
/** /**
+14 -8
View File
@@ -13,15 +13,21 @@
#define _LIBNSBMP_LOG_H_ #define _LIBNSBMP_LOG_H_
#ifdef NDEBUG #ifdef NDEBUG
# define LOG(x) ((void) 0) #define LOG(x) ((void)0)
#else #else
# ifdef __GNUC__ #ifdef __GNUC__
# define LOG(x) do { printf x, fputc('\n', stdout)); } while (0) #define LOG(x) \
# elif defined(__CC_NORCROFT) do { printf x, fputc('\n', stdout)); \
# define LOG(x) do { printf x, fputc('\n', stdout)); } while (0) } while (0)
# else #elif defined(__CC_NORCROFT)
# define LOG(x) do { printf x, fputc('\n', stdout)); } while (0) #define LOG(x) \
# endif do { printf x, fputc('\n', stdout)); \
} while (0)
#else
#define LOG(x) \
do { printf x, fputc('\n', stdout)); \
} while (0)
#endif
#endif #endif
#endif #endif
+621 -484
View File
File diff suppressed because it is too large Load Diff
+3222 -2438
View File
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+2122 -1563
View File
File diff suppressed because it is too large Load Diff
+28 -6
View File
@@ -1,18 +1,40 @@
#include <renderd7/Color.hpp> #include <renderd7/Color.hpp>
#include <map>
#define RGBA8(r, g, b, a) \ #define RGBA8(r, g, b, a) \
((((r)&0xFF) << 0) | (((g)&0xFF) << 8) | (((b)&0xFF) << 16) | \ ((((r)&0xFF) << 0) | (((g)&0xFF) << 8) | (((b)&0xFF) << 16) | \
(((a)&0xFF) << 24)) (((a)&0xFF) << 24))
uint32_t RenderD7::Color::Hex(const std::string color, uint8_t a) { // uint32_t RenderD7::Color::Hex(const std::string &color, uint8_t a) {
// if (color.length() < 7 ||
// std::regex_search(color.substr(1),
// std::regex("[^0-9A-Fa-f]"))) { // invalid color.
// return RenderD7::Color::Hex("#000000", 0);
// }
// int r = std::stoi(color.substr(1, 2), nullptr, 16);
// int g = std::stoi(color.substr(3, 2), nullptr, 16);
// int b = std::stoi(color.substr(5, 2), nullptr, 16);
// return RGBA8(r, g, b, a);
// }
// Lookup-Table für Hex-to-Dez-Konvertierung
static const std::map<char, int> HEX_TO_DEC = {
{'0', 0}, {'1', 1}, {'2', 2}, {'3', 3}, {'4', 4}, {'5', 5},
{'6', 6}, {'7', 7}, {'8', 8}, {'9', 9}, {'a', 10}, {'b', 11},
{'c', 12}, {'d', 13}, {'e', 14}, {'f', 15}, {'A', 10}, {'B', 11},
{'C', 12}, {'D', 13}, {'E', 14}, {'F', 15}};
uint32_t RenderD7::Color::Hex(const std::string &color, uint8_t a) {
if (color.length() < 7 || if (color.length() < 7 ||
std::regex_search(color.substr(1), std::find_if(color.begin() + 1, color.end(),
std::regex("[^0-9A-Fa-f]"))) { // invalid color. [](char c) { return !std::isxdigit(c); }) != color.end()) {
return RenderD7::Color::Hex("#000000", 0); return RenderD7::Color::Hex("#000000", 0);
} }
int r = std::stoi(color.substr(1, 2), nullptr, 16);
int g = std::stoi(color.substr(3, 2), nullptr, 16); int r = HEX_TO_DEC.at(color[1]) * 16 + HEX_TO_DEC.at(color[2]);
int b = std::stoi(color.substr(5, 2), nullptr, 16); int g = HEX_TO_DEC.at(color[3]) * 16 + HEX_TO_DEC.at(color[4]);
int b = HEX_TO_DEC.at(color[5]) * 16 + HEX_TO_DEC.at(color[6]);
return RGBA8(r, g, b, a); return RGBA8(r, g, b, a);
} }
+6 -5
View File
@@ -9,12 +9,13 @@
#include <filesystem> #include <filesystem>
std::vector<RenderD7::FileSystem::Entry> RenderD7::FileSystem::GetDirContent(std::string path) std::vector<RenderD7::FileSystem::Entry>
{ RenderD7::FileSystem::GetDirContent(std::string path) {
std::vector<RenderD7::FileSystem::Entry> res; std::vector<RenderD7::FileSystem::Entry> res;
for(const auto& entry : std::filesystem::directory_iterator(std::filesystem::path(path))) for (const auto &entry :
{ std::filesystem::directory_iterator(std::filesystem::path(path))) {
res.push_back({entry.path().string(), GetFileName(entry.path().string()), entry.is_directory()}); res.push_back({entry.path().string(), GetFileName(entry.path().string()),
entry.is_directory()});
} }
return res; return res;
} }
+10 -4
View File
@@ -77,7 +77,9 @@ static bool C3DTexToC2DImage(C2D_Image *texture, u32 width, u32 height,
return false; return false;
} }
static void OLD_C3DTexToC2DImage(C3D_Tex *tex, Tex3DS_SubTexture *subtex, u8 *buf, u32 size, u32 width, u32 height, GPU_TEXCOLOR format) { static void OLD_C3DTexToC2DImage(C3D_Tex *tex, Tex3DS_SubTexture *subtex,
u8 *buf, u32 size, u32 width, u32 height,
GPU_TEXCOLOR format) {
// RGBA -> ABGR // RGBA -> ABGR
for (u32 row = 0; row < width; row++) { for (u32 row = 0; row < width; row++) {
for (u32 col = 0; col < height; col++) { for (u32 col = 0; col < height; col++) {
@@ -114,10 +116,13 @@ static void OLD_C3DTexToC2DImage(C3D_Tex *tex, Tex3DS_SubTexture *subtex, u8 *bu
for (u32 x = 0; x < width; x++) { for (u32 x = 0; x < width; x++) {
for (u32 y = 0; y < height; y++) { for (u32 y = 0; y < height; y++) {
u32 dst_pos = ((((y >> 3) * (w_pow2 >> 3) + (x >> 3)) << 6) + ((x & 1) | ((y & 1) << 1) | ((x & 2) << 1) | ((y & 2) << 2) | ((x & 4) << 2) | ((y & 4) << 3))) * pixel_size; u32 dst_pos = ((((y >> 3) * (w_pow2 >> 3) + (x >> 3)) << 6) +
((x & 1) | ((y & 1) << 1) | ((x & 2) << 1) |
((y & 2) << 2) | ((x & 4) << 2) | ((y & 4) << 3))) *
pixel_size;
u32 src_pos = (y * width + x) * pixel_size; u32 src_pos = (y * width + x) * pixel_size;
memcpy(&((u8*)tex->data)[dst_pos], &((u8*)buf)[src_pos], pixel_size); memcpy(&((u8 *)tex->data)[dst_pos], &((u8 *)buf)[src_pos], pixel_size);
} }
} }
@@ -142,7 +147,8 @@ bool IMG_LoadImageFile(C2D_Image *texture, const char *path) {
C3D_Tex *tex = new C3D_Tex; C3D_Tex *tex = new C3D_Tex;
Tex3DS_SubTexture *subtex = new Tex3DS_SubTexture; Tex3DS_SubTexture *subtex = new Tex3DS_SubTexture;
OLD_C3DTexToC2DImage(tex, subtex, image, (u32)(width * height * 4), (u32)width, (u32)height, GPU_RGBA8); OLD_C3DTexToC2DImage(tex, subtex, image, (u32)(width * height * 4),
(u32)width, (u32)height, GPU_RGBA8);
texture->tex = tex; texture->tex = tex;
texture->subtex = subtex; texture->subtex = subtex;
stbi_image_free(image); stbi_image_free(image);
+2 -2
View File
@@ -162,7 +162,7 @@ static std::map<int, std::string> descos = {
{47, "Invalid command header."}, {47, "Invalid command header."},
}; };
//Need to Fix The Range based Values // Need to Fix The Range based Values
static std::map<int, std::string> descfs = { static std::map<int, std::string> descfs = {
{101, "Archive not mounted or mount-point not found."}, {101, "Archive not mounted or mount-point not found."},
{120, "Title or object not found."}, {120, "Title or object not found."},
@@ -264,7 +264,7 @@ static std::map<int, std::string> descqtm = {
{8, "Camera is already in use or busy."}, {8, "Camera is already in use or busy."},
}; };
//Need to Fix The Range based Values // Need to Fix The Range based Values
static std::map<int, std::string> descapplication = { static std::map<int, std::string> descapplication = {
{0, "The application raised an error. Please consult the application's " {0, "The application raised an error. Please consult the application's "
"source code or ask the author for assistance with it."}, "source code or ask the author for assistance with it."},
+7 -7
View File
@@ -432,7 +432,7 @@ Result RenderD7::Init::Main(std::string app_name) {
cfgfile = std::make_unique<INI::INIFile>(cfgpath + "/config.ini"); cfgfile = std::make_unique<INI::INIFile>(cfgpath + "/config.ini");
cfgfile->read(cfgstruct); cfgfile->read(cfgstruct);
std::string Fps = cfgstruct["settings"]["forceFrameRate"]; std::string Fps = cfgstruct["settings"]["forceFrameRate"];
C3D_FrameRate(RenderD7::Convert::StringtoFloat(Fps)); ////C3D_FrameRate(RenderD7::Convert::StringtoFloat(Fps));
metrikd = RenderD7::Convert::FloatToBool(RenderD7::Convert::StringtoFloat( metrikd = RenderD7::Convert::FloatToBool(RenderD7::Convert::StringtoFloat(
cfgstruct["metrik-settings"]["enableoverlay"])); cfgstruct["metrik-settings"]["enableoverlay"]));
mt_txtcolor = mt_txtcolor =
@@ -547,7 +547,7 @@ Result RenderD7::Init::Minimal(std::string app_name) {
cfgfile = std::make_unique<INI::INIFile>(cfgpath + "/config.ini"); cfgfile = std::make_unique<INI::INIFile>(cfgpath + "/config.ini");
cfgfile->read(cfgstruct); cfgfile->read(cfgstruct);
std::string Fps = cfgstruct["settings"]["forceFrameRate"]; std::string Fps = cfgstruct["settings"]["forceFrameRate"];
C3D_FrameRate(RenderD7::Convert::StringtoFloat(Fps)); //C3D_FrameRate(RenderD7::Convert::StringtoFloat(Fps));
metrikd = RenderD7::Convert::FloatToBool(RenderD7::Convert::StringtoFloat( metrikd = RenderD7::Convert::FloatToBool(RenderD7::Convert::StringtoFloat(
cfgstruct["metrik-settings"]["enableoverlay"])); cfgstruct["metrik-settings"]["enableoverlay"]));
mt_txtcolor = mt_txtcolor =
@@ -1020,8 +1020,7 @@ void RenderD7::RSettings::Draw(void) const {
RenderD7::OnScreen(Top); RenderD7::OnScreen(Top);
RenderD7::Draw::Rect(0, 21, 400, 220, RenderD7::Color::Hex("#eeeeee")); RenderD7::Draw::Rect(0, 21, 400, 220, RenderD7::Color::Hex("#eeeeee"));
RenderD7::Draw::Text(5, 30, 0.7f, DSEVENBLACK, RenderD7::Draw::Text(5, 30, 0.7f, DSEVENBLACK, std::string(CHANGELOG));
std::string(CHANGELOG));
RenderD7::Draw::Rect(0, 0, 400, 21, RenderD7::Color::Hex("#111111")); RenderD7::Draw::Rect(0, 0, 400, 21, RenderD7::Color::Hex("#111111"));
RenderD7::Draw::Text(0, 0, 0.7f, DSEVENWHITE, "RenderD7->Changelog"); RenderD7::Draw::Text(0, 0, 0.7f, DSEVENWHITE, "RenderD7->Changelog");
@@ -1030,7 +1029,8 @@ void RenderD7::RSettings::Draw(void) const {
RenderD7::OnScreen(Bottom); RenderD7::OnScreen(Bottom);
RenderD7::Draw::Rect(0, 0, 320, 240, RenderD7::Color::Hex("#eeeeee")); RenderD7::Draw::Rect(0, 0, 320, 240, RenderD7::Color::Hex("#eeeeee"));
RenderD7::Draw::Text(0, 0, 0.7f, RenderD7::Color::Hex("#111111"), RenderD7::Draw::Text(0, 0, 0.7f, RenderD7::Color::Hex("#111111"),
"Press B to Get back!\ntxty: " + std::to_string(txtposy)); "Press B to Get back!\ntxty: " +
std::to_string(txtposy));
} else if (m_state == RINFO) { } else if (m_state == RINFO) {
std::string rd7ver = RENDERD7VSTRING; std::string rd7ver = RENDERD7VSTRING;
@@ -1103,8 +1103,8 @@ void RenderD7::RSettings::Logic(u32 hDown, u32 hHeld, u32 hUp,
if (d7_hDown & KEY_TOUCH && RenderD7::touchTObj(d7_touch, buttons[3]) && if (d7_hDown & KEY_TOUCH && RenderD7::touchTObj(d7_touch, buttons[3]) &&
!metrikd) { !metrikd) {
cfgstruct["settings"]["forceFrameRate"] = Kbd(2, SWKBD_TYPE_NUMPAD); cfgstruct["settings"]["forceFrameRate"] = Kbd(2, SWKBD_TYPE_NUMPAD);
C3D_FrameRate(RenderD7::Convert::StringtoFloat( //C3D_FrameRate(RenderD7::Convert::StringtoFloat(
cfgstruct["settings"]["forceFrameRate"])); //cfgstruct["settings"]["forceFrameRate"]));
} }
if (d7_hDown & KEY_TOUCH && RenderD7::touchTObj(d7_touch, buttons[4])) { if (d7_hDown & KEY_TOUCH && RenderD7::touchTObj(d7_touch, buttons[4])) {
mt_screen = mt_screen ? 0 : 1; mt_screen = mt_screen ? 0 : 1;
+4 -5
View File
@@ -1,9 +1,8 @@
//rd7cc // rd7cc
#include <iostream>
#include <fstream> #include <fstream>
int main(int argc, char* argv[]) #include <iostream>
{ int main(int argc, char *argv[]) {
std::ofstream result ("result.hpp"); std::ofstream result("result.hpp");
result << "//Result" << std::endl; result << "//Result" << std::endl;