change image name to image path
parent
96a5a4a6e1
commit
009321fc2f
|
@ -85,7 +85,7 @@ typedef struct Cram_ContextCreateInfo
|
|||
|
||||
typedef struct Cram_ImageData
|
||||
{
|
||||
char *name;
|
||||
char *path;
|
||||
|
||||
int32_t x;
|
||||
int32_t y;
|
||||
|
|
12
src/cram.c
12
src/cram.c
|
@ -49,7 +49,7 @@ typedef struct Cram_Image Cram_Image;
|
|||
|
||||
struct Cram_Image
|
||||
{
|
||||
char *name;
|
||||
char *path;
|
||||
Rect originalRect;
|
||||
Rect trimmedRect;
|
||||
Rect packedRect;
|
||||
|
@ -531,7 +531,7 @@ void Cram_AddFile(Cram_Context *context, const char *path)
|
|||
|
||||
image = malloc(sizeof(Cram_Image));
|
||||
|
||||
image->name = Cram_Internal_GetImageName(path);
|
||||
image->path = strdup(path);
|
||||
|
||||
pixels = stbi_load(
|
||||
path,
|
||||
|
@ -769,12 +769,12 @@ int8_t Cram_Pack(Cram_Context *context)
|
|||
internalContext->imageDatas[i].width = image->trimmedRect.w;
|
||||
internalContext->imageDatas[i].height = image->trimmedRect.h;
|
||||
|
||||
internalContext->imageDatas[i].trimOffsetX = image->trimmedRect.x - image->originalRect.x;
|
||||
internalContext->imageDatas[i].trimOffsetY = image->trimmedRect.y - image->originalRect.y;
|
||||
internalContext->imageDatas[i].trimOffsetX = image->originalRect.x - image->trimmedRect.x;
|
||||
internalContext->imageDatas[i].trimOffsetY = image->originalRect.y - image->trimmedRect.y;
|
||||
internalContext->imageDatas[i].untrimmedWidth = image->originalRect.w;
|
||||
internalContext->imageDatas[i].untrimmedHeight = image->originalRect.h;
|
||||
|
||||
internalContext->imageDatas[i].name = strdup(internalContext->images[i]->name);
|
||||
internalContext->imageDatas[i].path = strdup(internalContext->images[i]->path);
|
||||
}
|
||||
|
||||
free(packerRects);
|
||||
|
@ -815,7 +815,7 @@ void Cram_Destroy(Cram_Context *context)
|
|||
free(internalContext->images[i]->pixels);
|
||||
}
|
||||
|
||||
free(internalContext->images[i]->name);
|
||||
free(internalContext->images[i]->path);
|
||||
free(internalContext->images[i]);
|
||||
}
|
||||
|
||||
|
|
|
@ -103,6 +103,34 @@ uint8_t check_dir_exists(char *path)
|
|||
}
|
||||
}
|
||||
|
||||
static char* relative_path(char *fullPath, char *inputDir)
|
||||
{
|
||||
int32_t index = 0;
|
||||
|
||||
while (fullPath[index] == inputDir[index])
|
||||
{
|
||||
index += 1;
|
||||
}
|
||||
|
||||
return &fullPath[index + 1]; /* add one to remove separator */
|
||||
}
|
||||
|
||||
static char* replace(char *string, char character, char newCharacter)
|
||||
{
|
||||
int32_t i = 0;
|
||||
size_t len = strlen(string);
|
||||
|
||||
for (i = 0; i < len; i += 1)
|
||||
{
|
||||
if (string[i] == character)
|
||||
{
|
||||
string[i] = newCharacter;
|
||||
}
|
||||
}
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
Cram_ContextCreateInfo createInfo;
|
||||
|
@ -244,7 +272,7 @@ int main(int argc, char *argv[])
|
|||
for (i = 0; i < imageCount; i += 1)
|
||||
{
|
||||
JsonBuilder_StartObject(jsonBuilder);
|
||||
JsonBuilder_AppendStringProperty(jsonBuilder, "Name", imageDatas[i].name);
|
||||
JsonBuilder_AppendStringProperty(jsonBuilder, "Name", replace(relative_path(imageDatas[i].path, inputDirPath), '\\', '/'));
|
||||
JsonBuilder_AppendIntProperty(jsonBuilder, "X", imageDatas[i].x);
|
||||
JsonBuilder_AppendIntProperty(jsonBuilder, "Y", imageDatas[i].y);
|
||||
JsonBuilder_AppendIntProperty(jsonBuilder, "W", imageDatas[i].width);
|
||||
|
|
Loading…
Reference in New Issue