add premultiply option
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
05ffce873b
commit
597d8628d7
|
@ -11,13 +11,15 @@ Cram ships with a default command line interface implemented in C, but if you wi
|
||||||
Command Line Usage
|
Command Line Usage
|
||||||
-----
|
-----
|
||||||
```sh
|
```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.
|
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.
|
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.
|
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.
|
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.
|
||||||
|
|
|
@ -89,7 +89,7 @@ static void dirwalk(char *dir)
|
||||||
|
|
||||||
void print_help()
|
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)
|
uint8_t check_dir_exists(char *path)
|
||||||
|
@ -137,6 +137,8 @@ int main(int argc, char *argv[])
|
||||||
uint8_t *pixelData;
|
uint8_t *pixelData;
|
||||||
int32_t width;
|
int32_t width;
|
||||||
int32_t height;
|
int32_t height;
|
||||||
|
uint8_t premultiply;
|
||||||
|
uint8_t alpha;
|
||||||
char *arg;
|
char *arg;
|
||||||
char *inputDirPath = NULL;
|
char *inputDirPath = NULL;
|
||||||
char *outputDirPath = NULL;
|
char *outputDirPath = NULL;
|
||||||
|
@ -156,6 +158,7 @@ int main(int argc, char *argv[])
|
||||||
createInfo.trim = 1;
|
createInfo.trim = 1;
|
||||||
createInfo.maxDimension = 8192;
|
createInfo.maxDimension = 8192;
|
||||||
createInfo.name = NULL;
|
createInfo.name = NULL;
|
||||||
|
premultiply = 0;
|
||||||
|
|
||||||
if (argc < 2)
|
if (argc < 2)
|
||||||
{
|
{
|
||||||
|
@ -177,6 +180,10 @@ int main(int argc, char *argv[])
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (strcmp(arg, "--premultiply") == 0)
|
||||||
|
{
|
||||||
|
premultiply = 1;
|
||||||
|
}
|
||||||
else if (strcmp(arg, "--notrim") == 0)
|
else if (strcmp(arg, "--notrim") == 0)
|
||||||
{
|
{
|
||||||
createInfo.trim = 0;
|
createInfo.trim = 0;
|
||||||
|
@ -245,6 +252,19 @@ int main(int argc, char *argv[])
|
||||||
/* output pixel data */
|
/* output pixel data */
|
||||||
|
|
||||||
Cram_GetPixelData(context, &pixelData, &width, &height);
|
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);
|
imageOutputFilename = malloc(strlen(outputDirPath) + strlen(createInfo.name) + 6);
|
||||||
strcpy(imageOutputFilename, outputDirPath);
|
strcpy(imageOutputFilename, outputDirPath);
|
||||||
strcat(imageOutputFilename, separatorString);
|
strcat(imageOutputFilename, separatorString);
|
||||||
|
|
Loading…
Reference in New Issue