Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/WolfireGames/overgrowth.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authorStephan Vedder <vedder@mbits.info>2022-05-03 18:17:10 +0300
committerStephan Vedder <vedder@mbits.info>2022-05-10 11:45:00 +0300
commitd4aa66bfffad9b0dee5dc6d48acb52f6cd80c1ff (patch)
tree41561e258bea45002655c08c79d17af85010d169 /Source
parent85b70abbf01b4a41d6e72d3c442744632f10bdb7 (diff)
Replace freeimage
Diffstat (limited to 'Source')
-rw-r--r--Source/Asset/Asset/image_sampler.cpp30
-rw-r--r--Source/Asset/Asset/image_sampler.h3
-rw-r--r--Source/Compat/platformsetup.cpp5
-rw-r--r--Source/Graphics/converttexture.cpp2
-rw-r--r--Source/Graphics/heightmap.cpp43
-rw-r--r--Source/Graphics/textures.cpp2
-rw-r--r--Source/Images/freeimage_wrapper.cpp252
-rw-r--r--Source/Images/freeimage_wrapper.h129
-rw-r--r--Source/Images/image_export.cpp46
-rw-r--r--Source/Images/stbimage_wrapper.cpp28
-rw-r--r--Source/Images/stbimage_wrapper.h28
-rw-r--r--Source/Images/texture_data.cpp2
-rw-r--r--Source/Internal/datemodified.cpp4
-rw-r--r--Source/Main/engine.cpp16
-rw-r--r--Source/Objects/object.h2
-rw-r--r--Source/Ogda/Builders/crunchaction.cpp2
-rw-r--r--Source/Ogda/Builders/dxt5action.cpp2
17 files changed, 110 insertions, 486 deletions
diff --git a/Source/Asset/Asset/image_sampler.cpp b/Source/Asset/Asset/image_sampler.cpp
index 473ce7c3..08579fba 100644
--- a/Source/Asset/Asset/image_sampler.cpp
+++ b/Source/Asset/Asset/image_sampler.cpp
@@ -87,22 +87,6 @@ ImageSampler::byte4 ImageSampler::GetPixel(int x, int y) const {
return pixels_[x * height_ + y];
}
-void ImageSampler::LoadDataFromFIBitmap(FIBITMAP* image) {
- width_ = getWidth(image);
- height_ = getHeight(image);
- pixels_.resize(width_ * height_);
- for (int i = 0; i < width_; ++i) {
- for (int j = 0; j < height_; ++j) {
- FIquad val;
- getPixelColor(image, i, j, &val);
- pixels_[i * height_ + j][0] = val.rgbRed;
- pixels_[i * height_ + j][1] = val.rgbGreen;
- pixels_[i * height_ + j][2] = val.rgbBlue;
- pixels_[i * height_ + j][3] = val.rgbReserved;
- }
- }
-}
-
int ImageSampler::Load(const std::string& path, uint32_t load_flags) {
std::string load_path;
ModID cache_modsource;
@@ -128,14 +112,20 @@ int ImageSampler::Load(const std::string& path, uint32_t load_flags) {
FatalError("Error", "Could not find image sampler file \"%s\"", path_.c_str());
}
*/
- FIBITMAP* fibitmap = GenericLoader(abs_path);
- if (!fibitmap) {
+ int n = 0;
+ // Tell stb_image that we want 4 components (RGBA)
+ stbi_uc* data = stbi_load(abs_path, &width_, &width_, &n, 4);
+
+ if (data == nullptr || n != 4) {
return kLoadErrorGeneralFileError;
}
- LoadDataFromFIBitmap(fibitmap);
- UnloadBitmap(fibitmap);
+ pixels_.resize(width_ * height_);
+ std::memcpy(pixels_.data(), data, width_ * height_ * 4);
+
+ stbi_image_free(data);
+
char write_path[kPathSize];
FormatString(write_path, kPathSize, "%s%s%s", GetWritePath(modsource).c_str(), path.c_str(), suffix);
modsource_ = modsource;
diff --git a/Source/Asset/Asset/image_sampler.h b/Source/Asset/Asset/image_sampler.h
index 11da7ebd..ccdc2c44 100644
--- a/Source/Asset/Asset/image_sampler.h
+++ b/Source/Asset/Asset/image_sampler.h
@@ -31,7 +31,7 @@
#include <Asset/assets.h>
#include <Math/vec4.h>
-#include <Images/freeimage_wrapper.h>
+#include <Images/stbimage_wrapper.h>
#include <vector>
@@ -67,7 +67,6 @@ class ImageSampler : public Asset {
static const int kImageSamplerCacheVersion = 2;
byte4 GetPixel(int x, int y) const;
- void LoadDataFromFIBitmap(FIBITMAP* image);
vec4 GetInterpolatedColor(float x, float y) const;
bool ReadCacheFile(const std::string& path, uint16_t checksum);
void WriteCacheFile(const std::string& path);
diff --git a/Source/Compat/platformsetup.cpp b/Source/Compat/platformsetup.cpp
index ed8b1bcd..df5a6926 100644
--- a/Source/Compat/platformsetup.cpp
+++ b/Source/Compat/platformsetup.cpp
@@ -82,7 +82,6 @@ void SetUpEnvironment(char* program_path, const char* overloaded_write_dir, cons
AddPath(write_dir, kWriteDir);
}
- FreeImage_Initialise();
#elif defined(_WIN32)
std::string cwd;
if (strlen(overloaded_working_dir) > 0) {
@@ -166,9 +165,7 @@ void SetUpEnvironment(char* program_path, const char* overloaded_write_dir, cons
}
void DisposeEnvironment() {
-#if PLATFORM_UNIX
- FreeImage_DeInitialise();
-#elif defined(_WIN32)
+#if defined(_WIN32)
FreeConsole();
#endif
}
diff --git a/Source/Graphics/converttexture.cpp b/Source/Graphics/converttexture.cpp
index dfd5ea60..62992aa0 100644
--- a/Source/Graphics/converttexture.cpp
+++ b/Source/Graphics/converttexture.cpp
@@ -32,7 +32,7 @@
#include <Compat/fileio.h>
#include <Compat/compat.h>
-#include <Images/freeimage_wrapper.h>
+#include <Images/stbimage_wrapper.h>
#include <Logging/logdata.h>
#include <cstring>
diff --git a/Source/Graphics/heightmap.cpp b/Source/Graphics/heightmap.cpp
index 58e6c4d4..e4119265 100644
--- a/Source/Graphics/heightmap.cpp
+++ b/Source/Graphics/heightmap.cpp
@@ -31,7 +31,7 @@
#include <Internal/filesystem.h>
#include <Compat/fileio.h>
-#include <Images/freeimage_wrapper.h>
+#include <Images/stbimage_wrapper.h>
bool HeightmapImage::ReadCacheFile(const std::string& path, uint16_t checksum) {
FILE* file = my_fopen(path.c_str(), "rb");
@@ -91,51 +91,44 @@ bool HeightmapImage::LoadData(const std::string& rel_path, HMScale scaled) {
ModID modsource;
FindFilePath(rel_path.c_str(), abs_path, kPathSize, kDataPaths | kModPaths, true, NULL, &modsource);
modsource_ = modsource;
- FIBitmapContainer image_container(GenericLoader(abs_path, 0));
- FIBITMAP* image = image_container.get();
- // FreeImage_Save(FIF_TARGA, image, (file_name+".tga").c_str());
- if (image == NULL) {
+
+ // Tell stb_image that we want 4 components (RGBA)
+ int img_width = 0, img_height = 0, num_comp = 0;
+ float* data = stbi_loadf(abs_path, &img_width, &img_height, &num_comp, 0);
+
+ if (data == NULL) {
FatalError("Error", "Could not load heightmap: %s", rel_path.c_str());
} else {
- fiTYPE image_type = getImageType(image);
- int bytes_per_pixel = getBPP(image) / 8;
if (scaled) {
- width_ = kTerrainDimX; // FreeImage_GetWidth(image);
- depth_ = kTerrainDimY; // FreeImage_GetHeight(image);
+ width_ = kTerrainDimX;
+ depth_ = kTerrainDimY;
} else {
- width_ = getWidth(image);
- depth_ = getHeight(image);
+ width_ = img_width;
+ depth_ = img_height;
}
int heightDataSize = width_ * depth_;
- int imageDataSize = heightDataSize * bytes_per_pixel;
- if (0 < heightDataSize && 0 < imageDataSize) {
+ if (0 < heightDataSize) {
// ...allocate enough space for the height data...
height_data_.resize(heightDataSize, 0);
// m_flowData.resize(heightDataSize,vecf(2,0));
float scale_factor = kTerrainHeightScale;
- float x_scale = getWidth(image) / (float)width_;
- float z_scale = getHeight(image) / (float)depth_;
+ float x_scale = img_width / (float)width_;
+ float z_scale = img_height / (float)depth_;
- if (image_type == FIWT_UINT16) { // e.g. 16 bit PNGs
+ if (num_comp != 1) { // monochrome texture
for (int z = 0; z < depth_; z++) { // flipped
- unsigned short* bits = (unsigned short*)getScanLine(image, (int)(z * z_scale));
- for (int x = 0; x < width_; x++) {
- height_data_[x + (((depth_ - 1) - z) * width_)] = ((float)bits[(int)(x * x_scale)]) / scale_factor;
- }
- }
- } else if (image_type == FIWT_BITMAP) {
- for (int z = 0; z < depth_; z++) {
- uint8_t* bits = (uint8_t*)getScanLine(image, (int)(z * z_scale));
+ float* bits = &data[((int)(z * z_scale)) * img_height];
for (int x = 0; x < width_; x++) {
- height_data_[x + (((depth_ - 1) - z) * width_)] = ((float)bits[(int)(x * x_scale) * bytes_per_pixel]) / scale_factor * 256.0f;
+ height_data_[x + (((depth_ - 1) - z) * width_)] = (bits[(int)(x * x_scale)] * 65535.0f) / scale_factor;
}
}
} else {
FatalError("Error", "Heightmaps must be 16-bit grayscale PNGs.");
}
+ stbi_image_free(data);
char path[kPathSize];
FormatString(path, kPathSize, "%s%s%s", GetWritePath(modsource).c_str(), rel_path.c_str(), cache_suffix.c_str());
WriteCacheFile(path);
diff --git a/Source/Graphics/textures.cpp b/Source/Graphics/textures.cpp
index e639963b..d155efe9 100644
--- a/Source/Graphics/textures.cpp
+++ b/Source/Graphics/textures.cpp
@@ -50,7 +50,7 @@
#include <Internal/config.h>
#include <Images/texture_data.h>
-#include <Images/freeimage_wrapper.h>
+#include <Images/stbimage_wrapper.h>
#include <Images/image_export.hpp>
#include <Timing/timingevent.h>
diff --git a/Source/Images/freeimage_wrapper.cpp b/Source/Images/freeimage_wrapper.cpp
deleted file mode 100644
index 50e58890..00000000
--- a/Source/Images/freeimage_wrapper.cpp
+++ /dev/null
@@ -1,252 +0,0 @@
-//-----------------------------------------------------------------------------
-// Name: freeimage_wrapper.cpp
-// Developer: Wolfire Games LLC
-// Author: Phillip Isola
-// Description: Wraps up FreeImage library
-// License: Read below
-//-----------------------------------------------------------------------------
-//
-//
-// Copyright 2022 Wolfire Games LLC
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-//-----------------------------------------------------------------------------
-#include "freeimage_wrapper.h"
-
-#include <Compat/fileio.h>
-#include <Compat/compat.h>
-
-#include <Math/enginemath.h>
-#include <Internal/error.h>
-#include <Logging/logdata.h>
-#include <opengl.h>
-
-#include <crnlib.h>
-#include <dds_defs.h>
-#include <FreeImage.h>
-
-#include <cstring>
-#include <vector>
-
-using namespace crnlib;
-using std::string;
-
-// http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogDeBruijn
-static const uint32_t MultiplyDeBruijnBitPosition[32] =
- {
- 0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30,
- 8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31};
-
-static uint32_t uintLog2(uint32_t v) {
- v |= v >> 1; // first round down to one less than a power of 2
- v |= v >> 2;
- v |= v >> 4;
- v |= v >> 8;
- v |= v >> 16;
-
- return MultiplyDeBruijnBitPosition[(uint32_t)(v * 0x07C4ACDDU) >> 27];
-}
-
-vec3 getInterpolatedColorUV(FIBITMAP* image, float x, float y) {
- x = max(0.01f, min(0.99f, x));
- y = max(0.01f, min(0.99f, y));
- return getInterpolatedColor(image, x * FreeImage_GetWidth(image) + 0.5f, y * FreeImage_GetHeight(image) + 1.0f);
-}
-
-vec3 getInterpolatedColor(FIBITMAP* image, float x, float y) {
- RGBQUAD top_left, top_right, bottom_left, bottom_right;
- FreeImage_GetPixelColor(image,
- (unsigned int)x,
- (unsigned int)y,
- &top_left);
- FreeImage_GetPixelColor(image,
- (unsigned int)x + 1,
- (unsigned int)y,
- &top_right);
- FreeImage_GetPixelColor(image,
- (unsigned int)x,
- (unsigned int)y + 1,
- &bottom_left);
- FreeImage_GetPixelColor(image,
- (unsigned int)x + 1,
- (unsigned int)y + 1,
- &bottom_right);
-
- float x_weight = x - (int)x;
- float y_weight = y - (int)y;
-
- RGBQUAD left;
- left.rgbRed = (BYTE)(top_left.rgbRed * (1 - y_weight) + bottom_left.rgbRed * (y_weight));
- left.rgbGreen = (BYTE)(top_left.rgbGreen * (1 - y_weight) + bottom_left.rgbGreen * (y_weight));
- left.rgbBlue = (BYTE)(top_left.rgbBlue * (1 - y_weight) + bottom_left.rgbBlue * (y_weight));
- RGBQUAD right;
- right.rgbRed = (BYTE)(top_right.rgbRed * (1 - y_weight) + bottom_right.rgbRed * (y_weight));
- right.rgbGreen = (BYTE)(top_right.rgbGreen * (1 - y_weight) + bottom_right.rgbGreen * (y_weight));
- right.rgbBlue = (BYTE)(top_right.rgbBlue * (1 - y_weight) + bottom_right.rgbBlue * (y_weight));
-
- vec3 value(0.0f);
- value.r() = ((BYTE)(left.rgbRed * (1 - x_weight) + right.rgbRed * (x_weight))) / 255.0f;
- value.g() = ((BYTE)(left.rgbGreen * (1 - x_weight) + right.rgbGreen * (x_weight))) / 255.0f;
- value.b() = ((BYTE)(left.rgbBlue * (1 - x_weight) + right.rgbBlue * (x_weight))) / 255.0f;
-
- return value;
-}
-
-vec4 getInterpolatedRGBAUV(FIBITMAP* image, float x, float y) {
- x = max(0.01f, min(0.99f, x));
- y = max(0.01f, min(0.99f, y));
- return getInterpolatedRGBA(image, x * FreeImage_GetWidth(image) + 0.5f, y * FreeImage_GetHeight(image) + 1.0f);
-}
-
-vec4 getInterpolatedRGBA(FIBITMAP* image, float x, float y) {
- RGBQUAD top_left, top_right, bottom_left, bottom_right;
- FreeImage_GetPixelColor(image,
- (unsigned int)x,
- (unsigned int)y,
- &top_left);
- FreeImage_GetPixelColor(image,
- (unsigned int)x + 1,
- (unsigned int)y,
- &top_right);
- FreeImage_GetPixelColor(image,
- (unsigned int)x,
- (unsigned int)y + 1,
- &bottom_left);
- FreeImage_GetPixelColor(image,
- (unsigned int)x + 1,
- (unsigned int)y + 1,
- &bottom_right);
-
- float x_weight = x - (int)x;
- float y_weight = y - (int)y;
-
- RGBQUAD left;
- left.rgbRed = (BYTE)(top_left.rgbRed * (1 - y_weight) + bottom_left.rgbRed * (y_weight));
- left.rgbGreen = (BYTE)(top_left.rgbGreen * (1 - y_weight) + bottom_left.rgbGreen * (y_weight));
- left.rgbBlue = (BYTE)(top_left.rgbBlue * (1 - y_weight) + bottom_left.rgbBlue * (y_weight));
- left.rgbReserved = (BYTE)(top_left.rgbReserved * (1 - y_weight) + bottom_left.rgbReserved * (y_weight));
- RGBQUAD right;
- right.rgbRed = (BYTE)(top_right.rgbRed * (1 - y_weight) + bottom_right.rgbRed * (y_weight));
- right.rgbGreen = (BYTE)(top_right.rgbGreen * (1 - y_weight) + bottom_right.rgbGreen * (y_weight));
- right.rgbBlue = (BYTE)(top_right.rgbBlue * (1 - y_weight) + bottom_right.rgbBlue * (y_weight));
- right.rgbReserved = (BYTE)(top_right.rgbReserved * (1 - y_weight) + bottom_right.rgbReserved * (y_weight));
-
- vec4 value(0.0f);
- value.r() = ((BYTE)(left.rgbRed * (1 - x_weight) + right.rgbRed * (x_weight))) / 255.0f;
- value.g() = ((BYTE)(left.rgbGreen * (1 - x_weight) + right.rgbGreen * (x_weight))) / 255.0f;
- value.b() = ((BYTE)(left.rgbBlue * (1 - x_weight) + right.rgbBlue * (x_weight))) / 255.0f;
- value.a() = ((BYTE)(left.rgbReserved * (1 - x_weight) + right.rgbReserved * (x_weight))) / 255.0f;
-
- return value;
-}
-
-vec3 getColor(FIBITMAP* image, float x, float y) {
- RGBQUAD color;
- FreeImage_GetPixelColor(image,
- (unsigned int)x,
- (unsigned int)y,
- &color);
- return vec3(color.rgbRed, color.rgbGreen, color.rgbBlue);
-}
-
-unsigned int getWidth(FIBITMAP* image) {
- return FreeImage_GetWidth(image);
-}
-
-unsigned int getHeight(FIBITMAP* image) {
- return FreeImage_GetHeight(image);
-}
-
-int getPixelColor(FIBITMAP* image, unsigned int x, unsigned int y, FIquad* value) {
- RGBQUAD quad;
- int ret = FreeImage_GetPixelColor(image, x, y, &quad);
- value->rgbRed = quad.rgbRed;
- value->rgbGreen = quad.rgbGreen;
- value->rgbBlue = quad.rgbBlue;
- value->rgbReserved = quad.rgbReserved;
- return ret;
-}
-
-void UnloadBitmap(FIBITMAP* image) {
- FreeImage_Unload(image);
-}
-
-fiTYPE getImageType(FIBITMAP* image) {
- return (fiTYPE)FreeImage_GetImageType(image);
-}
-
-unsigned int getBPP(FIBITMAP* image) {
- return FreeImage_GetBPP(image);
-}
-
-uint8_t* getScanLine(FIBITMAP* image, int scanline) {
- return FreeImage_GetScanLine(image, scanline);
-}
-
-/** Generic image loader -- from FreeImage documentation:
-http://internap.dl.sourceforge.net/sourceforge/freeimage/FreeImage3110.pdf
-@param lpszPathName Pointer to the full file name
-@param flag Optional load flag constant
-@return Returns the loaded dib if successful, returns NULL otherwise
-*/
-FIBITMAP* GenericLoader(const char* abs_path, int flag) {
-#ifdef _WIN32
- string path_str = abs_path;
- ShortenWindowsPath(path_str);
- const char* path = path_str.c_str();
-#else
- const char* path = abs_path;
-#endif
- FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;
- // check the file signature and deduce its format
- // (the second argument is currently not used by FreeImage)
- fif = FreeImage_GetFileType(path, 0);
- if (fif == FIF_UNKNOWN) {
- // no signature ?
- // try to guess the file format from the file extension
- fif = FreeImage_GetFIFFromFilename(path);
- }
- // check that the plugin has reading capabilities ...
- if ((fif != FIF_UNKNOWN) && FreeImage_FIFSupportsReading(fif)) {
- // ok, let's load the file
- FIBITMAP* dib = FreeImage_Load(fif, path, flag);
- // unless a bad file format, we are done !
- return dib;
- }
- return NULL;
-}
-
-FIBitmapContainer::FIBitmapContainer(FIBITMAP* _image) {
- image = _image;
-}
-
-FIBitmapContainer::~FIBitmapContainer() {
- reset(NULL);
-}
-
-void FIBitmapContainer::reset(FIBITMAP* _image) {
- if (image) {
- FreeImage_Unload(image);
- image = NULL;
- }
- image = _image;
-}
-
-FIBITMAP* FIBitmapContainer::get() {
- return image;
-}
-
-const FIBITMAP* FIBitmapContainer::get() const {
- return image;
-}
diff --git a/Source/Images/freeimage_wrapper.h b/Source/Images/freeimage_wrapper.h
deleted file mode 100644
index 69799318..00000000
--- a/Source/Images/freeimage_wrapper.h
+++ /dev/null
@@ -1,129 +0,0 @@
-//-----------------------------------------------------------------------------
-// Name: freeimage_wrapper.h
-// Developer: Wolfire Games LLC
-// Author: Phillip Isola
-// Description: Wraps up FreeImage library
-// License: Read below
-//-----------------------------------------------------------------------------
-//
-//
-// Copyright 2022 Wolfire Games LLC
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-//-----------------------------------------------------------------------------
-#pragma once
-
-#include <Math/vec3.h>
-#include <Math/vec4.h>
-
-#include <Images/ddsformat.hpp>
-#include <Internal/integer.h>
-
-#include <string>
-
-struct FIquad {
-#if FREEIMAGE_COLORORDER == FREEIMAGE_COLORORDER_BGR
- uint8_t rgbBlue;
- uint8_t rgbGreen;
- uint8_t rgbRed;
-#else
- uint8_t rgbRed;
- uint8_t rgbGreen;
- uint8_t rgbBlue;
-#endif // FREEIMAGE_COLORORDER
- uint8_t rgbReserved;
-};
-
-enum fiFORMAT {
- FIWF_UNKNOWN = -1,
- FIWF_BMP = 0,
- FIWF_ICO = 1,
- FIWF_JPEG = 2,
- FIWF_JNG = 3,
- FIWF_KOALA = 4,
- FIWF_LBM = 5,
- FIWF_IFF = FIWF_LBM,
- FIWF_MNG = 6,
- FIWF_PBM = 7,
- FIWF_PBMRAW = 8,
- FIWF_PCD = 9,
- FIWF_PCX = 10,
- FIWF_PGM = 11,
- FIWF_PGMRAW = 12,
- FIWF_PNG = 13,
- FIWF_PPM = 14,
- FIWF_PPMRAW = 15,
- FIWF_RAS = 16,
- FIWF_TARGA = 17,
- FIWF_TIFF = 18,
- FIWF_WBMP = 19,
- FIWF_PSD = 20,
- FIWF_CUT = 21,
- FIWF_XBM = 22,
- FIWF_XPM = 23,
- FIWF_DDS = 24,
- FIWF_GIF = 25,
- FIWF_HDR = 26,
- FIWF_FAXG3 = 27,
- FIWF_SGI = 28,
- FIWF_EXR = 29,
- FIWF_J2K = 30,
- FIWF_JP2 = 31,
- FIWF_PFM = 32,
- FIWF_PICT = 33,
- FIWF_RAW = 34
-};
-
-enum fiTYPE {
- FIWT_UNKNOWN = 0, // unknown type
- FIWT_BITMAP = 1, // standard image : 1-, 4-, 8-, 16-, 24-, 32-bit
- FIWT_UINT16 = 2, // array of unsigned short : unsigned 16-bit
- FIWT_INT16 = 3, // array of short : signed 16-bit
- FIWT_UINT32 = 4, // array of unsigned long : unsigned 32-bit
- FIWT_INT32 = 5, // array of long : signed 32-bit
- FIWT_FLOAT = 6, // array of float : 32-bit IEEE floating point
- FIWT_DOUBLE = 7, // array of double : 64-bit IEEE floating point
- FIWT_COMPLEX = 8, // array of FICOMPLEX : 2 x 64-bit IEEE floating point
- FIWT_RGB16 = 9, // 48-bit RGB image : 3 x 16-bit
- FIWT_RGBA16 = 10, // 64-bit RGBA image : 4 x 16-bit
- FIWT_RGBF = 11, // 96-bit RGB float image : 3 x 32-bit IEEE floating point
- FIWT_RGBAF = 12 // 128-bit RGBA float image : 4 x 32-bit IEEE floating point
-};
-
-struct FIBITMAP;
-
-class FIBitmapContainer {
- FIBITMAP* image;
-
- public:
- FIBitmapContainer(FIBITMAP* _image = NULL);
- ~FIBitmapContainer();
- void reset(FIBITMAP* _image);
- FIBITMAP* get();
- const FIBITMAP* get() const;
-};
-
-vec3 getInterpolatedColor(FIBITMAP* image, float x, float y);
-vec3 getInterpolatedColorUV(FIBITMAP* image, float x, float y);
-FIBITMAP* GenericLoader(const char* lpszPathName, int flag = 0);
-vec3 getColor(FIBITMAP* image, float x, float y);
-vec4 getInterpolatedRGBAUV(FIBITMAP* image, float x, float y);
-vec4 getInterpolatedRGBA(FIBITMAP* image, float x, float y);
-unsigned int getWidth(FIBITMAP* image);
-unsigned int getHeight(FIBITMAP* image);
-int getPixelColor(FIBITMAP* image, unsigned int x, unsigned int y, FIquad* value);
-void UnloadBitmap(FIBITMAP* image);
-fiTYPE getImageType(FIBITMAP* image);
-unsigned int getBPP(FIBITMAP* image);
-uint8_t* getScanLine(FIBITMAP* image, int scanline);
diff --git a/Source/Images/image_export.cpp b/Source/Images/image_export.cpp
index 55f2c03e..51752f1f 100644
--- a/Source/Images/image_export.cpp
+++ b/Source/Images/image_export.cpp
@@ -25,7 +25,7 @@
#include "image_export.hpp"
#include <Images/image_export.hpp>
-#include <Images/freeimage_wrapper.h>
+#include <Images/stbimage_wrapper.h>
#include <Internal/error.h>
#include <Internal/filesystem.h>
@@ -37,7 +37,6 @@
#include <Memory/allocation.h>
#include <Logging/logdata.h>
-#include <FreeImage.h>
#include <crnlib.h>
#include <vector>
@@ -114,43 +113,34 @@ void ImageExport::ScaleImageUp(const unsigned char *data,
void ImageExport::SavePNG(const char *file_path, unsigned char *data, unsigned long width, unsigned long height, unsigned short levels) {
std::vector<unsigned char> scaled_data;
ImageExport::ScaleImageUp(data, levels, &width, &height, &scaled_data);
- FREE_IMAGE_FORMAT format = FIF_PNG;
- FIBITMAP *image = FreeImage_ConvertFromRawBits(&scaled_data[0], width, height, 4 * width, 32, 0xC0, 0x38, 0x7);
CreateParentDirs(file_path);
#ifdef _WIN32
createfile(file_path);
std::string short_path(file_path);
ShortenWindowsPath(short_path);
- if (!FreeImage_Save(format, image, short_path.c_str())) {
+ if (!stbi_write_png(short_path.c_str(), width, height, 3, scaled_data.data(), width * 4)) {
DisplayError("Error", "Problem exporting .png file");
}
#else
- if (!FreeImage_Save(format, image, file_path)) {
+ if (!stbi_write_png(file_path, width, height, 3, scaled_data.data(), width * 4)) {
DisplayError("Error", "Problem exporting .png file");
}
#endif
- FreeImage_Unload(image);
}
void ImageExport::SavePNGTransparent(const char *file_path, unsigned char *data, unsigned long width, unsigned long height, unsigned short levels) {
std::vector<unsigned char> scaled_data;
ImageExport::ScaleImageUp(data, levels, &width, &height, &scaled_data);
- FREE_IMAGE_FORMAT format = FIF_PNG;
- FIBITMAP *image = FreeImage_ConvertFromRawBits(&scaled_data[0], width, height, 4 * width, 32, 0xC0, 0x38, 0x7);
- LOGI << "BPP: " << (int)FreeImage_GetBPP(image) << std::endl;
- LOGI << "IsTransparent: " << (int)FreeImage_IsTransparent(image) << std::endl;
- FreeImage_SetTransparent(image, true);
- LOGI << "IsTransparent: " << (int)FreeImage_IsTransparent(image) << std::endl;
-
- int bytespp = FreeImage_GetLine(image) / FreeImage_GetWidth(image);
- for (unsigned y = 0; y < FreeImage_GetHeight(image); y++) {
- BYTE *bits = FreeImage_GetScanLine(image, y);
- for (unsigned x = 0; x < FreeImage_GetWidth(image); x++) {
+
+ int bytespp = 4;
+ for (unsigned y = 0; y < height; y++) {
+ unsigned char *bits = scaled_data.data() + y * width * 4;
+ for (unsigned x = 0; x < width; x++) {
// Set pixel color to green with a transparency of 128
- bits[FI_RGBA_RED] = min(255, (int)((bits[FI_RGBA_RED] / 255.0f / (scaled_data[y * width * 4 + x * 4 + 3] / 255.0f)) * 255));
- bits[FI_RGBA_GREEN] = min(255, (int)((bits[FI_RGBA_GREEN] / 255.0f / (scaled_data[y * width * 4 + x * 4 + 3] / 255.0f)) * 255));
- bits[FI_RGBA_BLUE] = min(255, (int)((bits[FI_RGBA_BLUE] / 255.0f / (scaled_data[y * width * 4 + x * 4 + 3] / 255.0f)) * 255));
- bits[FI_RGBA_ALPHA] = scaled_data[y * width * 4 + x * 4 + 3];
+ bits[0] = min(255, (int)((bits[0] / 255.0f / (scaled_data[y * width * 4 + x * 4 + 3] / 255.0f)) * 255));
+ bits[1] = min(255, (int)((bits[1] / 255.0f / (scaled_data[y * width * 4 + x * 4 + 3] / 255.0f)) * 255));
+ bits[2] = min(255, (int)((bits[2] / 255.0f / (scaled_data[y * width * 4 + x * 4 + 3] / 255.0f)) * 255));
+ bits[3] = scaled_data[y * width * 4 + x * 4 + 3];
// jump to next pixel
bits += bytespp;
}
@@ -161,34 +151,30 @@ void ImageExport::SavePNGTransparent(const char *file_path, unsigned char *data,
createfile(file_path);
std::string short_path(file_path);
ShortenWindowsPath(short_path);
- if (!FreeImage_Save(format, image, short_path.c_str())) {
+ if (!stbi_write_png(short_path.c_str(), width, height, 4, scaled_data.data(), width * 4)) {
DisplayError("Error", "Problem exporting .png file");
}
#else
- if (!FreeImage_Save(format, image, file_path)) {
+ if (!stbi_write_png(file_path, width, height, 4, scaled_data.data(), width * 4)) {
DisplayError("Error", "Problem exporting .png file");
}
#endif
- FreeImage_Unload(image);
}
void ImageExport::SaveJPEG(const char *abs_path, unsigned char *data, unsigned long width, unsigned long height) {
- FREE_IMAGE_FORMAT format = FIF_JPEG;
- FIBITMAP *image = FreeImage_ConvertFromRawBits(data, width, height, 3 * width, 24, 0xC0, 0x38, 0x7);
CreateParentDirs(abs_path);
#ifdef _WIN32
createfile(abs_path);
std::string short_path(abs_path);
ShortenWindowsPath(short_path);
- if (!FreeImage_Save(format, image, short_path.c_str(), JPEG_QUALITYSUPERB)) {
+ if (!stbi_write_jpg(short_path.c_str(), width, height, 3, data, 85)) {
DisplayError("Error", "Problem exporting .jpeg file");
}
#else
- if (!FreeImage_Save(format, image, abs_path, JPEG_QUALITYSUPERB)) {
+ if (!stbi_write_jpg(abs_path, width, height, 3, data, 85)) {
DisplayError("Error", "Problem exporting .jpeg file");
}
#endif
- FreeImage_Unload(image);
}
void ImageExport::SavePNGofGrayscaleFloats(const char *file_path, std::vector<float> &data, unsigned long width, unsigned long height) {
diff --git a/Source/Images/stbimage_wrapper.cpp b/Source/Images/stbimage_wrapper.cpp
new file mode 100644
index 00000000..7450cfcf
--- /dev/null
+++ b/Source/Images/stbimage_wrapper.cpp
@@ -0,0 +1,28 @@
+//-----------------------------------------------------------------------------
+// Name: stbimage_wrapper.cpp
+// Developer: Wolfire Games LLC
+// Author: Stephan Vedder
+// Description: Wraps up stb_image library
+// License: Read below
+//-----------------------------------------------------------------------------
+//
+//
+// Copyright 2022 Wolfire Games LLC
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-----------------------------------------------------------------------------
+
+#define STB_IMAGE_IMPLEMENTATION
+#define STB_IMAGE_WRITE_IMPLEMENTATION
+#include "stbimage_wrapper.h" \ No newline at end of file
diff --git a/Source/Images/stbimage_wrapper.h b/Source/Images/stbimage_wrapper.h
new file mode 100644
index 00000000..b784b72f
--- /dev/null
+++ b/Source/Images/stbimage_wrapper.h
@@ -0,0 +1,28 @@
+//-----------------------------------------------------------------------------
+// Name: stbimage_wrapper.h
+// Developer: Wolfire Games LLC
+// Author: Stephan Vedder
+// Description: Wraps up stb_image library
+// License: Read below
+//-----------------------------------------------------------------------------
+//
+//
+// Copyright 2022 Wolfire Games LLC
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-----------------------------------------------------------------------------
+#pragma once
+
+#include <stb_image.h>
+#include <stb_image_write.h> \ No newline at end of file
diff --git a/Source/Images/texture_data.cpp b/Source/Images/texture_data.cpp
index ac86ec13..6c2a16fb 100644
--- a/Source/Images/texture_data.cpp
+++ b/Source/Images/texture_data.cpp
@@ -24,7 +24,7 @@
//-----------------------------------------------------------------------------
#include "texture_data.h"
-#include <Images/freeimage_wrapper.h>
+#include <Images/stbimage_wrapper.h>
#include <Images/image_export.hpp>
#include <Internal/common.h>
diff --git a/Source/Internal/datemodified.cpp b/Source/Internal/datemodified.cpp
index dddc8c04..38bc3d4c 100644
--- a/Source/Internal/datemodified.cpp
+++ b/Source/Internal/datemodified.cpp
@@ -89,7 +89,7 @@ bool GetDateModifiedString(const char *file_name, char *buffer, int buffer_size)
char timebuf[26];
// Get data associated with "crt_stat.c":
- const char* path = file_name;
+ const char *path = file_name;
result = stat(path, &buf);
// Check if statistics are valid:
@@ -162,7 +162,7 @@ int64_t GetDateModifiedInt64(const char *abs_path) {
int result;
// Get data associated with "crt_stat.c":
- const char* path = abs_path;
+ const char *path = abs_path;
result = stat(path, &buf);
// Check if statistics are valid:
diff --git a/Source/Main/engine.cpp b/Source/Main/engine.cpp
index 3a6d4cce..2de1b840 100644
--- a/Source/Main/engine.cpp
+++ b/Source/Main/engine.cpp
@@ -135,7 +135,6 @@
#include <Sound/sound.h>
#include <Main/debuglevelload.h>
-#include <FreeImage.h>
#include <SDL.h>
#include <algorithm>
@@ -5877,20 +5876,6 @@ void Engine::GenerateLevelCache(ModInstance* mod_instance) {
}
}
-/**
-FreeImage error handler
-@param fif Format / Plugin responsible for the error
-@param message Error message
-*/
-void FreeImageErrorHandler(FREE_IMAGE_FORMAT fif, const char* message) {
- printf("\n*** ");
- if (fif != FIF_UNKNOWN) {
- printf("%s Format\n", FreeImage_GetFormatFromFIF(fif));
- }
- printf(message);
- printf(" ***\n");
-}
-
void Engine::Initialize() {
current_menu_player = -1;
waiting_for_input_ = false;
@@ -5960,7 +5945,6 @@ void Engine::Initialize() {
Steamworks::Instance()->Initialize();
#endif
// multiplayer.Initialize();
- FreeImage_SetOutputMessage(FreeImageErrorHandler);
if (Engine::instance_ != NULL) {
LOGF << "Engine only supports one instance at any time, if this need changes, refactoring will be needed for all situations that refer to Engine::Instance()" << std::endl;
diff --git a/Source/Objects/object.h b/Source/Objects/object.h
index f69b9028..91b66f24 100644
--- a/Source/Objects/object.h
+++ b/Source/Objects/object.h
@@ -217,7 +217,7 @@ class Object {
virtual void Update(float timestep) {} // Is only called on certain objects that are registered as needing a frequent update.
virtual void InfrequentUpdate(); // Is called on all objects, but there is no guarantee on how often.
- // Interpolation boilerplate for all objects in multiplayer
+ // Interpolation boilerplate for all objects in multiplayer
virtual bool Initialize() = 0;
virtual void SetImposter(bool set) {}
diff --git a/Source/Ogda/Builders/crunchaction.cpp b/Source/Ogda/Builders/crunchaction.cpp
index cd600cfc..8137b04a 100644
--- a/Source/Ogda/Builders/crunchaction.cpp
+++ b/Source/Ogda/Builders/crunchaction.cpp
@@ -27,7 +27,7 @@
#include <Ogda/jobhandler.h>
#include <Internal/filesystem.h>
#include <Graphics/converttexture.h>
-#include <Images/freeimage_wrapper.h>
+#include <Images/stbimage_wrapper.h>
#include <Internal/common.h>
#include <Internal/filesystem.h>
#include <Internal/datemodified.h>
diff --git a/Source/Ogda/Builders/dxt5action.cpp b/Source/Ogda/Builders/dxt5action.cpp
index 45e4d0b2..945b0347 100644
--- a/Source/Ogda/Builders/dxt5action.cpp
+++ b/Source/Ogda/Builders/dxt5action.cpp
@@ -27,7 +27,7 @@
#include <Ogda/jobhandler.h>
#include <Internal/filesystem.h>
#include <Graphics/converttexture.h>
-#include <Images/freeimage_wrapper.h>
+#include <Images/stbimage_wrapper.h>
#include <Internal/common.h>
#include <Internal/filesystem.h>
#include <Internal/datemodified.h>