Initial PNG support (courtesy of lodepng).

This commit is contained in:
Wolfvak 2018-03-29 20:49:51 -03:00 committed by d0k3
parent 823f3b6d60
commit 03014a72ee
5 changed files with 8058 additions and 1 deletions

View File

@ -6,7 +6,7 @@ SOURCE := source
BUILD := build
SUBARCH := -D$(PROCESSOR) -mcpu=arm946e-s -mtune=arm946e-s -mfloat-abi=soft -mthumb
INCDIRS := source source/common source/filesys source/crypto source/fatfs source/nand source/virtual source/game source/gamecart source/quicklz source/qrcodegen source/system source/utils
INCDIRS := source source/common source/filesys source/crypto source/fatfs source/nand source/virtual source/game source/gamecart source/lodepng source/quicklz source/qrcodegen source/system source/utils
INCLUDE := $(foreach dir,$(INCDIRS),-I"$(shell pwd)/$(dir)")
ASFLAGS += $(SUBARCH) $(INCLUDE)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

32
arm9/source/system/png.c Normal file
View File

@ -0,0 +1,32 @@
#include <stddef.h>
#include <stdint.h>
#include "lodepng.h"
#include "png.h"
#include "ui.h"
u8 *PNG_Decompress(const u8 *png, size_t png_len, size_t *w, size_t *h)
{
u8 *img;
u32 res;
size_t w_, h_;
res = lodepng_decode24(&img, &w_, &h_, png, png_len);
if (res) {
ShowPrompt(false, "PNG error: %s", lodepng_error_text(res));
return NULL;
}
// maybe process in batches of 3 pixels / 12 bytes at a time?
for (size_t i = 0; i < (w_ * h_ * 3); i += 3) {
u8 c = img[i];
img[i] = img[i + 2];
img[i + 2] = c;
}
if (w) *w = w_;
if (h) *h = h_;
return img;
}

7
arm9/source/system/png.h Normal file
View File

@ -0,0 +1,7 @@
#pragma once
#include <stdint.h>
#include "common.h"
#include "lodepng/lodepng.h"
u8 *PNG_Decompress(const u8 *png, size_t png_len, size_t *w, size_t *h);