Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build/configs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ if (WIN32)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /W3 /WX /Ot /GF /Gm- /GR- /Gy /GL /Zc:wchar_t-")
elseif (UNIX AND NOT APPLE)
if (OPT_SANITIZE)
set(SANITIZE "-fsanitize=address -fsanitize=leak -fsanitize=undefined")
set(SANITIZE "-fsanitize=address -fsanitize=leak -fsanitize=undefined -fno-omit-frame-pointer -no-pie")
else()
set(SANITIZE "")
endif()
Expand Down
2 changes: 2 additions & 0 deletions ext/common/common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ set(PXCOMMON_SOURCES
${PXCOMMON_DIR}/psx_linear_allocator.c
${PXCOMMON_DIR}/psx_file.h
${PXCOMMON_DIR}/psx_file.c
${PXCOMMON_DIR}/psx_common.h
${PXCOMMON_DIR}/psx_common.c
)

set(LIBX_COMMON psx_common)
Expand Down
57 changes: 57 additions & 0 deletions ext/common/psx_common.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright (c) 2025, Zhang Ji Peng
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include <picasso_ext.h>

#include "psx_common.h"

void psx_log(const char* format, ...)
{
va_list args;
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
}

const char* psx_result_get_string(psx_result result)
{
switch (result) {
case S_OK:
return "Ok";
case S_BAD_PARAMS:
return "Bad parameters";
case S_NOT_SUPPORT:
return "Not support";
case S_OUT_OF_MEMORY:
return "Out of memory";
case S_INIT_FAILURE:
return "Init failure";
case S_FAILURE:
return "Internal failure";
default:
return "Unknown";
}
}
22 changes: 13 additions & 9 deletions ext/common/psx_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
#include <stdbool.h>
#else
#if !defined(_MSC_VER)
typedef int bool;
#include <stddef.h>
typedef int32_t bool;
#define true 1;
#define false 0;
#endif
Expand Down Expand Up @@ -92,14 +93,6 @@
/* assert */
#define ASSERT(cond) assert((cond))

/* logs*/
static INLINE void psx_log(const char* format, ...)
{
va_list args;
va_start(args, format);
fprintf(stderr, format, args);
va_end(args);
}
#define LOG_ERROR(...) \
psx_log(__VA_ARGS__)

Expand All @@ -109,4 +102,15 @@ static INLINE void psx_log(const char* format, ...)
type(const type& o); \
type& operator=(const type& o); \

#ifdef __cplusplus
extern "C" {
#endif

/* logs*/
void psx_log(const char* format, ...);

#ifdef __cplusplus
}
#endif

#endif /*_PSX_COMMON_H_*/
2 changes: 1 addition & 1 deletion ext/image_coders/apple/apple.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ find_library(COREGRAPHICS_LIBRARY CoreGraphics)
find_library(COREFOUNDATION_LIBRARY CoreFoundation)
find_library(IMAGEIO_LIBRARY ImageIO)

target_link_libraries(${LIBX_CGIMAGE} PUBLIC ${COREGRAPHICS_LIBRARY} ${COREFOUNDATION_LIBRARY} ${IMAGEIO_LIBRARY})
target_link_libraries(${LIBX_CGIMAGE} PUBLIC ${COREGRAPHICS_LIBRARY} ${COREFOUNDATION_LIBRARY} ${IMAGEIO_LIBRARY} ${LIBX_COMMON})

set_target_properties(${LIBX_CGIMAGE}
PROPERTIES
Expand Down
40 changes: 20 additions & 20 deletions ext/image_coders/apple/images_module.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
void* writer_param;
};

static int read_image_info(const ps_byte* data, size_t len, psx_image_header* header)
static int32_t read_image_info(const ps_byte* data, size_t len, psx_image_header* header)
{
CFDataRef cg_data = CFDataCreate(kCFAllocatorDefault, data, len);
if (!cg_data) {
Expand All @@ -74,40 +74,40 @@ static int read_image_info(const ps_byte* data, size_t len, psx_image_header* he
return -1; // out of memory
}

int bpp = 4; // 4 bytes per pixel
int32_t bpp = 4; // 4 bytes per pixel
size_t width = CGImageGetWidth(image);
size_t height = CGImageGetHeight(image);
size_t rowbytes = width * bpp;

header->priv = ctx;
header->width = (int)width;
header->height = (int)height;
header->pitch = (int)rowbytes;
header->width = (int32_t)width;
header->height = (int32_t)height;
header->pitch = (int32_t)rowbytes;
header->depth = 32;
header->bpp = bpp;
header->format = 0;
header->alpha = 1;
header->frames = (int)CGImageSourceGetCount(ctx->source);
header->frames = (int32_t)CGImageSourceGetCount(ctx->source);

CGImageRelease(image);
CFRelease(cg_data);
return 0;
}

static int release_read_image_info(psx_image_header* header)
static int32_t release_read_image_info(psx_image_header* header)
{
struct cg_image_ctx* ctx = (struct cg_image_ctx*)header->priv;
CFRelease(ctx->source);
free(ctx);
return 0;
}

static int decode_image_data(psx_image_header* header, const psx_image* image, psx_image_frame* frame, int idx, ps_byte* buffer, size_t buffer_len)
static int32_t decode_image_data(psx_image_header* header, const psx_image* image, psx_image_frame* frame, int32_t idx, ps_byte* buffer, size_t buffer_len)
{
struct cg_image_ctx* ctx = (struct cg_image_ctx*)header->priv;

int width = header->width;
int height = header->height;
int32_t width = header->width;
int32_t height = header->height;

size_t bitsPerComponent = 8;
CGBitmapInfo cgInfo = kCGBitmapByteOrder32Big | kCGImageAlphaNoneSkipLast;
Expand All @@ -130,7 +130,7 @@ static int decode_image_data(psx_image_header* header, const psx_image* image, p
return 0;
}

static int get_bpp(ps_color_format fmt)
static int32_t get_bpp(ps_color_format fmt)
{
switch (fmt) {
case COLOR_FORMAT_RGBA:
Expand All @@ -149,7 +149,7 @@ static int get_bpp(ps_color_format fmt)
}
}

static int get_depth(ps_color_format fmt)
static int32_t get_depth(ps_color_format fmt)
{
switch (fmt) {
case COLOR_FORMAT_RGBA:
Expand Down Expand Up @@ -179,7 +179,7 @@ static size_t consumer_putbytes(void* info, const void* buffer, size_t count)
.putBytes = consumer_putbytes,
};

static int write_image_info(const psx_image* image, image_writer_fn func, void* param, float quality, psx_image_header* header)
static int32_t write_image_info(const psx_image* image, image_writer_fn func, void* param, float quality, psx_image_header* header)
{
struct cg_image_ctx* ctx = (struct cg_image_ctx*)calloc(1, sizeof(struct cg_image_ctx));
if (!ctx) {
Expand All @@ -197,22 +197,22 @@ static int write_image_info(const psx_image* image, image_writer_fn func, void*
header->pitch = image->pitch;
header->depth = get_depth(image->format);
header->bpp = get_bpp(image->format);
header->format = (int)image->format;
header->format = (int32_t)image->format;
header->alpha = 1;
header->frames = 1;
return 0;
}

static int release_write_image_info(psx_image_header* header)
static int32_t release_write_image_info(psx_image_header* header)
{
struct cg_image_ctx* ctx = (struct cg_image_ctx*)header->priv;
CGDataConsumerRelease(ctx->consumer);
free(ctx);
return 0;
}

static int encode_image_data(psx_image_header* header, const psx_image* image, psx_image_frame* frame,
int idx, const ps_byte* buffer, size_t buffer_len, int* ret)
static int32_t encode_image_data(psx_image_header* header, const psx_image* image, psx_image_frame* frame,
int32_t idx, const ps_byte* buffer, size_t buffer_len, int32_t* ret)
{
struct cg_image_ctx* ctx = (struct cg_image_ctx*)header->priv;

Expand Down Expand Up @@ -251,8 +251,8 @@ static int encode_image_data(psx_image_header* header, const psx_image* image, p
static psx_image_operator * cg_coder = NULL;
static module_handle lib_image = INVALID_HANDLE;

typedef int (*register_func)(const char*, const ps_byte*, size_t, size_t, psx_priority_level, psx_image_operator*);
typedef int (*unregister_func)(psx_image_operator*);
typedef int32_t (*register_func)(const char*, const ps_byte*, size_t, size_t, psx_priority_level, psx_image_operator*);
typedef int32_t (*unregister_func)(psx_image_operator*);

void psx_image_module_init(void)
{
Expand Down Expand Up @@ -303,7 +303,7 @@ void psx_image_module_shutdown(void)
_module_unload(lib_image);
}

const char* psx_image_module_get_string(int idx)
const char* psx_image_module_get_string(int32_t idx)
{
switch (idx) {
case MODULE_NAME:
Expand Down
4 changes: 2 additions & 2 deletions ext/image_coders/gif/gif.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ set(LIBX_GIF psxm_image_gif)
add_definitions(-DEXPORT)
add_library(${LIBX_GIF} ${PXGIF_SOURCES})
if(OPT_SYSTEM_GIF AND GIF)
target_link_libraries(${LIBX_GIF} PRIVATE ${GIF})
target_link_libraries(${LIBX_GIF} PRIVATE ${GIF} ${LIBX_COMMON})
else()
target_link_libraries(${LIBX_GIF} PRIVATE gif)
target_link_libraries(${LIBX_GIF} PRIVATE gif ${LIBX_COMMON})
endif()
install(TARGETS ${LIBX_GIF} LIBRARY DESTINATION lib/modules ARCHIVE DESTINATION lib/modules)

Expand Down
Loading
Loading