mirror of
https://github.com/AntonioND/nitro-engine.git
synced 2025-06-19 17:15:32 -04:00
tools: Remove nitro_texture_converter
This has been replaced by img2ds, which supports more image formats as input and is more maintainable.
This commit is contained in:
parent
a800ffbb5a
commit
527f524e7c
2
tools/nitro_texture_converter/.gitignore
vendored
2
tools/nitro_texture_converter/.gitignore
vendored
@ -1,2 +0,0 @@
|
||||
nitro_texture_converter
|
||||
*.o
|
@ -1,53 +0,0 @@
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
# Copyright (c) 2008-2009, 2019, Antonio Niño Díaz
|
||||
#
|
||||
# This file is part of Nitro Engine
|
||||
|
||||
NAME := nitro_texture_converter
|
||||
# Either leave the extension empty or assign .exe to it for Windows
|
||||
EXT :=
|
||||
|
||||
PKG_CONFIG := pkg-config
|
||||
PNGCFLAGS := `$(PKG_CONFIG) --static --cflags libpng`
|
||||
PNGLDFLAGS := `$(PKG_CONFIG) --static --libs-only-L libpng`
|
||||
PNGLDLIBS := `$(PKG_CONFIG) --static --libs-only-l libpng`
|
||||
|
||||
CFLAGS := -Wall
|
||||
RM := rm -rf
|
||||
|
||||
all: $(NAME)$(EXT)
|
||||
|
||||
OBJS := \
|
||||
convert_a1rgb5.o \
|
||||
convert_a3rgb32.o \
|
||||
convert_a5rgb8.o \
|
||||
convert_depthbmp.o \
|
||||
convert_rgb16.o \
|
||||
convert_rgb256.o \
|
||||
convert_rgb4.o \
|
||||
load_png.o \
|
||||
nitro_texture_converter.o \
|
||||
palette.o \
|
||||
|
||||
$(NAME)$(EXT): $(OBJS)
|
||||
$(CC) $(CFLAGS) $(PNGLDFLAGS) -o $@ $(OBJS) $(PNGLDLIBS)
|
||||
|
||||
.c.o:
|
||||
$(CC) $(CFLAGS) $(PNGCFLAGS) -c -o $@ $<
|
||||
|
||||
# Target used to remove all files generated by other Makefile targets
|
||||
|
||||
clean:
|
||||
$(RM) $(NAME) $(NAME).exe $(OBJS)
|
||||
|
||||
# Targets to cross-compile Windows binaries from Linux. Not used to compile
|
||||
# natively from Windows.
|
||||
|
||||
mingw32:
|
||||
env PKG_CONFIG_PATH=/usr/i686-w64-mingw32/sys-root/mingw/lib/pkgconfig/ \
|
||||
make CC=i686-w64-mingw32-gcc EXT=.exe
|
||||
|
||||
mingw64:
|
||||
env PKG_CONFIG_PATH=/usr/x86_64-w64-mingw32/sys-root/mingw/lib/pkgconfig/ \
|
||||
make CC=x86_64-w64-mingw32-gcc EXT=.exe
|
@ -1,47 +0,0 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
//
|
||||
// Copyright (c) 2008-2009, 2019, Antonio Niño Díaz
|
||||
//
|
||||
// This file is part of Nitro Engine
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int ConvertARGBintoA1RGB5(void *data, int size, char *texture_filename)
|
||||
{
|
||||
printf("A1RGB5:\n");
|
||||
printf("- If image alpha == 0 -> Result alpha = 0.\n");
|
||||
printf("- If image alpha != 0 -> Result alpha = 1.\n\n");
|
||||
|
||||
FILE *OUTPUT_FILE = fopen(texture_filename, "wb+");
|
||||
|
||||
if (!OUTPUT_FILE) {
|
||||
printf("Couldn't open %s in write mode!!\n\n",
|
||||
texture_filename);
|
||||
return -1;
|
||||
}
|
||||
|
||||
unsigned char *data_pointer = (unsigned char *)data;
|
||||
|
||||
unsigned short pixel_data = 0;
|
||||
|
||||
int a;
|
||||
for (a = 0; a < size; a += 4) {
|
||||
pixel_data = (data_pointer[a] >> 3) & 31; //Red
|
||||
pixel_data |= ((data_pointer[a + 1] >> 3) & 31) << 5; //Green
|
||||
pixel_data |= ((data_pointer[a + 2] >> 3) & 31) << 10; //Blue
|
||||
pixel_data |= (data_pointer[a + 3] > 0) << 15; //Alpha
|
||||
|
||||
if (fwrite(&pixel_data, sizeof(pixel_data), 1, OUTPUT_FILE) !=
|
||||
1) {
|
||||
fclose(OUTPUT_FILE);
|
||||
printf("Write error!!\n\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
fclose(OUTPUT_FILE);
|
||||
|
||||
printf("Created file: %s\n\n", texture_filename);
|
||||
|
||||
return 1;
|
||||
}
|
@ -1,120 +0,0 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
//
|
||||
// Copyright (c) 2008-2009, 2019, Antonio Niño Díaz
|
||||
//
|
||||
// This file is part of Nitro Engine
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "palette.h"
|
||||
|
||||
int ConvertARGBintoA3RGB32(void *data, int size, char *texture_filename,
|
||||
char *palette_filename)
|
||||
{
|
||||
printf("A3RGB32:\n");
|
||||
printf("- If the image has more than 32 colors the program\n");
|
||||
printf(" will try to optimise the palette (discouraged).\n\n");
|
||||
|
||||
unsigned char *data_pointer = (unsigned char *)data;
|
||||
|
||||
int a;
|
||||
|
||||
printf("Creating palette...\n\n");
|
||||
|
||||
int colors_used;
|
||||
int optimization = 0;
|
||||
|
||||
// Try to find a palette
|
||||
while (1) {
|
||||
Palette_New(32, optimization);
|
||||
|
||||
for (a = 0; a < size; a += 4) {
|
||||
// Alpha not used in palettes
|
||||
Palette_NewColor((data_pointer[a] >> 3) & 31,
|
||||
(data_pointer[a + 1] >> 3) & 31,
|
||||
(data_pointer[a + 2] >> 3) & 31);
|
||||
}
|
||||
|
||||
colors_used = Palette_GetColorsUsed();
|
||||
|
||||
if (colors_used != -1)
|
||||
break; // OK ;)
|
||||
|
||||
optimization++; // Let's try again...
|
||||
}
|
||||
|
||||
if (optimization > 0)
|
||||
printf("Palette optimized after %d tries.\n\n", optimization);
|
||||
|
||||
printf("The palette has got %d colors.\n\n", colors_used);
|
||||
|
||||
// Now, save it to a file...
|
||||
FILE *OUTPUT_FILE = fopen(palette_filename, "wb+");
|
||||
|
||||
if (!OUTPUT_FILE) {
|
||||
printf("Couldn't open %s in write mode!!\n\n",
|
||||
palette_filename);
|
||||
return -1;
|
||||
}
|
||||
|
||||
unsigned short color = 0;
|
||||
int red = 0, green = 0, blue = 0;
|
||||
|
||||
int b;
|
||||
for (b = 0; b < colors_used; b++) {
|
||||
Palette_GetColor(b, &red, &green, &blue);
|
||||
|
||||
color = red & 31;
|
||||
color |= (green & 31) << 5;
|
||||
color |= (blue & 31) << 10;
|
||||
// Alpha not used in palettes
|
||||
|
||||
if (fwrite(&color, sizeof(color), 1, OUTPUT_FILE) != 1) {
|
||||
fclose(OUTPUT_FILE);
|
||||
printf("Write error!!\n\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
fclose(OUTPUT_FILE);
|
||||
|
||||
printf("Created file: %s\n\n", palette_filename);
|
||||
|
||||
// Palette created. Now, let's generate the texture
|
||||
printf("Creating texture...\n\n");
|
||||
|
||||
OUTPUT_FILE = fopen(texture_filename, "wb+");
|
||||
|
||||
if (!OUTPUT_FILE) {
|
||||
printf("Couldn't open %s in write mode!!\n\n",
|
||||
texture_filename);
|
||||
return -1;
|
||||
}
|
||||
|
||||
unsigned char index_ = 0;
|
||||
unsigned char alpha_ = 0;
|
||||
|
||||
int c;
|
||||
for (c = 0; c < size; c += 4) {
|
||||
index_ = Palette_GetIndex((data_pointer[c] >> 3) & 31,
|
||||
(data_pointer[c + 1] >> 3) & 31,
|
||||
(data_pointer[c + 2] >> 3) & 31);
|
||||
|
||||
alpha_ = (data_pointer[c + 3] >> 5) & 0x7;
|
||||
|
||||
unsigned char save_to_file = (alpha_ << 5) | (index_ & 31);
|
||||
|
||||
if (fwrite(&save_to_file, sizeof(save_to_file), 1, OUTPUT_FILE)
|
||||
!= 1) {
|
||||
fclose(OUTPUT_FILE);
|
||||
printf("Write error!!\n\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
fclose(OUTPUT_FILE);
|
||||
|
||||
printf("Created file: %s\n\n", texture_filename);
|
||||
|
||||
return 1;
|
||||
}
|
@ -1,121 +0,0 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
//
|
||||
// Copyright (c) 2008-2009, 2019, Antonio Niño Díaz
|
||||
//
|
||||
// This file is part of Nitro Engine
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "palette.h"
|
||||
|
||||
int ConvertARGBintoA5RGB8(void *data, int size, char *texture_filename,
|
||||
char *palette_filename)
|
||||
{
|
||||
printf("A5RGB8:\n");
|
||||
printf("- If the image has more than 8 colors the program\n");
|
||||
printf(" will try to optimise the palette (discouraged).\n\n");
|
||||
|
||||
unsigned char *data_pointer = (unsigned char *)data;
|
||||
|
||||
int a;
|
||||
|
||||
printf("Creating palette...\n\n");
|
||||
|
||||
int colors_used;
|
||||
int optimization = 0;
|
||||
|
||||
// Try to find a palette
|
||||
while (1) {
|
||||
Palette_New(8, optimization);
|
||||
|
||||
for (a = 0; a < size; a += 4) {
|
||||
// Alpha not used in palettes
|
||||
Palette_NewColor((data_pointer[a] >> 3) & 31,
|
||||
(data_pointer[a + 1] >> 3) & 31,
|
||||
(data_pointer[a + 2] >> 3) & 31);
|
||||
}
|
||||
|
||||
colors_used = Palette_GetColorsUsed();
|
||||
|
||||
if (colors_used != -1)
|
||||
break; // OK ;)
|
||||
|
||||
optimization++; // Let's try again...
|
||||
}
|
||||
|
||||
if (optimization > 0)
|
||||
printf("Palette optimized after %d tries.\n\n", optimization);
|
||||
|
||||
printf("The palette has got %d colors.\n\n", colors_used);
|
||||
|
||||
// Now, save it to a file...
|
||||
FILE *OUTPUT_FILE = fopen(palette_filename, "wb+");
|
||||
|
||||
if (!OUTPUT_FILE) {
|
||||
printf("Couldn't open %s in write mode!!\n\n",
|
||||
palette_filename);
|
||||
return -1;
|
||||
}
|
||||
|
||||
unsigned short color = 0;
|
||||
int red = 0, green = 0, blue = 0;
|
||||
|
||||
int b;
|
||||
for (b = 0; b < colors_used; b++) {
|
||||
Palette_GetColor(b, &red, &green, &blue);
|
||||
|
||||
color = red & 31;
|
||||
color |= (green & 31) << 5;
|
||||
color |= (blue & 31) << 10;
|
||||
// Alpha not used in palettes
|
||||
|
||||
if (fwrite(&color, sizeof(color), 1, OUTPUT_FILE) != 1) {
|
||||
fclose(OUTPUT_FILE);
|
||||
printf("Write error!!\n\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
fclose(OUTPUT_FILE);
|
||||
|
||||
printf("Created file: %s\n\n", palette_filename);
|
||||
|
||||
// Palette created. Now, let's generate the texture
|
||||
printf("Creating texture...\n\n");
|
||||
|
||||
OUTPUT_FILE = fopen(texture_filename, "wb+");
|
||||
|
||||
if (!OUTPUT_FILE) {
|
||||
printf("Couldn't open %s in write mode!!\n\n",
|
||||
texture_filename);
|
||||
return -1;
|
||||
}
|
||||
|
||||
unsigned char index_ = 0;
|
||||
unsigned char alpha_ = 0;
|
||||
|
||||
int c;
|
||||
for (c = 0; c < size; c += 4) {
|
||||
index_ =
|
||||
Palette_GetIndex((data_pointer[c] >> 3) & 31,
|
||||
(data_pointer[c + 1] >> 3) & 31,
|
||||
(data_pointer[c + 2] >> 3) & 31);
|
||||
|
||||
alpha_ = (data_pointer[c + 3] >> 3) & 0x1F;
|
||||
|
||||
unsigned char save_to_file = (alpha_ << 3) | (index_ & 0x7);
|
||||
|
||||
if (fwrite(&save_to_file, sizeof(save_to_file), 1, OUTPUT_FILE)
|
||||
!= 1) {
|
||||
fclose(OUTPUT_FILE);
|
||||
printf("Write error!!\n\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
fclose(OUTPUT_FILE);
|
||||
|
||||
printf("Created file: %s\n\n", texture_filename);
|
||||
|
||||
return 1;
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
//
|
||||
// Copyright (c) 2008-2009, 2019, Antonio Niño Díaz
|
||||
//
|
||||
// This file is part of Nitro Engine
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int ConvertARGBintoDEPTHBMP(void *data, int size, char *texture_filename)
|
||||
{
|
||||
printf("DEPTHBMP:\n");
|
||||
printf("- Depth is calculated like this:\n");
|
||||
printf(" if(R) -> 0x00000 (Hides 2D + 3D)\n");
|
||||
printf(" else 0x67FF + (0x1800 * (B) / 255) (Gradually hides 3D)\n");
|
||||
printf(" NOTE: It may change in the future...\n");
|
||||
printf("- If image alpha == 0 -> Fog = 1.\n");
|
||||
printf("- If image alpha != 0 -> Fog = 0.\n\n");
|
||||
|
||||
FILE *OUTPUT_FILE = fopen(texture_filename, "wb+");
|
||||
|
||||
if (!OUTPUT_FILE) {
|
||||
printf("Couldn't open %s in write mode!!\n\n",
|
||||
texture_filename);
|
||||
return -1;
|
||||
}
|
||||
|
||||
unsigned char *data_pointer = (unsigned char *)data;
|
||||
|
||||
unsigned short pixel_data = 0;
|
||||
|
||||
int a;
|
||||
for (a = 0; a < size; a += 4) {
|
||||
//int depth = ((data_pointer[a] + data_pointer[a+1] + data_pointer[a+2]) << 6 ) / 3;
|
||||
|
||||
if (data_pointer[a])
|
||||
pixel_data = 0x00000;
|
||||
else
|
||||
pixel_data =
|
||||
0x67FF + (0x1800 * data_pointer[a + 2] / 255);
|
||||
|
||||
pixel_data &= 0x7FFF;
|
||||
if (data_pointer[a + 3] == 0)
|
||||
pixel_data |= 1 << 15; // If alpha == 0 -> Fog enabled
|
||||
|
||||
if (fwrite(&pixel_data, sizeof(pixel_data), 1, OUTPUT_FILE) !=
|
||||
1) {
|
||||
fclose(OUTPUT_FILE);
|
||||
printf("Write error!!\n\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
fclose(OUTPUT_FILE);
|
||||
|
||||
printf("Created file: %s\n\n", texture_filename);
|
||||
|
||||
return 1;
|
||||
}
|
@ -1,159 +0,0 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
//
|
||||
// Copyright (c) 2008-2009, 2019, Antonio Niño Díaz
|
||||
//
|
||||
// This file is part of Nitro Engine
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "palette.h"
|
||||
|
||||
int ConvertARGBintoRGB16(void *data, int size, char *texture_filename,
|
||||
char *palette_filename)
|
||||
{
|
||||
printf("RGB16:\n");
|
||||
printf("- If image alpha == 0 -> Color index = 0.\n");
|
||||
printf("- If image alpha != 0 -> Color index = actual color.\n");
|
||||
printf(" (Palette color 0 can be transparent.)\n");
|
||||
printf("- If image has more than 16 colors the program will try\n");
|
||||
printf(" to optimize the palette (not recommended).\n\n");
|
||||
|
||||
unsigned char *data_pointer = (unsigned char *)data;
|
||||
|
||||
int a;
|
||||
// Check if transparent...
|
||||
bool transparent_image = false;
|
||||
a = 0;
|
||||
while (a < size) {
|
||||
if (data_pointer[a + 3] == 0) {
|
||||
transparent_image = true;
|
||||
break;
|
||||
}
|
||||
a += 4;
|
||||
}
|
||||
|
||||
printf("Creating palette...\n\n");
|
||||
|
||||
int colors_used;
|
||||
int optimization = 0;
|
||||
|
||||
//Try to find a palette
|
||||
while (1) {
|
||||
Palette_New(16, optimization);
|
||||
|
||||
// Dummy color for transparence
|
||||
if (transparent_image)
|
||||
Palette_NewColor(255, 255, 255);
|
||||
|
||||
for (a = 0; a < size; a += 4) {
|
||||
// If alpha > 0
|
||||
if (data_pointer[a + 3] > 0) {
|
||||
//Alpha not used in palettes
|
||||
Palette_NewColor((data_pointer[a] >> 3) & 31,
|
||||
(data_pointer[a + 1] >> 3) & 31,
|
||||
(data_pointer[a + 2] >> 3) & 31);
|
||||
}
|
||||
}
|
||||
|
||||
colors_used = Palette_GetColorsUsed();
|
||||
|
||||
if (colors_used == 1) {
|
||||
printf("Image alpha channel is always 0!!\n\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (colors_used != -1)
|
||||
break; // OK ;)
|
||||
|
||||
optimization++; // Let's try again...
|
||||
}
|
||||
|
||||
if (optimization > 0)
|
||||
printf("Palette optimized after %d tries.\n\n", optimization);
|
||||
|
||||
printf("The palette has got %d colors.\n\n", colors_used);
|
||||
|
||||
// Now, save it to a file...
|
||||
FILE *OUTPUT_FILE = fopen(palette_filename, "wb+");
|
||||
|
||||
if (!OUTPUT_FILE) {
|
||||
printf("Couldn't open %s in write mode!!\n\n",
|
||||
palette_filename);
|
||||
return -1;
|
||||
}
|
||||
|
||||
unsigned short color = 0;
|
||||
int red = 0, green = 0, blue = 0;
|
||||
|
||||
int b;
|
||||
for (b = 0; b < colors_used; b++) {
|
||||
Palette_GetColor(b, &red, &green, &blue);
|
||||
|
||||
color = red & 31;
|
||||
color |= (green & 31) << 5;
|
||||
color |= (blue & 31) << 10;
|
||||
// Alpha not used in palettes
|
||||
|
||||
if (fwrite(&color, sizeof(color), 1, OUTPUT_FILE) != 1) {
|
||||
fclose(OUTPUT_FILE);
|
||||
printf("Write error!!\n\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
fclose(OUTPUT_FILE);
|
||||
|
||||
printf("Created file: %s\n\n", palette_filename);
|
||||
|
||||
// Palette created. Now, let's generate the texture
|
||||
printf("Creating texture...\n\n");
|
||||
|
||||
OUTPUT_FILE = fopen(texture_filename, "wb+");
|
||||
|
||||
if (!OUTPUT_FILE) {
|
||||
printf("Couldn't open %s in write mode!!\n\n",
|
||||
texture_filename);
|
||||
return -1;
|
||||
}
|
||||
|
||||
unsigned char index_ = 0, index2_ = 0;
|
||||
|
||||
int c;
|
||||
for (c = 0; c < size; c += 8) {
|
||||
// 2 colors per byte
|
||||
if (data_pointer[c + 3] > 0) {
|
||||
index_ =
|
||||
Palette_GetIndex((data_pointer[c] >> 3) & 31,
|
||||
(data_pointer[c + 1] >> 3) & 31,
|
||||
(data_pointer[c + 2] >> 3) & 31);
|
||||
} else {
|
||||
index_ = 0; // 0 = transparent
|
||||
}
|
||||
|
||||
if (data_pointer[c + 3 + 4] > 0) {
|
||||
index2_ =
|
||||
Palette_GetIndex((data_pointer[c + 4] >> 3) & 31,
|
||||
(data_pointer[c + 4 + 1] >> 3) &
|
||||
31,
|
||||
(data_pointer[c + 4 + 2] >> 3) &
|
||||
31);
|
||||
} else {
|
||||
index2_ = 0;
|
||||
}
|
||||
|
||||
unsigned char save_to_file = (index_ & 0xF) | (index2_ << 4);
|
||||
if (fwrite(&save_to_file, sizeof(save_to_file), 1, OUTPUT_FILE)
|
||||
!= 1) {
|
||||
fclose(OUTPUT_FILE);
|
||||
printf("Write error!!\n\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
fclose(OUTPUT_FILE);
|
||||
|
||||
printf("Created file: %s\n\n", texture_filename);
|
||||
|
||||
return 1;
|
||||
}
|
@ -1,145 +0,0 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
//
|
||||
// Copyright (c) 2008-2009, 2019, Antonio Niño Díaz
|
||||
//
|
||||
// This file is part of Nitro Engine
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "palette.h"
|
||||
|
||||
int ConvertARGBintoRGB256(void *data, int size, char *texture_filename,
|
||||
char *palette_filename)
|
||||
{
|
||||
printf("RGB256:\n");
|
||||
printf("- If image alpha == 0 -> Color index = 0.\n");
|
||||
printf("- If image alpha != 0 -> Color index = actual color.\n");
|
||||
printf(" (Palette color 0 can be transparent.)\n");
|
||||
printf("- If image has more than 256 colors the program will try\n");
|
||||
printf(" to optimize the palette (not recommended).\n\n");
|
||||
|
||||
unsigned char *data_pointer = (unsigned char *)data;
|
||||
|
||||
int a;
|
||||
// Check if transparent...
|
||||
bool transparent_image = false;
|
||||
a = 0;
|
||||
while (a < size) {
|
||||
if (data_pointer[a + 3] == 0) {
|
||||
transparent_image = true;
|
||||
break;
|
||||
}
|
||||
a += 4;
|
||||
}
|
||||
|
||||
printf("Creating palette...\n\n");
|
||||
|
||||
int colors_used;
|
||||
int optimization = 0;
|
||||
|
||||
//Try to find a palette
|
||||
while (1) {
|
||||
Palette_New(256, optimization);
|
||||
|
||||
// Dummy color for transparence
|
||||
if (transparent_image)
|
||||
Palette_NewColor(255, 255, 255);
|
||||
|
||||
for (a = 0; a < size; a += 4) {
|
||||
// If alpha > 0
|
||||
if (data_pointer[a + 3] > 0) {
|
||||
// Alpha not used in palettes
|
||||
Palette_NewColor((data_pointer[a] >> 3) & 31,
|
||||
(data_pointer[a + 1] >> 3) & 31,
|
||||
(data_pointer[a + 2] >> 3) & 31);
|
||||
}
|
||||
}
|
||||
|
||||
colors_used = Palette_GetColorsUsed();
|
||||
|
||||
if (colors_used == 1) {
|
||||
printf("Image alpha channel is always 0!!\n\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (colors_used != -1)
|
||||
break; // OK ;)
|
||||
|
||||
optimization++; // Let's try again...
|
||||
}
|
||||
|
||||
if (optimization > 0)
|
||||
printf("Palette optimized after %d tries.\n\n", optimization);
|
||||
|
||||
printf("The palette has got %d colors.\n\n", colors_used);
|
||||
|
||||
// Now, save it to a file...
|
||||
FILE *OUTPUT_FILE = fopen(palette_filename, "wb+");
|
||||
|
||||
if (!OUTPUT_FILE) {
|
||||
printf("Couldn't open %s in write mode!!\n\n",
|
||||
palette_filename);
|
||||
return -1;
|
||||
}
|
||||
|
||||
unsigned short color = 0;
|
||||
int red = 0, green = 0, blue = 0;
|
||||
|
||||
int b;
|
||||
for (b = 0; b < colors_used; b++) {
|
||||
Palette_GetColor(b, &red, &green, &blue);
|
||||
|
||||
color = red & 31;
|
||||
color |= (green & 31) << 5;
|
||||
color |= (blue & 31) << 10;
|
||||
// Alpha not used in palettes
|
||||
|
||||
if (fwrite(&color, sizeof(color), 1, OUTPUT_FILE) != 1) {
|
||||
fclose(OUTPUT_FILE);
|
||||
printf("Write error!!\n\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
fclose(OUTPUT_FILE);
|
||||
|
||||
printf("Created file: %s\n\n", palette_filename);
|
||||
|
||||
// Palette created. Now, let's generate the texture
|
||||
printf("Creating texture...\n\n");
|
||||
|
||||
OUTPUT_FILE = fopen(texture_filename, "wb+");
|
||||
|
||||
if (!OUTPUT_FILE) {
|
||||
printf("Couldn't open %s in write mode!!\n\n",
|
||||
texture_filename);
|
||||
return -1;
|
||||
}
|
||||
|
||||
unsigned char index_ = 0;
|
||||
|
||||
int c;
|
||||
for (c = 0; c < size; c += 4) {
|
||||
if (data_pointer[c + 3] > 0) {
|
||||
index_ =
|
||||
Palette_GetIndex((data_pointer[c] >> 3) & 31,
|
||||
(data_pointer[c + 1] >> 3) & 31,
|
||||
(data_pointer[c + 2] >> 3) & 31);
|
||||
} else {
|
||||
index_ = 0; // 0 = transparent
|
||||
}
|
||||
|
||||
if (fwrite(&index_, sizeof(index_), 1, OUTPUT_FILE) != 1) {
|
||||
fclose(OUTPUT_FILE);
|
||||
printf("Write error!!\n\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
fclose(OUTPUT_FILE);
|
||||
|
||||
printf("Created file: %s\n\n", texture_filename);
|
||||
|
||||
return 1;
|
||||
}
|
@ -1,178 +0,0 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
//
|
||||
// Copyright (c) 2008-2009, 2019, Antonio Niño Díaz
|
||||
//
|
||||
// This file is part of Nitro Engine
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "palette.h"
|
||||
|
||||
int ConvertARGBintoRGB4(void *data, int size, char *texture_filename,
|
||||
char *palette_filename)
|
||||
{
|
||||
printf("RGB4:\n");
|
||||
printf("- If image alpha == 0 -> Color index = 0.\n");
|
||||
printf("- If image alpha != 0 -> Color index = actual color.\n");
|
||||
printf(" (Palette color 0 can be transparent.)\n");
|
||||
printf("- If image has more than 4 colors the program will try\n");
|
||||
printf(" to optimize the palette (not recommended).\n\n");
|
||||
|
||||
unsigned char *data_pointer = (unsigned char *)data;
|
||||
|
||||
int a;
|
||||
// Check if transparent...
|
||||
bool transparent_image = false;
|
||||
a = 0;
|
||||
while (a < size) {
|
||||
if (data_pointer[a + 3] == 0) {
|
||||
transparent_image = true;
|
||||
break;
|
||||
}
|
||||
a += 4;
|
||||
}
|
||||
|
||||
printf("Creating palette...\n\n");
|
||||
|
||||
int colors_used;
|
||||
int optimization = 0;
|
||||
|
||||
// Try to find a palette
|
||||
while (1) {
|
||||
Palette_New(4, optimization);
|
||||
|
||||
// Dummy color for transparence
|
||||
if (transparent_image)
|
||||
Palette_NewColor(255, 255, 255);
|
||||
|
||||
for (a = 0; a < size; a += 4) {
|
||||
// If alpha > 0
|
||||
if (data_pointer[a + 3] > 0) {
|
||||
// Alpha not used in palettes
|
||||
Palette_NewColor((data_pointer[a] >> 3) & 31,
|
||||
(data_pointer[a + 1] >> 3) & 31,
|
||||
(data_pointer[a + 2] >> 3) & 31);
|
||||
}
|
||||
}
|
||||
|
||||
colors_used = Palette_GetColorsUsed();
|
||||
|
||||
if (colors_used == 1) {
|
||||
printf("Image alpha channel is always 0!!\n\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (colors_used != -1)
|
||||
break; // OK ;)
|
||||
|
||||
optimization++; // Let's try again...
|
||||
}
|
||||
|
||||
if (optimization > 0)
|
||||
printf("Palette optimized after %d tries.\n\n", optimization);
|
||||
|
||||
printf("The palette has got %d colors.\n\n", colors_used);
|
||||
|
||||
// Now, save it to a file...
|
||||
FILE *OUTPUT_FILE = fopen(palette_filename, "wb+");
|
||||
|
||||
if (!OUTPUT_FILE) {
|
||||
printf("Couldn't open %s in write mode!!\n\n",
|
||||
palette_filename);
|
||||
return -1;
|
||||
}
|
||||
|
||||
unsigned short color = 0;
|
||||
int red = 0, green = 0, blue = 0;
|
||||
|
||||
int b;
|
||||
for (b = 0; b < colors_used; b++) {
|
||||
Palette_GetColor(b, &red, &green, &blue);
|
||||
|
||||
color = red & 31;
|
||||
color |= (green & 31) << 5;
|
||||
color |= (blue & 31) << 10;
|
||||
// Alpha not used in palettes
|
||||
|
||||
if (fwrite(&color, sizeof(color), 1, OUTPUT_FILE) != 1) {
|
||||
fclose(OUTPUT_FILE);
|
||||
printf("Write error!!\n\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
fclose(OUTPUT_FILE);
|
||||
|
||||
printf("Created file: %s\n\n", palette_filename);
|
||||
|
||||
// Palette created. Now, let's generate the texture
|
||||
printf("Creating texture...\n\n");
|
||||
|
||||
OUTPUT_FILE = fopen(texture_filename, "wb+");
|
||||
|
||||
if (!OUTPUT_FILE) {
|
||||
printf("Couldn't open %s in write mode!!\n\n",
|
||||
texture_filename);
|
||||
return -1;
|
||||
}
|
||||
|
||||
unsigned char index_[4] = { 0, 0, 0, 0 };
|
||||
|
||||
int c;
|
||||
for (c = 0; c < size; c += 16) {
|
||||
// 4 colors per byte
|
||||
if (data_pointer[c + 3] > 0) {
|
||||
index_[0] =
|
||||
Palette_GetIndex((data_pointer[c] >> 3) & 31,
|
||||
(data_pointer[c + 1] >> 3) & 31,
|
||||
(data_pointer[c + 2] >> 3) & 31);
|
||||
} else {
|
||||
index_[0] = 0; // 0 = transparent
|
||||
}
|
||||
|
||||
if (data_pointer[c + 3] > 0) {
|
||||
index_[1] =
|
||||
Palette_GetIndex((data_pointer[c + 4] >> 3) & 31,
|
||||
(data_pointer[c + 4 + 1] >> 3) & 31,
|
||||
(data_pointer[c + 4 + 2] >> 3) & 31);
|
||||
} else {
|
||||
index_[1] = 0;
|
||||
}
|
||||
|
||||
if (data_pointer[c + 3] > 0) {
|
||||
index_[2] =
|
||||
Palette_GetIndex((data_pointer[c + 8] >> 3) & 31,
|
||||
(data_pointer[c + 8 + 1] >> 3) & 31,
|
||||
(data_pointer[c + 8 + 2] >> 3) & 31);
|
||||
} else {
|
||||
index_[2] = 0;
|
||||
}
|
||||
|
||||
if (data_pointer[c + 3] > 0) {
|
||||
index_[3] =
|
||||
Palette_GetIndex((data_pointer[c + 12] >> 3) & 31,
|
||||
(data_pointer[c + 12 + 1] >> 3) & 31,
|
||||
(data_pointer[c + 12 + 2] >> 3) & 31);
|
||||
} else {
|
||||
index_[3] = 0;
|
||||
}
|
||||
|
||||
unsigned char save_to_file =
|
||||
(index_[0] & 0x3) | ((index_[1] & 0x3) << 2) |
|
||||
((index_[2] & 0x3) << 4) | ((index_[3] & 0x3) << 6);
|
||||
|
||||
if (fwrite(&save_to_file, sizeof(save_to_file), 1, OUTPUT_FILE)
|
||||
!= 1) {
|
||||
fclose(OUTPUT_FILE);
|
||||
printf("Write error!!\n\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
fclose(OUTPUT_FILE);
|
||||
|
||||
printf("Created file: %s\n\n", texture_filename);
|
||||
|
||||
return 1;
|
||||
}
|
@ -1,67 +0,0 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
//
|
||||
// Copyright (c) 2008-2009, 2019, 2022 Antonio Niño Díaz
|
||||
//
|
||||
// This file is part of Nitro Engine
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <png.h>
|
||||
|
||||
#define PNG_BYTES_TO_CHECK 4
|
||||
#define MAX_WIDTH_HEIGHT 1024
|
||||
|
||||
#if !defined(PNG_SIMPLIFIED_READ_SUPPORTED)
|
||||
# error "This code needs libpng 1.6"
|
||||
#endif
|
||||
|
||||
void *LoadPNGtoARGB(char *filename, int *buffer_size)
|
||||
{
|
||||
printf("Loading file %s...\n\n", filename);
|
||||
|
||||
png_image image;
|
||||
|
||||
// Only the image structure version number needs to be set
|
||||
memset(&image, 0, sizeof image);
|
||||
image.version = PNG_IMAGE_VERSION;
|
||||
|
||||
if (!png_image_begin_read_from_file(&image, filename))
|
||||
{
|
||||
printf("%s(): png_image_begin_read_from_file(): %s",
|
||||
__func__, image.message);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
image.format = PNG_FORMAT_RGBA;
|
||||
|
||||
png_bytep buffer;
|
||||
buffer = malloc(PNG_IMAGE_SIZE(image));
|
||||
|
||||
if (buffer == NULL)
|
||||
{
|
||||
png_image_free(&image);
|
||||
printf("%s(): Not enough memory", __func__);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!png_image_finish_read(&image, NULL, buffer, 0, NULL))
|
||||
{
|
||||
printf("%s(): png_image_finish_read(): %s", __func__, image.message);
|
||||
free(buffer);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int _width = image.width;
|
||||
int _height = image.height;
|
||||
|
||||
printf("PNG information:\n");
|
||||
printf(" Width: %d\n", _width);
|
||||
printf(" Height: %d\n", _height);
|
||||
printf("\n");
|
||||
|
||||
*buffer_size = _height * _width * 4;
|
||||
|
||||
return buffer;
|
||||
}
|
@ -1,172 +0,0 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
//
|
||||
// Copyright (c) 2008-2009, 2019, Antonio Niño Díaz
|
||||
//
|
||||
// This file is part of Nitro Engine
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define NITRO_TEXTURE_CONVERTER_VERSION "1.1.0"
|
||||
|
||||
#define FORMAT_TYPES 7
|
||||
|
||||
const char *FORMAT_STRINGS[FORMAT_TYPES] = {
|
||||
"A1RGB5", "RGB256", "RGB16", "RGB4", "A3RGB32", "A5RGB8", "DEPTHBMP"
|
||||
};
|
||||
|
||||
void PrintUsage(void)
|
||||
{
|
||||
printf("Usage:\n");
|
||||
printf(" Nitro_Texture_Converter [input].png [format]\n\n");
|
||||
|
||||
printf("Output files:\n");
|
||||
printf(" [input]_tex.bin - Texture\n");
|
||||
printf(" [input]_pal.bin - Palette (if any)\n\n");
|
||||
|
||||
printf("Format list: (Palete format is always RGB5)\n");
|
||||
printf(" A1RGB5 - 1 Alpha, 5 Red Green Blue\n");
|
||||
printf(" RGB256 - 8 Palette (256 colors)\n");
|
||||
printf(" RGB16 - 4 Palette (16 colors)\n");
|
||||
printf(" RGB4 - 2 Palette (4 colors)\n");
|
||||
printf(" A3RGB32 - 3 Alpha, 5 Palette (32 colors\n");
|
||||
printf(" A5RGB8 - 5 Alpha, 3 Palette (8 colors\n");
|
||||
printf(" DEPTHBMP - 1 Fog enable, 15 Depth (For clear BMP)\n\n\n");
|
||||
}
|
||||
|
||||
int GetFormat(char *string)
|
||||
{
|
||||
int a;
|
||||
for (a = 0; a < FORMAT_TYPES; a++) {
|
||||
if (strcmp(string, FORMAT_STRINGS[a]) == 0)
|
||||
return a;
|
||||
}
|
||||
|
||||
printf("Format %s unsupported!\n\n", string);
|
||||
return -1;
|
||||
}
|
||||
|
||||
void *LoadPNGtoARGB(char *filename, int *buffer_size);
|
||||
|
||||
int ConvertARGBintoA1RGB5(void *data, int size, char *texture_filename);
|
||||
int ConvertARGBintoRGB256(void *data, int size, char *texture_filename,
|
||||
char *palette_filename);
|
||||
int ConvertARGBintoRGB16(void *data, int size, char *texture_filename,
|
||||
char *palette_filename);
|
||||
int ConvertARGBintoRGB4(void *data, int size, char *texture_filename,
|
||||
char *palette_filename);
|
||||
int ConvertARGBintoA3RGB32(void *data, int size, char *texture_filename,
|
||||
char *palette_filename);
|
||||
int ConvertARGBintoA5RGB8(void *data, int size, char *texture_filename,
|
||||
char *palette_filename);
|
||||
int ConvertARGBintoDEPTHBMP(void *data, int size, char *texture_filename);
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
printf("Nitro Texture Converter - v"
|
||||
NITRO_TEXTURE_CONVERTER_VERSION "\n");
|
||||
printf("\n");
|
||||
printf("Copyright (c) 2008-2011, 2019 Antonio Nino Diaz\n");
|
||||
printf("\n");
|
||||
|
||||
if (argc != 3) {
|
||||
PrintUsage();
|
||||
return 1;
|
||||
}
|
||||
|
||||
int OUTPUT_FORMAT = GetFormat(argv[2]);
|
||||
if (OUTPUT_FORMAT == -1) {
|
||||
PrintUsage();
|
||||
return 1;
|
||||
}
|
||||
|
||||
char *test_extension_png = argv[1] + strlen(argv[1]) - strlen(".png");
|
||||
if (strcmp(test_extension_png, ".png") != 0) {
|
||||
printf
|
||||
("Input file must have the name like this: [input].png\n\n");
|
||||
PrintUsage();
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("Converting %s into format %s...\n\n", argv[1], argv[2]);
|
||||
|
||||
int ARGB_BUFFER_SIZE = 0; //Convert it into ARGB raw data
|
||||
void *ARGB_BUFFER = LoadPNGtoARGB(argv[1], &ARGB_BUFFER_SIZE);
|
||||
if (ARGB_BUFFER == NULL)
|
||||
return -1;
|
||||
|
||||
// Get output filenames
|
||||
int __strlen = strlen(argv[1]) - strlen(".png");
|
||||
char OUTPUT_BASE_FILENAME[FILENAME_MAX];
|
||||
strncpy(OUTPUT_BASE_FILENAME, argv[1], __strlen);
|
||||
OUTPUT_BASE_FILENAME[__strlen] = '\0';
|
||||
|
||||
char OUTPUT_TEXTURE_FILENAME[FILENAME_MAX];
|
||||
snprintf(OUTPUT_TEXTURE_FILENAME, sizeof(OUTPUT_TEXTURE_FILENAME),
|
||||
"%s_tex.bin", OUTPUT_BASE_FILENAME);
|
||||
|
||||
char OUTPUT_PALETTE_FILENAME[FILENAME_MAX];
|
||||
snprintf(OUTPUT_PALETTE_FILENAME, sizeof(OUTPUT_PALETTE_FILENAME),
|
||||
"%s_pal.bin", OUTPUT_BASE_FILENAME);
|
||||
|
||||
// Convert raw data into the format requested
|
||||
|
||||
int returned_value = 0;
|
||||
|
||||
switch (OUTPUT_FORMAT) {
|
||||
case 0: // A1RGB5
|
||||
returned_value =
|
||||
ConvertARGBintoA1RGB5(ARGB_BUFFER, ARGB_BUFFER_SIZE,
|
||||
OUTPUT_TEXTURE_FILENAME);
|
||||
break;
|
||||
case 1: // RGB256
|
||||
returned_value =
|
||||
ConvertARGBintoRGB256(ARGB_BUFFER, ARGB_BUFFER_SIZE,
|
||||
OUTPUT_TEXTURE_FILENAME,
|
||||
OUTPUT_PALETTE_FILENAME);
|
||||
break;
|
||||
case 2: // RGB16
|
||||
returned_value =
|
||||
ConvertARGBintoRGB16(ARGB_BUFFER, ARGB_BUFFER_SIZE,
|
||||
OUTPUT_TEXTURE_FILENAME,
|
||||
OUTPUT_PALETTE_FILENAME);
|
||||
break;
|
||||
case 3: // RGB4
|
||||
returned_value =
|
||||
ConvertARGBintoRGB4(ARGB_BUFFER, ARGB_BUFFER_SIZE,
|
||||
OUTPUT_TEXTURE_FILENAME,
|
||||
OUTPUT_PALETTE_FILENAME);
|
||||
break;
|
||||
case 4: // A3RGB32
|
||||
returned_value =
|
||||
ConvertARGBintoA3RGB32(ARGB_BUFFER, ARGB_BUFFER_SIZE,
|
||||
OUTPUT_TEXTURE_FILENAME,
|
||||
OUTPUT_PALETTE_FILENAME);
|
||||
break;
|
||||
case 5: // A5RGB8
|
||||
returned_value =
|
||||
ConvertARGBintoA5RGB8(ARGB_BUFFER, ARGB_BUFFER_SIZE,
|
||||
OUTPUT_TEXTURE_FILENAME,
|
||||
OUTPUT_PALETTE_FILENAME);
|
||||
break;
|
||||
case 6: // DEPTHBMP
|
||||
returned_value =
|
||||
ConvertARGBintoDEPTHBMP(ARGB_BUFFER, ARGB_BUFFER_SIZE,
|
||||
OUTPUT_TEXTURE_FILENAME);
|
||||
break;
|
||||
default:
|
||||
//Program should never get here!
|
||||
printf("Please, select a valid format!\n\n");
|
||||
break;
|
||||
}
|
||||
|
||||
free(ARGB_BUFFER);
|
||||
|
||||
if (returned_value < 1)
|
||||
return -2;
|
||||
|
||||
printf("Done!!\n\n");
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,130 +0,0 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
//
|
||||
// Copyright (c) 2008-2009, 2019, Antonio Niño Díaz
|
||||
//
|
||||
// This file is part of Nitro Engine
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "palette.h"
|
||||
|
||||
typedef struct {
|
||||
unsigned char red, green, blue;
|
||||
} _COLOR_;
|
||||
|
||||
_COLOR_ palette_ptr[MAX_PALETTE_COLORS];
|
||||
int colors_used, max_colors;
|
||||
bool warning_maxcolors;
|
||||
bool can_optimize;
|
||||
int MAX_COLOR_DIFFERENCE;
|
||||
|
||||
bool palette_error;
|
||||
|
||||
static int Square(int number)
|
||||
{
|
||||
return number * number;
|
||||
}
|
||||
|
||||
void Palette_New(int maxcolors, int optimize)
|
||||
{
|
||||
colors_used = 0;
|
||||
warning_maxcolors = false;
|
||||
max_colors = maxcolors;
|
||||
palette_error = false;
|
||||
|
||||
if (optimize > 0) {
|
||||
can_optimize = true;
|
||||
MAX_COLOR_DIFFERENCE = optimize;
|
||||
}
|
||||
}
|
||||
|
||||
void Palette_NewColor(unsigned char red, unsigned char green,
|
||||
unsigned char blue)
|
||||
{
|
||||
if (palette_error)
|
||||
return;
|
||||
|
||||
int a;
|
||||
for (a = 0; a < colors_used; a++) {
|
||||
// If same color
|
||||
if (palette_ptr[a].red == red && palette_ptr[a].green == green
|
||||
&& palette_ptr[a].blue == blue)
|
||||
return;
|
||||
}
|
||||
|
||||
// Find if there is a very similar color...
|
||||
if (can_optimize) {
|
||||
// Find the most similar color
|
||||
for (a = 0; a < colors_used; a++) {
|
||||
if (MAX_COLOR_DIFFERENCE >
|
||||
Square(palette_ptr[a].red - red) +
|
||||
Square(palette_ptr[a].green - green) +
|
||||
Square(palette_ptr[a].blue - blue))
|
||||
return; // Found, don't add the new color
|
||||
}
|
||||
}
|
||||
|
||||
// Add the color
|
||||
if (colors_used < max_colors) {
|
||||
palette_ptr[colors_used].red = red;
|
||||
palette_ptr[colors_used].green = green;
|
||||
palette_ptr[colors_used].blue = blue;
|
||||
colors_used++;
|
||||
return;
|
||||
}
|
||||
|
||||
// Couldn't add a color...
|
||||
palette_error = true;
|
||||
}
|
||||
|
||||
int Palette_GetIndex(unsigned char red, unsigned char green, unsigned char blue)
|
||||
{
|
||||
int a;
|
||||
for (a = 0; a < colors_used; a++) {
|
||||
// If same color
|
||||
if (palette_ptr[a].red == red && palette_ptr[a].green == green
|
||||
&& palette_ptr[a].blue == blue)
|
||||
return a;
|
||||
}
|
||||
|
||||
if (can_optimize) {
|
||||
int difference = 10000000;
|
||||
int chosen_color = -1;
|
||||
// Not found the same color, find a similar one
|
||||
for (a = 0; a < colors_used; a++) {
|
||||
int newdifference =
|
||||
Square(palette_ptr[a].red - red) +
|
||||
Square(palette_ptr[a].green - green) +
|
||||
Square(palette_ptr[a].blue - blue);
|
||||
|
||||
if (difference > newdifference) {
|
||||
chosen_color = a;
|
||||
difference = newdifference;
|
||||
}
|
||||
}
|
||||
|
||||
return chosen_color;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Palette_GetColor(int index, int *red, int *green, int *blue)
|
||||
{
|
||||
if (index < colors_used) {
|
||||
*red = palette_ptr[index].red;
|
||||
*green = palette_ptr[index].green;
|
||||
*blue = palette_ptr[index].blue;
|
||||
} else {
|
||||
*red = *green = *blue = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int Palette_GetColorsUsed(void)
|
||||
{
|
||||
if (palette_error)
|
||||
return -1;
|
||||
|
||||
return colors_used;
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
//
|
||||
// Copyright (c) 2008-2009, 2019, Antonio Niño Díaz
|
||||
//
|
||||
// This file is part of Nitro Engine
|
||||
|
||||
#ifndef PALETTE_H__
|
||||
#define PALETTE_H__
|
||||
|
||||
// 256 is the max. number of colors for a palette for NDS
|
||||
#define MAX_PALETTE_COLORS 256
|
||||
|
||||
void Palette_New(int maxcolors, int optimize);
|
||||
|
||||
void Palette_NewColor(unsigned char red, unsigned char green,
|
||||
unsigned char blue);
|
||||
|
||||
int Palette_GetIndex(unsigned char red, unsigned char green,
|
||||
unsigned char blue);
|
||||
|
||||
void Palette_GetColor(int index, int *red, int *green, int *blue);
|
||||
|
||||
int Palette_GetColorsUsed(void);
|
||||
|
||||
#endif // PALETTE_H__
|
@ -1,58 +0,0 @@
|
||||
Just some things you have to know...
|
||||
|
||||
|
||||
1. This program converts any PNG into RGBA 8 bits of depth before converting it
|
||||
into any other format, so any PNG should work the same. That conversion is done
|
||||
by libpng.
|
||||
|
||||
|
||||
2. If the image size is not power of 2 the program will output a warning message
|
||||
but it will convert it anyway. Be careful. If the width is not power of two the
|
||||
image will need much more time to load (and use as much memory as if it was the
|
||||
closest power of two). If the height is not a power of two, it will only use the
|
||||
strictly needed memory, so this is actually advisable.
|
||||
|
||||
|
||||
3. DEPTHBMP is just a depth map used for clear BMP. It is quite complicated to
|
||||
find the correct depth, so I've done what I can to make it easier to
|
||||
understand... It may change in the future. Depth is calculated like this:
|
||||
|
||||
IF RED THEN 0x00000 (Hides 2D projection + 3D)
|
||||
ELSE 0x67FF + (0x1800 * BLUE / 255) (Gradually hides 3D)
|
||||
|
||||
Take a look at the clear_bmp example to see how it works exactly.
|
||||
|
||||
|
||||
4. If the image has alpha channel, it will be used for transparency in this way:
|
||||
|
||||
- A1RGB5:
|
||||
|
||||
IF alpha == 0 THEN texture_alpha = 0 ELSE texture_alpha = 1
|
||||
|
||||
- RGB256/RGB16/RGB4:
|
||||
|
||||
First, if for any pixel alpha == 0, a dummy color will be put at index 0.
|
||||
In that case the next expression is used:
|
||||
|
||||
IF alpha == 0 THEN color_index = 0 ELSE color_index = actual_color_index
|
||||
|
||||
In this way, you can set the color 0 to transparent in texture propierties.
|
||||
|
||||
- A3RGB32:
|
||||
|
||||
texture_alpha = alpha >> 5
|
||||
|
||||
- A5RGB8:
|
||||
|
||||
texture_alpha = alpha >> 3
|
||||
|
||||
- DEPTHBMP:
|
||||
|
||||
IF alpha == 0 THEN fog_enabled = 1 ELSE fog_enabled = 0
|
||||
|
||||
|
||||
5. For paletted textures (RGB256/RGB16/RGB4/A3RGB32/A5RGB8): If the original
|
||||
image has more colors than allowed, this program will find a palette with less
|
||||
colors than the original, but the image will lose quality. You should do this in
|
||||
your image edition program to get the best possible result, but you can use this
|
||||
tool if you want to.
|
@ -1,2 +0,0 @@
|
||||
Nitro_Texture_Converter test.png A3RGB32
|
||||
pause
|
Binary file not shown.
Before Width: | Height: | Size: 27 KiB |
@ -3,11 +3,6 @@ Nitro Engine Tools
|
||||
|
||||
The following tools are used to export models created on the PC to the NDS:
|
||||
|
||||
- **Nitro_Texture_Converter**
|
||||
|
||||
It converts any PNG into any DS texture format (except compressed format).
|
||||
It uses the alpha channel (if any) for texture transparency.
|
||||
|
||||
- **obj2dl**
|
||||
|
||||
Converts a Wavefront OBJ file into a NDS display list.
|
||||
|
Loading…
Reference in New Issue
Block a user