(#7202) giflib: modernize + install binaries

* giflib: modernize + install binaries

* gitlib: reformat test_package.c

* giflib: add BUNDLE for iOS

Co-authored-by: SpaceIm <30052553+SpaceIm@users.noreply.github.com>

* giflib: set explicit libs in `package_info`

Co-authored-by: SpaceIm <30052553+SpaceIm@users.noreply.github.com>

* giflib: add getopt-for-visual-studio build requirement

Co-authored-by: SpaceIm <30052553+SpaceIm@users.noreply.github.com>
This commit is contained in:
Anonymous Maarten
2021-09-08 23:03:50 +02:00
committed by GitHub
parent 1a2c069a9a
commit 3756b45297
5 changed files with 129 additions and 79 deletions

View File

@@ -19,9 +19,38 @@ if(NOT BUILD_SHARED_LIBS)
endif()
add_library(${PROJECT_NAME} ${SOURCE_FILES})
if(WIN32 AND BUILD_SHARED_LIBS)
set_property(TARGET ${PROJECT_NAME} PROPERTY PREFIX "")
endif()
install(TARGETS ${PROJECT_NAME}
set(GIF_UTILS
gif2rgb
gifbuild
giffix
giftext
giftool
gifclrmp
)
add_library(giflib_util STATIC
"source_subfolder/qprintf.c"
"source_subfolder/quantize.c"
"source_subfolder/getarg.c"
)
target_link_libraries(giflib_util PRIVATE ${PROJECT_NAME})
foreach(GIF_UTIL ${GIF_UTILS})
add_executable(${GIF_UTIL} "source_subfolder/${GIF_UTIL}.c")
target_link_libraries(${GIF_UTIL} PRIVATE ${PROJECT_NAME} giflib_util)
endforeach()
find_library(M_LIBRARY NAMES m)
if(M_LIBRARY)
target_link_libraries(gifclrmp PRIVATE ${M_LIBRARY})
endif()
install(TARGETS ${PROJECT_NAME} ${GIF_UTILS}
ARCHIVE DESTINATION "lib"
LIBRARY DESTINATION "lib"
RUNTIME DESTINATION "bin")
RUNTIME DESTINATION "bin"
BUNDLE DESTINATION "bin")
install(FILES "source_subfolder/gif_lib.h" DESTINATION "include")

View File

@@ -1,18 +1,27 @@
from conans import CMake, ConanFile, tools
from conans.errors import ConanInvalidConfiguration
import os
required_conan_version = ">=1.33.0"
class GiflibConan(ConanFile):
name = "giflib"
description = "A library and utilities for reading and writing GIF images."
url = "https://github.com/conan-io/conan-center-index"
license = "MIT"
homepage = "http://giflib.sourceforge.net"
topics = ("conan", "giflib", "image", "multimedia", "format", "graphics")
topics = ("giflib", "image", "multimedia", "format", "graphics")
settings = "os", "arch", "compiler", "build_type"
options = {"shared": [True, False], "fPIC": [True, False]}
default_options = {"shared": False, "fPIC": True}
exports_sources = ["CMakeLists.txt", "patches/*"]
options = {
"shared": [True, False],
"fPIC": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
}
exports_sources = "CMakeLists.txt", "patches/*"
generators = "cmake"
_cmake = None
@@ -31,16 +40,18 @@ class GiflibConan(ConanFile):
del self.settings.compiler.libcxx
del self.settings.compiler.cppstd
def requirements(self):
if self.settings.compiler == "Visual Studio":
self.requires("getopt-for-visual-studio/20200201")
def source(self):
tools.get(**self.conan_data["sources"][self.version])
os.rename("%s-%s" % (self.name, self.version), self._source_subfolder)
tools.get(**self.conan_data["sources"][self.version],
destination=self._source_subfolder, strip_root=True)
def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.configure()
return self._cmake
@@ -50,19 +61,21 @@ class GiflibConan(ConanFile):
def build(self):
self._patch_sources()
cmake = self._configure_cmake()
cmake.build()
def package(self):
self.copy("COPYING", src=self._source_subfolder, dst="licenses")
cmake = self._configure_cmake()
cmake.install()
self.copy("COPYING", src=self._source_subfolder, dst="licenses")
def package_info(self):
self.cpp_info.names["cmake_find_package"] = "GIF"
self.cpp_info.names["cmake_find_package_multi"] = "GIF"
self.cpp_info.libs = tools.collect_libs(self)
self.cpp_info.libs = ["gif"]
if self.settings.compiler == "Visual Studio":
self.cpp_info.defines.append("USE_GIF_DLL" if self.options.shared else "USE_GIF_LIB")
bin_path = os.path.join(self.package_folder, "bin")
self.output.info("Appending PATH environment variable: {}".format(bin_path))
self.env_info.PATH.append(bin_path)

View File

@@ -1,8 +1,10 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)
project(test_package C)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
conan_basic_setup(TARGETS)
find_package(GIF REQUIRED CONFIG)
add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
target_link_libraries(${PROJECT_NAME} PRIVATE GIF::GIF)

View File

@@ -1,9 +1,10 @@
from conans import ConanFile, CMake, tools
import os
class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"
generators = "cmake", "cmake_find_package_multi"
def build(self):
cmake = CMake(self)
@@ -11,7 +12,9 @@ class TestPackageConan(ConanFile):
cmake.build()
def test(self):
if not tools.cross_building(self.settings):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
command = "%s testimg.gif" % bin_path
self.run(command, run_environment=True)
self.run("{} testimg.gif".format(bin_path), run_environment=True)
assert os.path.isfile("testimg.gif")
self.run("gif2rgb -o testimg.rgb testimg.gif".format(bin_path), run_environment=True)
assert os.path.isfile("testimg.rgb.R")

View File

@@ -1,92 +1,96 @@
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include "gif_lib.h"
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define LINE_LEN 40
#define IMAGEWIDTH LINE_LEN*GIF_FONT_WIDTH
#define LINE_LEN 40
#define IMAGEWIDTH LINE_LEN*GIF_FONT_WIDTH
static int BackGround = 0;
static void QuitGifError(GifFileType *GifFile);
static void GenRasterTextLine(GifRowType *RasterBuffer, char *TextLine,
int BufferWidth, int ForeGroundIndex);
int BufferWidth, int ForeGroundIndex);
/******************************************************************************
Interpret the command line and generate the given GIF file.
******************************************************************************/
int main(int argc, char **argv)
{
int i, j, l, ColorMapSize, ErrorCode;
int i, j, l, ColorMapSize, ErrorCode;
char Line[LINE_LEN];
GifRowType RasterBuffer[GIF_FONT_HEIGHT];
ColorMapObject *ColorMap;
GifFileType *GifFile;
GifColorType ScratchMap[256];
GifColorType ScratchMap[256];
if (argc < 2) {
fprintf(stderr, "Usage: %s OUTPUTGIF\n", argv[0]);
exit(1);
}
/* Allocate the raster buffer for GIF_FONT_HEIGHT scan lines. */
for (i = 0; i < GIF_FONT_HEIGHT; i++)
{
if ((RasterBuffer[i] = (GifRowType) malloc(sizeof(GifPixelType) *
IMAGEWIDTH)) == NULL)
exit(1);
if ((RasterBuffer[i] = (GifRowType) malloc(sizeof(GifPixelType) * IMAGEWIDTH)) == NULL)
exit(1);
}
/* Open stdout for the output file: */
if ((GifFile = EGifOpenFileName("out.gif", 0, &ErrorCode)) == NULL) {
printf("error: %d\n", ErrorCode);
exit(EXIT_FAILURE);
if ((GifFile = EGifOpenFileName(argv[1], 0, &ErrorCode)) == NULL) {
printf("error: %d\n", ErrorCode);
exit(EXIT_FAILURE);
}
/* Read the color map in ColorFile into this color map: */
for (ColorMapSize = 0; ColorMapSize < 256; ColorMapSize++)
{
ScratchMap[ColorMapSize].Red = ColorMapSize;
ScratchMap[ColorMapSize].Green = ColorMapSize;
ScratchMap[ColorMapSize].Blue = ColorMapSize;
ScratchMap[ColorMapSize].Green = ColorMapSize;
ScratchMap[ColorMapSize].Blue = ColorMapSize;
}
if ((ColorMap = GifMakeMapObject(1 << GifBitSize(ColorMapSize), ScratchMap)) == NULL)
exit(1);
exit(1);
if (EGifPutScreenDesc(GifFile,
IMAGEWIDTH, ColorMapSize * GIF_FONT_HEIGHT,
GifBitSize(ColorMapSize),
BackGround, ColorMap) == GIF_ERROR)
QuitGifError(GifFile);
IMAGEWIDTH, ColorMapSize * GIF_FONT_HEIGHT,
GifBitSize(ColorMapSize),
BackGround, ColorMap) == GIF_ERROR)
QuitGifError(GifFile);
/* Dump out the image descriptor: */
if (EGifPutImageDesc(GifFile,
0, 0, IMAGEWIDTH, ColorMapSize * GIF_FONT_HEIGHT, false, NULL) == GIF_ERROR)
QuitGifError(GifFile);
0, 0, IMAGEWIDTH, ColorMapSize * GIF_FONT_HEIGHT, false, NULL) == GIF_ERROR)
QuitGifError(GifFile);
printf("\n%s: Image 1 at (%d, %d) [%dx%d]: \n",
"test_package", GifFile->Image.Left, GifFile->Image.Top,
GifFile->Image.Width, GifFile->Image.Height);
"test_package", GifFile->Image.Left, GifFile->Image.Top,
GifFile->Image.Width, GifFile->Image.Height);
for (i = l = 0; i < ColorMap->ColorCount; i++) {
(void)snprintf(Line, sizeof(Line),
"Color %-3d: [%-3d, %-3d, %-3d] ", i,
ColorMap->Colors[i].Red,
ColorMap->Colors[i].Green,
ColorMap->Colors[i].Blue);
GenRasterTextLine(RasterBuffer, Line, IMAGEWIDTH, i);
for (j = 0; j < GIF_FONT_HEIGHT; j++) {
if (EGifPutLine(GifFile, RasterBuffer[j], IMAGEWIDTH) == GIF_ERROR)
QuitGifError(GifFile);
printf("\b\b\b\b%-4d", l++);
}
for (i = l = 0; i < ColorMap->ColorCount; i++)
{
(void)snprintf(Line, sizeof(Line),
"Color %-3d: [%-3d, %-3d, %-3d] ", i,
ColorMap->Colors[i].Red,
ColorMap->Colors[i].Green,
ColorMap->Colors[i].Blue);
GenRasterTextLine(RasterBuffer, Line, IMAGEWIDTH, i);
for (j = 0; j < GIF_FONT_HEIGHT; j++)
{
if (EGifPutLine(GifFile, RasterBuffer[j], IMAGEWIDTH) == GIF_ERROR)
QuitGifError(GifFile);
printf("\b\b\b\b%-4d", l++);
}
}
if (EGifCloseFile(GifFile, &ErrorCode) == GIF_ERROR)
{
if (EGifCloseFile(GifFile, &ErrorCode) == GIF_ERROR) {
printf("error: %d\n", ErrorCode);
if (GifFile != NULL) {
EGifCloseFile(GifFile, NULL);
}
exit(EXIT_FAILURE);
if (GifFile != NULL) {
EGifCloseFile(GifFile, NULL);
}
exit(EXIT_FAILURE);
}
return 0;
@@ -96,23 +100,24 @@ int main(int argc, char **argv)
Close output file (if open), and exit.
******************************************************************************/
static void GenRasterTextLine(GifRowType *RasterBuffer, char *TextLine,
int BufferWidth, int ForeGroundIndex)
int BufferWidth, int ForeGroundIndex)
{
unsigned char c;
unsigned char Byte, Mask;
int i, j, k, CharPosX, Len = (int)strlen(TextLine);
for (i = 0; i < BufferWidth; i++)
for (j = 0; j < GIF_FONT_HEIGHT; j++) RasterBuffer[j][i] = BackGround;
for (j = 0; j < GIF_FONT_HEIGHT; j++)
RasterBuffer[j][i] = BackGround;
for (i = CharPosX = 0; i < Len; i++, CharPosX += GIF_FONT_WIDTH) {
c = TextLine[i];
for (j = 0; j < GIF_FONT_HEIGHT; j++) {
Byte = GifAsciiTable8x8[(unsigned short)c][j];
for (k = 0, Mask = 128; k < GIF_FONT_WIDTH; k++, Mask >>= 1)
if (Byte & Mask)
RasterBuffer[j][CharPosX + k] = ForeGroundIndex;
}
c = TextLine[i];
for (j = 0; j < GIF_FONT_HEIGHT; j++) {
Byte = GifAsciiTable8x8[(unsigned short)c][j];
for (k = 0, Mask = 128; k < GIF_FONT_WIDTH; k++, Mask >>= 1)
if (Byte & Mask)
RasterBuffer[j][CharPosX + k] = ForeGroundIndex;
}
}
}
@@ -123,9 +128,7 @@ static void QuitGifError(GifFileType *GifFile)
{
if (GifFile != NULL) {
printf("error: %d\n", GifFile->Error);
EGifCloseFile(GifFile, NULL);
EGifCloseFile(GifFile, NULL);
}
exit(EXIT_FAILURE);
}
/* vim: ts=8 sw=8 et */