Compare commits

...

7 Commits
1.0.0 ... main

Author SHA1 Message Date
cosmonaut c0dbc791e6 define separator on apple
continuous-integration/drone/push Build is passing Details
2024-01-30 17:39:41 -08:00
cosmonaut 08ac44514e 1.1.1
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is passing Details
2023-10-06 15:12:28 -07:00
cosmonaut 8c32994d4f Fix windows exe generation (#2)
continuous-integration/drone/push Build is passing Details
MinGW is not respecting the BUILD_SHARED_LIBS default value. Cool!

Reviewed-on: #2
2023-10-06 22:10:55 +00:00
cosmonaut fe1f334223 1.1.0
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is passing Details
2023-08-22 11:01:25 -07:00
cosmonaut 613fffcf6b fix linux release file name 2023-08-22 11:01:25 -07:00
cosmonaut 597d8628d7 add premultiply option
continuous-integration/drone/push Build is passing Details
2023-08-22 01:38:21 -07:00
cosmonaut 05ffce873b rename cramcli linux executable
continuous-integration/drone/push Build is passing Details
continuous-integration/drone Build is passing Details
2023-05-27 17:17:34 -07:00
5 changed files with 41 additions and 13 deletions

View File

@ -10,13 +10,14 @@ steps:
- cd ./build
- cmake -DCMAKE_C_COMPILER=/usr/bin/clang -S .. -B .
- make
- mv ./cramcli ./cramcli-linux-amd64
- name: build-windows
image: thatcosmonaut/moonworks-build
commands:
- cmake -E make_directory ./windows-build
- cd ./windows-build
- mingw64-cmake -S .. -B .
- mingw64-cmake -DBUILD_SHARED_LIBS=OFF -S .. -B .
- make
- name: gitea_release
@ -26,7 +27,7 @@ steps:
api_key:
from_secret: gitea_token
files:
- ./build/cramcli
- ./build/cramcli-linux-amd64
- ./windows-build/cramcli.exe
when:
event: tag

View File

@ -5,8 +5,8 @@ option(BUILD_CLI "Build command line executable" ON)
option(BUILD_SHARED_LIBS "Build shared library" OFF)
SET(LIB_MAJOR_VERSION "1")
SET(LIB_MINOR_VERSION "0")
SET(LIB_REVISION "0")
SET(LIB_MINOR_VERSION "1")
SET(LIB_REVISION "1")
SET(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_REVISION}")
# Build Type
@ -56,6 +56,12 @@ if(BUILD_SHARED_LIBS)
set(LINKSTYLE PUBLIC)
endif()
if(BUILD_SHARED_LIBS)
add_library(Cram SHARED ${SOURCE_FILES})
else()
add_library(Cram STATIC ${SOURCE_FILES})
endif()
if(BUILD_CLI)
file(GLOB CLI_SOURCES
tools/cli/lib/stb_image_write.h
@ -80,11 +86,6 @@ if(BUILD_CLI)
endif()
endif()
if(BUILD_SHARED_LIBS)
add_library(Cram SHARED ${SOURCE_FILES})
else()
add_library(Cram STATIC ${SOURCE_FILES})
endif()
# Build flags
if(NOT MSVC)

View File

@ -11,13 +11,15 @@ Cram ships with a default command line interface implemented in C, but if you wi
Command Line Usage
-----
```sh
Usage: cramcli input_dir output_dir atlas_name [--padding padding_value] [--notrim] [--dimension max_dimension]
Usage: cramcli input_dir output_dir atlas_name [--padding padding_value] [--premultiply] [--notrim] [--dimension max_dimension]
```
Cram CLI expects input images to be in PNG format and will output a PNG and a JSON metadata file that you can use to properly display the images in your game. Cram will recursively walk all the subdirectories of `input_dir` to generate your texture atlas.
Padding is set to 0 by default. If you need to use linear filtering, set padding to at least 1. If you need to use texture compression, set padding to at least 4.
Premultiply is off by default. If you will be using linear filtering on these images, you should turn this on or you will get strange artifacts.
Trimming is on by default. Use `--notrim` if for some weird reason you want it off.
Max dimension value is set to 8192 by default since that is a common max texture size for basically every GPU out there. Use `--dimension [max_dimension]` to override this maximum.

View File

@ -54,6 +54,10 @@
#define SEPARATOR '/'
#endif
#ifdef __APPLE__
#define SEPARATOR '/'
#endif
#ifndef max
#define max(x, y) (((x) > (y)) ? (x) : (y))
#endif
@ -68,8 +72,8 @@ extern "C"
#endif /* __cplusplus */
#define CRAM_MAJOR_VERSION 1
#define CRAM_MINOR_VERSION 0
#define CRAM_PATCH_VERSION 0
#define CRAM_MINOR_VERSION 1
#define CRAM_PATCH_VERSION 1
#define CRAM_COMPILED_VERSION ( \
(CRAM_MAJOR_VERSION * 100 * 100) + \

View File

@ -89,7 +89,7 @@ static void dirwalk(char *dir)
void print_help()
{
fprintf(stdout, "Usage: cram input_dir output_dir atlas_name [--padding padding_value] [--notrim] [--dimension max_dimension]");
fprintf(stdout, "Usage: cram input_dir output_dir atlas_name [--padding padding_value] [--premultiply] [--notrim] [--dimension max_dimension]");
}
uint8_t check_dir_exists(char *path)
@ -137,6 +137,8 @@ int main(int argc, char *argv[])
uint8_t *pixelData;
int32_t width;
int32_t height;
uint8_t premultiply;
uint8_t alpha;
char *arg;
char *inputDirPath = NULL;
char *outputDirPath = NULL;
@ -156,6 +158,7 @@ int main(int argc, char *argv[])
createInfo.trim = 1;
createInfo.maxDimension = 8192;
createInfo.name = NULL;
premultiply = 0;
if (argc < 2)
{
@ -177,6 +180,10 @@ int main(int argc, char *argv[])
return 1;
}
}
else if (strcmp(arg, "--premultiply") == 0)
{
premultiply = 1;
}
else if (strcmp(arg, "--notrim") == 0)
{
createInfo.trim = 0;
@ -245,6 +252,19 @@ int main(int argc, char *argv[])
/* output pixel data */
Cram_GetPixelData(context, &pixelData, &width, &height);
if (premultiply)
{
for (i = 0; i < width * height * 4; i += 4)
{
alpha = pixelData[i + 3];
pixelData[i + 0] = (uint8_t) (((uint32_t) (pixelData[i + 0]) * alpha) / 255);
pixelData[i + 1] = (uint8_t) (((uint32_t) (pixelData[i + 1]) * alpha) / 255);
pixelData[i + 2] = (uint8_t) (((uint32_t) (pixelData[i + 2]) * alpha) / 255);
}
}
imageOutputFilename = malloc(strlen(outputDirPath) + strlen(createInfo.name) + 6);
strcpy(imageOutputFilename, outputDirPath);
strcat(imageOutputFilename, separatorString);