linux compatibility fixes
parent
009321fc2f
commit
95c2b46244
|
@ -57,18 +57,27 @@ if(BUILD_SHARED_LIBS)
|
|||
endif()
|
||||
|
||||
if(BUILD_CLI)
|
||||
add_executable(cramcli
|
||||
tools/cli/lib/dirent.h
|
||||
file(GLOB CLI_SOURCES
|
||||
tools/cli/lib/stb_image_write.h
|
||||
tools/cli/json_writer.h
|
||||
tools/cli/main.c
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
list(APPEND CLI_SOURCES tools/cli/lib/dirent.h)
|
||||
endif()
|
||||
|
||||
add_executable(cramcli ${CLI_SOURCES})
|
||||
|
||||
if(BUILD_SHARED_LIBS)
|
||||
target_link_libraries(cramcli PUBLIC Cram)
|
||||
else()
|
||||
target_link_libraries(cramcli PRIVATE Cram)
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
target_include_directories(cramcli PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/tools/cli/lib/windows>)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(BUILD_SHARED_LIBS)
|
||||
|
@ -80,6 +89,7 @@ endif()
|
|||
# Build flags
|
||||
if(NOT MSVC)
|
||||
set_property(TARGET Cram PROPERTY COMPILE_FLAGS "-std=gnu99 -Wall -Wno-strict-aliasing -pedantic")
|
||||
target_link_libraries(Cram PUBLIC m)
|
||||
endif()
|
||||
|
||||
# includes
|
||||
|
|
|
@ -54,6 +54,14 @@
|
|||
#define SEPARATOR '/'
|
||||
#endif
|
||||
|
||||
#ifndef max
|
||||
#define max(x, y) (((x) > (y)) ? (x) : (y))
|
||||
#endif
|
||||
|
||||
#ifndef min
|
||||
#define min(x, y) (((x) < (y)) ? (x) : (y))
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
|
|
28
src/cram.c
28
src/cram.c
|
@ -104,19 +104,6 @@ typedef struct PackScoreInfo
|
|||
|
||||
/* Pixel data functions */
|
||||
|
||||
/* https://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2 */
|
||||
static uint32_t Cram_Internal_NextPowerOfTwo(uint32_t v)
|
||||
{
|
||||
v--;
|
||||
v |= v >> 1;
|
||||
v |= v >> 2;
|
||||
v |= v >> 4;
|
||||
v |= v >> 8;
|
||||
v |= v >> 16;
|
||||
v++;
|
||||
return v;
|
||||
}
|
||||
|
||||
static uint8_t Cram_Internal_IsImageEqual(Cram_Image *a, Cram_Image *b)
|
||||
{
|
||||
int32_t i;
|
||||
|
@ -499,21 +486,6 @@ Cram_Context* Cram_Init(Cram_ContextCreateInfo *createInfo)
|
|||
return (Cram_Context*) context;
|
||||
}
|
||||
|
||||
static char* Cram_Internal_GetImageName(const char *path)
|
||||
{
|
||||
char *lastSeparator = strrchr(path, SEPARATOR) + 1;
|
||||
size_t returnBytes = strlen(lastSeparator) + 1;
|
||||
char *name = malloc(returnBytes);
|
||||
int32_t i;
|
||||
|
||||
for (i = 0; i < returnBytes; i += 1)
|
||||
{
|
||||
name[i] = lastSeparator[i];
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
void Cram_AddFile(Cram_Context *context, const char *path)
|
||||
{
|
||||
Cram_Internal_Context *internalContext = (Cram_Internal_Context*) context;
|
||||
|
|
|
@ -29,6 +29,8 @@
|
|||
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define INITIAL_JSON_OUTPUT_CAPACITY 2048
|
||||
|
||||
|
@ -114,7 +116,7 @@ void JsonBuilder_AppendStringProperty(JsonBuilder *builder, char *propertyName,
|
|||
void JsonBuilder_AppendIntProperty(JsonBuilder *builder, char *propertyName, int32_t value)
|
||||
{
|
||||
char buffer[65];
|
||||
itoa(value, buffer, 10);
|
||||
sprintf(buffer, "%d", value);
|
||||
JsonBuilder_AppendProperty(builder, propertyName, buffer, 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -24,8 +24,8 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include <dirent.h>
|
||||
#include "cram.h"
|
||||
#include "dirent.h"
|
||||
#include "json_writer.h"
|
||||
|
||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
|
@ -48,7 +48,7 @@ static const char* GetFilenameExtension(const char *filename)
|
|||
/* Mostly taken from K&R C 2nd edition page 182 */
|
||||
static void dirwalk(char *dir)
|
||||
{
|
||||
dirent *dp;
|
||||
struct dirent *dp;
|
||||
DIR *dfd;
|
||||
char subname[2048];
|
||||
|
||||
|
@ -135,8 +135,8 @@ int main(int argc, char *argv[])
|
|||
{
|
||||
Cram_ContextCreateInfo createInfo;
|
||||
uint8_t *pixelData;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
int32_t width;
|
||||
int32_t height;
|
||||
char *arg;
|
||||
char *inputDirPath = NULL;
|
||||
char *outputDirPath = NULL;
|
||||
|
@ -299,7 +299,7 @@ int main(int argc, char *argv[])
|
|||
return 1;
|
||||
}
|
||||
|
||||
fprintf(jsonOutput, jsonBuilder->string);
|
||||
fprintf(jsonOutput, "%s", jsonBuilder->string);
|
||||
|
||||
JsonBuilder_Destroy(jsonBuilder);
|
||||
fclose(jsonOutput);
|
||||
|
|
Loading…
Reference in New Issue