mirror of
https://github.com/rupertwh/bmplib.git
synced 2026-02-04 05:35:48 +00:00
make it compile with MS Visual Studio
* add dll import/export declarations * add casts to avoid compiler warnings * fix long vs long long error, unearthed by compiling under Windows Compiling with Visual Studio still needs some manual work that is otherwise done by meson: * create config.h * compile and run gen-huffman.c and gen-reversebits.c to create the header files huffman-codes.h and reversebits.h gitignore visual studio
This commit is contained in:
6
.gitignore
vendored
6
.gitignore
vendored
@@ -3,3 +3,9 @@ _debug
|
||||
_release
|
||||
*.sublime-workspace
|
||||
*.patch
|
||||
.vs
|
||||
[Dd]ebug
|
||||
[Rr]elease
|
||||
bmplib
|
||||
gen-huffman
|
||||
gen-reversebits
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
#include <stdint.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#define BMPLIB_LIB
|
||||
|
||||
#include "config.h"
|
||||
#include "bmplib.h"
|
||||
#include "logging.h"
|
||||
@@ -187,9 +189,6 @@ int cm_count_bits(unsigned long v)
|
||||
{
|
||||
int bits = 0;
|
||||
|
||||
if (v < 0)
|
||||
v = -v;
|
||||
|
||||
while (v) {
|
||||
bits++;
|
||||
v >>= 1;
|
||||
@@ -309,12 +308,12 @@ int cm_is_one_of(int n, int candidate, ...)
|
||||
|
||||
int cm_align4padding(unsigned long long a)
|
||||
{
|
||||
return cm_align4size(a) - a;
|
||||
return (int) (cm_align4size(a) - a);
|
||||
}
|
||||
|
||||
int cm_align2padding(unsigned long long a)
|
||||
{
|
||||
return cm_align2size(a) - a;
|
||||
return (int) (cm_align2size(a) - a);
|
||||
}
|
||||
|
||||
|
||||
|
||||
27
bmp-common.h
27
bmp-common.h
@@ -36,6 +36,12 @@
|
||||
#define ATTR_CONST
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
#define API
|
||||
#else
|
||||
#define API __attribute__ ((visibility ("default")))
|
||||
#endif
|
||||
|
||||
union Pixel {
|
||||
unsigned int value[4];
|
||||
struct {
|
||||
@@ -48,7 +54,7 @@ union Pixel {
|
||||
|
||||
struct Colormask {
|
||||
union {
|
||||
unsigned long value[4];
|
||||
unsigned long long value[4];
|
||||
struct {
|
||||
unsigned long long red;
|
||||
unsigned long long green;
|
||||
@@ -57,21 +63,21 @@ struct Colormask {
|
||||
};
|
||||
} mask;
|
||||
union {
|
||||
unsigned long value[4];
|
||||
int value[4];
|
||||
struct {
|
||||
unsigned long red;
|
||||
unsigned long green;
|
||||
unsigned long blue;
|
||||
unsigned long alpha;
|
||||
int red;
|
||||
int green;
|
||||
int blue;
|
||||
int alpha;
|
||||
};
|
||||
} shift;
|
||||
union {
|
||||
int value[4];
|
||||
struct {
|
||||
int red;
|
||||
int green;
|
||||
int blue;
|
||||
int alpha;
|
||||
int red;
|
||||
int green;
|
||||
int blue;
|
||||
int alpha;
|
||||
};
|
||||
} bits;
|
||||
union {
|
||||
@@ -228,7 +234,6 @@ int write_s32_le(FILE *file, int32_t val);
|
||||
int read_s16_le(FILE *file, int16_t *val);
|
||||
int read_s32_le(FILE *file, int32_t *val);
|
||||
|
||||
#define API __attribute__ ((visibility ("default")))
|
||||
|
||||
|
||||
#define HMAGIC_READ 0x44414552UL
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
#include <stdint.h>
|
||||
#include <math.h>
|
||||
|
||||
#define BMPLIB_LIB
|
||||
|
||||
#include "config.h"
|
||||
#include "bmplib.h"
|
||||
#include "logging.h"
|
||||
@@ -226,7 +228,7 @@ static void s_read_whole_image(BMPREAD_R rp, unsigned char *restrict image)
|
||||
|
||||
linesize = (size_t) rp->width * rp->result_bytes_per_pixel;
|
||||
|
||||
for (y = 0; y < rp->height; y += yoff) {
|
||||
for (y = 0; y < (int) rp->height; y += yoff) {
|
||||
real_y = (rp->orientation == BMP_ORIENT_TOPDOWN) ? y : rp->height-1-y;
|
||||
s_read_one_line(rp, image + real_y * linesize);
|
||||
if (rp->rle_eof || s_stopping_error(rp))
|
||||
@@ -263,7 +265,7 @@ static void s_read_one_line(BMPREAD_R rp, unsigned char *restrict line)
|
||||
}
|
||||
|
||||
if (!(rp->rle_eof || s_stopping_error(rp))) {
|
||||
if (yoff > rp->height - rp->lbl_file_y) {
|
||||
if (yoff > (int) rp->height - rp->lbl_file_y) {
|
||||
rp->invalid_delta = TRUE;
|
||||
}
|
||||
rp->lbl_file_y += yoff;
|
||||
@@ -277,7 +279,7 @@ static void s_read_one_line(BMPREAD_R rp, unsigned char *restrict line)
|
||||
}
|
||||
|
||||
rp->lbl_y++;
|
||||
if (rp->lbl_y >= rp->height) {
|
||||
if (rp->lbl_y >= (int) rp->height) {
|
||||
rp->image_loaded = TRUE;
|
||||
}
|
||||
}
|
||||
@@ -354,12 +356,12 @@ static int s_read_rgb_line(BMPREAD_R rp, unsigned char *restrict line)
|
||||
d = s_s2_13_to_float(px.value[i]);
|
||||
if (i < 3 && rp->conv64 == BMP_CONV64_SRGB)
|
||||
d = s_srgb_gamma_float(d);
|
||||
((float*)line)[offs+i] = d;
|
||||
((float*)line)[offs+i] = (float) d;
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < rp->result_channels; i++) {
|
||||
d = s_int_to_float(px.value[i], rp->cmask.bits.value[i]);
|
||||
((float*)line)[offs + i] = d;
|
||||
((float*)line)[offs + i] = (float) d;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -490,11 +492,11 @@ static inline int s_read_rgb_pixel(BMPREAD_R rp, union Pixel *restrict px)
|
||||
v |= ((unsigned long long)byte) << i;
|
||||
}
|
||||
|
||||
px->red = (v & rp->cmask.mask.red) >> rp->cmask.shift.red;
|
||||
px->green = (v & rp->cmask.mask.green) >> rp->cmask.shift.green;
|
||||
px->blue = (v & rp->cmask.mask.blue) >> rp->cmask.shift.blue;
|
||||
px->red = (unsigned int) ((v & rp->cmask.mask.red) >> rp->cmask.shift.red);
|
||||
px->green = (unsigned int) ((v & rp->cmask.mask.green) >> rp->cmask.shift.green);
|
||||
px->blue = (unsigned int) ((v & rp->cmask.mask.blue) >> rp->cmask.shift.blue);
|
||||
if (rp->has_alpha)
|
||||
px->alpha = (v & rp->cmask.mask.alpha) >> rp->cmask.shift.alpha;
|
||||
px->alpha = (unsigned int) ((v & rp->cmask.mask.alpha) >> rp->cmask.shift.alpha);
|
||||
else
|
||||
px->alpha = (1<<rp->result_bitsperchannel) - 1;
|
||||
|
||||
@@ -784,8 +786,8 @@ static int s_huff_find_eol(BMPREAD_R rp);
|
||||
|
||||
static void s_read_huffman_line(BMPREAD_R rp, unsigned char *restrict line)
|
||||
{
|
||||
size_t x = 0, offs;
|
||||
int runlen;
|
||||
size_t offs;
|
||||
int x = 0, runlen;
|
||||
int black = 0;
|
||||
|
||||
while (x < rp->width) {
|
||||
@@ -820,7 +822,7 @@ static void s_read_huffman_line(BMPREAD_R rp, unsigned char *restrict line)
|
||||
}
|
||||
|
||||
for (int i = 0; i < runlen; i++, x++) {
|
||||
offs = x * rp->result_bytes_per_pixel;
|
||||
offs = (size_t) x * rp->result_bytes_per_pixel;
|
||||
if (rp->result_indexed) {
|
||||
line[offs] = black;
|
||||
} else {
|
||||
@@ -922,7 +924,7 @@ static inline void s_int_to_result_format(BMPREAD_R rp, int frombits, unsigned c
|
||||
}
|
||||
switch (rp->result_format) {
|
||||
case BMP_FORMAT_FLOAT:
|
||||
((float*)px)[c] = (double) v / ((1ULL<<frombits)-1);
|
||||
((float*)px)[c] = (float) ((double) v / ((1ULL<<frombits)-1));
|
||||
break;
|
||||
case BMP_FORMAT_S2_13:
|
||||
((uint16_t*)px)[c] = (uint16_t) ((double) v / ((1ULL<<frombits)-1) * 8192.0 + 0.5);
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define BMPLIB_LIB
|
||||
|
||||
#include "config.h"
|
||||
#include "bmplib.h"
|
||||
#include "logging.h"
|
||||
|
||||
16
bmp-read.c
16
bmp-read.c
@@ -25,6 +25,8 @@
|
||||
#include <limits.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#define BMPLIB_LIB
|
||||
|
||||
#include "config.h"
|
||||
#include "bmplib.h"
|
||||
#include "logging.h"
|
||||
@@ -457,10 +459,10 @@ static int s_single_dim_val(BMPHANDLE h, enum Dimint dim)
|
||||
ret = (int) rp->orientation;
|
||||
break;
|
||||
case DIM_XDPI:
|
||||
ret = rp->ih->xpelspermeter / 39.37 + 0.5;
|
||||
ret = (int) (rp->ih->xpelspermeter / (100.0 / 2.54) + 0.5);
|
||||
break;
|
||||
case DIM_YDPI:
|
||||
ret = rp->ih->ypelspermeter / 39.37 + 0.5;
|
||||
ret = (int) (rp->ih->ypelspermeter / (100.0 / 2.54) + 0.5);
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
@@ -833,8 +835,8 @@ static struct Palette* s_read_palette(BMPREAD_R rp)
|
||||
*****************************************************************************/
|
||||
static int s_read_masks_from_bitfields(BMPREAD_R rp);
|
||||
static int s_create_implicit_colormasks(BMPREAD_R rp);
|
||||
static inline unsigned long s_calc_bits_for_mask(unsigned long long mask);
|
||||
static inline unsigned long s_calc_shift_for_mask(unsigned long long mask);
|
||||
static inline int s_calc_bits_for_mask(unsigned long long mask);
|
||||
static inline int s_calc_shift_for_mask(unsigned long long mask);
|
||||
|
||||
static int s_read_colormasks(BMPREAD_R rp)
|
||||
{
|
||||
@@ -878,7 +880,7 @@ static int s_read_colormasks(BMPREAD_R rp)
|
||||
return FALSE;
|
||||
}
|
||||
if (!(rp->cmask.mask.red | rp->cmask.mask.green | rp->cmask.mask.blue)) {
|
||||
logerr(rp->log, "Empty color masks. Corrupted BMP?");
|
||||
logerr(rp->log, "Empty color masks. Corrupt BMP?");
|
||||
rp->lasterr = BMP_ERR_INVALID;
|
||||
return FALSE;
|
||||
}
|
||||
@@ -1086,7 +1088,7 @@ static int s_create_implicit_colormasks(BMPREAD_R rp)
|
||||
* s_calc_bits_for_mask
|
||||
*****************************************************************************/
|
||||
|
||||
static inline unsigned long s_calc_bits_for_mask(unsigned long long mask)
|
||||
static inline int s_calc_bits_for_mask(unsigned long long mask)
|
||||
{
|
||||
int bits = 0;
|
||||
|
||||
@@ -1110,7 +1112,7 @@ static inline unsigned long s_calc_bits_for_mask(unsigned long long mask)
|
||||
* s_calc_shift_for_mask
|
||||
*****************************************************************************/
|
||||
|
||||
static inline unsigned long s_calc_shift_for_mask(unsigned long long mask)
|
||||
static inline int s_calc_shift_for_mask(unsigned long long mask)
|
||||
{
|
||||
int shift = 0;
|
||||
|
||||
|
||||
49
bmp-write.c
49
bmp-write.c
@@ -26,6 +26,8 @@
|
||||
#include <stdarg.h>
|
||||
#include <math.h>
|
||||
|
||||
#define BMPLIB_LIB
|
||||
|
||||
#include "config.h"
|
||||
#include "bmplib.h"
|
||||
#include "logging.h"
|
||||
@@ -33,8 +35,6 @@
|
||||
#include "huffman.h"
|
||||
#include "bmp-write.h"
|
||||
|
||||
|
||||
|
||||
static void s_decide_outformat(BMPWRITE_R wp);
|
||||
static int s_write_palette(BMPWRITE_R wp);
|
||||
static int s_save_line_rgb(BMPWRITE_R wp, const unsigned char *line);
|
||||
@@ -351,8 +351,8 @@ API BMPRESULT bmpwrite_set_resolution(BMPHANDLE h, int xdpi, int ydpi)
|
||||
if (s_check_already_saved(wp))
|
||||
return BMP_RESULT_ERROR;
|
||||
|
||||
wp->ih->xpelspermeter = 39.37 * xdpi + 0.5;
|
||||
wp->ih->ypelspermeter = 39.37 * ydpi + 0.5;
|
||||
wp->ih->xpelspermeter = (LONG) (100.0 / 2.54 * xdpi + 0.5);
|
||||
wp->ih->ypelspermeter = (LONG) (100.0 / 2.54 * ydpi + 0.5);
|
||||
|
||||
return BMP_RESULT_OK;
|
||||
}
|
||||
@@ -667,10 +667,10 @@ static void s_decide_outformat(BMPWRITE_R wp)
|
||||
wp->outbytes_per_pixel = wp->ih->bitcount / 8;
|
||||
|
||||
if (wp->ih->version >= BMPINFO_V4 && !wp->out64bit) {
|
||||
wp->ih->redmask = wp->cmask.mask.red << wp->cmask.shift.red;
|
||||
wp->ih->greenmask = wp->cmask.mask.green << wp->cmask.shift.green;
|
||||
wp->ih->bluemask = wp->cmask.mask.blue << wp->cmask.shift.blue;
|
||||
wp->ih->alphamask = wp->cmask.mask.alpha << wp->cmask.shift.alpha;
|
||||
wp->ih->redmask = (DWORD) (wp->cmask.mask.red << wp->cmask.shift.red);
|
||||
wp->ih->greenmask = (DWORD) (wp->cmask.mask.green << wp->cmask.shift.green);
|
||||
wp->ih->bluemask = (DWORD) (wp->cmask.mask.blue << wp->cmask.shift.blue);
|
||||
wp->ih->alphamask = (DWORD) (wp->cmask.mask.alpha << wp->cmask.shift.alpha);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -680,7 +680,7 @@ static void s_decide_outformat(BMPWRITE_R wp)
|
||||
filesize = bitmapsize + BMPFHSIZE + wp->ih->size + wp->palette_size;
|
||||
|
||||
wp->fh->type = 0x4d42; /* "BM" */
|
||||
wp->fh->size = (wp->rle || filesize > UINT32_MAX) ? 0 : filesize;
|
||||
wp->fh->size = (DWORD) ((wp->rle || filesize > UINT32_MAX) ? 0 : filesize);
|
||||
wp->fh->offbits = BMPFHSIZE + wp->ih->size + wp->palette_size;
|
||||
|
||||
wp->ih->width = wp->width;
|
||||
@@ -689,7 +689,7 @@ static void s_decide_outformat(BMPWRITE_R wp)
|
||||
else
|
||||
wp->ih->height = -wp->height;
|
||||
wp->ih->planes = 1;
|
||||
wp->ih->sizeimage = (wp->rle || bitmapsize > UINT32_MAX) ? 0 : bitmapsize;
|
||||
wp->ih->sizeimage = (DWORD) ((wp->rle || bitmapsize > UINT32_MAX) ? 0 : bitmapsize);
|
||||
}
|
||||
|
||||
|
||||
@@ -902,11 +902,11 @@ static int s_try_saving_image_size(BMPWRITE_R wp)
|
||||
|
||||
if (fseek(wp->file, 2, SEEK_SET)) /* file header -> bfSize */
|
||||
return FALSE;
|
||||
if (file_size <= UINT32_MAX && !write_u32_le(wp->file, file_size))
|
||||
if (file_size <= UINT32_MAX && !write_u32_le(wp->file, (uint32_t) file_size))
|
||||
return FALSE;
|
||||
if (fseek(wp->file, 14 + 20, SEEK_SET)) /* info header -> biSizeImage */
|
||||
return FALSE;
|
||||
if (image_size <= UINT32_MAX && !write_u32_le(wp->file, image_size))
|
||||
if (image_size <= UINT32_MAX && !write_u32_le(wp->file, (uint32_t) image_size))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
@@ -919,9 +919,9 @@ static int s_try_saving_image_size(BMPWRITE_R wp)
|
||||
|
||||
static int s_save_line_rgb(BMPWRITE_R wp, const unsigned char *line)
|
||||
{
|
||||
size_t offs;
|
||||
unsigned long bytes = 0;
|
||||
int i, x, bits_used = 0;
|
||||
size_t offs;
|
||||
unsigned long long bytes = 0;
|
||||
int i, x, bits_used = 0;
|
||||
|
||||
for (x = 0; x < wp->width; x++) {
|
||||
offs = (size_t) x * (size_t) wp->source_channels;
|
||||
@@ -939,7 +939,7 @@ static int s_save_line_rgb(BMPWRITE_R wp, const unsigned char *line)
|
||||
}
|
||||
} else {
|
||||
bytes = s_set_outpixel_rgb(wp, line, offs);
|
||||
if (bytes == (unsigned long)-1)
|
||||
if (bytes == (unsigned long long)-1)
|
||||
return BMP_RESULT_ERROR;
|
||||
|
||||
for (i = 0; i < wp->outbytes_per_pixel; i++) {
|
||||
@@ -1296,7 +1296,7 @@ static inline unsigned long long s_set_outpixel_rgb(BMPWRITE_R wp,
|
||||
|
||||
switch (wp->source_format) {
|
||||
case BMP_FORMAT_INT:
|
||||
source_max = (1ULL<<wp->source_bitsperchannel) - 1;
|
||||
source_max = (double) ((1ULL<<wp->source_bitsperchannel) - 1);
|
||||
switch(wp->source_bitsperchannel) {
|
||||
case 8:
|
||||
comp[0] = buffer[offs];
|
||||
@@ -1327,7 +1327,8 @@ static inline unsigned long long s_set_outpixel_rgb(BMPWRITE_R wp,
|
||||
return (unsigned long long)-1;
|
||||
}
|
||||
for (i = 0; i < outchannels; i++) {
|
||||
comp[i] = comp[i] * (wp->out64bit ? 8192.0 : wp->cmask.maxval.val[i]) / source_max + 0.5;
|
||||
comp[i] = (unsigned long) (comp[i] * (wp->out64bit ? 8192.0 :
|
||||
wp->cmask.maxval.val[i]) / source_max + 0.5);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -1348,9 +1349,9 @@ static inline unsigned long long s_set_outpixel_rgb(BMPWRITE_R wp,
|
||||
if (dcomp[i] < 0.0)
|
||||
comp[i] = 0;
|
||||
else if (dcomp[i] > 1.0)
|
||||
comp[i] = wp->cmask.mask.value[i];
|
||||
comp[i] = (unsigned long) wp->cmask.mask.value[i];
|
||||
else
|
||||
comp[i] = dcomp[i] * wp->cmask.maxval.val[i] + 0.5;
|
||||
comp[i] = (unsigned long) (dcomp[i] * wp->cmask.maxval.val[i] + 0.5);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -1370,9 +1371,9 @@ static inline unsigned long long s_set_outpixel_rgb(BMPWRITE_R wp,
|
||||
if (comp[i] & 0x8000)
|
||||
comp[i] = 0;
|
||||
else if (comp[i] > 0x2000)
|
||||
comp[i] = wp->cmask.mask.value[i];
|
||||
comp[i] = (unsigned long) wp->cmask.mask.value[i];
|
||||
else
|
||||
comp[i] = comp[i] / 8192.0 * wp->cmask.maxval.val[i] + 0.5;
|
||||
comp[i] = (unsigned long) (comp[i] / 8192.0 * wp->cmask.maxval.val[i] + 0.5);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -1383,7 +1384,7 @@ static inline unsigned long long s_set_outpixel_rgb(BMPWRITE_R wp,
|
||||
}
|
||||
|
||||
for (i = 0, bytes = 0; i < outchannels; i++) {
|
||||
bytes |= ((unsigned long long) (comp[i] & wp->cmask.mask.value[i])) << wp->cmask.shift.value[i];
|
||||
bytes |= ((unsigned long long)comp[i] & wp->cmask.mask.value[i]) << wp->cmask.shift.value[i];
|
||||
}
|
||||
if (!wp->has_alpha && wp->out64bit)
|
||||
bytes |= 8192ULL << wp->cmask.shift.alpha;
|
||||
@@ -1502,7 +1503,7 @@ static int s_write_bmp_info_header(BMPWRITE_R wp)
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
for (int i = 0; i < wp->ih->size - 40; i++) {
|
||||
for (int i = 0; (DWORD) i < wp->ih->size - 40; i++) {
|
||||
if (EOF == putc(0, wp->file))
|
||||
return FALSE;
|
||||
wp->bytes_written++;
|
||||
|
||||
105
bmplib.h
105
bmplib.h
@@ -31,6 +31,17 @@
|
||||
#define DEPR(m)
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
#ifdef BMPLIB_LIB
|
||||
#define APIDECL __declspec(dllexport)
|
||||
#else
|
||||
#define APIDECL __declspec(dllimport)
|
||||
#endif
|
||||
#else
|
||||
#define APIDECL
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct Bmphandle *BMPHANDLE;
|
||||
|
||||
|
||||
@@ -194,80 +205,80 @@ enum BmpFormat {
|
||||
typedef enum BmpFormat BMPFORMAT;
|
||||
|
||||
|
||||
BMPHANDLE bmpread_new(FILE *file);
|
||||
APIDECL BMPHANDLE bmpread_new(FILE *file);
|
||||
|
||||
BMPRESULT bmpread_load_info(BMPHANDLE h);
|
||||
APIDECL BMPRESULT bmpread_load_info(BMPHANDLE h);
|
||||
|
||||
BMPRESULT bmpread_dimensions(BMPHANDLE h,
|
||||
APIDECL BMPRESULT bmpread_dimensions(BMPHANDLE h,
|
||||
int *width,
|
||||
int *height,
|
||||
int *channels,
|
||||
int *bitsperchannel,
|
||||
BMPORIENT *orientation);
|
||||
|
||||
int bmpread_width(BMPHANDLE h);
|
||||
int bmpread_height(BMPHANDLE h);
|
||||
int bmpread_channels(BMPHANDLE h);
|
||||
int bmpread_bitsperchannel(BMPHANDLE h);
|
||||
BMPORIENT bmpread_orientation(BMPHANDLE h);
|
||||
APIDECL int bmpread_width(BMPHANDLE h);
|
||||
APIDECL int bmpread_height(BMPHANDLE h);
|
||||
APIDECL int bmpread_channels(BMPHANDLE h);
|
||||
APIDECL int bmpread_bitsperchannel(BMPHANDLE h);
|
||||
APIDECL BMPORIENT bmpread_orientation(BMPHANDLE h);
|
||||
|
||||
int bmpread_resolution_xdpi(BMPHANDLE h);
|
||||
int bmpread_resolution_ydpi(BMPHANDLE h);
|
||||
APIDECL int bmpread_resolution_xdpi(BMPHANDLE h);
|
||||
APIDECL int bmpread_resolution_ydpi(BMPHANDLE h);
|
||||
|
||||
size_t bmpread_buffersize(BMPHANDLE h);
|
||||
APIDECL size_t bmpread_buffersize(BMPHANDLE h);
|
||||
|
||||
BMPRESULT bmpread_load_image(BMPHANDLE h, unsigned char **buffer);
|
||||
BMPRESULT bmpread_load_line(BMPHANDLE h, unsigned char **buffer);
|
||||
APIDECL BMPRESULT bmpread_load_image(BMPHANDLE h, unsigned char **buffer);
|
||||
APIDECL BMPRESULT bmpread_load_line(BMPHANDLE h, unsigned char **buffer);
|
||||
|
||||
|
||||
int bmpread_num_palette_colors(BMPHANDLE h);
|
||||
BMPRESULT bmpread_load_palette(BMPHANDLE h, unsigned char **palette);
|
||||
APIDECL int bmpread_num_palette_colors(BMPHANDLE h);
|
||||
APIDECL BMPRESULT bmpread_load_palette(BMPHANDLE h, unsigned char **palette);
|
||||
|
||||
|
||||
void bmpread_set_undefined(BMPHANDLE h, BMPUNDEFINED mode);
|
||||
void bmpread_set_insanity_limit(BMPHANDLE h, size_t limit);
|
||||
APIDECL void bmpread_set_undefined(BMPHANDLE h, BMPUNDEFINED mode);
|
||||
APIDECL void bmpread_set_insanity_limit(BMPHANDLE h, size_t limit);
|
||||
|
||||
int bmpread_is_64bit(BMPHANDLE h);
|
||||
BMPRESULT bmpread_set_64bit_conv(BMPHANDLE h, BMPCONV64 conv);
|
||||
APIDECL int bmpread_is_64bit(BMPHANDLE h);
|
||||
APIDECL BMPRESULT bmpread_set_64bit_conv(BMPHANDLE h, BMPCONV64 conv);
|
||||
|
||||
BMPINFOVER bmpread_info_header_version(BMPHANDLE h);
|
||||
const char* bmpread_info_header_name(BMPHANDLE h);
|
||||
int bmpread_info_header_size(BMPHANDLE h);
|
||||
int bmpread_info_compression(BMPHANDLE h);
|
||||
const char* bmpread_info_compression_name(BMPHANDLE h);
|
||||
int bmpread_info_bitcount(BMPHANDLE h);
|
||||
BMPRESULT bmpread_info_channel_bits(BMPHANDLE h, int *r, int *g, int *b, int *a);
|
||||
APIDECL BMPINFOVER bmpread_info_header_version(BMPHANDLE h);
|
||||
APIDECL const char* bmpread_info_header_name(BMPHANDLE h);
|
||||
APIDECL int bmpread_info_header_size(BMPHANDLE h);
|
||||
APIDECL int bmpread_info_compression(BMPHANDLE h);
|
||||
APIDECL const char* bmpread_info_compression_name(BMPHANDLE h);
|
||||
APIDECL int bmpread_info_bitcount(BMPHANDLE h);
|
||||
APIDECL BMPRESULT bmpread_info_channel_bits(BMPHANDLE h, int *r, int *g, int *b, int *a);
|
||||
|
||||
|
||||
|
||||
|
||||
BMPHANDLE bmpwrite_new(FILE *file);
|
||||
APIDECL BMPHANDLE bmpwrite_new(FILE *file);
|
||||
|
||||
BMPRESULT bmpwrite_set_dimensions(BMPHANDLE h,
|
||||
APIDECL BMPRESULT bmpwrite_set_dimensions(BMPHANDLE h,
|
||||
unsigned width,
|
||||
unsigned height,
|
||||
unsigned channels,
|
||||
unsigned bitsperchannel);
|
||||
BMPRESULT bmpwrite_set_resolution(BMPHANDLE h, int xdpi, int ydpi);
|
||||
BMPRESULT bmpwrite_set_output_bits(BMPHANDLE h, int red, int green, int blue, int alpha);
|
||||
BMPRESULT bmpwrite_set_palette(BMPHANDLE h, int numcolors, const unsigned char *palette);
|
||||
BMPRESULT bmpwrite_allow_2bit(BMPHANDLE h);
|
||||
BMPRESULT bmpwrite_allow_huffman(BMPHANDLE h);
|
||||
BMPRESULT bmpwrite_set_rle(BMPHANDLE h, BMPRLETYPE type);
|
||||
BMPRESULT bmpwrite_set_orientation(BMPHANDLE h, BMPORIENT orientation);
|
||||
BMPRESULT bmpwrite_set_64bit(BMPHANDLE h);
|
||||
APIDECL BMPRESULT bmpwrite_set_resolution(BMPHANDLE h, int xdpi, int ydpi);
|
||||
APIDECL BMPRESULT bmpwrite_set_output_bits(BMPHANDLE h, int red, int green, int blue, int alpha);
|
||||
APIDECL BMPRESULT bmpwrite_set_palette(BMPHANDLE h, int numcolors, const unsigned char *palette);
|
||||
APIDECL BMPRESULT bmpwrite_allow_2bit(BMPHANDLE h);
|
||||
APIDECL BMPRESULT bmpwrite_allow_huffman(BMPHANDLE h);
|
||||
APIDECL BMPRESULT bmpwrite_set_rle(BMPHANDLE h, BMPRLETYPE type);
|
||||
APIDECL BMPRESULT bmpwrite_set_orientation(BMPHANDLE h, BMPORIENT orientation);
|
||||
APIDECL BMPRESULT bmpwrite_set_64bit(BMPHANDLE h);
|
||||
|
||||
BMPRESULT bmpwrite_save_image(BMPHANDLE h, const unsigned char *image);
|
||||
BMPRESULT bmpwrite_save_line(BMPHANDLE h, const unsigned char *line);
|
||||
APIDECL BMPRESULT bmpwrite_save_image(BMPHANDLE h, const unsigned char *image);
|
||||
APIDECL BMPRESULT bmpwrite_save_line(BMPHANDLE h, const unsigned char *line);
|
||||
|
||||
|
||||
BMPRESULT bmp_set_number_format(BMPHANDLE h, BMPFORMAT format);
|
||||
APIDECL BMPRESULT bmp_set_number_format(BMPHANDLE h, BMPFORMAT format);
|
||||
|
||||
void bmp_free(BMPHANDLE h);
|
||||
APIDECL void bmp_free(BMPHANDLE h);
|
||||
|
||||
const char* bmp_errmsg(BMPHANDLE h);
|
||||
APIDECL const char* bmp_errmsg(BMPHANDLE h);
|
||||
|
||||
const char* bmp_version(void);
|
||||
APIDECL const char* bmp_version(void);
|
||||
|
||||
|
||||
/* these errorcodes aren't part of the API yet, but will be.
|
||||
@@ -304,15 +315,11 @@ const char* bmp_version(void);
|
||||
* removed from future versions:
|
||||
*/
|
||||
|
||||
int DEPR("use bmpread_orientation() instead") bmpread_topdown(BMPHANDLE h);
|
||||
void DEPR("use bmpread_set_undefined() instead") bmpread_set_undefined_to_alpha(BMPHANDLE h, int mode);
|
||||
int DEPR("use bmpread_bitsperchannel() instead") bmpread_bits_per_channel(BMPHANDLE h);
|
||||
APIDECL int DEPR("use bmpread_orientation() instead") bmpread_topdown(BMPHANDLE h);
|
||||
APIDECL void DEPR("use bmpread_set_undefined() instead") bmpread_set_undefined_to_alpha(BMPHANDLE h, int mode);
|
||||
APIDECL int DEPR("use bmpread_bitsperchannel() instead") bmpread_bits_per_channel(BMPHANDLE h);
|
||||
|
||||
|
||||
#ifdef DEBUG
|
||||
void print_huff_table(void);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
29
logging.c
29
logging.c
@@ -22,6 +22,7 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <limits.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "config.h"
|
||||
@@ -29,24 +30,25 @@
|
||||
|
||||
|
||||
struct Log {
|
||||
size_t size;
|
||||
char *buffer;
|
||||
int size;
|
||||
char *buffer;
|
||||
};
|
||||
|
||||
|
||||
/* logerr(log, fmt, ...) and logsyserr(log, fmt, ...) are
|
||||
* printf-style logging functions.
|
||||
*
|
||||
* Use logsyserr() where perror() would be used, logerr()
|
||||
* otherwise.
|
||||
*
|
||||
* 'separator' and 'inter' can have any length
|
||||
* 'air' is just there so we don't need to realloc every
|
||||
* single time.
|
||||
*/
|
||||
|
||||
|
||||
static const char separator[]="\n"; /* separator between log entries */
|
||||
static const char inter[]=": "; /* between own message and sys err text */
|
||||
static const int air = 80; /* how much more than required we allocate */
|
||||
static const int air = 80; /* how much more than required we allocate */
|
||||
|
||||
static int s_allocate(LOG log, size_t add_chars);
|
||||
static void s_log(LOG log, const char *file, int line, const char *function,
|
||||
@@ -75,7 +77,7 @@ LOG logcreate(void)
|
||||
void logfree(LOG log)
|
||||
{
|
||||
if (log) {
|
||||
if (log->size != (size_t)-1 && log->buffer)
|
||||
if (log->size != -1 && log->buffer)
|
||||
free(log->buffer);
|
||||
free(log);
|
||||
}
|
||||
@@ -165,7 +167,7 @@ static void s_log(LOG log, const char *file, int line, const char *function,
|
||||
va_list argsdup;
|
||||
int len = 0,addl_len, required_len;
|
||||
|
||||
if (log->size == (size_t)-1)
|
||||
if (log->size == -1)
|
||||
return; /* log is set to a string literal (panic) */
|
||||
|
||||
#ifdef DEBUG
|
||||
@@ -219,20 +221,27 @@ static int s_allocate(LOG log, size_t add_chars)
|
||||
char *tmp;
|
||||
size_t newsize;
|
||||
|
||||
if (log->size == (size_t)-1)
|
||||
if (log->size == -1)
|
||||
return 0; /* log is set to a string literal (panic) */
|
||||
|
||||
add_chars += air;
|
||||
|
||||
newsize = log->size + add_chars;
|
||||
newsize = (size_t) log->size + add_chars;
|
||||
if (newsize > INT_MAX) {
|
||||
panic(log);
|
||||
return 0;
|
||||
}
|
||||
|
||||
tmp = realloc(log->buffer, newsize);
|
||||
if (tmp) {
|
||||
log->buffer = tmp;
|
||||
if (log->size == 0)
|
||||
log->buffer[0] = 0;
|
||||
log->size = newsize;
|
||||
} else
|
||||
} else {
|
||||
panic(log);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -245,7 +254,7 @@ static int s_allocate(LOG log, size_t add_chars)
|
||||
|
||||
static void panic(LOG log)
|
||||
{
|
||||
log->size = (size_t) -1;
|
||||
log->size = -1;
|
||||
log->buffer = "PANIC! bmplib encountered an error while trying to set "
|
||||
"an error message";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user