From 82677e551820b74eb366ca60060d18acb3a12f69 Mon Sep 17 00:00:00 2001 From: Fabian Giesen Date: Mon, 8 Dec 2014 19:51:39 -0800 Subject: [PATCH 1/2] stb_truetype: Fix implicit conversion warnings. --- stb_truetype.h | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/stb_truetype.h b/stb_truetype.h index cc0173d..85d47c1 100644 --- a/stb_truetype.h +++ b/stb_truetype.h @@ -869,7 +869,7 @@ enum { // languageID for STBTT_PLATFORM_ID_MAC #define STBTT_MAX_OVERSAMPLE 8 #endif -typedef stbtt__test_oversample_pow2[(STBTT_MAX_OVERSAMPLE & (STBTT_MAX_OVERSAMPLE-1)) == 0 ? 1 : -1]; +typedef int stbtt__test_oversample_pow2[(STBTT_MAX_OVERSAMPLE & (STBTT_MAX_OVERSAMPLE-1)) == 0 ? 1 : -1]; ////////////////////////////////////////////////////////////////////////// // @@ -2173,7 +2173,6 @@ static void stbtt__h_prefilter(unsigned char *pixels, int w, int h, int stride_i for (j=0; j < h; ++j) { int i; unsigned int total; - unsigned char *pixels_ahead = pixels + (kernel_width); memset(buffer, 0, kernel_width); total = 0; @@ -2184,28 +2183,28 @@ static void stbtt__h_prefilter(unsigned char *pixels, int w, int h, int stride_i for (i=0; i <= safe_w; ++i) { total += pixels[i] - buffer[i & STBTT__OVER_MASK]; buffer[(i+kernel_width) & STBTT__OVER_MASK] = pixels[i]; - pixels[i] = total / 2; + pixels[i] = (unsigned char) (total / 2); } break; case 3: for (i=0; i <= safe_w; ++i) { total += pixels[i] - buffer[i & STBTT__OVER_MASK]; buffer[(i+kernel_width) & STBTT__OVER_MASK] = pixels[i]; - pixels[i] = total / 3; + pixels[i] = (unsigned char) (total / 3); } break; case 4: for (i=0; i <= safe_w; ++i) { total += pixels[i] - buffer[i & STBTT__OVER_MASK]; buffer[(i+kernel_width) & STBTT__OVER_MASK] = pixels[i]; - pixels[i] = total / 4; + pixels[i] = (unsigned char) (total / 4); } break; default: for (i=0; i <= safe_w; ++i) { total += pixels[i] - buffer[i & STBTT__OVER_MASK]; buffer[(i+kernel_width) & STBTT__OVER_MASK] = pixels[i]; - pixels[i] = total / kernel_width; + pixels[i] = (unsigned char) (total / kernel_width); } break; } @@ -2213,7 +2212,7 @@ static void stbtt__h_prefilter(unsigned char *pixels, int w, int h, int stride_i for (; i < w; ++i) { assert(pixels[i] == 0); total -= buffer[i & STBTT__OVER_MASK]; - pixels[i] = total / kernel_width; + pixels[i] = (unsigned char) (total / kernel_width); } pixels += stride_in_bytes; @@ -2228,7 +2227,6 @@ static void stbtt__v_prefilter(unsigned char *pixels, int w, int h, int stride_i for (j=0; j < w; ++j) { int i; unsigned int total; - unsigned char *pixels_ahead = pixels + (kernel_width)*stride_in_bytes; memset(buffer, 0, kernel_width); total = 0; @@ -2239,28 +2237,28 @@ static void stbtt__v_prefilter(unsigned char *pixels, int w, int h, int stride_i for (i=0; i <= safe_h; ++i) { total += pixels[i*stride_in_bytes] - buffer[i & STBTT__OVER_MASK]; buffer[(i+kernel_width) & STBTT__OVER_MASK] = pixels[i*stride_in_bytes]; - pixels[i*stride_in_bytes] = total / 2; + pixels[i*stride_in_bytes] = (unsigned char) (total / 2); } break; case 3: for (i=0; i <= safe_h; ++i) { total += pixels[i*stride_in_bytes] - buffer[i & STBTT__OVER_MASK]; buffer[(i+kernel_width) & STBTT__OVER_MASK] = pixels[i*stride_in_bytes]; - pixels[i*stride_in_bytes] = total / 3; + pixels[i*stride_in_bytes] = (unsigned char) (total / 3); } break; case 4: for (i=0; i <= safe_h; ++i) { total += pixels[i*stride_in_bytes] - buffer[i & STBTT__OVER_MASK]; buffer[(i+kernel_width) & STBTT__OVER_MASK] = pixels[i*stride_in_bytes]; - pixels[i*stride_in_bytes] = total / 4; + pixels[i*stride_in_bytes] = (unsigned char) (total / 4); } break; default: for (i=0; i <= safe_h; ++i) { total += pixels[i*stride_in_bytes] - buffer[i & STBTT__OVER_MASK]; buffer[(i+kernel_width) & STBTT__OVER_MASK] = pixels[i*stride_in_bytes]; - pixels[i*stride_in_bytes] = total / kernel_width; + pixels[i*stride_in_bytes] = (unsigned char) (total / kernel_width); } break; } @@ -2268,7 +2266,7 @@ static void stbtt__v_prefilter(unsigned char *pixels, int w, int h, int stride_i for (; i < h; ++i) { assert(pixels[i*stride_in_bytes] == 0); total -= buffer[i & STBTT__OVER_MASK]; - pixels[i*stride_in_bytes] = total / kernel_width; + pixels[i*stride_in_bytes] = (unsigned char) (total / kernel_width); } pixels += 1; @@ -2326,8 +2324,8 @@ int stbtt_PackFontRanges(stbtt_pack_context *spc, unsigned char *fontdata, int f scale * spc->v_oversample, 0,0, &x0,&y0,&x1,&y1); - rects[k].w = x1-x0 + spc->padding + spc->h_oversample-1; - rects[k].h = y1-y0 + spc->padding + spc->v_oversample-1; + rects[k].w = (stbrp_coord) (x1-x0 + spc->padding + spc->h_oversample-1); + rects[k].h = (stbrp_coord) (y1-y0 + spc->padding + spc->v_oversample-1); ++k; } } @@ -2344,12 +2342,13 @@ int stbtt_PackFontRanges(stbtt_pack_context *spc, unsigned char *fontdata, int f stbtt_packedchar *bc = &ranges[i].chardata_for_range[j]; int advance, lsb, x0,y0,x1,y1; int glyph = stbtt_FindGlyphIndex(&info, ranges[i].first_unicode_char_in_range + j); + stbrp_coord pad = (stbrp_coord) spc->padding; // pad on left and top - r->x += spc->padding; - r->y += spc->padding; - r->w -= spc->padding; - r->h -= spc->padding; + r->x += pad; + r->y += pad; + r->w -= pad; + r->h -= pad; stbtt_GetGlyphHMetrics(&info, glyph, &advance, &lsb); stbtt_GetGlyphBitmapBox(&info, glyph, scale * spc->h_oversample, From d9e121f4c73e34ec1f9b7dd6dac19a11c1cd1ee1 Mon Sep 17 00:00:00 2001 From: Fabian Giesen Date: Mon, 8 Dec 2014 19:53:12 -0800 Subject: [PATCH 2/2] stb_rect_pack: Fix implicit conversion warnings. --- stb_rect_pack.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/stb_rect_pack.h b/stb_rect_pack.h index c30654f..74eb61d 100644 --- a/stb_rect_pack.h +++ b/stb_rect_pack.h @@ -231,7 +231,7 @@ STBRP_DEF void stbrp_init_target(stbrp_context *context, int width, int height, context->extra[0].x = 0; context->extra[0].y = 0; context->extra[0].next = &context->extra[1]; - context->extra[1].x = width; + context->extra[1].x = (stbrp_coord) width; #ifdef STBRP_LARGE_RECTS context->extra[1].y = (1<<30); #else @@ -406,8 +406,8 @@ static stbrp__findresult stbrp__skyline_pack_rectangle(stbrp_context *context, i // on success, create new node node = context->free_head; - node->x = res.x; - node->y = res.y + height; + node->x = (stbrp_coord) res.x; + node->y = (stbrp_coord) (res.y + height); context->free_head = node->next; @@ -439,7 +439,7 @@ static stbrp__findresult stbrp__skyline_pack_rectangle(stbrp_context *context, i node->next = cur; if (cur->x < res.x + width) - cur->x = res.x+width; + cur->x = (stbrp_coord) (res.x + width); #ifdef _DEBUG cur = context->active_head;