mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-23 15:52:55 +01:00
Merge pull request #2798 from janisozaur/lodepng-cleanup
Cleanup unused lodepng stuff
This commit is contained in:
@@ -26,7 +26,6 @@ project(${PROJECT})
|
||||
add_definitions(-DORCT2_RESOURCE_DIR="${ORCT2_RESOURCE_DIR}")
|
||||
add_definitions(-DHAVE_CONFIG_H)
|
||||
add_definitions(-DCURL_STATICLIB)
|
||||
add_definitions(-DUSE_LIBPNG)
|
||||
|
||||
INCLUDE(FindPkgConfig)
|
||||
|
||||
|
||||
@@ -1513,7 +1513,6 @@
|
||||
GCC_OPTIMIZATION_LEVEL = 0;
|
||||
GCC_PREPROCESSOR_DEFINITIONS = (
|
||||
"DEBUG=1",
|
||||
USE_LIBPNG,
|
||||
);
|
||||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
|
||||
@@ -1556,7 +1555,6 @@
|
||||
GCC_C_LANGUAGE_STANDARD = gnu99;
|
||||
GCC_DYNAMIC_NO_PIC = NO;
|
||||
GCC_NO_COMMON_BLOCKS = YES;
|
||||
GCC_PREPROCESSOR_DEFINITIONS = USE_LIBPNG;
|
||||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
|
||||
GCC_WARN_FOUR_CHARACTER_CONSTANTS = YES;
|
||||
|
||||
@@ -147,7 +147,6 @@ OpenRCT2 is licensed under the GNU General Public Licence version 3.0. For
|
||||
the complete licence text, see the file 'licence.txt'. This licence applies
|
||||
to all files in this distribution, except as noted below.
|
||||
|
||||
argparse | MIT licence.
|
||||
Jansson | MIT licence.
|
||||
libcURL | MIT (or Modified BSD-style) licence.
|
||||
libspeex | BSD-style license.
|
||||
|
||||
@@ -338,7 +338,7 @@
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<StructMemberAlignment>1Byte</StructMemberAlignment>
|
||||
<PreprocessorDefinitions>$(OpenRCT2_DEFINES);DEBUG;USE_LIBPNG;_CRT_SECURE_NO_WARNINGS;_USE_MATH_DEFINES;CURL_STATICLIB;SDL_MAIN_HANDLED;_WINSOCK_DEPRECATED_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>$(OpenRCT2_DEFINES);DEBUG;_CRT_SECURE_NO_WARNINGS;_USE_MATH_DEFINES;CURL_STATICLIB;SDL_MAIN_HANDLED;_WINSOCK_DEPRECATED_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
<ObjectFileName>$(IntDir)\%(RelativeDir)</ObjectFileName>
|
||||
@@ -364,7 +364,7 @@
|
||||
<TreatSpecificWarningsAsErrors>4013</TreatSpecificWarningsAsErrors>
|
||||
<OmitFramePointers />
|
||||
<BufferSecurityCheck>false</BufferSecurityCheck>
|
||||
<PreprocessorDefinitions>$(OpenRCT2_DEFINES);USE_LIBPNG;_CRT_SECURE_NO_WARNINGS;_USE_MATH_DEFINES;CURL_STATICLIB;SDL_MAIN_HANDLED;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>$(OpenRCT2_DEFINES);_CRT_SECURE_NO_WARNINGS;_USE_MATH_DEFINES;CURL_STATICLIB;SDL_MAIN_HANDLED;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ObjectFileName>$(IntDir)\%(RelativeDir)</ObjectFileName>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
|
||||
@@ -379,4 +379,4 @@
|
||||
</ItemDefinitionGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets" />
|
||||
</Project>
|
||||
</Project>
|
||||
|
||||
@@ -1,20 +1,13 @@
|
||||
#ifdef USE_LIBPNG
|
||||
#include <png.h>
|
||||
#else
|
||||
#include <lodepng/lodepng.h>
|
||||
#endif
|
||||
#include <png.h>
|
||||
|
||||
#include "image_io.h"
|
||||
|
||||
#ifdef USE_LIBPNG
|
||||
static void my_png_read_data(png_structp png_ptr, png_bytep data, png_size_t length);
|
||||
static void my_png_write_data(png_structp png_ptr, png_bytep data, png_size_t length);
|
||||
static void my_png_flush(png_structp png_ptr);
|
||||
#endif
|
||||
static void my_png_read_data(png_structp png_ptr, png_bytep data, png_size_t length);
|
||||
static void my_png_write_data(png_structp png_ptr, png_bytep data, png_size_t length);
|
||||
static void my_png_flush(png_structp png_ptr);
|
||||
|
||||
bool image_io_png_read(uint8 **pixels, uint32 *width, uint32 *height, const utf8 *path)
|
||||
{
|
||||
#ifdef USE_LIBPNG
|
||||
png_structp png_ptr;
|
||||
png_infop info_ptr;
|
||||
unsigned int sig_read = 0;
|
||||
@@ -91,28 +84,10 @@ bool image_io_png_read(uint8 **pixels, uint32 *width, uint32 *height, const utf8
|
||||
if (width != NULL) *width = pngWidth;
|
||||
if (height != NULL) *height = pngHeight;
|
||||
return true;
|
||||
#else
|
||||
// Read the pixels as 32bpp RGBA
|
||||
unsigned char *pngPixels;
|
||||
unsigned int pngWidth, pngHeight;
|
||||
unsigned int pngError = lodepng_decode_file(&pngPixels, &pngWidth, &pngHeight, path, LCT_RGBA, 8);
|
||||
if (pngError != 0) {
|
||||
free(pngPixels);
|
||||
log_error("Error creating PNG data, %u: %s", pngError, lodepng_error_text(pngError));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Return the output data
|
||||
*pixels = (uint8*)pngPixels;
|
||||
if (width != NULL) *width = pngWidth;
|
||||
if (height != NULL) *height = pngHeight;
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool image_io_png_write(const rct_drawpixelinfo *dpi, const rct_palette *palette, const utf8 *path)
|
||||
{
|
||||
#ifdef USE_LIBPNG
|
||||
// Get image size
|
||||
int stride = dpi->width + dpi->pitch;
|
||||
|
||||
@@ -178,50 +153,8 @@ bool image_io_png_write(const rct_drawpixelinfo *dpi, const rct_palette *palette
|
||||
png_free(png_ptr, png_palette);
|
||||
png_destroy_write_struct(&png_ptr, &info_ptr);
|
||||
return true;
|
||||
#else
|
||||
unsigned int error;
|
||||
unsigned char* png;
|
||||
size_t pngSize;
|
||||
LodePNGState state;
|
||||
|
||||
lodepng_state_init(&state);
|
||||
state.info_raw.colortype = LCT_PALETTE;
|
||||
|
||||
// Get image size
|
||||
int stride = dpi->width + dpi->pitch;
|
||||
|
||||
lodepng_palette_add(&state.info_raw, 0, 0, 0, 0);
|
||||
for (int i = 1; i < 256; i++) {
|
||||
const rct_palette_entry *entry = &palette->entries[i];
|
||||
uint8 r = entry->red;
|
||||
uint8 g = entry->green;
|
||||
uint8 b = entry->blue;
|
||||
uint8 a = 255;
|
||||
lodepng_palette_add(&state.info_raw, r, g, b, a);
|
||||
}
|
||||
|
||||
error = lodepng_encode(&png, &pngSize, dpi->bits, stride, dpi->height, &state);
|
||||
if (error != 0) {
|
||||
log_error("Error creating PNG data, %u: %s", error, lodepng_error_text(error));
|
||||
free(png);
|
||||
return false;
|
||||
} else {
|
||||
SDL_RWops *file = SDL_RWFromFile(path, "wb");
|
||||
if (file == NULL) {
|
||||
free(png);
|
||||
return false;
|
||||
}
|
||||
SDL_RWwrite(file, png, pngSize, 1);
|
||||
SDL_RWclose(file);
|
||||
}
|
||||
|
||||
free(png);
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef USE_LIBPNG
|
||||
|
||||
static void my_png_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
{
|
||||
SDL_RWops *file = (SDL_RWops*)png_get_io_ptr(png_ptr);
|
||||
@@ -239,8 +172,6 @@ static void my_png_flush(png_structp png_ptr)
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// Bitmap header structs, for cross platform purposes
|
||||
typedef struct {
|
||||
uint16 bfType;
|
||||
|
||||
Reference in New Issue
Block a user