Remove nsmbp and fix a critical bug

This commit is contained in:
tobid7 2023-03-09 21:19:17 +01:00
parent 66a35f28e6
commit 67edfa4245
15 changed files with 64 additions and 2182 deletions

View File

@ -10,7 +10,7 @@ include $(DEVKITARM)/3ds_rules
export renderd7_MAJOR := 0
export renderd7_MINOR := 9
export renderd7_PATCH := 0
export renderd7_PATCH := 1
VERSION := $(renderd7_MAJOR).$(renderd7_MINOR).$(renderd7_PATCH)
@ -32,7 +32,7 @@ TIME_TIME := $(shell date --iso=seconds)
# INCLUDES is a list of directories containing header files
#---------------------------------------------------------------------------------
TARGET := renderd7
SOURCES := source external/source external/libnsbmp/source
SOURCES := source external/source
DATA := data
INCLUDES := include

View File

@ -1,20 +0,0 @@
Copyright (C) 2006 Richard Wilson
Copyright (C) 2008 Sean Fox
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

File diff suppressed because it is too large Load Diff

423
external/source/fs.c vendored
View File

@ -1,423 +0,0 @@
#include <renderd7/external/fs.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/statvfs.h>
#define WORKING_DIR "/"
void Utils_U8_To_U16(u16 *buf, const u8 *input, size_t bufsize) {
ssize_t units = utf8_to_utf16(buf, input, bufsize);
if (units < 0)
units = 0;
buf[units] = 0;
}
FS_Archive archive, sdmc_archive, nand_archive;
Result FS_OpenArchive(FS_Archive *archive, FS_ArchiveID archiveID) {
Result ret = 0;
if (R_FAILED(ret = FSUSER_OpenArchive(archive, archiveID,
fsMakePath(PATH_EMPTY, ""))))
return ret;
return 0;
}
Result FS_CloseArchive(FS_Archive archive) {
Result ret = 0;
if (R_FAILED(ret = FSUSER_CloseArchive(archive)))
return ret;
return 0;
}
Result FS_OpenDir(Handle *handle, FS_Archive archive, const char *path) {
Result ret = 0;
u16 path_u16[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))))
return ret;
return 0;
}
Result FS_OpenFile(Handle *handle, FS_Archive archive, const char *path,
u32 flags, u32 attributes) {
Result ret = 0;
u16 path_u16[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)))
return ret;
return 0;
}
Result FS_MakeDir(FS_Archive archive, const char *path) {
Result ret = 0;
u16 path_u16[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)))
return ret;
return 0;
}
Result FS_CreateFile(FS_Archive archive, const char *path, u64 size) {
Result ret = 0;
u16 path_u16[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)))
return ret;
return 0;
}
Result FS_RecursiveMakeDir(FS_Archive archive, const char *path) {
Result ret = 0;
char buf[256];
char *p = NULL;
size_t len;
snprintf(buf, sizeof(buf), "%s", path);
len = strlen(buf);
if (buf[len - 1] == '/')
buf[len - 1] = 0;
for (p = buf + 1; *p; p++) {
if (*p == '/') {
*p = 0;
if (!FS_DirExists(archive, buf))
ret = FS_MakeDir(archive, buf);
*p = '/';
}
if (!FS_DirExists(archive, buf))
ret = FS_MakeDir(archive, buf);
}
return ret;
}
bool FS_FileExists(FS_Archive archive, const char *path) {
Handle handle;
u16 path_u16[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)))
return false;
if (R_FAILED(FSFILE_Close(handle)))
return false;
return true;
}
bool FS_DirExists(FS_Archive archive, const char *path) {
Handle handle;
u16 path_u16[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))))
return false;
if (R_FAILED(FSDIR_Close(handle)))
return false;
return true;
}
Result FS_GetFileSize(FS_Archive archive, const char *path, u64 *size) {
Result ret = 0;
Handle handle;
u16 path_u16[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)))
return ret;
if (R_FAILED(ret = FSFILE_GetSize(handle, size))) {
FSFILE_Close(handle);
return ret;
}
if (R_FAILED(ret = FSFILE_Close(handle)))
return ret;
return 0;
}
u64 FS_GetFreeStorage(FS_SystemMediaType media_type) {
FS_ArchiveResource resource = {0};
if (R_SUCCEEDED(FSUSER_GetArchiveResource(&resource, media_type)))
return (((u64)resource.freeClusters * (u64)resource.clusterSize));
return 0;
}
u64 FS_GetTotalStorage(FS_SystemMediaType media_type) {
FS_ArchiveResource resource = {0};
if (R_SUCCEEDED(FSUSER_GetArchiveResource(&resource, media_type)))
return (((u64)resource.totalClusters * (u64)resource.clusterSize));
return 0;
}
u64 FS_GetUsedStorage(FS_SystemMediaType media_type) {
return 0; //(FS_GetTotalStorage(media_type) - FS_GetUsedStorage(media_type));
}
Result FS_RemoveFile(FS_Archive archive, const char *path) {
Result ret = 0;
u16 path_u16[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))))
return ret;
return 0;
}
Result FS_RemoveDir(FS_Archive archive, const char *path) {
Result ret = 0;
u16 path_u16[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))))
return ret;
return 0;
}
Result FS_RemoveDirRecursive(FS_Archive archive, const char *path) {
Result ret = 0;
u16 path_u16[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))))
return ret;
return 0;
}
Result FS_RenameFile(FS_Archive archive, const char *old_filename,
const char *new_filename) {
Result ret = 0;
u16 old_filename_u16[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];
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))))
return ret;
return 0;
}
Result FS_RenameDir(FS_Archive archive, const char *old_dirname,
const char *new_dirname) {
Result ret = 0;
u16 old_dirname_u16[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];
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))))
return ret;
return 0;
}
Result FS_Read(FS_Archive archive, const char *path, u64 size, void *buf) {
Result ret = 0;
Handle handle;
u32 bytes_read = 0;
if (R_FAILED(ret = FS_OpenFile(&handle, archive, path, FS_OPEN_READ, 0)))
return ret;
if (R_FAILED(ret = FSFILE_Read(handle, &bytes_read, 0, buf, size))) {
FSFILE_Close(handle);
return ret;
}
if (R_FAILED(ret = FSFILE_Close(handle)))
return ret;
return 0;
}
Result FS_Write(FS_Archive archive, const char *path, const void *buf,
u32 size) {
Result ret = 0;
Handle handle;
u32 bytes_written = 0;
if (FS_FileExists(archive, path))
FS_RemoveFile(archive, path);
u16 path_u16[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)))
return ret;
if (R_FAILED(ret = FSUSER_OpenFile(&handle, archive,
fsMakePath(PATH_UTF16, path_u16),
FS_OPEN_WRITE, 0)))
return ret;
if (R_FAILED(ret = FSFILE_Write(handle, &bytes_written, 0, buf, size,
FS_WRITE_FLUSH))) {
FSFILE_Close(handle);
return ret;
}
if (R_FAILED(ret = FSFILE_Close(handle)))
return ret;
return 0;
}
char *FS_GetFileTimestamp(const char *path) {
static char timeStr[60];
u64 mtime = 0;
if (R_SUCCEEDED(archive_getmtime(path, &mtime))) {
time_t mt = mtime;
struct tm *timeStruct = gmtime(&mt);
int hours = timeStruct->tm_hour;
int minutes = timeStruct->tm_min;
int day = timeStruct->tm_mday;
int month = timeStruct->tm_mon + 1; // January being 0
int year = timeStruct->tm_year + 1900;
snprintf(timeStr, 60, "%d/%d/%d %2i:%02i", year, month, day, hours,
minutes);
} else
return NULL;
return timeStr;
}
FS_Path getPathInfo(const char *path, FS_ArchiveID *archive) {
*archive = ARCHIVE_SDMC;
FS_Path filePath = {0};
unsigned int prefixlen = 0;
if (!strncmp(path, "sdmc:/", 6)) {
prefixlen = 5;
} 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
char *actualPath = NULL;
asprintf(&actualPath, "%s%s", WORKING_DIR, path);
filePath = fsMakePath(PATH_ASCII, actualPath);
free(actualPath);
}
// if the filePath wasnt set above, set it
if (filePath.size == 0) {
filePath = fsMakePath(PATH_ASCII, path + prefixlen);
}
return filePath;
}
Result makeDirs(const char *path) {
Result ret = 0;
FS_ArchiveID archiveID;
FS_Path filePath = getPathInfo(path, &archiveID);
FS_Archive archive;
ret = FSUSER_OpenArchive(&archive, archiveID, fsMakePath(PATH_EMPTY, ""));
for (char *slashpos = strchr(path + 1, '/'); slashpos != NULL;
slashpos = strchr(slashpos + 1, '/')) {
char bak = *(slashpos);
*(slashpos) = '\0';
Handle dirHandle;
ret = FSUSER_OpenDirectory(&dirHandle, archive, filePath);
if (R_SUCCEEDED(ret))
FSDIR_Close(dirHandle);
else
ret = FSUSER_CreateDirectory(archive, filePath, FS_ATTRIBUTE_DIRECTORY);
*(slashpos) = bak;
}
FSUSER_CloseArchive(archive);
return ret;
}
Result openFile(Handle *fileHandle, const char *path, bool write) {
FS_ArchiveID archive;
FS_Path filePath = getPathInfo(path, &archive);
u32 flags = (write ? (FS_OPEN_CREATE | FS_OPEN_WRITE) : FS_OPEN_READ);
Result ret = 0;
ret = makeDirs(strdup(path));
ret = FSUSER_OpenFileDirectly(fileHandle, archive, fsMakePath(PATH_EMPTY, ""),
filePath, flags, 0);
if (write)
ret = FSFILE_SetSize(
*fileHandle,
0); // truncate the file to remove previous contents before writing
return ret;
}

View File

@ -12,20 +12,39 @@
namespace RenderD7 {
namespace Color {
/// @brief RGBA Struct
struct rgba {
/// @brief rgba Colors
uint8_t r, g, b, a;
};
/// @brief RGBA Class
class RGBA {
public:
/// @brief Construct
/// @param r
/// @param g
/// @param b
/// @param a
RGBA(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
: m_r(r), m_g(g), m_b(b), m_a(a) {}
/// @brief Get as Uint32
/// @return color
uint32_t toRGBA() const {
return (m_r << 24) | (m_g << 16) | (m_b << 8) | m_a;
}
uint8_t m_r, m_g, m_b, m_a;
};
/// @brief Convert RGB to Hex
/// @param r
/// @param g
/// @param b
/// @return Hex-String
std::string RGB2Hex(int r, int g, int b);
/// @brief Hex to U32
/// @param color
/// @param a
/// @return Color32
uint32_t Hex(const std::string &color, uint8_t a = 255);
} // namespace Color
} // namespace RenderD7

View File

@ -6,8 +6,28 @@
namespace RenderD7 {
namespace Draw {
/// @brief Draw Rectangle
/// @param x Pos X
/// @param y Pos Y
/// @param w Width
/// @param h Height
/// @param color Color
/// @return success ?
bool Rect(float x, float y, float w, float h, u32 color);
/// @brief Draw a not filled Rectangle
/// @param p1x Pos X
/// @param p1y Pos Y
/// @param w Width
/// @param h Height
/// @param color Color
/// @param scale Scale
/// @return success ?
bool NFRect(float p1x, float p1y, float w, float h, u32 color, float scale = 1);
/// @brief Draw A Pixel
/// @param x Pos X
/// @param y Pos Y
/// @param color Color
/// @return success ?
bool Px(float x, float y, u32 color);
void TextCentered(float x, float y, float size, u32 color, std::string Text,
int maxWidth = 0, int maxHeight = 0, C2D_Font fnt = nullptr);

View File

@ -10,7 +10,12 @@ namespace BitmapConverter {
unsigned decodeBMP(std::vector<unsigned char> &image, unsigned &w, unsigned &h,
const std::vector<unsigned char> &bmp);
/// @brief Convert A File
/// @param filename
/// @return data
std::vector<unsigned char> ConvertFile(std::string filename);
/// @brief Convert data
/// @param data
/// @return data
std::vector<unsigned char> ConvertData(std::vector<unsigned char> data);
} // namespace BitmapConverter

View File

@ -1,33 +0,0 @@
#include <3ds.h>
extern FS_Archive archive, sdmc_archive, nand_archive;
Result FS_OpenArchive(FS_Archive *archive, FS_ArchiveID id);
Result FS_CloseArchive(FS_Archive archive);
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_MakeDir(FS_Archive archive, const char *path);
Result FS_CreateFile(FS_Archive archive, const char *path, u64 size);
Result FS_RecursiveMakeDir(FS_Archive archive, const char *path);
bool FS_FileExists(FS_Archive archive, const char *path);
bool FS_DirExists(FS_Archive archive, const char *path);
Result FS_GetFileSize(FS_Archive archive, const char *path, u64 *size);
u64 FS_GetFreeStorage(FS_SystemMediaType media_type);
u64 FS_GetTotalStorage(FS_SystemMediaType media_type);
u64 FS_GetUsedStorage(FS_SystemMediaType media_type);
Result FS_RemoveFile(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_RenameFile(FS_Archive archive, const char *old_filename,
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_Write(FS_Archive archive, const char *path, const void *buf,
u32 size);
char *FS_GetFileTimestamp(const char *path);
Result makeDirs(const char *path);
Result openFile(Handle *fileHandle, const char *path, bool write);

View File

@ -1,251 +0,0 @@
/*
* Copyright 2006 Richard Wilson <richard.wilson@netsurf-browser.org>
* Copyright 2008 Sean Fox <dyntryx@gmail.com>
*
* This file is part of NetSurf's libnsbmp, http://www.netsurf-browser.org/
* Licenced under the MIT License,
* http://www.opensource.org/licenses/mit-license.php
*/
/**
* \file
* Bitmap file decoding interface.
*/
#ifndef libnsbmp_h_
#define libnsbmp_h_
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
/* bmp flags */
#define BMP_NEW 0
/** image is opaque (as opposed to having an alpha mask) */
#define BMP_OPAQUE (1 << 0)
/** memory should be wiped */
#define BMP_CLEAR_MEMORY (1 << 1)
/**
* error return values
*/
typedef enum {
BMP_OK = 0,
BMP_INSUFFICIENT_MEMORY = 1,
BMP_INSUFFICIENT_DATA = 2,
BMP_DATA_ERROR = 3
} bmp_result;
/**
* encoding types
*/
typedef enum {
BMP_ENCODING_RGB = 0,
BMP_ENCODING_RLE8 = 1,
BMP_ENCODING_RLE4 = 2,
BMP_ENCODING_BITFIELDS = 3
} bmp_encoding;
/* API for Bitmap callbacks */
typedef void *(*bmp_bitmap_cb_create)(int width, int height,
unsigned int state);
typedef void (*bmp_bitmap_cb_destroy)(void *bitmap);
typedef unsigned char *(*bmp_bitmap_cb_get_buffer)(void *bitmap);
typedef size_t (*bmp_bitmap_cb_get_bpp)(void *bitmap);
/**
* The Bitmap callbacks function table
*/
typedef struct bmp_bitmap_callback_vt_s {
/** Callback to allocate bitmap storage. */
bmp_bitmap_cb_create bitmap_create;
/** Called to free bitmap storage. */
bmp_bitmap_cb_destroy bitmap_destroy;
/** Return a pointer to the pixel data in a bitmap. */
bmp_bitmap_cb_get_buffer bitmap_get_buffer;
/** Find the width of a pixel row in bytes. */
bmp_bitmap_cb_get_bpp bitmap_get_bpp;
} bmp_bitmap_callback_vt;
/**
* bitmap image
*/
typedef struct bmp_image {
/** callbacks for bitmap functions */
bmp_bitmap_callback_vt bitmap_callbacks;
/** pointer to BMP data */
uint8_t *bmp_data;
/** width of BMP (valid after _analyse) */
uint32_t width;
/** heigth of BMP (valid after _analyse) */
uint32_t height;
/** whether the image has been decoded */
bool decoded;
/** decoded image */
void *bitmap;
/* Internal members are listed below */
/** total number of bytes of BMP data available */
uint32_t buffer_size;
/** pixel encoding type */
bmp_encoding encoding;
/** offset of bitmap data */
uint32_t bitmap_offset;
/** bits per pixel */
uint16_t bpp;
/** number of colours */
uint32_t colours;
/** colour table */
uint32_t *colour_table;
/** whether to use bmp's limited transparency */
bool limited_trans;
/** colour to display for "transparent" pixels when using limited
* transparency
*/
uint32_t trans_colour;
/** scanlines are top to bottom */
bool reversed;
/** image is part of an ICO, mask follows */
bool ico;
/** true if the bitmap does not contain an alpha channel */
bool opaque;
/** four bitwise mask */
uint32_t mask[4];
/** four bitwise shifts */
int32_t shift[4];
/** colour representing "transparency" in the bitmap */
uint32_t transparent_index;
} bmp_image;
typedef struct ico_image {
bmp_image bmp;
struct ico_image *next;
} ico_image;
/**
* icon image collection
*/
typedef struct ico_collection {
/** callbacks for bitmap functions */
bmp_bitmap_callback_vt bitmap_callbacks;
/** width of largest BMP */
uint16_t width;
/** heigth of largest BMP */
uint16_t height;
/* Internal members are listed below */
/** pointer to ICO data */
uint8_t *ico_data;
/** total number of bytes of ICO data available */
uint32_t buffer_size;
/** root of linked list of images */
ico_image *first;
} ico_collection;
/**
* Initialises bitmap ready for analysing the bitmap.
*
* \param bmp The Bitmap to initialise
* \param callbacks The callbacks the library will call on operations.
* \return BMP_OK on success or appropriate error code.
*/
bmp_result bmp_create(bmp_image *bmp, bmp_bitmap_callback_vt *callbacks);
/**
* Initialises icon ready for analysing the icon
*
* \param bmp The Bitmap to initialise
* \param callbacks The callbacks the library will call on operations.
* \return BMP_OK on success or appropriate error code.
*/
bmp_result ico_collection_create(ico_collection *ico,
bmp_bitmap_callback_vt *callbacks);
/**
* Analyse a BMP prior to decoding.
*
* This will scan the data provided and perform checks to ensure the data is a
* valid BMP and prepare the bitmap image structure ready for decode.
*
* This function must be called and resturn BMP_OK before bmp_decode() as it
* prepares the bmp internal state for the decode process.
*
* \param bmp the BMP image to analyse.
* \param size The size of data in cdata.
* \param data The bitmap source data.
* \return BMP_OK on success or error code on faliure.
*/
bmp_result bmp_analyse(bmp_image *bmp, size_t size, uint8_t *data);
/**
* Analyse an ICO prior to decoding.
*
* This function will scan the data provided and perform checks to ensure the
* data is a valid ICO.
*
* This function must be called before ico_find().
*
* \param ico the ICO image to analyse
* \param size The size of data in cdata.
* \param data The bitmap source data.
* \return BMP_OK on success
*/
bmp_result ico_analyse(ico_collection *ico, size_t size, uint8_t *data);
/**
* Decode a BMP
*
* This function decodes the BMP data such that bmp->bitmap is a valid
* image. The state of bmp->decoded is set to TRUE on exit such that it
* can easily be identified which BMPs are in a fully decoded state.
*
* \param bmp the BMP image to decode
* \return BMP_OK on success
*/
bmp_result bmp_decode(bmp_image *bmp);
/**
* Decode a BMP using "limited transparency"
*
* Bitmaps do not have native transparency support. However, there is a
* "trick" that is used in some instances in which the first pixel of the
* bitmap becomes the "transparency index". The decoding application can
* replace this index with whatever background colour it chooses to
* create the illusion of transparency.
*
* When to use transparency is at the discretion of the decoding
* application.
*
* \param bmp the BMP image to decode
* \param colour the colour to use as "transparent"
* \return BMP_OK on success
*/
bmp_result bmp_decode_trans(bmp_image *bmp, uint32_t transparent_colour);
/**
* Finds the closest BMP within an ICO collection
*
* This function finds the BMP with dimensions as close to a specified set
* as possible from the images in the collection.
*
* \param ico the ICO collection to examine
* \param width the preferred width (0 to use ICO header width)
* \param height the preferred height (0 to use ICO header height)
*/
bmp_image *ico_find(ico_collection *ico, uint16_t width, uint16_t height);
/**
* Finalise a BMP prior to destruction.
*
* \param bmp the BMP image to finalise.
*/
void bmp_finalise(bmp_image *bmp);
/**
* Finalise an ICO prior to destruction.
*
* \param ico the ICO image to finalise,
*/
void ico_finalise(ico_collection *ico);
#endif

View File

@ -1,33 +0,0 @@
/*
* Copyright 2003 James Bursa <bursa@users.sourceforge.net>
* Copyright 2004 John Tytgat <John.Tytgat@aaug.net>
*
* This file is part of NetSurf, http://www.netsurf-browser.org/
* Licenced under the MIT License,
* http://www.opensource.org/licenses/mit-license.php
*/
#include <stdio.h>
#ifndef _LIBNSBMP_LOG_H_
#define _LIBNSBMP_LOG_H_
#ifdef NDEBUG
#define LOG(x) ((void)0)
#else
#ifdef __GNUC__
#define LOG(x) \
do { printf x, fputc('\n', stdout)); \
} while (0)
#elif defined(__CC_NORCROFT)
#define LOG(x) \
do { printf x, fputc('\n', stdout)); \
} while (0)
#else
#define LOG(x) \
do { printf x, fputc('\n', stdout)); \
} while (0)
#endif
#endif
#endif

View File

@ -44,13 +44,11 @@
#include <renderd7/stringtool.hpp>
#include <renderd7/thread.hpp>
extern "C" {
#include <renderd7/external/fs.h>
}
#define RENDERD7VSTRING "0.9.0"
#define RENDERD7VSTRING "0.9.1"
#define CHANGELOG \
"0.9.0: Remove Stupid try of Console\nAdd Services list and Clean up " \
"0.9.1: Fix Critical bug in Spritesheet animations\nFix Color " \
"Conver(Hex)\n0.9.0: Remove Stupid try of Console\nAdd Services list and " \
"Clean up " \
"Code.\nAlso added Minimal Init for hax2.x\n0.8.5: Fix Deltatime \n0.8.4: " \
"A lot of Fixes and new\nFeatures for BitmapPrinter! \n0.8.3: Addet " \
"Overlaycount to Info\nand Addet ResultDecoder for errors.\n0.8.2: Fix a " \

View File

@ -1,5 +1,5 @@
#include <renderd7/Color.hpp>
#include <map>
#include <renderd7/Color.hpp>
#define RGBA8(r, g, b, a) \
((((r)&0xFF) << 0) | (((g)&0xFF) << 8) | (((b)&0xFF) << 16) | \

View File

@ -155,78 +155,6 @@ bool IMG_LoadImageFile(C2D_Image *texture, const char *path) {
return true;
}
extern "C" {
#include <renderd7/external/libnsbmp/libnsbmp.h>
}
static const u32 BYTES_PER_PIXEL = 4;
#define MAX_IMAGE_BYTES (48 * 1024 * 1024)
namespace LIBBMP {
static void *bitmap_create(int width, int height,
[[maybe_unused]] unsigned int state) {
/* ensure a stupidly large (>50Megs or so) bitmap is not created */
if ((static_cast<long long>(width) * static_cast<long long>(height)) >
(MAX_IMAGE_BYTES / BYTES_PER_PIXEL))
return nullptr;
return std::calloc(width * height, BYTES_PER_PIXEL);
}
static unsigned char *bitmap_get_buffer(void *bitmap) {
assert(bitmap);
return static_cast<unsigned char *>(bitmap);
}
static size_t bitmap_get_bpp([[maybe_unused]] void *bitmap) {
return BYTES_PER_PIXEL;
}
static void bitmap_destroy(void *bitmap) {
assert(bitmap);
std::free(bitmap);
}
} // namespace LIBBMP
unsigned Image_to_C3D(C2D_Image img, const std::vector<unsigned char> &bmpc) {
bmp_bitmap_callback_vt bitmap_callbacks = {
LIBBMP::bitmap_create, LIBBMP::bitmap_destroy, LIBBMP::bitmap_get_buffer,
LIBBMP::bitmap_get_bpp};
bmp_result code = BMP_OK;
bmp_image bmp;
bmp_create(&bmp, &bitmap_callbacks);
code = bmp_analyse(&bmp, bmpc.size(), (u8 *)bmpc.data());
if (code != BMP_OK) {
bmp_finalise(&bmp);
return 1;
}
code = bmp_decode(&bmp);
if (code != BMP_OK) {
if ((code != BMP_INSUFFICIENT_DATA) && (code != BMP_DATA_ERROR)) {
bmp_finalise(&bmp);
return 2;
}
/* skip if the decoded image would be ridiculously large */
if ((bmp.width * bmp.height) > 200000) {
bmp_finalise(&bmp);
return 3;
}
}
C2D_Image *texture = new C2D_Image();
bool ret = C3DTexToC2DImage(texture, static_cast<u32>(bmp.width),
static_cast<u32>(bmp.height),
static_cast<u8 *>(bmp.bitmap));
bmp_finalise(&bmp);
delete texture;
if (!ret) {
return 4;
}
return 0;
}
void RenderD7::Image::LoadPng(const std::string path) {
if (usedbgmsg) {
// RenderD7::Msg::Display("RenderD7", "Loading Png:" + path, Top);
@ -327,7 +255,9 @@ bool RenderD7::Image::Draw(float x, float y, float scaleX, float scaleY) {
void RenderD7::Image::LoadFromBitmap(BMP bitmap) {
loadet = false;
unsigned error = Image_to_C3D(this->img, bitmap.DATA());
unsigned error =
C3DTexToC2DImage(&this->img, bitmap.bmp_info_header.width,
bitmap.bmp_info_header.height, bitmap.data.data());
if (error == 0) {
this->loadet = true;
}

View File

@ -4,7 +4,7 @@
extern Log renderd7log;
RenderD7::SpriteSheetAnimation::SpriteSheetAnimation() {
renderd7log.Write("SpriteSheetAnimation createt!");
//
}
RenderD7::SpriteSheetAnimation::~SpriteSheetAnimation() {
//
@ -15,13 +15,13 @@ void RenderD7::SpriteSheetAnimation::Setup(RenderD7::Sheet *sheet,
float frame_begin,
float frame_finish) {
D_totaltime = frame_begin;
renderd7log.Write("frame_begin success");
this->images = imagecount;
renderd7log.Write("imagecount success");
this->sheet = sheet;
renderd7log.Write("sheet success");
this->time = frame_finish;
renderd7log.Write("frame_finish success");
RenderD7::SpriteSheetAnimation::FromSheet(this->sheet, startimage);
}
void RenderD7::SpriteSheetAnimation::Play(float timespeed) {

View File

@ -547,7 +547,7 @@ Result RenderD7::Init::Minimal(std::string app_name) {
cfgfile = std::make_unique<INI::INIFile>(cfgpath + "/config.ini");
cfgfile->read(cfgstruct);
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(
cfgstruct["metrik-settings"]["enableoverlay"]));
mt_txtcolor =
@ -932,6 +932,7 @@ void RenderD7::FrameEnd() {
if (!shouldbe_disabled)
OvlHandler();
/*if (d7_hHeld & KEY_R && d7_hDown & KEY_SELECT)
{
RenderD7::LoadSettings();
}*/
@ -1103,8 +1104,8 @@ void RenderD7::RSettings::Logic(u32 hDown, u32 hHeld, u32 hUp,
if (d7_hDown & KEY_TOUCH && RenderD7::touchTObj(d7_touch, buttons[3]) &&
!metrikd) {
cfgstruct["settings"]["forceFrameRate"] = Kbd(2, SWKBD_TYPE_NUMPAD);
//C3D_FrameRate(RenderD7::Convert::StringtoFloat(
//cfgstruct["settings"]["forceFrameRate"]));
// C3D_FrameRate(RenderD7::Convert::StringtoFloat(
// cfgstruct["settings"]["forceFrameRate"]));
}
if (d7_hDown & KEY_TOUCH && RenderD7::touchTObj(d7_touch, buttons[4])) {
mt_screen = mt_screen ? 0 : 1;