Rotate envmaps to be consistent with vanilla (#636)

* Start work on envmap rotation stuff

* n64graphic envmap rotation working

* Add comment to rotation function

* Fix DLs of non 32x32 env maps, fix envmap rotation

* fix metal flying vanish cap

* fix metal mario's medium poly butt

* new asset version for flipped env maps

* added missing env textures to extract script

* restore asset_needs_update

* Skip asset_needs_update calls if local version matches new version

* removed the goddard textures from envmap rotation

---------

Co-authored-by: mineqwerty <mineqwerty25@gmail.com>
Co-authored-by: thecozies <79979276+thecozies@users.noreply.github.com>
This commit is contained in:
Gregory Heskett
2023-09-18 09:10:56 -04:00
committed by GitHub
parent 8a83359ed1
commit ab0cebab7a
7 changed files with 126 additions and 49 deletions

View File

@@ -38,6 +38,45 @@ typedef struct
// N64 RGBA/IA/I/CI -> internal RGBA/IA
//---------------------------------------------------------
// Rotate raw image counterclockwise (width and height need swapped externally)
void rotate_raw_img(uint8_t *raw, int width, int height, int depth) {
uint8_t *tmp_rotated;
int bytes;
int size;
if (depth == 32) {
bytes = 4;
} else if (depth == 16) {
bytes = 2;
} else {
ERROR("rotated raw image does not have a valid depth");
return;
}
size = width * height * bytes;
tmp_rotated = malloc(size);
if (!tmp_rotated) {
ERROR("Error allocating %d bytes\n", size);
return;
}
int offset_src = 0;
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
int offset_dst = (((width - j - 1) * height) + i) * bytes;
for (int k = 0; k < bytes; k++) {
tmp_rotated[offset_dst + k] = raw[offset_src++];
}
}
}
bcopy(tmp_rotated, raw, size);
free(tmp_rotated);
tmp_rotated = NULL;
}
rgba *raw2rgba(const uint8_t *raw, int width, int height, int depth)
{
rgba *img;
@@ -602,6 +641,7 @@ typedef struct
int height;
int bin_truncate;
int pal_truncate;
int rotate_envmap;
} graphics_config;
static const graphics_config default_config =
@@ -619,6 +659,7 @@ static const graphics_config default_config =
.height = 32,
.bin_truncate = 1,
.pal_truncate = 1,
.rotate_envmap = 0,
};
typedef struct
@@ -701,7 +742,7 @@ static int parse_encoding(write_encoding *encoding, const char *str)
static void print_usage(void)
{
ERROR("Usage: n64graphics -e/-i BIN_FILE -g IMG_FILE [-p PAL_FILE] [-o BIN_OFFSET] [-P PAL_OFFSET] [-f FORMAT] [-c CI_FORMAT] [-w WIDTH] [-h HEIGHT] [-V]\n"
ERROR("Usage: n64graphics -e/-i BIN_FILE -g IMG_FILE [-p PAL_FILE] [-o BIN_OFFSET] [-P PAL_OFFSET] [-f FORMAT] [-c CI_FORMAT] [-w WIDTH] [-h HEIGHT] [-r ROTATE] [-V]\n"
"\n"
"n64graphics v" N64GRAPHICS_VERSION ": N64 graphics manipulator\n"
"\n"
@@ -715,6 +756,7 @@ static void print_usage(void)
" -s SCHEME output scheme: raw, u8 (hex), u64 (hex) (default: %s)\n"
" -w WIDTH export texture width (default: %d)\n"
" -h HEIGHT export texture height (default: %d)\n"
" -r ROTATE rotate envmap texture for rgba extraction only (default: false)\n"
"CI arguments:\n"
" -c CI_FORMAT CI palette format: rgba16, ia16 (default: %s)\n"
" -p PAL_FILE palette binary file to import/export from/to\n"
@@ -787,6 +829,14 @@ static int parse_arguments(int argc, char *argv[], graphics_config *config)
config->pal_offset = strtoul(argv[i], NULL, 0);
config->pal_truncate = 0;
break;
case 'r':
if (++i >= argc) return 0;
if (!strcmp(argv[i], "true") || !strcmp(argv[i], "True") || strtoul(argv[i], NULL, 0) == 1) {
config->rotate_envmap = 1;
} else {
config->rotate_envmap = 0;
}
break;
case 's':
if (++i >= argc) return 0;
if (!parse_encoding(&config->encoding, argv[i])) {
@@ -1006,6 +1056,12 @@ int main(int argc, char *argv[])
}
switch (config.format.format) {
case IMG_FORMAT_RGBA:
if (config.rotate_envmap) {
rotate_raw_img(raw, config.width, config.height, config.format.depth);
int tmp_height = config.height;
config.height = config.width;
config.width = tmp_height;
}
imgr = raw2rgba(raw, config.width, config.height, config.format.depth);
res = rgba2png(config.img_filename, imgr, config.width, config.height);
break;