Merge branch 'master' into working
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Sean Barrett · committed by Sean Barrett · parents 9534eb2, 07a598c · Browse files · 6 files·+323 added−171 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
6 files+323 added−171 removed
- tests:+4 added−0 removed
- other:+319 added−171 removed
Provenance
- Commit
1384715- Tree
ea831e0- Author
Sean Barrett <sean2@nothings.org>- Committer
Sean Barrett <sean2@nothings.org>- Parent 1
9534eb2- Parent 2
07a598c
6 files changed+323 added−171 removed
modified:tests/test_c_compilation.c+4 added
5 unmodified lines6 #define STB_IMAGE_IMPLEMENTATION7 #define STB_HERRINGBONE_WANG_TILE_IMEPLEMENTATIOn8 #define STB_IMAGE_RESIZE_IMPLEMENTATION9 #define STB_RECT_PACK_IMPLEMENTATION10+#define STB_VOXEL_RENDER_IMPLEMENTATION11 12 #include "stb_herringbone_wang_tile.h"13 #include "stb_image.h"14 #include "stb_image_write.h"3 unmodified lines18 #include "stb_divide.h"19 #include "stb_image_resize.h"20 #include "stb_rect_pack.h"21 22+#define STBVOX_CONFIG_MODE 123+#include "stb_voxel_render.h"24+25 #define STBTE_DRAW_RECT(x0,y0,x1,y1,color) 026 #define STBTE_DRAW_TILE(x,y,id,highlight,data) 027 #define STB_TILEMAP_EDITOR_IMPLEMENTATION28 #include "stb_tilemap_editor.h"modified:README.md+3 added-3 removed
4 unmodified lines567891011910111213141589 unmodified lines4 unmodified lines
library | lastest version | category | description--------------------- | ---- | -------- | --------------------------------**stb_vorbis.c** | 1.04 | audio | decode ogg vorbis files from file/memory to float/16-bit signed output**stb_image.h** | 2.02 | graphics | image loading/decoding from file/memory: JPG, PNG, TGA, BMP, PSD, GIF, HDR, PIC**stb_truetype.h** | 1.02 | graphics | parse, decode, and rasterize characters from truetype fonts**stb_image_write.h** | 0.97 | graphics | image writing to disk: PNG, TGA, BMP**stb_image.h** | 2.03 | graphics | image loading/decoding from file/memory: JPG, PNG, TGA, BMP, PSD, GIF, HDR, PIC**stb_truetype.h** | 1.03 | graphics | parse, decode, and rasterize characters from truetype fonts**stb_image_write.h** | 0.98 | graphics | image writing to disk: PNG, TGA, BMP**stb_image_resize.h** | 0.90 | graphics | resize images larger/smaller with good quality**stb_rect_pack.h** | 0.05 | graphics | simple 2D rectangle packer with decent quality**stretchy_buffer.h** | 1.01 | utility | typesafe dynamic array for C (i.e. approximation to vector<>), doesn't compile as C++**stb_textedit.h** | 1.5 | UI | guts of a text editor for games etc implementing them from scratch89 unmodified linesmodified:stb_image_write.h+66 added-34 removed
1-/* stb_image_write - v0.97 - public domain - http://nothings.org/stb/stb_image_write.h1+/* stb_image_write - v0.98 - public domain - http://nothings.org/stb/stb_image_write.h2 writes out PNG/BMP/TGA images to C stdio - Sean Barrett 20103 no warranty implied; use at your own risk4 5 2 unmodified lines8 #define STB_IMAGE_WRITE_IMPLEMENTATION9 10 in the file that you want to have the implementation.11 12-12 Will probably not work correctly with strict-aliasing optimizations.13 14 ABOUT:15 4 unmodified lines20 written by a decent optimizing implementation. This library is designed21 for source code compactness and simplicitly, not optimal image file size22 or run-time performance.23 24+BUILDING:25+26+ You can #define STBIW_ASSERT(x) before the #include to avoid using assert.h.27+ You can #define STBIW_MALLOC(), STBIW_REALLOC(), and STBIW_FREE() to replace28+ malloc,realloc,free.29+ You can define STBIW_MEMMOVE() to replace memmove()30+31 USAGE:32 33 There are four functions, one for each image file format:34 2 unmodified lines37 int stbi_write_tga(char const *filename, int w, int h, int comp, const void *data);38 int stbi_write_hdr(char const *filename, int w, int h, int comp, const void *data);39 40 Each function returns 0 on failure and non-0 on success.35- 41+42 The functions create an image file defined by the parameters. The image43 is a rectangle of pixels stored from left-to-right, top-to-bottom.44 Each pixel contains 'comp' channels of data stored interleaved with 8-bits45 per channel, in the following order: 1=Y, 2=YA, 3=RGB, 4=RGBA. (Y is4 unmodified lines50 51 PNG creates output files with the same number of components as the input.52 The BMP format expands Y to RGB in the file format and does not53 output alpha.48- 54+55 PNG supports writing rectangles of data even when the bytes storing rows of56 data are not consecutive in memory (e.g. sub-rectangles of a larger image),57 by supplying the stride between the beginning of adjacent rows. The other58 formats do not. (Thus you cannot write a native-format BMP through the BMP11 unmodified lines70 HDR71 Baldur Karlsson72 TGA monochrome:73 Jean-Sebastien Guay68- Bugfixes:69- Chribba@github74+ misc enhancements:75+ Tim Kelsey76+ bugfixes:77+ github:Chribba78 */79 80 #ifndef INCLUDE_STB_IMAGE_WRITE_H81 #define INCLUDE_STB_IMAGE_WRITE_H18 unmodified lines100 #include <stdarg.h>101 #include <stdlib.h>102 #include <stdio.h>103 #include <string.h>96-#include <assert.h>104 #include <math.h>105 106+#if defined(STBIW_MALLOC) && defined(STBIW_FREE) && defined(STBIW_REALLOC)107+// ok108+#elif !defined(STBIW_MALLOC) && !defined(STBIW_FREE) && !defined(STBIW_REALLOC)109+// ok110+#else111+#error "Must define all or none of STBIW_MALLOC, STBIW_FREE, and STBIW_REALLOC."112+#endif113+114+#ifndef STBIW_MALLOC115+#define STBIW_MALLOC(sz) malloc(sz)116+#define STBIW_REALLOC(p,sz) realloc(p,sz)117+#define STBIW_FREE(p) free(p)118+#endif119+#ifndef STBIW_MEMMOVE120+#define STBIW_MEMMOVE(a,b,sz) memmove(a,b,sz)121+#endif122+123+124+#ifndef STBIW_ASSERT125+#include <assert.h>126+#define STBIW_ASSERT(x) assert(x)127+#endif128+129 typedef unsigned int stbiw_uint32;130 typedef int stb_image_write_test[sizeof(stbiw_uint32)==4 ? 1 : -1];131 132 static void writefv(FILE *f, const char *fmt, va_list v)9 unmodified lines142 b[0]=(unsigned char)x; b[1]=(unsigned char)(x>>8);143 b[2]=(unsigned char)(x>>16); b[3]=(unsigned char)(x>>24);144 fwrite(b,4,1,f); break; }145 default:116- assert(0);146+ STBIW_ASSERT(0);147 return;148 }149 }150 }13 unmodified lines164 165 if (y <= 0)166 return;167 138- if (vdir < 0) 168+ if (vdir < 0)169 j_end = -1, j = y-1;170 else171 j_end = y, j = 0;172 88 unmodified lines261 262 void stbiw__write_run_data(FILE *f, int length, unsigned char databyte)263 {264 unsigned char lengthbyte = (unsigned char) (length+128);235- assert(length+128 <= 255);265+ STBIW_ASSERT(length+128 <= 255);266 fwrite(&lengthbyte, 1, 1, f);267 fwrite(&databyte, 1, 1, f);268 }269 270 void stbiw__write_dump_data(FILE *f, int length, unsigned char *data)271 {272 unsigned char lengthbyte = (unsigned char )(length & 0xff);243- assert(length <= 128); // inconsistent with spec but consistent with official code273+ STBIW_ASSERT(length <= 128); // inconsistent with spec but consistent with official code274 fwrite(&lengthbyte, 1, 1, f);275 fwrite(data, length, 1, f);276 }277 48 unmodified lines326 327 /* RLE each component separately */328 for (c=0; c < 4; c++) {329 unsigned char *comp = &scratch[width*c];300- int runstart = 0, head = 0, rlerun = 0;330 331 x = 0;332 while (x < width) {333 // find first run15 unmodified lines349 // if there's a run, output it350 if (r+2 < width) { // same test as what we break out of in search loop, so only true if we break'd351 // find next byte after run352 while (r < width && comp[r] == comp[x])324- ++r; 353+ ++r;354 // output run up to r355 while (x < r) {356 int len = r-x;357 if (len > 127) len = 127;13 unmodified lines371 if (y <= 0 || x <= 0 || data == NULL) return 0;372 f = fopen(filename, "wb");373 if (f) {374 /* Each component is stored separately. Allocate scratch space for full output scanline. */346- unsigned char *scratch = (unsigned char *) malloc(x*4);375+ unsigned char *scratch = (unsigned char *) STBIW_MALLOC(x*4);376 fprintf(f, "#?RADIANCE\n# Written by stb_image_write.h\nFORMAT=32-bit_rle_rgbe\n" );377 fprintf(f, "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n" , y, x);378 for(i=0; i < y; i++)379 stbiw__write_hdr_scanline(f, x, comp, scratch, data + comp*i*x);351- free(scratch);380+ STBIW_FREE(scratch);381 fclose(f);382 }383 return f != NULL;384 }11 unmodified lines396 #define stbiw__sbgrow(a,n) stbiw__sbgrowf((void **) &(a), (n), sizeof(*(a)))397 398 #define stbiw__sbpush(a, v) (stbiw__sbmaybegrow(a,1), (a)[stbiw__sbn(a)++] = (v))399 #define stbiw__sbcount(a) ((a) ? stbiw__sbn(a) : 0)371-#define stbiw__sbfree(a) ((a) ? free(stbiw__sbraw(a)),0 : 0)400+#define stbiw__sbfree(a) ((a) ? STBIW_FREE(stbiw__sbraw(a)),0 : 0)401 402 static void *stbiw__sbgrowf(void **arr, int increment, int itemsize)403 {404 int m = *arr ? 2*stbiw__sbm(*arr)+increment : increment+1;376- void *p = realloc(*arr ? stbiw__sbraw(*arr) : 0, itemsize * m + sizeof(int)*2);377- assert(p);405+ void *p = STBIW_REALLOC(*arr ? stbiw__sbraw(*arr) : 0, itemsize * m + sizeof(int)*2);406+ STBIW_ASSERT(p);407 if (p) {408 if (!*arr) ((int *) p)[1] = 0;409 *arr = (void *) ((int *) p + 2);410 stbiw__sbm(*arr) = m;76 unmodified lines487 hash_table[i] = NULL;488 489 i=0;490 while (i < data_len-3) {462- // hash next 3 bytes of data to be compressed 491+ // hash next 3 bytes of data to be compressed492 int h = stbiw__zhash(data+i)&(stbiw__ZHASH-1), best=3;493 unsigned char *bestloc = 0;494 unsigned char **hlist = hash_table[h];495 int n = stbiw__sbcount(hlist);4 unmodified lines500 }501 }502 // when hash table entry is too long, delete half the entries503 if (hash_table[h] && stbiw__sbn(hash_table[h]) == 2*quality) {475- memcpy(hash_table[h], hash_table[h]+quality, sizeof(hash_table[h][0])*quality);504+ STBIW_MEMMOVE(hash_table[h], hash_table[h]+quality, sizeof(hash_table[h][0])*quality);505 stbiw__sbn(hash_table[h]) = quality;506 }507 stbiw__sbpush(hash_table[h],data+i);508 14 unmodified lines523 }524 525 if (bestloc) {526 int d = (int) (data+i - bestloc); // distance back498- assert(d <= 32767 && best <= 258);527+ STBIW_ASSERT(d <= 32767 && best <= 258);528 for (j=0; best > lengthc[j+1]-1; ++j);529 stbiw__zlib_huff(j+257);530 if (lengtheb[j]) stbiw__zlib_add(best - lengthc[j], lengtheb[j]);531 for (j=0; d > distc[j+1]-1; ++j);32 unmodified lines564 stbiw__sbpush(out, (unsigned char) s1);565 }566 *out_len = stbiw__sbn(out);567 // make returned pointer freeable539- memmove(stbiw__sbraw(out), out, *out_len);568+ STBIW_MEMMOVE(stbiw__sbraw(out), out, *out_len);569 return (unsigned char *) stbiw__sbraw(out);570 }571 572 unsigned int stbiw__crc32(unsigned char *buffer, int len)38 unmodified lines611 612 if (stride_bytes == 0)613 stride_bytes = x * n;614 586- filt = (unsigned char *) malloc((x*n+1) * y); if (!filt) return 0;587- line_buffer = (signed char *) malloc(x * n); if (!line_buffer) { free(filt); return 0; }615+ filt = (unsigned char *) STBIW_MALLOC((x*n+1) * y); if (!filt) return 0;616+ line_buffer = (signed char *) STBIW_MALLOC(x * n); if (!line_buffer) { STBIW_FREE(filt); return 0; }617 for (j=0; j < y; ++j) {618 static int mapping[] = { 0,1,2,3,4 };619 static int firstmap[] = { 0,1,0,5,6 };620 int *mymap = j ? mapping : firstmap;30 unmodified lines651 }652 }653 // when we get here, best contains the filter type, and line_buffer contains the data654 filt[j*(x*n+1)] = (unsigned char) best;626- memcpy(filt+j*(x*n+1)+1, line_buffer, x*n);655+ STBIW_MEMMOVE(filt+j*(x*n+1)+1, line_buffer, x*n);656 }628- free(line_buffer);657+ STBIW_FREE(line_buffer);658 zlib = stbi_zlib_compress(filt, y*( x*n+1), &zlen, 8); // increase 8 to get smaller but use more memory630- free(filt);659+ STBIW_FREE(filt);660 if (!zlib) return 0;661 662 // each tag requires 12 bytes of overhead634- out = (unsigned char *) malloc(8 + 12+13 + 12+zlen + 12); 663+ out = (unsigned char *) STBIW_MALLOC(8 + 12+13 + 12+zlen + 12);664 if (!out) return 0;665 *out_len = 8 + 12+13 + 12+zlen + 12;666 667 o=out;639- memcpy(o,sig,8); o+= 8;668+ STBIW_MEMMOVE(o,sig,8); o+= 8;669 stbiw__wp32(o, 13); // header length670 stbiw__wptag(o, "IHDR");671 stbiw__wp32(o, x);672 stbiw__wp32(o, y);5 unmodified lines678 stbiw__wpcrc(&o,13);679 680 stbiw__wp32(o, zlen);681 stbiw__wptag(o, "IDAT");653- memcpy(o, zlib, zlen); o += zlen; free(zlib);682+ STBIW_MEMMOVE(o, zlib, zlen);683+ o += zlen;684+ STBIW_FREE(zlib);685 stbiw__wpcrc(&o, zlen);686 687 stbiw__wp32(o,0);688 stbiw__wptag(o, "IEND");689 stbiw__wpcrc(&o,0);690 660- assert(o == out + *out_len);691+ STBIW_ASSERT(o == out + *out_len);692 693 return out;694 }695 3 unmodified lines699 int len;700 unsigned char *png = stbi_write_png_to_mem((unsigned char *) data, stride_bytes, x, y, comp, &len);701 if (!png) return 0;702 f = fopen(filename, "wb");672- if (!f) { free(png); return 0; }703+ if (!f) { STBIW_FREE(png); return 0; }704 fwrite(png, 1, len, f);705 fclose(f);675- free(png);706+ STBIW_FREE(png);707 return 1;708 }709 #endif // STB_IMAGE_WRITE_IMPLEMENTATION710 711 /* Revision history681-712+ 0.98 (2015-04-08)713+ added STBIW_MALLOC, STBIW_ASSERT etc714 0.97 (2015-01-18)715 fixed HDR asserts, rewrote HDR rle logic716 0.96 (2015-01-17)717 add HDR output13 unmodified linesmodified:stb_image.h+121 added-22 removed
1-/* stb_image - v2.02 - public domain image loader - http://nothings.org/stb_image.h1+/* stb_image - v2.03 - public domain image loader - http://nothings.org/stb_image.h2 no warranty implied; use at your own risk3 4 Do this:5 #define STB_IMAGE_IMPLEMENTATION136 unmodified lines142 near-term back-compatibility use.143 144 145 Latest revision history:146+ 2.03 (2015-04-12) additional corruption checking147+ stbi_set_flip_vertically_on_load148+ fix NEON support; fix mingw support149 2.02 (2015-01-19) fix incorrect assert, fix warning150 2.01 (2015-01-17) fix various warnings151 2.00b (2014-12-25) fix STBI_MALLOC in progressive JPEG152 2.00 (2014-12-25) optimize JPEG, including x86 SSE2 & ARM NEON SIMD29 unmodified lines182 Martin "SpartanJ" Golini (stbi_info) Martin Golini183 James "moose2000" Brown (iPhone PNG) Roy Eltham184 Ben "Disch" Wenger (io callbacks) Luke Graham185 Omar Cornut (1/2/4-bit PNG) Thomas Ruf183- John Bartholomew186+ Nicolas Guillemot (vertical flip) John Bartholomew187 Ken Hamada188 Optimizations & bugfixes Cort Stratton189 Fabian "ryg" Giesen Blazej Dariusz Roszkowski190 Arseny Kapoulkine Thibault Reuille7 unmodified lines198 Tero Hanninen199 Sergio Gonzalez200 Cass Everitt201 Engin Manap202+ Martins Mozeiko203+ Joseph Thomson204+ Phil Jordan205 206 License:207 This software is in the public domain. Where that dedication is not208 recognized, you are granted a perpetual, irrevocable license to copy283 unmodified lines492 // indicate whether we should process iphone images back to canonical format,493 // or just pass them through "as-is"494 STBIDEF void stbi_convert_iphone_png_to_rgb(int flag_true_if_should_convert);495 496+// flip the image vertically, so the first pixel in the output array is the bottom left497+STBIDEF void stbi_set_flip_vertically_on_load(int flag_true_if_should_flip);498 499 // ZLIB client - used by PNG, available for other purposes500 501 STBIDEF char *stbi_zlib_decode_malloc_guesssize(const char *buffer, int len, int initial_size, int *outlen);129 unmodified lines631 #define STBI_REALLOC(p,sz) realloc(p,sz)632 #define STBI_FREE(p) free(p)633 #endif634 635+// x86/x64 detection636+#if defined(__x86_64__) || defined(_M_X64) || defined(__i386) || defined(_M_IX86)637+#define STBI__X86_TARGET638+#endif639+627-#if defined(__GNUC__) && !defined(__SSE2__) && !defined(STBI_NO_SIMD)640+#if defined(__GNUC__) && defined(STBI__X86_TARGET) && !defined(__SSE2__) && !defined(STBI_NO_SIMD)641 // gcc doesn't support sse2 intrinsics unless you compile with -msse2,642 // (but compiling with -msse2 allows the compiler to use SSE2 everywhere;643 // this is just broken and gcc are jerks for not fixing it properly644 // http://www.virtualdub.org/blog/pivot/entry.php?id=363 )645 #define STBI_NO_SIMD646 #endif647 635-#if !defined(STBI_NO_SIMD) && (defined(__x86_64__) || defined(_M_X64) || defined(__i386) || defined(_M_IX86))648+#if defined(__MINGW32__) && defined(STBI__X86_TARGET) && !defined(STBI_MINGW_ENABLE_SSE2) && !defined(STBI_NO_SIMD)649+// 32-bit MinGW wants ESP to be 16-byte aligned, but this is not in the650+// Windows ABI and VC++ as well as Windows DLLs don't maintain that invariant.651+// As a result, enabling SSE2 on 32-bit MinGW is dangerous when not652+// simultaneously enabling "-mstackrealign".653+//654+// See https://github.com/nothings/stb/issues/81 for more information.655+//656+// So default to no SSE2 on 32-bit MinGW. If you've read this far and added657+// -mstackrealign to your build settings, feel free to #define STBI_MINGW_ENABLE_SSE2.658+#define STBI_NO_SIMD659+#endif660+661+#if !defined(STBI_NO_SIMD) && defined(STBI__X86_TARGET)662 #define STBI_SSE2663 #include <emmintrin.h>664 665 #ifdef _MSC_VER244 unmodified lines910 #ifndef STBI_NO_HDR911 static stbi_uc *stbi__hdr_to_ldr(float *data, int x, int y, int comp);912 #endif913 888-static unsigned char *stbi_load_main(stbi__context *s, int *x, int *y, int *comp, int req_comp)914+static int stbi__vertically_flip_on_load = 0;915+916+STBIDEF void stbi_set_flip_vertically_on_load(int flag_true_if_should_flip)917 {918+ stbi__vertically_flip_on_load = flag_true_if_should_flip;919+}920+921+static unsigned char *stbi__load_main(stbi__context *s, int *x, int *y, int *comp, int req_comp)922+{923 #ifndef STBI_NO_JPEG924 if (stbi__jpeg_test(s)) return stbi__jpeg_load(s,x,y,comp,req_comp);925 #endif926 #ifndef STBI_NO_PNG30 unmodified lines957 958 return stbi__errpuc("unknown image type", "Image not of any known type, or corrupt");959 }960 961+static unsigned char *stbi__load_flip(stbi__context *s, int *x, int *y, int *comp, int req_comp)962+{963+ unsigned char *result = stbi__load_main(s, x, y, comp, req_comp);964+965+ if (stbi__vertically_flip_on_load && result != NULL) {966+ int w = *x, h = *y;967+ int depth = req_comp ? req_comp : *comp;968+ int row,col,z;969+ stbi_uc temp;970+971+ // @OPTIMIZE: use a bigger temp buffer and memcpy multiple pixels at once972+ for (row = 0; row < (h>>1); row++) {973+ for (col = 0; col < w; col++) {974+ for (z = 0; z < depth; z++) {975+ temp = result[(row * w + col) * depth + z];976+ result[(row * w + col) * depth + z] = result[((h - row - 1) * w + col) * depth + z];977+ result[((h - row - 1) * w + col) * depth + z] = temp;978+ }979+ }980+ }981+ }982+983+ return result;984+}985+986+static void stbi__float_postprocess(float *result, int *x, int *y, int *comp, int req_comp)987+{988+ if (stbi__vertically_flip_on_load && result != NULL) {989+ int w = *x, h = *y;990+ int depth = req_comp ? req_comp : *comp;991+ int row,col,z;992+ float temp;993+994+ // @OPTIMIZE: use a bigger temp buffer and memcpy multiple pixels at once995+ for (row = 0; row < (h>>1); row++) {996+ for (col = 0; col < w; col++) {997+ for (z = 0; z < depth; z++) {998+ temp = result[(row * w + col) * depth + z];999+ result[(row * w + col) * depth + z] = result[((h - row - 1) * w + col) * depth + z];1000+ result[((h - row - 1) * w + col) * depth + z] = temp;1001+ }1002+ }1003+ }1004+ }1005+}1006+1007+1008 #ifndef STBI_NO_STDIO1009 1010 static FILE *stbi__fopen(char const *filename, char const *mode)1011 {22 unmodified lines1034 {1035 unsigned char *result;1036 stbi__context s;1037 stbi__start_file(&s,f);958- result = stbi_load_main(&s,x,y,comp,req_comp);1038+ result = stbi__load_flip(&s,x,y,comp,req_comp);1039 if (result) {1040 // need to 'unget' all the characters in the IO buffer1041 fseek(f, - (int) (s.img_buffer_end - s.img_buffer), SEEK_CUR);1042 }4 unmodified lines1047 STBIDEF stbi_uc *stbi_load_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp)1048 {1049 stbi__context s;1050 stbi__start_mem(&s,buffer,len);971- return stbi_load_main(&s,x,y,comp,req_comp);1051+ return stbi__load_flip(&s,x,y,comp,req_comp);1052 }1053 1054 STBIDEF stbi_uc *stbi_load_from_callbacks(stbi_io_callbacks const *clbk, void *user, int *x, int *y, int *comp, int req_comp)1055 {1056 stbi__context s;1057 stbi__start_callbacks(&s, (stbi_io_callbacks *) clbk, user);978- return stbi_load_main(&s,x,y,comp,req_comp);1058+ return stbi__load_flip(&s,x,y,comp,req_comp);1059 }1060 1061 #ifndef STBI_NO_LINEAR982-static float *stbi_loadf_main(stbi__context *s, int *x, int *y, int *comp, int req_comp)1062+static float *stbi__loadf_main(stbi__context *s, int *x, int *y, int *comp, int req_comp)1063 {1064 unsigned char *data;1065 #ifndef STBI_NO_HDR986- if (stbi__hdr_test(s))987- return stbi__hdr_load(s,x,y,comp,req_comp);1066+ if (stbi__hdr_test(s)) {1067+ float *hdr_data = stbi__hdr_load(s,x,y,comp,req_comp);1068+ if (hdr_data)1069+ stbi__float_postprocess(hdr_data,x,y,comp,req_comp);1070+ return hdr_data;1071+ }1072 #endif989- data = stbi_load_main(s, x, y, comp, req_comp);1073+ data = stbi__load_flip(s, x, y, comp, req_comp);1074 if (data)1075 return stbi__ldr_to_hdr(data, *x, *y, req_comp ? req_comp : *comp);1076 return stbi__errpf("unknown image type", "Image not of any known type, or corrupt");1077 }1 unmodified line1079 STBIDEF float *stbi_loadf_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp)1080 {1081 stbi__context s;1082 stbi__start_mem(&s,buffer,len);999- return stbi_loadf_main(&s,x,y,comp,req_comp);1083+ return stbi__loadf_main(&s,x,y,comp,req_comp);1084 }1085 1086 STBIDEF float *stbi_loadf_from_callbacks(stbi_io_callbacks const *clbk, void *user, int *x, int *y, int *comp, int req_comp)1087 {1088 stbi__context s;1089 stbi__start_callbacks(&s, (stbi_io_callbacks *) clbk, user);1006- return stbi_loadf_main(&s,x,y,comp,req_comp);1090+ return stbi__loadf_main(&s,x,y,comp,req_comp);1091 }1092 1093 #ifndef STBI_NO_STDIO1094 STBIDEF float *stbi_loadf(char const *filename, int *x, int *y, int *comp, int req_comp)9 unmodified lines1104 STBIDEF float *stbi_loadf_from_file(FILE *f, int *x, int *y, int *comp, int req_comp)1105 {1106 stbi__context s;1107 stbi__start_file(&s,f);1024- return stbi_loadf_main(&s,x,y,comp,req_comp);1108+ return stbi__loadf_main(&s,x,y,comp,req_comp);1109 }1110 #endif // !STBI_NO_STDIO1111 1112 #endif // !STBI_NO_LINEAR114 unmodified lines1227 }1228 1229 static void stbi__skip(stbi__context *s, int n)1230 {1231+ if (n < 0) {1232+ s->img_buffer = s->img_buffer_end;1233+ return;1234+ }1235 if (s->io.read) {1236 int blen = (int) (s->img_buffer_end - s->img_buffer);1237 if (blen < n) {1238 s->img_buffer = s->img_buffer_end;400 unmodified lines1639 if (j->code_bits < n) stbi__grow_buffer_unsafe(j);1640 1641 sgn = (stbi__int32)j->code_buffer >> 31; // sign bit is always in MSB1642 k = stbi_lrot(j->code_buffer, n);1643+ STBI_ASSERT(n >= 0 && n < sizeof(stbi__bmask)/sizeof(*stbi__bmask));1644 j->code_buffer = k & ~stbi__bmask[n];1645 k &= stbi__bmask[n];1646 j->code_bits -= n;1647 return k + (stbi__jbias[n] & ~sgn);1140 unmodified lines2788 // decode image to YCbCr format2789 static int stbi__decode_jpeg_image(stbi__jpeg *j)2790 {2791 int m;2792+ for (m = 0; m < 4; m++) {2793+ j->img_comp[m].raw_data = NULL;2794+ j->img_comp[m].raw_coeff = NULL;2795+ }2796 j->restart_interval = 0;2797 if (!stbi__decode_jpeg_header(j, STBI__SCAN_load)) return 0;2798 m = stbi__get_marker(j);2799 while (!stbi__EOI(m)) {671 unmodified lines3471 for (i=0; i < num; ++i)3472 ++sizes[sizelist[i]];3473 sizes[0] = 0;3474 for (i=1; i < 16; ++i)3382- STBI_ASSERT(sizes[i] <= (1 << i));3475+ if (sizes[i] > (1 << i))3476+ return stbi__err("bad sizes", "Corrupt PNG");3477 code = 0;3478 for (i=1; i < 16; ++i) {3479 next_code[i] = code;3480 z->firstcode[i] = (stbi__uint16) code;3481 z->firstsymbol[i] = (stbi__uint16) k;3482 code = (code + sizes[i]);3483 if (sizes[i])3390- if (code-1 >= (1 << i)) return stbi__err("bad codelengths","Corrupt JPEG");3484+ if (code-1 >= (1 << i)) return stbi__err("bad codelengths","Corrupt PNG");3485 z->maxcode[i] = code << (16-i); // preshift for inner loop3486 code <<= 1;3487 k += sizes[i];3488 }160 unmodified lines3649 }3650 p = (stbi_uc *) (zout - dist);3651 if (dist == 1) { // run of one byte; common in images.3652 stbi_uc v = *p;3559- do *zout++ = v; while (--len);3653+ if (len) { do *zout++ = v; while (--len); }3654 } else {3561- do *zout++ = *p++; while (--len);3655+ if (len) { do *zout++ = *p++; while (--len); }3656 }3657 }3658 }3659 }19 unmodified lines3679 3680 n = 0;3681 while (n < hlit + hdist) {3682 int c = stbi__zhuffman_decode(a, &z_codelength);3589- STBI_ASSERT(c >= 0 && c < 19);3683+ if (c < 0 || c >= 19) return stbi__err("bad codelengths", "Corrupt PNG");3684 if (c < 16)3685 lencodes[n++] = (stbi_uc) c;3686 else if (c == 16) {3687 c = stbi__zreceive(a,2)+3;688 unmodified lines4376 case STBI__PNG_TYPE('I','D','A','T'): {4377 if (first) return stbi__err("first not IHDR", "Corrupt PNG");4378 if (pal_img_n && !pal_len) return stbi__err("no PLTE","Corrupt PNG");4379 if (scan == STBI__SCAN_header) { s->img_n = pal_img_n; return 1; }4380+ if ((int)(ioff + c.length) < (int)ioff) return 0;4381 if (ioff + c.length > idata_limit) {4382 stbi_uc *p;4383 if (idata_limit == 0) idata_limit = c.length > 4096 ? c.length : 4096;4384 while (ioff + c.length > idata_limit)351 unmodified lines4736 if (target == 4) out[z++] = a;4737 }4738 } else {4739 for (i=0; i < (int) s->img_x; ++i) {4645- stbi__uint32 v = (stbi__uint32) (bpp == 16 ? stbi__get16le(s) : stbi__get32le(s));4740+ stbi__uint32 v = (bpp == 16 ? (stbi__uint32) stbi__get16le(s) : stbi__get32le(s));4741 int a;4742 out[z++] = STBI__BYTECAST(stbi__shiftsigned(v & mr, rshift, rcount));4743 out[z++] = STBI__BYTECAST(stbi__shiftsigned(v & mg, gshift, gcount));4744 out[z++] = STBI__BYTECAST(stbi__shiftsigned(v & mb, bshift, bcount));148 unmodified lines4893 *x = tga_width;4894 *y = tga_height;4895 if (comp) *comp = tga_comp;4896 4802- tga_data = (unsigned char*)stbi__malloc( tga_width * tga_height * tga_comp );4897+ tga_data = (unsigned char*)stbi__malloc( (size_t)tga_width * tga_height * tga_comp );4898 if (!tga_data) return stbi__errpuc("outofmem", "Out of memory");4899 4900 // skip to the data's starting position (offset usually = 0)4901 stbi__skip(s, tga_offset );652 unmodified lines5554 stbi__int32 codesize, codemask, avail, oldcode, bits, valid_bits, clear;5555 stbi__gif_lzw *p;5556 5557 lzw_cs = stbi__get8(s);5558+ if (lzw_cs > 12) return NULL;5559 clear = 1 << lzw_cs;5560 first = 1;5561 codesize = lzw_cs + 1;5562 codemask = (1 << codesize) - 1;723 unmodified lines6286 #endif // STB_IMAGE_IMPLEMENTATION6287 6288 /*6289 revision history:6290+ 2.03 (2015-04-12) extra corruption checking (mmozeiko)6291+ stbi_set_flip_vertically_on_load (nguillemot)6292+ fix NEON support; fix mingw support6293 2.02 (2015-01-19) fix incorrect assert, fix warning6294 2.01 (2015-01-17) fix various warnings; suppress SIMD on gcc 32-bit without -msse26295 2.00b (2014-12-25) fix STBI_MALLOC in progressive JPEG6296 2.00 (2014-12-25) optimize JPG, including x86 SSE2 & NEON SIMD (ryg)130 unmodified linesmodified:stb_truetype.h+127 added-110 removed
1-// stb_truetype.h - v1.02 - public domain1+// stb_truetype.h - v1.03 - public domain2 // authored from 2009-2014 by Sean Barrett / RAD Game Tools3 //4 // This library processes TrueType files:5 // parse files27 unmodified lines33 // Anthony Pesch34 // Johan Duparc35 // Hou Qiming36 // Fabian "ryg" Giesen37+// Martins Mozeiko38+// Cap Petschulat39+// Omar Cornut40+// github:aloucks41 //42 // Misc other:43 // Ryan Gordon44 //45 // VERSION HISTORY46 //47+// 1.03 (2015-04-12) STBTT_STATIC, fix memory leak in new packing, various fixes48 // 1.02 (2014-12-10) fix various warnings & compile issues w/ stb_rect_pack, C++49 // 1.01 (2014-12-08) fix subpixel position when oversampling to exactly match50 // non-oversampled; STBTT_POINT_SIZE for packed case only51 // 1.00 (2014-12-06) add new PackBegin etc. API, w/ support for oversampling35 unmodified lines87 // #define STB_TRUETYPE_IMPLEMENTATION88 // before the #include of this file. This expands out the actual89 // implementation into that C/C++ file.90 //91+// To make the implementation private to the file that generates the implementation,92+// #define STBTT_STATIC93+//94 // Simple 3D API (don't ship this, but it's fine for tools and quick start)95 // stbtt_BakeFontBitmap() -- bake a font to a bitmap for use as texture96 // stbtt_GetBakedQuad() -- compute quad to draw for a given char97 //131 unmodified lines229 #if 0230 #define STB_TRUETYPE_IMPLEMENTATION // force following include to generate implementation231 #include "stb_truetype.h"232 225-char ttf_buffer[1<<20];233+unsigned char ttf_buffer[1<<20];234 unsigned char temp_bitmap[512*512];235 236 stbtt_bakedchar cdata[96]; // ASCII 32..126 is 95 glyphs229-GLstbtt_uint ftex;237+GLuint ftex;238 239 void my_stbtt_initfont(void)240 {241 fread(ttf_buffer, 1, 1<<20, fopen("c:/windows/fonts/times.ttf", "rb"));8 unmodified lines250 251 void my_stbtt_print(float x, float y, char *text)252 {253 // assume orthographic projection with units = screen pixels, origin at top left254+ glEnable(GL_TEXTURE_2D);255 glBindTexture(GL_TEXTURE_2D, ftex);256 glBegin(GL_QUADS);257 while (*text) {258 if (*text >= 32 && *text < 128) {125 unmodified lines384 385 typedef char stbtt__check_size32[sizeof(stbtt_int32)==4 ? 1 : -1];386 typedef char stbtt__check_size16[sizeof(stbtt_int16)==2 ? 1 : -1];387 388+ #ifdef STBTT_STATIC389+ #define STBTT_DEF static390+ #else391+ #define STBTT_DEF extern392+ #endif393+394 // #define your own STBTT_sort() to override this to avoid qsort395 #ifndef STBTT_sort396 #include <stdlib.h>397 #define STBTT_sort(data,num_items,item_size,compare_func) qsort(data,num_items,item_size,compare_func)61 unmodified lines459 unsigned short x0,y0,x1,y1; // coordinates of bbox in bitmap460 float xoff,yoff,xadvance;461 } stbtt_bakedchar;462 448-extern int stbtt_BakeFontBitmap(const unsigned char *data, int offset, // font location (use offset=0 for plain .ttf)463+STBTT_DEF int stbtt_BakeFontBitmap(const unsigned char *data, int offset, // font location (use offset=0 for plain .ttf)464 float pixel_height, // height of font in pixels465 unsigned char *pixels, int pw, int ph, // bitmap to be filled in466 int first_char, int num_chars, // characters to bake467 stbtt_bakedchar *chardata); // you allocate this, it's num_chars long7 unmodified lines475 float x0,y0,s0,t0; // top-left476 float x1,y1,s1,t1; // bottom-right477 } stbtt_aligned_quad;478 464-extern void stbtt_GetBakedQuad(stbtt_bakedchar *chardata, int pw, int ph, // same data as above479+STBTT_DEF void stbtt_GetBakedQuad(stbtt_bakedchar *chardata, int pw, int ph, // same data as above480 int char_index, // character to display481 float *xpos, float *ypos, // pointers to current position in screen pixel space482 stbtt_aligned_quad *q, // output: quad to draw483 int opengl_fillrule); // true if opengl fill rule; false if DX9 or earlier24 unmodified lines508 } stbtt_packedchar;509 510 typedef struct stbtt_pack_context stbtt_pack_context;511 497-extern int stbtt_PackBegin(stbtt_pack_context *spc, unsigned char *pixels, int width, int height, int stride_in_bytes, int padding, void *alloc_context);512+STBTT_DEF int stbtt_PackBegin(stbtt_pack_context *spc, unsigned char *pixels, int width, int height, int stride_in_bytes, int padding, void *alloc_context);513 // Initializes a packing context stored in the passed-in stbtt_pack_context.514 // Future calls using this context will pack characters into the bitmap passed515 // in here: a 1-channel bitmap that is weight x height. stride_in_bytes is516 // the distance from one row to the next (or 0 to mean they are packed tightly2 unmodified lines519 // bilinear filtering).520 //521 // Returns 0 on failure, 1 on success.522 508-extern void stbtt_PackEnd (stbtt_pack_context *spc);523+STBTT_DEF void stbtt_PackEnd (stbtt_pack_context *spc);524 // Cleans up the packing context and frees all memory.525 526 #define STBTT_POINT_SIZE(x) (-(x))527 513-extern int stbtt_PackFontRange(stbtt_pack_context *spc, unsigned char *fontdata, int font_index, float font_size,528+STBTT_DEF int stbtt_PackFontRange(stbtt_pack_context *spc, unsigned char *fontdata, int font_index, float font_size,529 int first_unicode_char_in_range, int num_chars_in_range, stbtt_packedchar *chardata_for_range);530 // Creates character bitmaps from the font_index'th font found in fontdata (use531 // font_index=0 if you don't know what that is). It creates num_chars_in_range532 // bitmaps for characters with unicode values starting at first_unicode_char_in_range14 unmodified lines547 int num_chars_in_range;548 stbtt_packedchar *chardata_for_range; // output549 } stbtt_pack_range;550 536-extern int stbtt_PackFontRanges(stbtt_pack_context *spc, unsigned char *fontdata, int font_index, stbtt_pack_range *ranges, int num_ranges);551+STBTT_DEF int stbtt_PackFontRanges(stbtt_pack_context *spc, unsigned char *fontdata, int font_index, stbtt_pack_range *ranges, int num_ranges);552 // Creates character bitmaps from multiple ranges of characters stored in553 // ranges. This will usually create a better-packed bitmap than multiple554 // calls to stbtt_PackFontRange.555 556 542-extern void stbtt_PackSetOversampling(stbtt_pack_context *spc, unsigned int h_oversample, unsigned int v_oversample);557+STBTT_DEF void stbtt_PackSetOversampling(stbtt_pack_context *spc, unsigned int h_oversample, unsigned int v_oversample);558 // Oversampling a font increases the quality by allowing higher-quality subpixel559 // positioning, and is especially valuable at smaller text sizes.560 //561 // This function sets the amount of oversampling for all following calls to3 unmodified lines565 // oversampling requires 4x the storage of 1x1. For best results, render566 // oversampled textures with bilinear filtering. Look at the readme in567 // stb/tests/oversample for information about oversampled fonts568 554-extern void stbtt_GetPackedQuad(stbtt_packedchar *chardata, int pw, int ph, // same data as above569+STBTT_DEF void stbtt_GetPackedQuad(stbtt_packedchar *chardata, int pw, int ph, // same data as above570 int char_index, // character to display571 float *xpos, float *ypos, // pointers to current position in screen pixel space572 stbtt_aligned_quad *q, // output: quad to draw573 int align_to_integer);17 unmodified lines591 // FONT LOADING592 //593 //594 580-extern int stbtt_GetFontOffsetForIndex(const unsigned char *data, int index);595+STBTT_DEF int stbtt_GetFontOffsetForIndex(const unsigned char *data, int index);596 // Each .ttf/.ttc file may have more than one font. Each font has a sequential597 // index number starting from 0. Call this function to get the font offset for598 // a given index; it returns -1 if the index is out of range. A regular .ttf599 // file will only define one font and it always be at offset 0, so it will15 unmodified lines615 int index_map; // a cmap mapping for our chosen character encoding616 int indexToLocFormat; // format needed to map from glyph index to glyph617 } stbtt_fontinfo;618 604-extern int stbtt_InitFont(stbtt_fontinfo *info, const unsigned char *data, int offset);619+STBTT_DEF int stbtt_InitFont(stbtt_fontinfo *info, const unsigned char *data, int offset);620 // Given an offset into the file that defines a font, this function builds621 // the necessary cached info for the rest of the system. You must allocate622 // the stbtt_fontinfo yourself, and stbtt_InitFont will fill it out. You don't623 // need to do anything special to free it, because the contents are pure3 unmodified lines627 //////////////////////////////////////////////////////////////////////////////628 //629 // CHARACTER TO GLYPH-INDEX CONVERSIOn630 616-int stbtt_FindGlyphIndex(const stbtt_fontinfo *info, int unicode_codepoint);631+STBTT_DEF int stbtt_FindGlyphIndex(const stbtt_fontinfo *info, int unicode_codepoint);632 // If you're going to perform multiple operations on the same character633 // and you want a speed-up, call this function with the character you're634 // going to process, then use glyph-based functions instead of the635 // codepoint-based functions.3 unmodified lines639 //640 // CHARACTER PROPERTIES641 //642 628-extern float stbtt_ScaleForPixelHeight(const stbtt_fontinfo *info, float pixels);643+STBTT_DEF float stbtt_ScaleForPixelHeight(const stbtt_fontinfo *info, float pixels);644 // computes a scale factor to produce a font whose "height" is 'pixels' tall.645 // Height is measured as the distance from the highest ascender to the lowest646 // descender; in other words, it's equivalent to calling stbtt_GetFontVMetrics647 // and computing:648 // scale = pixels / (ascent - descent)649 // so if you prefer to measure height by the ascent only, use a similar calculation.650 636-extern float stbtt_ScaleForMappingEmToPixels(const stbtt_fontinfo *info, float pixels);651+STBTT_DEF float stbtt_ScaleForMappingEmToPixels(const stbtt_fontinfo *info, float pixels);652 // computes a scale factor to produce a font whose EM size is mapped to653 // 'pixels' tall. This is probably what traditional APIs compute, but654 // I'm not positive.655 641-extern void stbtt_GetFontVMetrics(const stbtt_fontinfo *info, int *ascent, int *descent, int *lineGap);656+STBTT_DEF void stbtt_GetFontVMetrics(const stbtt_fontinfo *info, int *ascent, int *descent, int *lineGap);657 // ascent is the coordinate above the baseline the font extends; descent658 // is the coordinate below the baseline the font extends (i.e. it is typically negative)659 // lineGap is the spacing between one row's descent and the next row's ascent...660 // so you should advance the vertical position by "*ascent - *descent + *lineGap"661 // these are expressed in unscaled coordinates, so you must multiply by662 // the scale factor for a given size663 649-extern void stbtt_GetFontBoundingBox(const stbtt_fontinfo *info, int *x0, int *y0, int *x1, int *y1);664+STBTT_DEF void stbtt_GetFontBoundingBox(const stbtt_fontinfo *info, int *x0, int *y0, int *x1, int *y1);665 // the bounding box around all possible characters666 652-extern void stbtt_GetCodepointHMetrics(const stbtt_fontinfo *info, int codepoint, int *advanceWidth, int *leftSideBearing);667+STBTT_DEF void stbtt_GetCodepointHMetrics(const stbtt_fontinfo *info, int codepoint, int *advanceWidth, int *leftSideBearing);668 // leftSideBearing is the offset from the current horizontal position to the left edge of the character669 // advanceWidth is the offset from the current horizontal position to the next horizontal position670 // these are expressed in unscaled coordinates671 657-extern int stbtt_GetCodepointKernAdvance(const stbtt_fontinfo *info, int ch1, int ch2);672+STBTT_DEF int stbtt_GetCodepointKernAdvance(const stbtt_fontinfo *info, int ch1, int ch2);673 // an additional amount to add to the 'advance' value between ch1 and ch2674 660-extern int stbtt_GetCodepointBox(const stbtt_fontinfo *info, int codepoint, int *x0, int *y0, int *x1, int *y1);675+STBTT_DEF int stbtt_GetCodepointBox(const stbtt_fontinfo *info, int codepoint, int *x0, int *y0, int *x1, int *y1);676 // Gets the bounding box of the visible part of the glyph, in unscaled coordinates677 663-extern void stbtt_GetGlyphHMetrics(const stbtt_fontinfo *info, int glyph_index, int *advanceWidth, int *leftSideBearing);664-extern int stbtt_GetGlyphKernAdvance(const stbtt_fontinfo *info, int glyph1, int glyph2);665-extern int stbtt_GetGlyphBox(const stbtt_fontinfo *info, int glyph_index, int *x0, int *y0, int *x1, int *y1);678+STBTT_DEF void stbtt_GetGlyphHMetrics(const stbtt_fontinfo *info, int glyph_index, int *advanceWidth, int *leftSideBearing);679+STBTT_DEF int stbtt_GetGlyphKernAdvance(const stbtt_fontinfo *info, int glyph1, int glyph2);680+STBTT_DEF int stbtt_GetGlyphBox(const stbtt_fontinfo *info, int glyph_index, int *x0, int *y0, int *x1, int *y1);681 // as above, but takes one or more glyph indices for greater efficiency682 683 684 //////////////////////////////////////////////////////////////////////////////19 unmodified lines704 unsigned char type,padding;705 } stbtt_vertex;706 #endif707 693-extern int stbtt_IsGlyphEmpty(const stbtt_fontinfo *info, int glyph_index);708+STBTT_DEF int stbtt_IsGlyphEmpty(const stbtt_fontinfo *info, int glyph_index);709 // returns non-zero if nothing is drawn for this glyph710 696-extern int stbtt_GetCodepointShape(const stbtt_fontinfo *info, int unicode_codepoint, stbtt_vertex **vertices);697-extern int stbtt_GetGlyphShape(const stbtt_fontinfo *info, int glyph_index, stbtt_vertex **vertices);711+STBTT_DEF int stbtt_GetCodepointShape(const stbtt_fontinfo *info, int unicode_codepoint, stbtt_vertex **vertices);712+STBTT_DEF int stbtt_GetGlyphShape(const stbtt_fontinfo *info, int glyph_index, stbtt_vertex **vertices);713 // returns # of vertices and fills *vertices with the pointer to them714 // these are expressed in "unscaled" coordinates715 //716 // The shape is a series of countours. Each one starts with2 unmodified lines719 // draws a line from previous endpoint to its x,y; a curveto720 // draws a quadratic bezier from previous endpoint to721 // its x,y, using cx,cy as the bezier control point.722 708-extern void stbtt_FreeShape(const stbtt_fontinfo *info, stbtt_vertex *vertices);723+STBTT_DEF void stbtt_FreeShape(const stbtt_fontinfo *info, stbtt_vertex *vertices);724 // frees the data allocated above725 726 //////////////////////////////////////////////////////////////////////////////727 //728 // BITMAP RENDERING729 //730 716-extern void stbtt_FreeBitmap(unsigned char *bitmap, void *userdata);731+STBTT_DEF void stbtt_FreeBitmap(unsigned char *bitmap, void *userdata);732 // frees the bitmap allocated below733 719-extern unsigned char *stbtt_GetCodepointBitmap(const stbtt_fontinfo *info, float scale_x, float scale_y, int codepoint, int *width, int *height, int *xoff, int *yoff);734+STBTT_DEF unsigned char *stbtt_GetCodepointBitmap(const stbtt_fontinfo *info, float scale_x, float scale_y, int codepoint, int *width, int *height, int *xoff, int *yoff);735 // allocates a large-enough single-channel 8bpp bitmap and renders the736 // specified character/glyph at the specified scale into it, with737 // antialiasing. 0 is no coverage (transparent), 255 is fully covered (opaque).738 // *width & *height are filled out with the width & height of the bitmap,739 // which is stored left-to-right, top-to-bottom.740 //741 // xoff/yoff are the offset it pixel space from the glyph origin to the top-left of the bitmap742 728-extern unsigned char *stbtt_GetCodepointBitmapSubpixel(const stbtt_fontinfo *info, float scale_x, float scale_y, float shift_x, float shift_y, int codepoint, int *width, int *height, int *xoff, int *yoff);743+STBTT_DEF unsigned char *stbtt_GetCodepointBitmapSubpixel(const stbtt_fontinfo *info, float scale_x, float scale_y, float shift_x, float shift_y, int codepoint, int *width, int *height, int *xoff, int *yoff);744 // the same as stbtt_GetCodepoitnBitmap, but you can specify a subpixel745 // shift for the character746 732-extern void stbtt_MakeCodepointBitmap(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, int codepoint);747+STBTT_DEF void stbtt_MakeCodepointBitmap(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, int codepoint);748 // the same as stbtt_GetCodepointBitmap, but you pass in storage for the bitmap749 // in the form of 'output', with row spacing of 'out_stride' bytes. the bitmap750 // is clipped to out_w/out_h bytes. Call stbtt_GetCodepointBitmapBox to get the751 // width and height and positioning info for it first.752 738-extern void stbtt_MakeCodepointBitmapSubpixel(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int codepoint);753+STBTT_DEF void stbtt_MakeCodepointBitmapSubpixel(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int codepoint);754 // same as stbtt_MakeCodepointBitmap, but you can specify a subpixel755 // shift for the character756 742-extern void stbtt_GetCodepointBitmapBox(const stbtt_fontinfo *font, int codepoint, float scale_x, float scale_y, int *ix0, int *iy0, int *ix1, int *iy1);757+STBTT_DEF void stbtt_GetCodepointBitmapBox(const stbtt_fontinfo *font, int codepoint, float scale_x, float scale_y, int *ix0, int *iy0, int *ix1, int *iy1);758 // get the bbox of the bitmap centered around the glyph origin; so the759 // bitmap width is ix1-ix0, height is iy1-iy0, and location to place760 // the bitmap top left is (leftSideBearing*scale,iy0).761 // (Note that the bitmap uses y-increases-down, but the shape uses762 // y-increases-up, so CodepointBitmapBox and CodepointBox are inverted.)763 749-extern void stbtt_GetCodepointBitmapBoxSubpixel(const stbtt_fontinfo *font, int codepoint, float scale_x, float scale_y, float shift_x, float shift_y, int *ix0, int *iy0, int *ix1, int *iy1);764+STBTT_DEF void stbtt_GetCodepointBitmapBoxSubpixel(const stbtt_fontinfo *font, int codepoint, float scale_x, float scale_y, float shift_x, float shift_y, int *ix0, int *iy0, int *ix1, int *iy1);765 // same as stbtt_GetCodepointBitmapBox, but you can specify a subpixel766 // shift for the character767 768 // the following functions are equivalent to the above functions, but operate769 // on glyph indices instead of Unicode codepoints (for efficiency)755-extern unsigned char *stbtt_GetGlyphBitmap(const stbtt_fontinfo *info, float scale_x, float scale_y, int glyph, int *width, int *height, int *xoff, int *yoff);756-extern unsigned char *stbtt_GetGlyphBitmapSubpixel(const stbtt_fontinfo *info, float scale_x, float scale_y, float shift_x, float shift_y, int glyph, int *width, int *height, int *xoff, int *yoff);757-extern void stbtt_MakeGlyphBitmap(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, int glyph);758-extern void stbtt_MakeGlyphBitmapSubpixel(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int glyph);759-extern void stbtt_GetGlyphBitmapBox(const stbtt_fontinfo *font, int glyph, float scale_x, float scale_y, int *ix0, int *iy0, int *ix1, int *iy1);760-extern void stbtt_GetGlyphBitmapBoxSubpixel(const stbtt_fontinfo *font, int glyph, float scale_x, float scale_y,float shift_x, float shift_y, int *ix0, int *iy0, int *ix1, int *iy1);770+STBTT_DEF unsigned char *stbtt_GetGlyphBitmap(const stbtt_fontinfo *info, float scale_x, float scale_y, int glyph, int *width, int *height, int *xoff, int *yoff);771+STBTT_DEF unsigned char *stbtt_GetGlyphBitmapSubpixel(const stbtt_fontinfo *info, float scale_x, float scale_y, float shift_x, float shift_y, int glyph, int *width, int *height, int *xoff, int *yoff);772+STBTT_DEF void stbtt_MakeGlyphBitmap(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, int glyph);773+STBTT_DEF void stbtt_MakeGlyphBitmapSubpixel(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int glyph);774+STBTT_DEF void stbtt_GetGlyphBitmapBox(const stbtt_fontinfo *font, int glyph, float scale_x, float scale_y, int *ix0, int *iy0, int *ix1, int *iy1);775+STBTT_DEF void stbtt_GetGlyphBitmapBoxSubpixel(const stbtt_fontinfo *font, int glyph, float scale_x, float scale_y,float shift_x, float shift_y, int *ix0, int *iy0, int *ix1, int *iy1);776 777 778 // @TODO: don't expose this structure779 typedef struct1 unmodified line781 int w,h,stride;782 unsigned char *pixels;783 } stbtt__bitmap;784 770-extern void stbtt_Rasterize(stbtt__bitmap *result, float flatness_in_pixels, stbtt_vertex *vertices, int num_verts, float scale_x, float scale_y, float shift_x, float shift_y, int x_off, int y_off, int invert, void *userdata);785+STBTT_DEF void stbtt_Rasterize(stbtt__bitmap *result, float flatness_in_pixels, stbtt_vertex *vertices, int num_verts, float scale_x, float scale_y, float shift_x, float shift_y, int x_off, int y_off, int invert, void *userdata);786 787 //////////////////////////////////////////////////////////////////////////////788 //789 // Finding the right font...15 unmodified lines805 // from the file yourself and do your own comparisons on them.806 // You have to have called stbtt_InitFont() first.807 808 794-extern int stbtt_FindMatchingFont(const unsigned char *fontdata, const char *name, int flags);809+STBTT_DEF int stbtt_FindMatchingFont(const unsigned char *fontdata, const char *name, int flags);810 // returns the offset (not index) of the font that matches, or -1 if none811 // if you use STBTT_MACSTYLE_DONTCARE, use a font name like "Arial Bold".812 // if you use any other flag, use a font name like "Arial"; this checks813 // the 'macStyle' header field; i don't know if fonts set this consistently2 unmodified lines816 #define STBTT_MACSTYLE_ITALIC 2817 #define STBTT_MACSTYLE_UNDERSCORE 4818 #define STBTT_MACSTYLE_NONE 8 // <= not same as 0, this makes us check the bitfield is 0819 805-extern int stbtt_CompareUTF8toUTF16_bigendian(const char *s1, int len1, const char *s2, int len2);820+STBTT_DEF int stbtt_CompareUTF8toUTF16_bigendian(const char *s1, int len1, const char *s2, int len2);821 // returns 1/0 whether the first string interpreted as utf8 is identical to822 // the second string interpreted as big-endian utf16... useful for strings from next func823 809-extern const char *stbtt_GetFontNameString(const stbtt_fontinfo *font, int *length, int platformID, int encodingID, int languageID, int nameID);824+STBTT_DEF const char *stbtt_GetFontNameString(const stbtt_fontinfo *font, int *length, int platformID, int encodingID, int languageID, int nameID);825 // returns the string (which may be big-endian double byte, e.g. for unicode)826 // and puts the length in bytes in *length.827 //828 // some of the values for the IDs are below; for more see the truetype spec:90 unmodified lines919 #define ttLONG(p) (* (stbtt_int32 *) (p))920 921 #else922 908- stbtt_uint16 ttUSHORT(const stbtt_uint8 *p) { return p[0]*256 + p[1]; }909- stbtt_int16 ttSHORT(const stbtt_uint8 *p) { return p[0]*256 + p[1]; }910- stbtt_uint32 ttULONG(const stbtt_uint8 *p) { return (p[0]<<24) + (p[1]<<16) + (p[2]<<8) + p[3]; }911- stbtt_int32 ttLONG(const stbtt_uint8 *p) { return (p[0]<<24) + (p[1]<<16) + (p[2]<<8) + p[3]; }923+ static stbtt_uint16 ttUSHORT(const stbtt_uint8 *p) { return p[0]*256 + p[1]; }924+ static stbtt_int16 ttSHORT(const stbtt_uint8 *p) { return p[0]*256 + p[1]; }925+ static stbtt_uint32 ttULONG(const stbtt_uint8 *p) { return (p[0]<<24) + (p[1]<<16) + (p[2]<<8) + p[3]; }926+ static stbtt_int32 ttLONG(const stbtt_uint8 *p) { return (p[0]<<24) + (p[1]<<16) + (p[2]<<8) + p[3]; }927 928 #endif929 930 #define stbtt_tag4(p,c0,c1,c2,c3) ((p)[0] == (c0) && (p)[1] == (c1) && (p)[2] == (c2) && (p)[3] == (c3))22 unmodified lines953 }954 return 0;955 }956 942-int stbtt_GetFontOffsetForIndex(const unsigned char *font_collection, int index)957+STBTT_DEF int stbtt_GetFontOffsetForIndex(const unsigned char *font_collection, int index)958 {959 // if it's just a font, there's only one valid index960 if (stbtt__isfont(font_collection))961 return index == 0 ? 0 : -1;10 unmodified lines972 }973 return -1;974 }975 961-int stbtt_InitFont(stbtt_fontinfo *info, const unsigned char *data2, int fontstart)976+STBTT_DEF int stbtt_InitFont(stbtt_fontinfo *info, const unsigned char *data2, int fontstart)977 {978 stbtt_uint8 *data = (stbtt_uint8 *) data2;979 stbtt_uint32 cmap, t;980 stbtt_int32 i,numTables;48 unmodified lines1029 info->indexToLocFormat = ttUSHORT(data+info->head + 50);1030 return 1;1031 }1032 1018-int stbtt_FindGlyphIndex(const stbtt_fontinfo *info, int unicode_codepoint)1033+STBTT_DEF int stbtt_FindGlyphIndex(const stbtt_fontinfo *info, int unicode_codepoint)1034 {1035 stbtt_uint8 *data = info->data;1036 stbtt_uint32 index_map = info->index_map;1037 16 unmodified lines1054 stbtt_uint16 segcount = ttUSHORT(data+index_map+6) >> 1;1055 stbtt_uint16 searchRange = ttUSHORT(data+index_map+8) >> 1;1056 stbtt_uint16 entrySelector = ttUSHORT(data+index_map+10);1057 stbtt_uint16 rangeShift = ttUSHORT(data+index_map+12) >> 1;1043- stbtt_uint16 item, offset, start, end;1058 1059 // do a binary search of the segments1060 stbtt_uint32 endCount = index_map + 14;1061 stbtt_uint32 search = endCount;8 unmodified lines1070 1071 // now decrement to bias correctly to find smallest1072 search -= 2;1073 while (entrySelector) {1074+ stbtt_uint16 end;1075 searchRange >>= 1;1061- start = ttUSHORT(data + search + searchRange*2 + segcount*2 + 2);1076 end = ttUSHORT(data + search + searchRange*2);1077 if (unicode_codepoint > end)1078 search += searchRange*2;1079 --entrySelector;1080 }1081 search += 2;1082 1083+ {1084+ stbtt_uint16 offset, start;1069- item = (stbtt_uint16) ((search - endCount) >> 1);1085+ stbtt_uint16 item = (stbtt_uint16) ((search - endCount) >> 1);1086 1071- STBTT_assert(unicode_codepoint <= ttUSHORT(data + endCount + 2*item));1072- start = ttUSHORT(data + index_map + 14 + segcount*2 + 2 + 2*item);1073- end = ttUSHORT(data + index_map + 14 + 2 + 2*item);1074- if (unicode_codepoint < start)1075- return 0;1087+ STBTT_assert(unicode_codepoint <= ttUSHORT(data + endCount + 2*item));1088+ start = ttUSHORT(data + index_map + 14 + segcount*2 + 2 + 2*item);1089+ if (unicode_codepoint < start)1090+ return 0;1091 1077- offset = ttUSHORT(data + index_map + 14 + segcount*6 + 2 + 2*item);1078- if (offset == 0)1079- return (stbtt_uint16) (unicode_codepoint + ttSHORT(data + index_map + 14 + segcount*4 + 2 + 2*item));1092+ offset = ttUSHORT(data + index_map + 14 + segcount*6 + 2 + 2*item);1093+ if (offset == 0)1094+ return (stbtt_uint16) (unicode_codepoint + ttSHORT(data + index_map + 14 + segcount*4 + 2 + 2*item));1095 1081- return ttUSHORT(data + offset + (unicode_codepoint-start)*2 + index_map + 14 + segcount*6 + 2 + 2*item);1096+ return ttUSHORT(data + offset + (unicode_codepoint-start)*2 + index_map + 14 + segcount*6 + 2 + 2*item);1097+ }1098 } else if (format == 12 || format == 13) {1099 stbtt_uint32 ngroups = ttULONG(data+index_map+12);1100 stbtt_int32 low,high;1101 low = 0; high = (stbtt_int32)ngroups;20 unmodified lines1122 STBTT_assert(0);1123 return 0;1124 }1125 1110-int stbtt_GetCodepointShape(const stbtt_fontinfo *info, int unicode_codepoint, stbtt_vertex **vertices)1126+STBTT_DEF int stbtt_GetCodepointShape(const stbtt_fontinfo *info, int unicode_codepoint, stbtt_vertex **vertices)1127 {1128 return stbtt_GetGlyphShape(info, stbtt_FindGlyphIndex(info, unicode_codepoint), vertices);1129 }1130 23 unmodified lines1154 1155 return g1==g2 ? -1 : g1; // if length is 0, return -11156 }1157 1142-int stbtt_GetGlyphBox(const stbtt_fontinfo *info, int glyph_index, int *x0, int *y0, int *x1, int *y1)1158+STBTT_DEF int stbtt_GetGlyphBox(const stbtt_fontinfo *info, int glyph_index, int *x0, int *y0, int *x1, int *y1)1159 {1160 int g = stbtt__GetGlyfOffset(info, glyph_index);1161 if (g < 0) return 0;1162 3 unmodified lines1166 if (y1) *y1 = ttSHORT(info->data + g + 8);1167 return 1;1168 }1169 1154-int stbtt_GetCodepointBox(const stbtt_fontinfo *info, int codepoint, int *x0, int *y0, int *x1, int *y1)1170+STBTT_DEF int stbtt_GetCodepointBox(const stbtt_fontinfo *info, int codepoint, int *x0, int *y0, int *x1, int *y1)1171 {1172 return stbtt_GetGlyphBox(info, stbtt_FindGlyphIndex(info,codepoint), x0,y0,x1,y1);1173 }1174 1159-int stbtt_IsGlyphEmpty(const stbtt_fontinfo *info, int glyph_index)1175+STBTT_DEF int stbtt_IsGlyphEmpty(const stbtt_fontinfo *info, int glyph_index)1176 {1177 stbtt_int16 numberOfContours;1178 int g = stbtt__GetGlyfOffset(info, glyph_index);1179 if (g < 0) return 1;16 unmodified lines1196 }1197 return num_vertices;1198 }1199 1184-int stbtt_GetGlyphShape(const stbtt_fontinfo *info, int glyph_index, stbtt_vertex **pvertices)1200+STBTT_DEF int stbtt_GetGlyphShape(const stbtt_fontinfo *info, int glyph_index, stbtt_vertex **pvertices)1201 {1202 stbtt_int16 numberOfContours;1203 stbtt_uint8 *endPtsOfContours;1204 stbtt_uint8 *data = info->data;217 unmodified lines1422 *pvertices = vertices;1423 return num_vertices;1424 }1425 1410-void stbtt_GetGlyphHMetrics(const stbtt_fontinfo *info, int glyph_index, int *advanceWidth, int *leftSideBearing)1426+STBTT_DEF void stbtt_GetGlyphHMetrics(const stbtt_fontinfo *info, int glyph_index, int *advanceWidth, int *leftSideBearing)1427 {1428 stbtt_uint16 numOfLongHorMetrics = ttUSHORT(info->data+info->hhea + 34);1429 if (glyph_index < numOfLongHorMetrics) {1430 if (advanceWidth) *advanceWidth = ttSHORT(info->data + info->hmtx + 4*glyph_index);3 unmodified lines1434 if (leftSideBearing) *leftSideBearing = ttSHORT(info->data + info->hmtx + 4*numOfLongHorMetrics + 2*(glyph_index - numOfLongHorMetrics));1435 }1436 }1437 1422-int stbtt_GetGlyphKernAdvance(const stbtt_fontinfo *info, int glyph1, int glyph2)1438+STBTT_DEF int stbtt_GetGlyphKernAdvance(const stbtt_fontinfo *info, int glyph1, int glyph2)1439 {1440 stbtt_uint8 *data = info->data + info->kern;1441 stbtt_uint32 needle, straw;1442 int l, r, m;21 unmodified lines1464 }1465 return 0;1466 }1467 1452-int stbtt_GetCodepointKernAdvance(const stbtt_fontinfo *info, int ch1, int ch2)1468+STBTT_DEF int stbtt_GetCodepointKernAdvance(const stbtt_fontinfo *info, int ch1, int ch2)1469 {1470 if (!info->kern) // if no kerning table, don't waste time looking up both codepoint->glyphs1471 return 0;1472 return stbtt_GetGlyphKernAdvance(info, stbtt_FindGlyphIndex(info,ch1), stbtt_FindGlyphIndex(info,ch2));1473 }1474 1459-void stbtt_GetCodepointHMetrics(const stbtt_fontinfo *info, int codepoint, int *advanceWidth, int *leftSideBearing)1475+STBTT_DEF void stbtt_GetCodepointHMetrics(const stbtt_fontinfo *info, int codepoint, int *advanceWidth, int *leftSideBearing)1476 {1477 stbtt_GetGlyphHMetrics(info, stbtt_FindGlyphIndex(info,codepoint), advanceWidth, leftSideBearing);1478 }1479 1464-void stbtt_GetFontVMetrics(const stbtt_fontinfo *info, int *ascent, int *descent, int *lineGap)1480+STBTT_DEF void stbtt_GetFontVMetrics(const stbtt_fontinfo *info, int *ascent, int *descent, int *lineGap)1481 {1482 if (ascent ) *ascent = ttSHORT(info->data+info->hhea + 4);1483 if (descent) *descent = ttSHORT(info->data+info->hhea + 6);1484 if (lineGap) *lineGap = ttSHORT(info->data+info->hhea + 8);1485 }1486 1471-void stbtt_GetFontBoundingBox(const stbtt_fontinfo *info, int *x0, int *y0, int *x1, int *y1)1487+STBTT_DEF void stbtt_GetFontBoundingBox(const stbtt_fontinfo *info, int *x0, int *y0, int *x1, int *y1)1488 {1489 *x0 = ttSHORT(info->data + info->head + 36);1490 *y0 = ttSHORT(info->data + info->head + 38);1491 *x1 = ttSHORT(info->data + info->head + 40);1492 *y1 = ttSHORT(info->data + info->head + 42);1493 }1494 1479-float stbtt_ScaleForPixelHeight(const stbtt_fontinfo *info, float height)1495+STBTT_DEF float stbtt_ScaleForPixelHeight(const stbtt_fontinfo *info, float height)1496 {1497 int fheight = ttSHORT(info->data + info->hhea + 4) - ttSHORT(info->data + info->hhea + 6);1498 return (float) height / fheight;1499 }1500 1485-float stbtt_ScaleForMappingEmToPixels(const stbtt_fontinfo *info, float pixels)1501+STBTT_DEF float stbtt_ScaleForMappingEmToPixels(const stbtt_fontinfo *info, float pixels)1502 {1503 int unitsPerEm = ttUSHORT(info->data + info->head + 18);1504 return pixels / unitsPerEm;1505 }1506 1491-void stbtt_FreeShape(const stbtt_fontinfo *info, stbtt_vertex *v)1507+STBTT_DEF void stbtt_FreeShape(const stbtt_fontinfo *info, stbtt_vertex *v)1508 {1509 STBTT_free(v, info->userdata);1510 }1511 1 unmodified line1513 //1514 // antialiasing software rasterizer1515 //1516 1501-void stbtt_GetGlyphBitmapBoxSubpixel(const stbtt_fontinfo *font, int glyph, float scale_x, float scale_y,float shift_x, float shift_y, int *ix0, int *iy0, int *ix1, int *iy1)1517+STBTT_DEF void stbtt_GetGlyphBitmapBoxSubpixel(const stbtt_fontinfo *font, int glyph, float scale_x, float scale_y,float shift_x, float shift_y, int *ix0, int *iy0, int *ix1, int *iy1)1518 {1519 int x0,y0,x1,y1;1520 if (!stbtt_GetGlyphBox(font, glyph, &x0,&y0,&x1,&y1)) {1521 // e.g. space character9 unmodified lines1531 if (iy1) *iy1 = STBTT_iceil (-y0 * scale_y + shift_y);1532 }1533 }1534 1519-void stbtt_GetGlyphBitmapBox(const stbtt_fontinfo *font, int glyph, float scale_x, float scale_y, int *ix0, int *iy0, int *ix1, int *iy1)1535+STBTT_DEF void stbtt_GetGlyphBitmapBox(const stbtt_fontinfo *font, int glyph, float scale_x, float scale_y, int *ix0, int *iy0, int *ix1, int *iy1)1536 {1537 stbtt_GetGlyphBitmapBoxSubpixel(font, glyph, scale_x, scale_y,0.0f,0.0f, ix0, iy0, ix1, iy1);1538 }1539 1524-void stbtt_GetCodepointBitmapBoxSubpixel(const stbtt_fontinfo *font, int codepoint, float scale_x, float scale_y, float shift_x, float shift_y, int *ix0, int *iy0, int *ix1, int *iy1)1540+STBTT_DEF void stbtt_GetCodepointBitmapBoxSubpixel(const stbtt_fontinfo *font, int codepoint, float scale_x, float scale_y, float shift_x, float shift_y, int *ix0, int *iy0, int *ix1, int *iy1)1541 {1542 stbtt_GetGlyphBitmapBoxSubpixel(font, stbtt_FindGlyphIndex(font,codepoint), scale_x, scale_y,shift_x,shift_y, ix0,iy0,ix1,iy1);1543 }1544 1529-void stbtt_GetCodepointBitmapBox(const stbtt_fontinfo *font, int codepoint, float scale_x, float scale_y, int *ix0, int *iy0, int *ix1, int *iy1)1545+STBTT_DEF void stbtt_GetCodepointBitmapBox(const stbtt_fontinfo *font, int codepoint, float scale_x, float scale_y, int *ix0, int *iy0, int *ix1, int *iy1)1546 {1547 stbtt_GetCodepointBitmapBoxSubpixel(font, codepoint, scale_x, scale_y,0.0f,0.0f, ix0,iy0,ix1,iy1);1548 }1549 272 unmodified lines1822 return 1;1823 }1824 1825 // returns number of contours1810-stbtt__point *stbtt_FlattenCurves(stbtt_vertex *vertices, int num_verts, float objspace_flatness, int **contour_lengths, int *num_contours, void *userdata)1826+static stbtt__point *stbtt_FlattenCurves(stbtt_vertex *vertices, int num_verts, float objspace_flatness, int **contour_lengths, int *num_contours, void *userdata)1827 {1828 stbtt__point *points=0;1829 int num_points=0;1830 60 unmodified lines1891 *num_contours = 0;1892 return NULL;1893 }1894 1879-void stbtt_Rasterize(stbtt__bitmap *result, float flatness_in_pixels, stbtt_vertex *vertices, int num_verts, float scale_x, float scale_y, float shift_x, float shift_y, int x_off, int y_off, int invert, void *userdata)1895+STBTT_DEF void stbtt_Rasterize(stbtt__bitmap *result, float flatness_in_pixels, stbtt_vertex *vertices, int num_verts, float scale_x, float scale_y, float shift_x, float shift_y, int x_off, int y_off, int invert, void *userdata)1896 {1897 float scale = scale_x > scale_y ? scale_y : scale_x;1898 int winding_count, *winding_lengths;1899 stbtt__point *windings = stbtt_FlattenCurves(vertices, num_verts, flatness_in_pixels / scale, &winding_lengths, &winding_count, userdata);3 unmodified lines1903 STBTT_free(windings, userdata);1904 }1905 }1906 1891-void stbtt_FreeBitmap(unsigned char *bitmap, void *userdata)1907+STBTT_DEF void stbtt_FreeBitmap(unsigned char *bitmap, void *userdata)1908 {1909 STBTT_free(bitmap, userdata);1910 }1911 1896-unsigned char *stbtt_GetGlyphBitmapSubpixel(const stbtt_fontinfo *info, float scale_x, float scale_y, float shift_x, float shift_y, int glyph, int *width, int *height, int *xoff, int *yoff)1912+STBTT_DEF unsigned char *stbtt_GetGlyphBitmapSubpixel(const stbtt_fontinfo *info, float scale_x, float scale_y, float shift_x, float shift_y, int glyph, int *width, int *height, int *xoff, int *yoff)1913 {1914 int ix0,iy0,ix1,iy1;1915 stbtt__bitmap gbm;1916 stbtt_vertex *vertices; 28 unmodified lines1945 STBTT_free(vertices, info->userdata);1946 return gbm.pixels;1947 } 1948 1933-unsigned char *stbtt_GetGlyphBitmap(const stbtt_fontinfo *info, float scale_x, float scale_y, int glyph, int *width, int *height, int *xoff, int *yoff)1949+STBTT_DEF unsigned char *stbtt_GetGlyphBitmap(const stbtt_fontinfo *info, float scale_x, float scale_y, int glyph, int *width, int *height, int *xoff, int *yoff)1950 {1951 return stbtt_GetGlyphBitmapSubpixel(info, scale_x, scale_y, 0.0f, 0.0f, glyph, width, height, xoff, yoff);1952 }1953 1938-void stbtt_MakeGlyphBitmapSubpixel(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int glyph)1954+STBTT_DEF void stbtt_MakeGlyphBitmapSubpixel(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int glyph)1955 {1956 int ix0,iy0;1957 stbtt_vertex *vertices;1958 int num_verts = stbtt_GetGlyphShape(info, glyph, &vertices);10 unmodified lines1969 1970 STBTT_free(vertices, info->userdata);1971 }1972 1957-void stbtt_MakeGlyphBitmap(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, int glyph)1973+STBTT_DEF void stbtt_MakeGlyphBitmap(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, int glyph)1974 {1975 stbtt_MakeGlyphBitmapSubpixel(info, output, out_w, out_h, out_stride, scale_x, scale_y, 0.0f,0.0f, glyph);1976 }1977 1962-unsigned char *stbtt_GetCodepointBitmapSubpixel(const stbtt_fontinfo *info, float scale_x, float scale_y, float shift_x, float shift_y, int codepoint, int *width, int *height, int *xoff, int *yoff)1978+STBTT_DEF unsigned char *stbtt_GetCodepointBitmapSubpixel(const stbtt_fontinfo *info, float scale_x, float scale_y, float shift_x, float shift_y, int codepoint, int *width, int *height, int *xoff, int *yoff)1979 {1980 return stbtt_GetGlyphBitmapSubpixel(info, scale_x, scale_y,shift_x,shift_y, stbtt_FindGlyphIndex(info,codepoint), width,height,xoff,yoff);1981 } 1982 1967-void stbtt_MakeCodepointBitmapSubpixel(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int codepoint)1983+STBTT_DEF void stbtt_MakeCodepointBitmapSubpixel(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int codepoint)1984 {1985 stbtt_MakeGlyphBitmapSubpixel(info, output, out_w, out_h, out_stride, scale_x, scale_y, shift_x, shift_y, stbtt_FindGlyphIndex(info,codepoint));1986 }1987 1972-unsigned char *stbtt_GetCodepointBitmap(const stbtt_fontinfo *info, float scale_x, float scale_y, int codepoint, int *width, int *height, int *xoff, int *yoff)1988+STBTT_DEF unsigned char *stbtt_GetCodepointBitmap(const stbtt_fontinfo *info, float scale_x, float scale_y, int codepoint, int *width, int *height, int *xoff, int *yoff)1989 {1990 return stbtt_GetCodepointBitmapSubpixel(info, scale_x, scale_y, 0.0f,0.0f, codepoint, width,height,xoff,yoff);1991 } 1992 1977-void stbtt_MakeCodepointBitmap(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, int codepoint)1993+STBTT_DEF void stbtt_MakeCodepointBitmap(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, int codepoint)1994 {1995 stbtt_MakeCodepointBitmapSubpixel(info, output, out_w, out_h, out_stride, scale_x, scale_y, 0.0f,0.0f, codepoint);1996 }1997 2 unmodified lines2000 // bitmap baking2001 //2002 // This is SUPER-CRAPPY packing to keep source code small2003 1988-extern int stbtt_BakeFontBitmap(const unsigned char *data, int offset, // font location (use offset=0 for plain .ttf)2004+STBTT_DEF int stbtt_BakeFontBitmap(const unsigned char *data, int offset, // font location (use offset=0 for plain .ttf)2005 float pixel_height, // height of font in pixels2006 unsigned char *pixels, int pw, int ph, // bitmap to be filled in2007 int first_char, int num_chars, // characters to bake2008 stbtt_bakedchar *chardata)36 unmodified lines2045 }2046 return bottom_y;2047 }2048 2033-void stbtt_GetBakedQuad(stbtt_bakedchar *chardata, int pw, int ph, int char_index, float *xpos, float *ypos, stbtt_aligned_quad *q, int opengl_fillrule)2049+STBTT_DEF void stbtt_GetBakedQuad(stbtt_bakedchar *chardata, int pw, int ph, int char_index, float *xpos, float *ypos, stbtt_aligned_quad *q, int opengl_fillrule)2050 {2051 float d3d_bias = opengl_fillrule ? 0 : -0.5f;2052 float ipw = 1.0f / pw, iph = 1.0f / ph;2053 stbtt_bakedchar *b = chardata + char_index;2038- int round_x = STBTT_ifloor((*xpos + b->xoff) + 0.5);2039- int round_y = STBTT_ifloor((*ypos + b->yoff) + 0.5);2054+ int round_x = STBTT_ifloor((*xpos + b->xoff) + 0.5f);2055+ int round_y = STBTT_ifloor((*ypos + b->yoff) + 0.5f);2056 2057 q->x0 = round_x + d3d_bias;2058 q->y0 = round_y + d3d_bias;2059 q->x1 = round_x + b->x1 - b->x0 + d3d_bias;88 unmodified lines2148 //2149 // This is SUPER-AWESOME (tm Ryan Gordon) packing using stb_rect_pack.h. If2150 // stb_rect_pack.h isn't available, it uses the BakeFontBitmap strategy.2151 2136-int stbtt_PackBegin(stbtt_pack_context *spc, unsigned char *pixels, int pw, int ph, int stride_in_bytes, int padding, void *alloc_context)2152+STBTT_DEF int stbtt_PackBegin(stbtt_pack_context *spc, unsigned char *pixels, int pw, int ph, int stride_in_bytes, int padding, void *alloc_context)2153 {2154 stbrp_context *context = (stbrp_context *) STBTT_malloc(sizeof(*context) ,alloc_context);2155 int num_nodes = pw - padding;2156 stbrp_node *nodes = (stbrp_node *) STBTT_malloc(sizeof(*nodes ) * num_nodes,alloc_context);21 unmodified lines2178 2179 return 1;2180 }2181 2166-void stbtt_PackEnd (stbtt_pack_context *spc)2182+STBTT_DEF void stbtt_PackEnd (stbtt_pack_context *spc)2183 {2184 STBTT_free(spc->nodes , spc->user_allocator_context);2185 STBTT_free(spc->pack_info, spc->user_allocator_context);2186 }2187 2172-void stbtt_PackSetOversampling(stbtt_pack_context *spc, unsigned int h_oversample, unsigned int v_oversample)2188+STBTT_DEF void stbtt_PackSetOversampling(stbtt_pack_context *spc, unsigned int h_oversample, unsigned int v_oversample)2189 {2190 STBTT_assert(h_oversample <= STBTT_MAX_OVERSAMPLE);2191 STBTT_assert(v_oversample <= STBTT_MAX_OVERSAMPLE);2192 if (h_oversample <= STBTT_MAX_OVERSAMPLE)11 unmodified lines2204 int j;2205 for (j=0; j < h; ++j) {2206 int i;2207 unsigned int total;2192- memset(buffer, 0, kernel_width);2208+ STBTT_memset(buffer, 0, kernel_width);2209 2210 total = 0;2211 2212 // make kernel_width a constant in common cases so compiler can optimize out the divide45 unmodified lines2258 int j;2259 for (j=0; j < w; ++j) {2260 int i;2261 unsigned int total;2246- memset(buffer, 0, kernel_width);2262+ STBTT_memset(buffer, 0, kernel_width);2263 2264 total = 0;2265 2266 // make kernel_width a constant in common cases so compiler can optimize out the divide49 unmodified lines2316 // direction to counter this.2317 return (float)-(oversample - 1) / (2.0f * (float)oversample);2318 }2319 2304-int stbtt_PackFontRanges(stbtt_pack_context *spc, unsigned char *fontdata, int font_index, stbtt_pack_range *ranges, int num_ranges)2320+STBTT_DEF int stbtt_PackFontRanges(stbtt_pack_context *spc, unsigned char *fontdata, int font_index, stbtt_pack_range *ranges, int num_ranges)2321 {2322 stbtt_fontinfo info;2323 float recip_h = 1.0f / spc->h_oversample;2324 float recip_v = 1.0f / spc->v_oversample;97 unmodified lines2422 ++k;2423 }2424 }2425 2426+ STBTT_free(rects, spc->user_allocator_context);2427 return return_value;2428 }2429 2413-int stbtt_PackFontRange(stbtt_pack_context *spc, unsigned char *fontdata, int font_index, float font_size,2430+STBTT_DEF int stbtt_PackFontRange(stbtt_pack_context *spc, unsigned char *fontdata, int font_index, float font_size,2431 int first_unicode_char_in_range, int num_chars_in_range, stbtt_packedchar *chardata_for_range)2432 {2433 stbtt_pack_range range;2434 range.first_unicode_char_in_range = first_unicode_char_in_range;2 unmodified lines2437 range.font_size = font_size;2438 return stbtt_PackFontRanges(spc, fontdata, font_index, &range, 1);2439 }2440 2424-void stbtt_GetPackedQuad(stbtt_packedchar *chardata, int pw, int ph, int char_index, float *xpos, float *ypos, stbtt_aligned_quad *q, int align_to_integer)2441+STBTT_DEF void stbtt_GetPackedQuad(stbtt_packedchar *chardata, int pw, int ph, int char_index, float *xpos, float *ypos, stbtt_aligned_quad *q, int align_to_integer)2442 {2443 float ipw = 1.0f / pw, iph = 1.0f / ph;2444 stbtt_packedchar *b = chardata + char_index;2445 2446 if (align_to_integer) {2430- float x = (float) STBTT_ifloor((*xpos + b->xoff) + 0.5);2431- float y = (float) STBTT_ifloor((*ypos + b->yoff) + 0.5);2447+ float x = (float) STBTT_ifloor((*xpos + b->xoff) + 0.5f);2448+ float y = (float) STBTT_ifloor((*ypos + b->yoff) + 0.5f);2449 q->x0 = x;2450 q->y0 = y;2451 q->x1 = x + b->xoff2 - b->xoff;2452 q->y1 = y + b->yoff2 - b->yoff;57 unmodified lines2510 }2511 return i;2512 }2513 2497-int stbtt_CompareUTF8toUTF16_bigendian(const char *s1, int len1, const char *s2, int len2) 2514+STBTT_DEF int stbtt_CompareUTF8toUTF16_bigendian(const char *s1, int len1, const char *s2, int len2) 2515 {2516 return len1 == stbtt__CompareUTF8toUTF16_bigendian_prefix((const stbtt_uint8*) s1, len1, (const stbtt_uint8*) s2, len2);2517 }2518 2519 // returns results in whatever encoding you request... but note that 2-byte encodings2520 // will be BIG-ENDIAN... use stbtt_CompareUTF8toUTF16_bigendian() to compare2504-const char *stbtt_GetFontNameString(const stbtt_fontinfo *font, int *length, int platformID, int encodingID, int languageID, int nameID)2521+STBTT_DEF const char *stbtt_GetFontNameString(const stbtt_fontinfo *font, int *length, int platformID, int encodingID, int languageID, int nameID)2522 {2523 stbtt_int32 i,count,stringOffset;2524 stbtt_uint8 *fc = font->data;2525 stbtt_uint32 offset = font->fontstart;88 unmodified lines2614 2615 return 0;2616 }2617 2601-int stbtt_FindMatchingFont(const unsigned char *font_collection, const char *name_utf8, stbtt_int32 flags)2618+STBTT_DEF int stbtt_FindMatchingFont(const unsigned char *font_collection, const char *name_utf8, stbtt_int32 flags)2619 {2620 stbtt_int32 i;2621 for (i=0;;++i) {2622 stbtt_int32 off = stbtt_GetFontOffsetForIndex(font_collection, i);7 unmodified linesmodified:stb_voxel_render.h+2 added-2 removed
1228 unmodified lines1229 #error "Can't store both rotation and vheight in lighting"1230 #endif1231 1232 1233-// The following are candidate voxel modes. Only modes 0, 1, and 20 are1233+// The following are candidate voxel modes. Only modes 0, 1, and 20, and 21 are1234 // currently implemented. Reducing the storage-per-quad further1235 // shouldn't improve performance, although obviously it allow you1236 // to create larger worlds without streaming.1237 //13 unmodified lines1251 // z extents 255 255 128 64? 64? 64 64 32 64 128 255 255 128 64 1281252 1253 // not sure why I only wrote down the above "result data" and didn't preserve1254 // the vertex formats, but here I've tried to reconstruct the designs...1255-// mode # 3 is wrong, one byte too large1255+// mode # 3 is wrong, one byte too large, but they may have been an error originally1256 1257 // Mode: 0 1 2 3 4 5 6 10 11 12 20 21 22 23 241258 // =============================================================================================================1259 // bytes per quad 32 20 14 12 10 6 6 8 8 4 20 10 6 42478 unmodified lines