Skip to content

Commit

Permalink
Merge pull request #29 from francois-random/cmake+orientation+fix_mem…
Browse files Browse the repository at this point in the history
…leak

add cmake as build system + add epeg_set/get_orientation + fix memleak in epeg_close
  • Loading branch information
mattes authored Mar 31, 2023
2 parents 8efd57d + 60a89de commit 37fe52b
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 1 deletion.
89 changes: 89 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
cmake_minimum_required(VERSION 3.0)

project(libepeg)
set (VERSION "0.9.2")

option(BUILD_STATIC_LIB "Build static library" ON)
option(BUILD_SHARED_LIB "Build shared library" ON)


# Build configuration
################################################################################

set(CMAKE_POSITION_INDEPENDENT_CODE ON)


# Platform specific build configuration
################################################################################

if(MSVC)
message(STATUS "Building for windows")
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
endif()


# Source files
################################################################################


file(GLOB_RECURSE libepeg_SRC src/lib/*.c)
list(SORT libepeg_SRC)


set(libepeg_HEADER src/lib/Epeg.h)

include(CheckIncludeFile)

if(DEFINED JPEG_INCLUDE_DIRECTORY)
include_directories(BEFORE SYSTEM "${JPEG_INCLUDE_DIRECTORY}")
list(APPEND CMAKE_REQUIRED_INCLUDES ${JPEG_INCLUDE_DIRECTORY})
endif()

if(DEFINED EXIF_INCLUDE_DIRECTORY)
include_directories(BEFORE SYSTEM "${EXIF_INCLUDE_DIRECTORY}")
list(APPEND CMAKE_REQUIRED_INCLUDES ${EXIF_INCLUDE_DIRECTORY})
endif()

CHECK_INCLUDE_FILE(jerror.h HAS_LIBJPEG)
if(NOT HAS_LIBJPEG)
message(FATAL_ERROR "Error: jerror.h not found, you must first install libjpeg or specify JPEG_INCLUDE_DIRECTORY!")
endif()


CHECK_INCLUDE_FILE(libexif/exif-data.h HAS_LIBEXIF)
if(NOT HAS_LIBEXIF)
message(FATAL_ERROR "Error: libexif/exif-data.h not found, you must first install libexif or specify EXIF_INCLUDE_DIRECTORY!")
endif()

# Build
################################################################################

# Build library
if (BUILD_SHARED_LIB)
message("* Building shared library")
add_library(epeg_shared SHARED ${libepeg_SRC})
target_link_libraries(epeg_shared ${EXTRA_LIBS})
set_target_properties(epeg_shared PROPERTIES OUTPUT_NAME epeg)
endif()

if (BUILD_STATIC_LIB)
message("* Building static library")
add_library(epeg_static STATIC ${libepeg_SRC})
target_link_libraries(epeg_static ${EXTRA_LIBS})
set_target_properties(epeg_static PROPERTIES OUTPUT_NAME epeg)
endif()

if (NOT EXISTS src/lib/config.h)
file(WRITE src/lib/config.h "")
endif()


if (BUILD_SHARED_LIB)
install(TARGETS epeg_shared DESTINATION lib)
endif()
if (BUILD_STATIC_LIB)
install(TARGETS epeg_static DESTINATION lib)
endif()

install(FILES ${libepeg_HEADER} DESTINATION include)

2 changes: 2 additions & 0 deletions src/lib/Epeg.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ extern "C" {
EAPI Epeg_Image *epeg_memory_open (unsigned char *data, int size);
EAPI void epeg_size_get (Epeg_Image *im, int *w, int *h);
EAPI void epeg_decode_size_set (Epeg_Image *im, int w, int h);
EAPI void epeg_orientation_get (Epeg_Image *im, int *orientation);
EAPI void epeg_orientation_set (Epeg_Image *im, int orientation);
EAPI void epeg_colorspace_get (Epeg_Image *im, int *space);
EAPI void epeg_decode_colorspace_set (Epeg_Image *im, Epeg_Colorspace colorspace);
EAPI const void *epeg_pixels_get (Epeg_Image *im, int x, int y, int w, int h);
Expand Down
31 changes: 30 additions & 1 deletion src/lib/epeg_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,35 @@ epeg_size_get(Epeg_Image *im, int *w, int *h)
if (h) *h = im->in.h;
}

/**
* Return the original JPEG orientation.
* @param im A handle to an opened Epeg image.
* @param orientation A pointer to the orientation value to be filled in.
*
* Returns the image orientation.
*
*/

EAPI void
epeg_orientation_get(Epeg_Image *im, int *orientation)
{
if (orientation) *orientation = im->in.orientation;
}

/**
* Sets the image orientation.
* @param im A handle to an opened Epeg image.
* @param orientation The orientation value to set.
*
*
*/

EAPI void
epeg_orientation_set(Epeg_Image *im, int orientation)
{
im->in.orientation = orientation;
}

/**
* Return the original JPEG pixel color space.
* @param im A handle to an opened Epeg image.
Expand Down Expand Up @@ -771,7 +800,7 @@ epeg_close(Epeg_Image *im)
if (im->in.thumb_info.mime) free(im->in.thumb_info.mime);
if (im->out.file) free(im->out.file);
if (!im->out.file) free(im->out.jinfo.dest);
if (im->out.f || im->in.mem.data) jpeg_destroy_compress(&(im->out.jinfo));
if (im->out.f || im->out.mem.data) jpeg_destroy_compress(&(im->out.jinfo));
if (im->out.f) fclose(im->out.f);
if (im->out.comment) free(im->out.comment);
free(im);
Expand Down

0 comments on commit 37fe52b

Please sign in to comment.