Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a bunch of warnings #57

Merged
merged 17 commits into from
Jul 12, 2024
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
15 changes: 1 addition & 14 deletions crnlib/crn_assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,7 @@ void crnlib_fail(const char* pExp, const char* pFile, unsigned line);
void trace(const char* pFmt, va_list args);
void trace(const char* pFmt, ...);

// Borrowed from boost libraries.
template <bool x>
struct crnlib_assume_failure;
template <>
struct crnlib_assume_failure<true> {
enum { blah = 1 };
};
template <int x>
struct crnlib_assume_try {};

#define CRNLIB_JOINER_FINAL(a, b) a##b
#define CRNLIB_JOINER(a, b) CRNLIB_JOINER_FINAL(a, b)
#define CRNLIB_JOIN(a, b) CRNLIB_JOINER(a, b)
#define CRNLIB_ASSUME(p) typedef crnlib_assume_try<sizeof(crnlib_assume_failure<(bool)(p)>)> CRNLIB_JOIN(crnlib_assume_typedef, __COUNTER__)
#define CRNLIB_ASSUME(p) static_assert(p, "")

#ifdef NDEBUG
template <typename T>
Expand Down
4 changes: 2 additions & 2 deletions crnlib/crn_command_line_params.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
#include "crn_winhdr.h"
#endif
namespace crnlib {
void get_command_line_as_single_string(dynamic_string& cmd_line, int argc, char* argv[]) {
argc, argv;
#if CRNLIB_USE_WIN32_API
void get_command_line_as_single_string(dynamic_string& cmd_line, int /* argc */, char** /* argv */) {
cmd_line.set(GetCommandLineA());
#else
void get_command_line_as_single_string(dynamic_string& cmd_line, int argc, char* argv[]) {
cmd_line.clear();
for (int i = 0; i < argc; i++) {
dynamic_string tmp(argv[i]);
Expand Down
7 changes: 0 additions & 7 deletions crnlib/crn_comp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ bool crn_comp::pack_color_endpoints(crnlib::vector<uint8>& packed_data, const cr
prev[0].clear();
prev[1].clear();

int total_residuals = 0;

for (uint endpoint_index = 0; endpoint_index < m_color_endpoints.size(); endpoint_index++) {
const uint endpoint = remapped_endpoints[endpoint_index];

Expand All @@ -48,7 +46,6 @@ bool crn_comp::pack_color_endpoints(crnlib::vector<uint8>& packed_data, const cr
for (uint j = 0; j < 2; j++) {
for (uint k = 0; k < 3; k++) {
int delta = cur[j][k] - prev[j][k];
total_residuals += delta * delta;
int sym = delta & component_limits[j * 3 + k];
int table = (k == 1) ? 1 : 0;
hist[table].inc_freq(sym);
Expand Down Expand Up @@ -126,8 +123,6 @@ bool crn_comp::pack_alpha_endpoints(crnlib::vector<uint8>& packed_data, const cr
uint prev[2];
utils::zero_object(prev);

int total_residuals = 0;

for (uint endpoint_index = 0; endpoint_index < m_alpha_endpoints.size(); endpoint_index++) {
const uint endpoint = remapped_endpoints[endpoint_index];

Expand All @@ -137,8 +132,6 @@ bool crn_comp::pack_alpha_endpoints(crnlib::vector<uint8>& packed_data, const cr

for (uint j = 0; j < 2; j++) {
int delta = cur[j] - prev[j];
total_residuals += delta * delta;

int sym = delta & 255;

hist.inc_freq(sym);
Expand Down
2 changes: 1 addition & 1 deletion crnlib/crn_data_stream_serializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ class data_stream_serializer {
}

return true;
};
}

template <typename T>
bool read_vector(T& vec, uint num_expected = UINT_MAX) {
Expand Down
4 changes: 2 additions & 2 deletions crnlib/crn_dxt_endpoint_refiner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,13 @@ void dxt_endpoint_refiner::optimize_dxt5(vec3F low_color, vec3F high_color) {

uint16 solutions[529];
uint solutions_count = 0;
solutions[solutions_count++] = L0 == H0 ? H0 ? H0 - 1 << 8 | L0 : 1 : L0 > H0 ? H0 << 8 | L0 : L0 << 8 | H0;
solutions[solutions_count++] = L0 == H0 ? H0 ? (H0 - 1) << 8 | L0 : 1 : L0 > H0 ? H0 << 8 | L0 : L0 << 8 | H0;
uint8 minL = L0 <= 11 ? 0 : L0 - 11, maxL = L0 >= 244 ? 255 : L0 + 11;
uint8 minH = H0 <= 11 ? 0 : H0 - 11, maxH = H0 >= 244 ? 255 : H0 + 11;
for (uint16 L = minL; L <= maxL; L++) {
for (uint16 H = minH; H <= maxH; H++) {
if ((maxH < L || L <= H || H < minL) && (L != L0 || H != H0) && (L != H0 || H != L0))
solutions[solutions_count++] = L == H ? H ? H - 1 << 8 | L : 1 : L > H ? H << 8 | L : L << 8 | H;
solutions[solutions_count++] = L == H ? H ? (H - 1) << 8 | L : 1 : L > H ? H << 8 | L : L << 8 | H;
}
}

Expand Down
4 changes: 3 additions & 1 deletion crnlib/crn_dxt_fast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,21 @@ static inline uint pack_color(const color_quad_u8& c) {
return (mul_8bit(c.r, 31) << 11) + (mul_8bit(c.g, 63) << 5) + mul_8bit(c.b, 31);
}

#if 0
static inline void lerp_color(color_quad_u8& result, const color_quad_u8& p1, const color_quad_u8& p2, uint f) {
CRNLIB_ASSERT(f <= 255);

result.r = static_cast<uint8>(p1.r + mul_8bit(p2.r - p1.r, f));
result.g = static_cast<uint8>(p1.g + mul_8bit(p2.g - p1.g, f));
result.b = static_cast<uint8>(p1.b + mul_8bit(p2.b - p1.b, f));
}
#endif

static inline void eval_colors(color_quad_u8* pColors, uint c0, uint c1) {
unpack_color(pColors[0], c0);
unpack_color(pColors[1], c1);

#if 0
#if 0
lerp_color(pColors[2], pColors[0], pColors[1], 0x55);
lerp_color(pColors[3], pColors[0], pColors[1], 0xAA);
#else
Expand Down
8 changes: 3 additions & 5 deletions crnlib/crn_etc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1157,10 +1157,9 @@ void pack_etc1_block_init() {

// Packs solid color blocks efficiently using a set of small precomputed tables.
// For random 888 inputs, MSE results are better than Erricson's ETC1 packer in "slow" mode ~9.5% of the time, is slightly worse only ~.01% of the time, and is equal the rest of the time.
static uint64 pack_etc1_block_solid_color(etc1_block& block, const uint8* pColor, crn_etc1_pack_params& pack_params, pack_etc1_block_context& context) {
static uint64 pack_etc1_block_solid_color(etc1_block& block, const uint8* pColor, crn_etc1_pack_params& /* pack_params */, pack_etc1_block_context& /* context */) {
CRNLIB_ASSERT(g_etc1_inverse_lookup[0][255]);

context, pack_params;
static uint s_next_comp[4] = {1, 2, 0, 1};

uint best_error = cUINT32_MAX, best_i = 0;
Expand Down Expand Up @@ -1237,13 +1236,12 @@ static uint64 pack_etc1_block_solid_color(etc1_block& block, const uint8* pColor
static uint pack_etc1_block_solid_color_constrained(
etc1_optimizer::results& results,
uint num_colors, const uint8* pColor,
crn_etc1_pack_params& pack_params,
pack_etc1_block_context& context,
crn_etc1_pack_params& /* pack_params */,
pack_etc1_block_context& /* context */,
bool use_diff,
const color_quad_u8* pBase_color5_unscaled) {
CRNLIB_ASSERT(g_etc1_inverse_lookup[0][255]);

context, pack_params;
static uint s_next_comp[4] = {1, 2, 0, 1};

uint best_error = cUINT32_MAX, best_i = 0;
Expand Down
11 changes: 4 additions & 7 deletions crnlib/crn_file_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,17 @@ bool file_utils::get_file_size(const char* pFilename, uint64& file_size) {
return true;
}
#elif defined(__GNUC__)
bool file_utils::is_read_only(const char* pFilename) {
pFilename;
bool file_utils::is_read_only(const char* /* pFilename */) {
// TODO
return false;
}

bool file_utils::disable_read_only(const char* pFilename) {
pFilename;
bool file_utils::disable_read_only(const char* /* pFilename */) {
// TODO
return false;
}

bool file_utils::is_older_than(const char* pSrcFilename, const char* pDstFilename) {
pSrcFilename, pDstFilename;
bool file_utils::is_older_than(const char* /* pSrcFilename */, const char* /* pDstFilename */) {
// TODO
return false;
}
Expand Down Expand Up @@ -220,7 +217,7 @@ bool file_utils::is_drive_separator(char c) {
#ifdef WIN32
return (c == ':');
#else
c;
(void)c;
return false;
#endif
}
Expand Down
6 changes: 1 addition & 5 deletions crnlib/crn_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@

#define CRNLIB_NO_COPY_OR_ASSIGNMENT_OP(c) \
c(const c&); \
c& operator=(const c&);
#define CRNLIB_NO_HEAP_ALLOC() \
private: \
static void* operator new(size_t); \
static void* operator new[](size_t);
c& operator=(const c&)

namespace crnlib {
namespace helpers {
Expand Down
1 change: 0 additions & 1 deletion crnlib/crn_image_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "crn_data_stream_serializer.h"

namespace crnlib {
enum pixel_format;

namespace image_utils {
enum read_flags_t {
Expand Down
14 changes: 2 additions & 12 deletions crnlib/crn_jpgd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,6 @@ inline int jpeg_decoder::huff_decode(huff_tables* pH, int& extra_bits) {
// Tables and macro used to fully decode the DPCM differences.
static const int s_extend_test[16] = {0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080, 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000};
static const int s_extend_offset[16] = {0, 1 - (1 << 1), 1 - (1 << 2), 1 - (1 << 3), 1 - (1 << 4), 1 - (1 << 5), 1 - (1 << 6), 1 - (1 << 7), 1 - (1 << 8), 1 - (1 << 9), 1 - (1 << 10), 1 - (1 << 11), 1 - (1 << 12), 1 - (1 << 13), 1 - (1 << 14), 1 - (1 << 15)};
static const int s_extend_mask[] = {0, (1 << 0), (1 << 1), (1 << 2), (1 << 3), (1 << 4), (1 << 5), (1 << 6), (1 << 7), (1 << 8), (1 << 9), (1 << 10), (1 << 11), (1 << 12), (1 << 13), (1 << 14), (1 << 15), (1 << 16)};
// The logical AND's in this macro are to shut up static code analysis (aren't really necessary - couldn't find another way to do this)
#define JPGD_HUFF_EXTEND(x, s) (((x) < s_extend_test[s & 15]) ? ((x) + s_extend_offset[s & 15]) : (x))

Expand Down Expand Up @@ -1144,13 +1143,10 @@ void jpeg_decoder::read_sos_marker() {

// Finds the next marker.
int jpeg_decoder::next_marker() {
uint c, bytes;

bytes = 0;
uint c;

do {
do {
bytes++;
c = get_bits(8);
} while (c != 0xFF);

Expand Down Expand Up @@ -1595,7 +1591,7 @@ void jpeg_decoder::load_next_row() {
int i;
jpgd_block_t* p;
jpgd_quant_t* q;
int mcu_row, mcu_block, row_block = 0;
int mcu_row, mcu_block = 0;
int component_num, component_id;
int block_x_mcu[JPGD_MAX_COMPONENTS];

Expand Down Expand Up @@ -1625,8 +1621,6 @@ void jpeg_decoder::load_next_row() {
if (p[g_ZAG[i]])
p[g_ZAG[i]] = static_cast<jpgd_block_t>(p[g_ZAG[i]] * q[i]);

row_block++;

if (m_comps_in_scan == 1)
block_x_mcu[component_id]++;
else {
Expand Down Expand Up @@ -1711,8 +1705,6 @@ static inline int dequantize_ac(int c, int q) {

// Decodes and dequantizes the next row of coefficients.
void jpeg_decoder::decode_next_row() {
int row_block = 0;

for (int mcu_row = 0; mcu_row < m_mcus_per_row; mcu_row++) {
if ((m_restart_interval) && (m_restarts_left == 0))
process_restart();
Expand Down Expand Up @@ -1790,8 +1782,6 @@ void jpeg_decoder::decode_next_row() {
}

m_mcu_block_max_zag[mcu_block] = k;

row_block++;
}

if (m_freq_domain_chroma_upsample)
Expand Down
2 changes: 1 addition & 1 deletion crnlib/crn_miniz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ typedef unsigned char mz_validate_uint64[sizeof(mz_uint64) == 8 ? 1 : -1];
#ifdef _MSC_VER
#define MZ_FORCEINLINE __forceinline
#elif defined(__GNUC__)
#define MZ_FORCEINLINE __attribute__((__always_inline__))
#define MZ_FORCEINLINE __attribute__((__always_inline__)) inline
illwieckz marked this conversation as resolved.
Show resolved Hide resolved
#else
#define MZ_FORCEINLINE
#endif
Expand Down
13 changes: 4 additions & 9 deletions crnlib/crn_mipmapped_texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1074,8 +1074,10 @@ bool mipmapped_texture::write_dds(data_stream_serializer& serializer) const {
const mip_level* pLevel = get_level(face, level);

if (dxt_format) {
#if !defined(NDEBUG)
const uint width = pLevel->get_width();
const uint height = pLevel->get_height();
#endif

CRNLIB_ASSERT(width == math::maximum<uint>(1, m_width >> level));
CRNLIB_ASSERT(height == math::maximum<uint>(1, m_height >> level));
Expand All @@ -1096,11 +1098,12 @@ bool mipmapped_texture::write_dds(data_stream_serializer& serializer) const {
p = &tmp;
}

#if !defined(NDEBUG)
const uint num_blocks_x = (width + 3) >> 2;
const uint num_blocks_y = (height + 3) >> 2;
#endif

CRNLIB_ASSERT(num_blocks_x * num_blocks_y * p->get_elements_per_block() == p->get_total_elements());
width, height, num_blocks_x, num_blocks_y;

const uint size_in_bytes = p->get_total_elements() * sizeof(dxt_image::element);
if (size_in_bytes > write_buf.size())
Expand Down Expand Up @@ -1849,8 +1852,6 @@ bool mipmapped_texture::convert(pixel_format fmt, bool cook, const dxt_image::pa
for (uint l = 0; l < m_faces[f].size(); l++)
total_pixels += m_faces[f][l]->get_total_pixels();

uint num_pixels_processed = 0;

uint progress_start = p.m_progress_start;

for (uint f = 0; f < m_faces.size(); f++) {
Expand All @@ -1869,8 +1870,6 @@ bool mipmapped_texture::convert(pixel_format fmt, bool cook, const dxt_image::pa
clear();
return false;
}

num_pixels_processed += num_pixels;
}
}

Expand Down Expand Up @@ -2722,8 +2721,6 @@ bool mipmapped_texture::read_crn_from_memory(const void* pData, uint data_size,
return false;
}

uint total_pixels = 0;

void* pFaces[cCRNMaxFaces];
for (uint f = tex_info.m_faces; f < cCRNMaxFaces; f++)
pFaces[f] = NULL;
Expand All @@ -2737,8 +2734,6 @@ bool mipmapped_texture::read_crn_from_memory(const void* pData, uint data_size,
const uint row_pitch = num_blocks_x * tex_info.m_bytes_per_block;
const uint size_of_face = num_blocks_y * row_pitch;

total_pixels += num_blocks_x * num_blocks_y * 4 * 4 * tex_info.m_faces;

#if 0
t.start();
#endif
Expand Down
4 changes: 4 additions & 0 deletions crnlib/crn_qdxt1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -780,11 +780,15 @@ bool qdxt1::pack(dxt1_block* pDst_elements, uint elements_per_block, const qdxt1

// trace("endpoint clusters: %u\n", m_endpoint_cluster_indices.size());

#if 0
uint total_blocks = 0;
#endif
uint max_blocks = 0;
for (uint i = 0; i < m_endpoint_cluster_indices.size(); i++) {
uint num = m_endpoint_cluster_indices[i].size();
#if 0
total_blocks += num;
#endif
max_blocks = math::maximum(max_blocks, num);
}
#if 0
Expand Down
2 changes: 0 additions & 2 deletions crnlib/crn_qdxt5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -693,11 +693,9 @@ bool qdxt5::pack(dxt5_block* pDst_elements, uint elements_per_block, const qdxt5
} else
m_endpoint_clusterizer.retrieve_clusters(max_endpoint_clusters, m_endpoint_cluster_indices);

uint total_blocks = 0;
uint max_blocks = 0;
for (uint i = 0; i < m_endpoint_cluster_indices.size(); i++) {
uint num = m_endpoint_cluster_indices[i].size();
total_blocks += num;
max_blocks = math::maximum(max_blocks, num);
}

Expand Down
2 changes: 0 additions & 2 deletions crnlib/crn_resample_filters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ static double bessel0(double x) {
return sum;
}

static const float KAISER_ALPHA = 4.0;
static double kaiser(double alpha, double half_width, double x) {
const double ratio = (x / half_width);
return bessel0(alpha * sqrt(1 - ratio * ratio)) / bessel0(alpha);
Expand All @@ -265,7 +264,6 @@ static float kaiser_filter(float t) {
// db atten
const float att = 40.0f;
const float alpha = (float)(exp(log((double)0.58417 * (att - 20.96)) * 0.4) + 0.07886 * (att - 20.96));
//const float alpha = KAISER_ALPHA;
return (float)clean(sinc(t) * kaiser(alpha, KAISER_SUPPORT, t));
}

Expand Down
2 changes: 0 additions & 2 deletions crnlib/crn_texture_comp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,6 @@ static bool create_dds_tex(const crn_comp_params& params, mipmapped_texture& dds
}

bool create_texture_mipmaps(mipmapped_texture& work_tex, const crn_comp_params& params, const crn_mipmap_params& mipmap_params, bool generate_mipmaps) {
crn_comp_params new_params(params);

bool generate_new_mips = false;

switch (mipmap_params.m_mode) {
Expand Down
Loading