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

Fixed compilation for older C #915

Closed
wants to merge 5 commits into from
Closed
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
37 changes: 18 additions & 19 deletions addons/color/color.c
Original file line number Diff line number Diff line change
Expand Up @@ -764,27 +764,26 @@ double al_color_distance_ciede2000(ALLEGRO_COLOR color1,
* http://www.ece.rochester.edu/~gsharma/ciede2000/ciede2000noteCRNA.pdf
*/
float l1, a1, b1, l2, a2, b2;
double pi = ALLEGRO_PI, dl, ml, c1, c2, mc, fac, g, dc, h1, h2, dh = 0, mh, t, sl, mls, sc, sh, rt;
al_color_rgb_to_lab(color1.r, color1.g, color1.b, &l1, &a1, &b1);
al_color_rgb_to_lab(color2.r, color2.g, color2.b, &l2, &a2, &b2);
double pi = ALLEGRO_PI;
double dl = l1 - l2;
double ml = (l1 + l2) / 2;
double c1 = sqrt(a1 * a1 + b1 * b1);
double c2 = sqrt(a2 * a2 + b2 * b2);
double mc = (c1 + c2) / 2;
double fac = sqrt(pow(mc, 7) / (pow(mc, 7) + tf7));
double g = 0.5 * (1 - fac);
dl = l1 - l2;
ml = (l1 + l2) / 2;
c1 = sqrt(a1 * a1 + b1 * b1);
c2 = sqrt(a2 * a2 + b2 * b2);
mc = (c1 + c2) / 2;
fac = sqrt(pow(mc, 7) / (pow(mc, 7) + tf7));
g = 0.5 * (1 - fac);
a1 *= 1 + g;
a2 *= 1 + g;
c1 = sqrt(a1 * a1 + b1 * b1);
c2 = sqrt(a2 * a2 + b2 * b2);
double dc = c2 - c1;
dc = c2 - c1;
mc = (c1 + c2) / 2;
fac = sqrt(pow(mc, 7) / (pow(mc, 7) + tf7));
double h1 = fmod(2 * pi + atan2(b1, a1), 2 * pi);
double h2 = fmod(2 * pi + atan2(b2, a2), 2 * pi);
double dh = 0;
double mh = h1 + h2;
h1 = fmod(2 * pi + atan2(b1, a1), 2 * pi);
h2 = fmod(2 * pi + atan2(b2, a2), 2 * pi);
mh = h1 + h2;
if (c1 * c2 != 0) {
dh = h2 - h1;
if (dh > pi) dh -= 2 * pi;
Expand All @@ -794,13 +793,13 @@ double al_color_distance_ciede2000(ALLEGRO_COLOR color1,
else mh = (h1 + h2 - 2 * pi) / 2;
}
dh = 2 * sqrt(c1 * c2) * sin(dh / 2);
double t = 1 - 0.17 * cos(mh - pi / 6) + 0.24 * cos(2 * mh) +
t = 1 - 0.17 * cos(mh - pi / 6) + 0.24 * cos(2 * mh) +
0.32 * cos(3 * mh + pi / 30) - 0.2 * cos(4 * mh - pi * 7 / 20);
double mls = pow(ml - 0.5, 2);
double sl = 1 + 1.5 * mls / sqrt(0.002 + mls);
double sc = 1 + 4.5 * mc;
double sh = 1 + 1.5 * mc * t;
double rt = -2 * fac * sin(pi / 3 *
mls = pow(ml - 0.5, 2);
sl = 1 + 1.5 * mls / sqrt(0.002 + mls);
sc = 1 + 4.5 * mc;
sh = 1 + 1.5 * mc * t;
rt = -2 * fac * sin(pi / 3 *
exp(-pow(mh / pi * 36 / 5 - 11, 2)));
return sqrt(pow(dl / sl, 2) + pow(dc / sc, 2) +
pow(dh / sh, 2) + rt * dc / sc * dh / sh);
Expand Down
39 changes: 24 additions & 15 deletions addons/font/bmfont.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,9 @@ static void add_codepoint(BMFONT_PARSER *parser, int codepoint) {
return;
}
if (codepoint == range->first + range->count) {
BMFONT_RANGE * range2;
append_char(parser, range);
BMFONT_RANGE *range2 = range->next;
range2 = range->next;
if (range2 != NULL && codepoint == range2->first - 1) {
combine_ranges(data, range, range2);
}
Expand All @@ -154,11 +155,12 @@ static BMFONT_CHAR *find_codepoint(BMFONT_DATA *data, int codepoint) {
static void add_page(BMFONT_PARSER *parser, char const *filename) {
ALLEGRO_FONT *font = parser->font;
BMFONT_DATA *data = font->data;
ALLEGRO_BITMAP *page;
data->pages_count++;
data->pages = al_realloc(data->pages, data->pages_count *
sizeof *data->pages);
al_set_path_filename(parser->path, filename);
ALLEGRO_BITMAP *page = al_load_bitmap_flags(
page = al_load_bitmap_flags(
al_path_cstr(parser->path, '/'), data->flags);
data->pages[data->pages_count - 1] = page;
}
Expand Down Expand Up @@ -244,8 +246,8 @@ static int font_descent(const ALLEGRO_FONT *f) {
}

static int get_kerning(BMFONT_CHAR *prev, int c) {
if (!prev) return 0;
int i;
if (!prev) return 0;
for (i = 0; i < prev->kerning_pairs; i++) {
if (prev->kerning[i].second == c) {
int a = prev->kerning[i].amount;
Expand Down Expand Up @@ -278,12 +280,14 @@ static int each_character(const ALLEGRO_FONT *f, ALLEGRO_COLOR color,

static int measure_char(const ALLEGRO_FONT *f, ALLEGRO_COLOR color,
int ch, float x, float y, ALLEGRO_GLYPH *glyph) {
(void)color;
(void)y;
BMFONT_DATA *data = f->data;
BMFONT_CHAR *c = find_codepoint(data, ch);
BMFONT_DATA *data;
BMFONT_CHAR *c;
int advance = 0;
int xo = 0, yo = 0, w = 0, h = 0;
(void)color;
(void)y;
data = f->data;
c = find_codepoint(data, ch);
if (c) {
advance = c->xadvance;
xo = c->xoffset;
Expand Down Expand Up @@ -378,12 +382,13 @@ static int text_length(const ALLEGRO_FONT *f, const ALLEGRO_USTR *text) {
static int render_char(const ALLEGRO_FONT *f, ALLEGRO_COLOR color, int ch, float x, float y) {
BMFONT_DATA *data = f->data;
BMFONT_CHAR *c = find_codepoint(data, ch);
ALLEGRO_BITMAP *page;
if (!c) {
if (f->fallback) return f->fallback->vtable->render_char(
f->fallback, color, ch, x, y);
return 0;
}
ALLEGRO_BITMAP *page = data->pages[c->page];
page = data->pages[c->page];
al_draw_tinted_bitmap_region(page, color, c->x, c->y, c->width, c->height,
x + c->xoffset, y + c->yoffset, 0);
return c->xadvance;
Expand Down Expand Up @@ -413,13 +418,13 @@ static void destroy_range(BMFONT_RANGE *range) {
static void destroy(ALLEGRO_FONT *f) {
BMFONT_DATA *data = f->data;
BMFONT_RANGE *range = data->range_first;
int i;
while (range) {
BMFONT_RANGE *next = range->next;
destroy_range(range);
range = next;
}

int i;
for (i = 0; i < data->pages_count; i++) {
al_destroy_bitmap(data->pages[i]);
}
Expand Down Expand Up @@ -479,29 +484,33 @@ static ALLEGRO_FONT_VTABLE _al_font_vtable_xml = {
ALLEGRO_FONT *_al_load_bmfont_xml(const char *filename, int size,
int font_flags)
{
ALLEGRO_FILE *f;
BMFONT_PARSER _parser;
BMFONT_PARSER *parser;
BMFONT_DATA *data;
ALLEGRO_FONT *font;
int i;
(void)size;
ALLEGRO_FILE *f = al_fopen(filename, "r");
f = al_fopen(filename, "r");
if (!f) {
ALLEGRO_DEBUG("Could not open %s.\n", filename);
return NULL;
}

BMFONT_DATA *data = al_calloc(1, sizeof *data);
BMFONT_PARSER _parser;
BMFONT_PARSER *parser = &_parser;
data = al_calloc(1, sizeof *data);
parser = &_parser;
parser->tag = al_ustr_new("");
parser->attribute = al_ustr_new("");
parser->path = al_create_path(filename);
data->flags = font_flags;

ALLEGRO_FONT *font = al_calloc(1, sizeof *font);
font = al_calloc(1, sizeof *font);
font->vtable = &_al_font_vtable_xml;
font->data = data;
parser->font = font;

_al_xml_parse(f, xml_callback, parser);

int i;
for (i = 0; i < data->kerning_pairs; i++) {
BMFONT_KERNING *k = data->kerning + i;
BMFONT_CHAR *c = find_codepoint(data, k->first);
Expand Down
3 changes: 2 additions & 1 deletion addons/image/jpg.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ static void save_jpg_entry_helper(ALLEGRO_FILE *fp, ALLEGRO_BITMAP *bmp,
{
struct jpeg_compress_struct cinfo;
struct my_err_mgr jerr;
const char *level;
ALLEGRO_LOCKED_REGION *lock;

data->error = false;
Expand Down Expand Up @@ -325,7 +326,7 @@ static void save_jpg_entry_helper(ALLEGRO_FILE *fp, ALLEGRO_BITMAP *bmp,
cinfo.in_color_space = JCS_RGB;
jpeg_set_defaults(&cinfo);

const char* level = al_get_config_value(al_get_system_config(), "image", "jpeg_quality_level");
level = al_get_config_value(al_get_system_config(), "image", "jpeg_quality_level");
jpeg_set_quality(&cinfo, level ? strtol(level, NULL, 10) : 75, true);

jpeg_start_compress(&cinfo, 1);
Expand Down
3 changes: 2 additions & 1 deletion addons/image/pcx.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ ALLEGRO_BITMAP *_al_load_pcx_f(ALLEGRO_FILE *f, int flags)
unsigned char *buf;
PalEntry pal[256];
bool keep_index;
char color_plane;
ASSERT(f);

al_fgetc(f); /* skip manufacturer ID */
al_fgetc(f); /* skip version flag */
al_fgetc(f); /* skip encoding flag */

char color_plane = al_fgetc(f);
color_plane = al_fgetc(f);
if (color_plane != 8) { /* we like 8 bit color planes */
ALLEGRO_ERROR("Invalid color plane %d.\n", color_plane);
return NULL;
Expand Down
3 changes: 2 additions & 1 deletion addons/image/png.c
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ bool _al_save_png_f(ALLEGRO_FILE *fp, ALLEGRO_BITMAP *bmp)
png_structp png_ptr = NULL;
png_infop info_ptr = NULL;
int colour_type;
int z_level;

/* Create and initialize the png_struct with the
* desired error handler functions.
Expand Down Expand Up @@ -545,7 +546,7 @@ bool _al_save_png_f(ALLEGRO_FILE *fp, ALLEGRO_BITMAP *bmp)
colour_type = PNG_COLOR_TYPE_RGB_ALPHA;

/* Set compression level. */
int z_level = translate_compression_level(
z_level = translate_compression_level(
al_get_config_value(al_get_system_config(), "image", "png_compression_level")
);
png_set_compression_level(png_ptr, z_level);
Expand Down
2 changes: 1 addition & 1 deletion addons/ttf/ttf.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ static unsigned char *alloc_glyph_region(ALLEGRO_TTF_FONT_DATA *data,
bool lock_whole_page)
{
ALLEGRO_BITMAP *page;
REGION lock_rect;
int w4 = align4(w);
int h4 = align4(h);
int glyph_size = w4 > h4 ? w4 : h4;
Expand Down Expand Up @@ -264,7 +265,6 @@ static unsigned char *alloc_glyph_region(ALLEGRO_TTF_FONT_DATA *data,
data->page_line_height = h4;
}

REGION lock_rect;
if (lock_whole_page) {
lock_rect.x = 0;
lock_rect.y = 0;
Expand Down
3 changes: 2 additions & 1 deletion src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -706,13 +706,14 @@ bool al_remove_config_key(ALLEGRO_CONFIG *config, char const *section,
ALLEGRO_USTR const *ukey = al_ref_cstr(&key_info, key);
void *value;
ALLEGRO_CONFIG_ENTRY * e;
ALLEGRO_CONFIG_SECTION *s;

if (section == NULL)
section = "";

usection = al_ref_cstr(&section_info, section);

ALLEGRO_CONFIG_SECTION *s = find_section(config, usection);
s = find_section(config, usection);
if (!s)
return false;

Expand Down
3 changes: 1 addition & 2 deletions src/opengl/extensions.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ static uint32_t parse_opengl_version(const char *s)
/* Reads version info out of glGetString(GL_VERSION) */
static uint32_t _al_ogl_version(void)
{
const char *str;
char const *value = al_get_config_value(al_get_system_config(), "opengl",
"force_opengl_version");
if (value) {
Expand All @@ -145,8 +146,6 @@ static uint32_t _al_ogl_version(void)
return v;
}

const char *str;

str = (const char *)glGetString(GL_VERSION);
if (str) {
#ifdef ALLEGRO_CFG_OPENGLES
Expand Down
3 changes: 2 additions & 1 deletion src/opengl/ogl_bitmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,7 @@ GLuint al_get_opengl_texture(ALLEGRO_BITMAP *bitmap)
*/
void al_remove_opengl_fbo(ALLEGRO_BITMAP *bitmap)
{
ALLEGRO_FBO_INFO *info;
ALLEGRO_BITMAP_EXTRA_OPENGL *ogl_bitmap;
if (bitmap->parent)
bitmap = bitmap->parent;
Expand All @@ -1157,7 +1158,7 @@ void al_remove_opengl_fbo(ALLEGRO_BITMAP *bitmap)
ASSERT(ogl_bitmap->fbo_info->fbo_state > FBO_INFO_UNUSED);
ASSERT(ogl_bitmap->fbo_info->fbo != 0);

ALLEGRO_FBO_INFO *info = ogl_bitmap->fbo_info;
info = ogl_bitmap->fbo_info;
_al_ogl_del_fbo(info);

if (info->fbo_state == FBO_INFO_PERSISTENT) {
Expand Down
26 changes: 18 additions & 8 deletions src/opengl/ogl_fbo.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,18 @@ static void attach_depth_buffer(ALLEGRO_FBO_INFO *info)
ALLEGRO_DISPLAY *display = _al_get_bitmap_display(info->owner);
int w = al_get_bitmap_width(info->owner);
int h = al_get_bitmap_height(info->owner);
int samples = 0;
bool extension_supported;
GLint e;

if (bits == 24) gldepth = GL_DEPTH_COMPONENT24;

glGenRenderbuffersEXT(1, &rb);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, rb);

int samples = al_get_bitmap_samples(info->owner);
samples = al_get_bitmap_samples(info->owner);

bool extension_supported;

#ifdef ALLEGRO_CFG_OPENGLES
(void)display;
extension_supported = al_have_opengl_extension("EXT_multisampled_render_to_texture");
Expand All @@ -206,7 +209,7 @@ static void attach_depth_buffer(ALLEGRO_FBO_INFO *info)
info->buffers.dw = w;
info->buffers.dw = h;
info->buffers.depth = bits;
GLint e = glGetError();
e = glGetError();
if (e) {
ALLEGRO_ERROR("glRenderbufferStorage failed! bits=%d w=%d h=%d (%s)\n",
bits, w, h, _al_gl_error_string(e));
Expand All @@ -232,6 +235,7 @@ static void attach_multisample_buffer(ALLEGRO_FBO_INFO *info)
{
#if !defined ALLEGRO_RASPBERRYPI && (!defined ALLEGRO_ANDROID || defined ALLEGRO_CFG_OPENGLES3)
ALLEGRO_BITMAP *b = info->owner;
ALLEGRO_DISPLAY *display = NULL;
int samples = al_get_bitmap_samples(b);

if (info->buffers.multisample_buffer != 0) {
Expand All @@ -245,7 +249,7 @@ static void attach_multisample_buffer(ALLEGRO_FBO_INFO *info)

if (!samples)
return;
ALLEGRO_DISPLAY *display = _al_get_bitmap_display(info->owner);
display = _al_get_bitmap_display(info->owner);
if (!display->ogl_extras->extension_list->ALLEGRO_GL_EXT_framebuffer_multisample)
return;

Expand Down Expand Up @@ -505,20 +509,26 @@ void _al_ogl_setup_fbo(ALLEGRO_DISPLAY *display, ALLEGRO_BITMAP *bitmap)
void _al_ogl_finalize_fbo(ALLEGRO_DISPLAY *display,
ALLEGRO_BITMAP *bitmap)
{
ALLEGRO_FBO_INFO *info = NULL;
ALLEGRO_BITMAP_EXTRA_OPENGL *extra = bitmap->extra;

#ifndef ALLEGRO_CFG_OPENGLES
int w, h;
GLuint blit_fbo;
#endif

if (!extra)
return;
ALLEGRO_FBO_INFO *info = extra->fbo_info;
info = extra->fbo_info;
(void)display;
if (!info)
return;
if (!info->buffers.multisample_buffer)
return;
#ifndef ALLEGRO_CFG_OPENGLES
int w = al_get_bitmap_width(bitmap);
int h = al_get_bitmap_height(bitmap);
w = al_get_bitmap_width(bitmap);
h = al_get_bitmap_height(bitmap);

GLuint blit_fbo;
glGenFramebuffersEXT(1, &blit_fbo);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, blit_fbo);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
Expand Down
5 changes: 4 additions & 1 deletion src/win/wgl_disp.c
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,7 @@ static bool create_display_internals(ALLEGRO_DISPLAY_WGL *wgl_disp)
WGL_DISPLAY_PARAMETERS ndp;
int window_x, window_y;
int major, minor;
bool fc = false;

/* The window is created in a separate thread so we need to pass this
* TLS on
Expand Down Expand Up @@ -967,7 +968,9 @@ static bool create_display_internals(ALLEGRO_DISPLAY_WGL *wgl_disp)
if ((disp->flags & ALLEGRO_OPENGL_3_0) || major != 0) {
if (major == 0)
major = 3;
bool fc = (disp->flags & ALLEGRO_OPENGL_FORWARD_COMPATIBLE) != 0;
if (disp->flags & ALLEGRO_OPENGL_FORWARD_COMPATIBLE)
fc = true;

wgl_disp->glrc = init_ogl_context_ex(wgl_disp->dc, fc, major,
minor);
}
Expand Down