Merge branch 'oversample_shift' of https://github.com/rygorous/stb

This commit is contained in:
Sean Barrett 2014-12-08 20:00:18 -08:00
commit 34eec7cc5d
2 changed files with 22 additions and 23 deletions

View File

@ -236,7 +236,7 @@ STBRP_DEF void stbrp_init_target(stbrp_context *context, int width, int height,
context->extra[0].x = 0; context->extra[0].x = 0;
context->extra[0].y = 0; context->extra[0].y = 0;
context->extra[0].next = &context->extra[1]; context->extra[0].next = &context->extra[1];
context->extra[1].x = width; context->extra[1].x = (stbrp_coord) width;
#ifdef STBRP_LARGE_RECTS #ifdef STBRP_LARGE_RECTS
context->extra[1].y = (1<<30); context->extra[1].y = (1<<30);
#else #else
@ -411,8 +411,8 @@ static stbrp__findresult stbrp__skyline_pack_rectangle(stbrp_context *context, i
// on success, create new node // on success, create new node
node = context->free_head; node = context->free_head;
node->x = res.x; node->x = (stbrp_coord) res.x;
node->y = res.y + height; node->y = (stbrp_coord) (res.y + height);
context->free_head = node->next; context->free_head = node->next;
@ -444,7 +444,7 @@ static stbrp__findresult stbrp__skyline_pack_rectangle(stbrp_context *context, i
node->next = cur; node->next = cur;
if (cur->x < res.x + width) if (cur->x < res.x + width)
cur->x = res.x+width; cur->x = (stbrp_coord) (res.x + width);
#ifdef _DEBUG #ifdef _DEBUG
cur = context->active_head; cur = context->active_head;

View File

@ -881,7 +881,7 @@ enum { // languageID for STBTT_PLATFORM_ID_MAC
#define STBTT_MAX_OVERSAMPLE 8 #define STBTT_MAX_OVERSAMPLE 8
#endif #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];
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
// //
@ -2185,7 +2185,6 @@ static void stbtt__h_prefilter(unsigned char *pixels, int w, int h, int stride_i
for (j=0; j < h; ++j) { for (j=0; j < h; ++j) {
int i; int i;
unsigned int total; unsigned int total;
unsigned char *pixels_ahead = pixels + (kernel_width);
memset(buffer, 0, kernel_width); memset(buffer, 0, kernel_width);
total = 0; total = 0;
@ -2196,28 +2195,28 @@ static void stbtt__h_prefilter(unsigned char *pixels, int w, int h, int stride_i
for (i=0; i <= safe_w; ++i) { for (i=0; i <= safe_w; ++i) {
total += pixels[i] - buffer[i & STBTT__OVER_MASK]; total += pixels[i] - buffer[i & STBTT__OVER_MASK];
buffer[(i+kernel_width) & STBTT__OVER_MASK] = pixels[i]; buffer[(i+kernel_width) & STBTT__OVER_MASK] = pixels[i];
pixels[i] = total / 2; pixels[i] = (unsigned char) (total / 2);
} }
break; break;
case 3: case 3:
for (i=0; i <= safe_w; ++i) { for (i=0; i <= safe_w; ++i) {
total += pixels[i] - buffer[i & STBTT__OVER_MASK]; total += pixels[i] - buffer[i & STBTT__OVER_MASK];
buffer[(i+kernel_width) & STBTT__OVER_MASK] = pixels[i]; buffer[(i+kernel_width) & STBTT__OVER_MASK] = pixels[i];
pixels[i] = total / 3; pixels[i] = (unsigned char) (total / 3);
} }
break; break;
case 4: case 4:
for (i=0; i <= safe_w; ++i) { for (i=0; i <= safe_w; ++i) {
total += pixels[i] - buffer[i & STBTT__OVER_MASK]; total += pixels[i] - buffer[i & STBTT__OVER_MASK];
buffer[(i+kernel_width) & STBTT__OVER_MASK] = pixels[i]; buffer[(i+kernel_width) & STBTT__OVER_MASK] = pixels[i];
pixels[i] = total / 4; pixels[i] = (unsigned char) (total / 4);
} }
break; break;
default: default:
for (i=0; i <= safe_w; ++i) { for (i=0; i <= safe_w; ++i) {
total += pixels[i] - buffer[i & STBTT__OVER_MASK]; total += pixels[i] - buffer[i & STBTT__OVER_MASK];
buffer[(i+kernel_width) & STBTT__OVER_MASK] = pixels[i]; buffer[(i+kernel_width) & STBTT__OVER_MASK] = pixels[i];
pixels[i] = total / kernel_width; pixels[i] = (unsigned char) (total / kernel_width);
} }
break; break;
} }
@ -2225,7 +2224,7 @@ static void stbtt__h_prefilter(unsigned char *pixels, int w, int h, int stride_i
for (; i < w; ++i) { for (; i < w; ++i) {
assert(pixels[i] == 0); assert(pixels[i] == 0);
total -= buffer[i & STBTT__OVER_MASK]; total -= buffer[i & STBTT__OVER_MASK];
pixels[i] = total / kernel_width; pixels[i] = (unsigned char) (total / kernel_width);
} }
pixels += stride_in_bytes; pixels += stride_in_bytes;
@ -2240,7 +2239,6 @@ static void stbtt__v_prefilter(unsigned char *pixels, int w, int h, int stride_i
for (j=0; j < w; ++j) { for (j=0; j < w; ++j) {
int i; int i;
unsigned int total; unsigned int total;
unsigned char *pixels_ahead = pixels + (kernel_width)*stride_in_bytes;
memset(buffer, 0, kernel_width); memset(buffer, 0, kernel_width);
total = 0; total = 0;
@ -2251,28 +2249,28 @@ static void stbtt__v_prefilter(unsigned char *pixels, int w, int h, int stride_i
for (i=0; i <= safe_h; ++i) { for (i=0; i <= safe_h; ++i) {
total += pixels[i*stride_in_bytes] - buffer[i & STBTT__OVER_MASK]; total += pixels[i*stride_in_bytes] - buffer[i & STBTT__OVER_MASK];
buffer[(i+kernel_width) & STBTT__OVER_MASK] = pixels[i*stride_in_bytes]; 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; break;
case 3: case 3:
for (i=0; i <= safe_h; ++i) { for (i=0; i <= safe_h; ++i) {
total += pixels[i*stride_in_bytes] - buffer[i & STBTT__OVER_MASK]; total += pixels[i*stride_in_bytes] - buffer[i & STBTT__OVER_MASK];
buffer[(i+kernel_width) & STBTT__OVER_MASK] = pixels[i*stride_in_bytes]; 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; break;
case 4: case 4:
for (i=0; i <= safe_h; ++i) { for (i=0; i <= safe_h; ++i) {
total += pixels[i*stride_in_bytes] - buffer[i & STBTT__OVER_MASK]; total += pixels[i*stride_in_bytes] - buffer[i & STBTT__OVER_MASK];
buffer[(i+kernel_width) & STBTT__OVER_MASK] = pixels[i*stride_in_bytes]; 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; break;
default: default:
for (i=0; i <= safe_h; ++i) { for (i=0; i <= safe_h; ++i) {
total += pixels[i*stride_in_bytes] - buffer[i & STBTT__OVER_MASK]; total += pixels[i*stride_in_bytes] - buffer[i & STBTT__OVER_MASK];
buffer[(i+kernel_width) & STBTT__OVER_MASK] = pixels[i*stride_in_bytes]; 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; break;
} }
@ -2280,7 +2278,7 @@ static void stbtt__v_prefilter(unsigned char *pixels, int w, int h, int stride_i
for (; i < h; ++i) { for (; i < h; ++i) {
assert(pixels[i*stride_in_bytes] == 0); assert(pixels[i*stride_in_bytes] == 0);
total -= buffer[i & STBTT__OVER_MASK]; 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; pixels += 1;
@ -2338,8 +2336,8 @@ int stbtt_PackFontRanges(stbtt_pack_context *spc, unsigned char *fontdata, int f
scale * spc->v_oversample, scale * spc->v_oversample,
0,0, 0,0,
&x0,&y0,&x1,&y1); &x0,&y0,&x1,&y1);
rects[k].w = x1-x0 + spc->padding + spc->h_oversample-1; rects[k].w = (stbrp_coord) (x1-x0 + spc->padding + spc->h_oversample-1);
rects[k].h = y1-y0 + spc->padding + spc->v_oversample-1; rects[k].h = (stbrp_coord) (y1-y0 + spc->padding + spc->v_oversample-1);
++k; ++k;
} }
} }
@ -2356,12 +2354,13 @@ int stbtt_PackFontRanges(stbtt_pack_context *spc, unsigned char *fontdata, int f
stbtt_packedchar *bc = &ranges[i].chardata_for_range[j]; stbtt_packedchar *bc = &ranges[i].chardata_for_range[j];
int advance, lsb, x0,y0,x1,y1; int advance, lsb, x0,y0,x1,y1;
int glyph = stbtt_FindGlyphIndex(&info, ranges[i].first_unicode_char_in_range + j); 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 // pad on left and top
r->x += spc->padding; r->x += pad;
r->y += spc->padding; r->y += pad;
r->w -= spc->padding; r->w -= pad;
r->h -= spc->padding; r->h -= pad;
stbtt_GetGlyphHMetrics(&info, glyph, &advance, &lsb); stbtt_GetGlyphHMetrics(&info, glyph, &advance, &lsb);
stbtt_GetGlyphBitmapBox(&info, glyph, stbtt_GetGlyphBitmapBox(&info, glyph,
scale * spc->h_oversample, scale * spc->h_oversample,