Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
itdan3344
stb
提交
667d8408
S
stb
项目概览
itdan3344
/
stb
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
stb
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
667d8408
编写于
1月 16, 2016
作者:
S
Sean Barrett
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'working'
上级
418d21f2
f1d2002a
变更
7
展开全部
隐藏空白更改
内联
并排
Showing
7 changed file
with
595 addition
and
404 deletion
+595
-404
stb_image.h
stb_image.h
+300
-199
stb_image_write.h
stb_image_write.h
+91
-40
stb_truetype.h
stb_truetype.h
+32
-21
stb_vorbis.c
stb_vorbis.c
+160
-139
tests/image_test.c
tests/image_test.c
+6
-4
tests/stb.dsp
tests/stb.dsp
+4
-0
tests/test_vorbis.c
tests/test_vorbis.c
+2
-1
未找到文件。
stb_image.h
浏览文件 @
667d8408
此差异已折叠。
点击以展开。
stb_image_write.h
浏览文件 @
667d8408
/* stb_image_write - v1.0
0
- public domain - http://nothings.org/stb/stb_image_write.h
/* stb_image_write - v1.0
1
- public domain - http://nothings.org/stb/stb_image_write.h
writes out PNG/BMP/TGA images to C stdio - Sean Barrett 2010-2015
no warranty implied; use at your own risk
...
...
@@ -34,7 +34,7 @@ USAGE:
int stbi_write_png(char const *filename, int w, int h, int comp, const void *data, int stride_in_bytes);
int stbi_write_bmp(char const *filename, int w, int h, int comp, const void *data);
int stbi_write_tga(char const *filename, int w, int h, int comp, const void *data);
int stbi_write_hdr(char const *filename, int w, int h, int comp, const
void
*data);
int stbi_write_hdr(char const *filename, int w, int h, int comp, const
float
*data);
There are also four equivalent functions that use an arbitrary write function. You are
expected to open/close your file-equivalent before and after calling these:
...
...
@@ -98,12 +98,16 @@ CREDITS:
github:Chribba
Guillaume Chereau
github:jry2
github:romigrou
Sergio Gonzalez
Jonas Karlsson
Filip Wasil
LICENSE
This software is in the public domain. Where that dedication is not
recognized, you are granted a perpetual, irrevocable license to copy,
distribute, and modify this file as you see fit.
distribute, and modify this file as you see fit.
*/
...
...
@@ -144,8 +148,12 @@ STBIWDEF int stbi_write_hdr_to_func(stbi_write_func *func, void *context, int w,
#ifdef STB_IMAGE_WRITE_IMPLEMENTATION
#ifdef _WIN32
#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#endif
#ifndef _CRT_NONSTDC_NO_DEPRECATE
#define _CRT_NONSTDC_NO_DEPRECATE
#endif
#endif
#ifndef STBI_WRITE_NO_STDIO
...
...
@@ -157,19 +165,25 @@ STBIWDEF int stbi_write_hdr_to_func(stbi_write_func *func, void *context, int w,
#include <string.h>
#include <math.h>
#if defined(STBIW_MALLOC) && defined(STBIW_FREE) &&
defined(STBIW_REALLOC
)
#if defined(STBIW_MALLOC) && defined(STBIW_FREE) &&
(defined(STBIW_REALLOC) || defined(STBIW_REALLOC_SIZED)
)
// ok
#elif !defined(STBIW_MALLOC) && !defined(STBIW_FREE) && !defined(STBIW_REALLOC)
#elif !defined(STBIW_MALLOC) && !defined(STBIW_FREE) && !defined(STBIW_REALLOC)
&& !defined(STBIW_REALLOC_SIZED)
// ok
#else
#error "Must define all or none of STBIW_MALLOC, STBIW_FREE, and STBIW_REALLOC."
#error "Must define all or none of STBIW_MALLOC, STBIW_FREE, and STBIW_REALLOC
(or STBIW_REALLOC_SIZED)
."
#endif
#ifndef STBIW_MALLOC
#define STBIW_MALLOC(sz) malloc(sz)
#define STBIW_REALLOC(p,
sz) realloc(p,
sz)
#define STBIW_FREE(p) free(p)
#define STBIW_MALLOC(sz)
malloc(sz)
#define STBIW_REALLOC(p,
newsz) realloc(p,new
sz)
#define STBIW_FREE(p)
free(p)
#endif
#ifndef STBIW_REALLOC_SIZED
#define STBIW_REALLOC_SIZED(p,oldsz,newsz) STBIW_REALLOC(p,newsz)
#endif
#ifndef STBIW_MEMMOVE
#define STBIW_MEMMOVE(a,b,sz) memmove(a,b,sz)
#endif
...
...
@@ -180,6 +194,8 @@ STBIWDEF int stbi_write_hdr_to_func(stbi_write_func *func, void *context, int w,
#define STBIW_ASSERT(x) assert(x)
#endif
#define STBIW_UCHAR(x) (unsigned char) ((x) & 0xff)
typedef
struct
{
stbi_write_func
*
func
;
...
...
@@ -228,21 +244,21 @@ static void stbiw__writefv(stbi__write_context *s, const char *fmt, va_list v)
while
(
*
fmt
)
{
switch
(
*
fmt
++
)
{
case
' '
:
break
;
case
'1'
:
{
unsigned
char
x
=
(
unsigned
char
)
va_arg
(
v
,
int
);
case
'1'
:
{
unsigned
char
x
=
STBIW_UCHAR
(
va_arg
(
v
,
int
)
);
s
->
func
(
s
->
context
,
&
x
,
1
);
break
;
}
case
'2'
:
{
int
x
=
va_arg
(
v
,
int
);
unsigned
char
b
[
2
];
b
[
0
]
=
(
unsigned
char
)
x
;
b
[
1
]
=
(
unsigned
char
)
(
x
>>
8
);
b
[
0
]
=
STBIW_UCHAR
(
x
)
;
b
[
1
]
=
STBIW_UCHAR
(
x
>>
8
);
s
->
func
(
s
->
context
,
b
,
2
);
break
;
}
case
'4'
:
{
stbiw_uint32
x
=
va_arg
(
v
,
int
);
unsigned
char
b
[
4
];
b
[
0
]
=
(
unsigned
char
)
x
;
b
[
1
]
=
(
unsigned
char
)
(
x
>>
8
);
b
[
2
]
=
(
unsigned
char
)
(
x
>>
16
);
b
[
3
]
=
(
unsigned
char
)
(
x
>>
24
);
b
[
0
]
=
STBIW_UCHAR
(
x
)
;
b
[
1
]
=
STBIW_UCHAR
(
x
>>
8
);
b
[
2
]
=
STBIW_UCHAR
(
x
>>
16
);
b
[
3
]
=
STBIW_UCHAR
(
x
>>
24
);
s
->
func
(
s
->
context
,
b
,
4
);
break
;
}
default:
...
...
@@ -419,13 +435,13 @@ static int stbi_write_tga_core(stbi__write_context *s, int x, int y, int comp, v
}
if
(
diff
)
{
unsigned
char
header
=
(
unsigned
char
)
(
len
-
1
);
unsigned
char
header
=
STBIW_UCHAR
(
len
-
1
);
s
->
func
(
s
->
context
,
&
header
,
1
);
for
(
k
=
0
;
k
<
len
;
++
k
)
{
stbiw__write_pixel
(
s
,
-
1
,
comp
,
has_alpha
,
0
,
begin
+
k
*
comp
);
}
}
else
{
unsigned
char
header
=
(
unsigned
char
)
(
len
-
129
);
unsigned
char
header
=
STBIW_UCHAR
(
len
-
129
);
s
->
func
(
s
->
context
,
&
header
,
1
);
stbiw__write_pixel
(
s
,
-
1
,
comp
,
has_alpha
,
0
,
begin
);
}
...
...
@@ -467,7 +483,7 @@ void stbiw__linear_to_rgbe(unsigned char *rgbe, float *linear)
int
exponent
;
float
maxcomp
=
stbiw__max
(
linear
[
0
],
stbiw__max
(
linear
[
1
],
linear
[
2
]));
if
(
maxcomp
<
1e-32
)
{
if
(
maxcomp
<
1e-32
f
)
{
rgbe
[
0
]
=
rgbe
[
1
]
=
rgbe
[
2
]
=
rgbe
[
3
]
=
0
;
}
else
{
float
normalize
=
(
float
)
frexp
(
maxcomp
,
&
exponent
)
*
256
.
0
f
/
maxcomp
;
...
...
@@ -481,7 +497,7 @@ void stbiw__linear_to_rgbe(unsigned char *rgbe, float *linear)
void
stbiw__write_run_data
(
stbi__write_context
*
s
,
int
length
,
unsigned
char
databyte
)
{
unsigned
char
lengthbyte
=
(
unsigned
char
)
(
length
+
128
);
unsigned
char
lengthbyte
=
STBIW_UCHAR
(
length
+
128
);
STBIW_ASSERT
(
length
+
128
<=
255
);
s
->
func
(
s
->
context
,
&
lengthbyte
,
1
);
s
->
func
(
s
->
context
,
&
databyte
,
1
);
...
...
@@ -489,7 +505,7 @@ void stbiw__write_run_data(stbi__write_context *s, int length, unsigned char dat
void
stbiw__write_dump_data
(
stbi__write_context
*
s
,
int
length
,
unsigned
char
*
data
)
{
unsigned
char
lengthbyte
=
(
unsigned
char
)(
length
&
0xff
);
unsigned
char
lengthbyte
=
STBIW_UCHAR
(
length
);
STBIW_ASSERT
(
length
<=
128
);
// inconsistent with spec but consistent with official code
s
->
func
(
s
->
context
,
&
lengthbyte
,
1
);
s
->
func
(
s
->
context
,
data
,
length
);
...
...
@@ -647,7 +663,7 @@ int stbi_write_hdr(char const *filename, int x, int y, int comp, const float *da
static
void
*
stbiw__sbgrowf
(
void
**
arr
,
int
increment
,
int
itemsize
)
{
int
m
=
*
arr
?
2
*
stbiw__sbm
(
*
arr
)
+
increment
:
increment
+
1
;
void
*
p
=
STBIW_REALLOC
(
*
arr
?
stbiw__sbraw
(
*
arr
)
:
0
,
itemsize
*
m
+
sizeof
(
int
)
*
2
);
void
*
p
=
STBIW_REALLOC
_SIZED
(
*
arr
?
stbiw__sbraw
(
*
arr
)
:
0
,
*
arr
?
(
stbiw__sbm
(
*
arr
)
*
itemsize
+
sizeof
(
int
)
*
2
)
:
0
,
itemsize
*
m
+
sizeof
(
int
)
*
2
);
STBIW_ASSERT
(
p
);
if
(
p
)
{
if
(
!*
arr
)
((
int
*
)
p
)[
1
]
=
0
;
...
...
@@ -660,7 +676,7 @@ static void *stbiw__sbgrowf(void **arr, int increment, int itemsize)
static
unsigned
char
*
stbiw__zlib_flushf
(
unsigned
char
*
data
,
unsigned
int
*
bitbuffer
,
int
*
bitcount
)
{
while
(
*
bitcount
>=
8
)
{
stbiw__sbpush
(
data
,
(
unsigned
char
)
*
bitbuffer
);
stbiw__sbpush
(
data
,
STBIW_UCHAR
(
*
bitbuffer
)
);
*
bitbuffer
>>=
8
;
*
bitcount
-=
8
;
}
...
...
@@ -795,7 +811,7 @@ unsigned char * stbi_zlib_compress(unsigned char *data, int data_len, int *out_l
{
// compute adler32 on input
unsigned
int
k
=
0
,
s1
=
1
,
s2
=
0
;
unsigned
int
s1
=
1
,
s2
=
0
;
int
blocklen
=
(
int
)
(
data_len
%
5552
);
j
=
0
;
while
(
j
<
data_len
)
{
...
...
@@ -804,10 +820,10 @@ unsigned char * stbi_zlib_compress(unsigned char *data, int data_len, int *out_l
j
+=
blocklen
;
blocklen
=
5552
;
}
stbiw__sbpush
(
out
,
(
unsigned
char
)
(
s2
>>
8
));
stbiw__sbpush
(
out
,
(
unsigned
char
)
s2
);
stbiw__sbpush
(
out
,
(
unsigned
char
)
(
s1
>>
8
));
stbiw__sbpush
(
out
,
(
unsigned
char
)
s1
);
stbiw__sbpush
(
out
,
STBIW_UCHAR
(
s2
>>
8
));
stbiw__sbpush
(
out
,
STBIW_UCHAR
(
s2
)
);
stbiw__sbpush
(
out
,
STBIW_UCHAR
(
s1
>>
8
));
stbiw__sbpush
(
out
,
STBIW_UCHAR
(
s1
)
);
}
*
out_len
=
stbiw__sbn
(
out
);
// make returned pointer freeable
...
...
@@ -815,21 +831,52 @@ unsigned char * stbi_zlib_compress(unsigned char *data, int data_len, int *out_l
return
(
unsigned
char
*
)
stbiw__sbraw
(
out
);
}
unsigned
int
stbiw__crc32
(
unsigned
char
*
buffer
,
int
len
)
static
unsigned
int
stbiw__crc32
(
unsigned
char
*
buffer
,
int
len
)
{
static
unsigned
int
crc_table
[
256
];
static
unsigned
int
crc_table
[
256
]
=
{
0x00000000
,
0x77073096
,
0xEE0E612C
,
0x990951BA
,
0x076DC419
,
0x706AF48F
,
0xE963A535
,
0x9E6495A3
,
0x0eDB8832
,
0x79DCB8A4
,
0xE0D5E91E
,
0x97D2D988
,
0x09B64C2B
,
0x7EB17CBD
,
0xE7B82D07
,
0x90BF1D91
,
0x1DB71064
,
0x6AB020F2
,
0xF3B97148
,
0x84BE41DE
,
0x1ADAD47D
,
0x6DDDE4EB
,
0xF4D4B551
,
0x83D385C7
,
0x136C9856
,
0x646BA8C0
,
0xFD62F97A
,
0x8A65C9EC
,
0x14015C4F
,
0x63066CD9
,
0xFA0F3D63
,
0x8D080DF5
,
0x3B6E20C8
,
0x4C69105E
,
0xD56041E4
,
0xA2677172
,
0x3C03E4D1
,
0x4B04D447
,
0xD20D85FD
,
0xA50AB56B
,
0x35B5A8FA
,
0x42B2986C
,
0xDBBBC9D6
,
0xACBCF940
,
0x32D86CE3
,
0x45DF5C75
,
0xDCD60DCF
,
0xABD13D59
,
0x26D930AC
,
0x51DE003A
,
0xC8D75180
,
0xBFD06116
,
0x21B4F4B5
,
0x56B3C423
,
0xCFBA9599
,
0xB8BDA50F
,
0x2802B89E
,
0x5F058808
,
0xC60CD9B2
,
0xB10BE924
,
0x2F6F7C87
,
0x58684C11
,
0xC1611DAB
,
0xB6662D3D
,
0x76DC4190
,
0x01DB7106
,
0x98D220BC
,
0xEFD5102A
,
0x71B18589
,
0x06B6B51F
,
0x9FBFE4A5
,
0xE8B8D433
,
0x7807C9A2
,
0x0F00F934
,
0x9609A88E
,
0xE10E9818
,
0x7F6A0DBB
,
0x086D3D2D
,
0x91646C97
,
0xE6635C01
,
0x6B6B51F4
,
0x1C6C6162
,
0x856530D8
,
0xF262004E
,
0x6C0695ED
,
0x1B01A57B
,
0x8208F4C1
,
0xF50FC457
,
0x65B0D9C6
,
0x12B7E950
,
0x8BBEB8EA
,
0xFCB9887C
,
0x62DD1DDF
,
0x15DA2D49
,
0x8CD37CF3
,
0xFBD44C65
,
0x4DB26158
,
0x3AB551CE
,
0xA3BC0074
,
0xD4BB30E2
,
0x4ADFA541
,
0x3DD895D7
,
0xA4D1C46D
,
0xD3D6F4FB
,
0x4369E96A
,
0x346ED9FC
,
0xAD678846
,
0xDA60B8D0
,
0x44042D73
,
0x33031DE5
,
0xAA0A4C5F
,
0xDD0D7CC9
,
0x5005713C
,
0x270241AA
,
0xBE0B1010
,
0xC90C2086
,
0x5768B525
,
0x206F85B3
,
0xB966D409
,
0xCE61E49F
,
0x5EDEF90E
,
0x29D9C998
,
0xB0D09822
,
0xC7D7A8B4
,
0x59B33D17
,
0x2EB40D81
,
0xB7BD5C3B
,
0xC0BA6CAD
,
0xEDB88320
,
0x9ABFB3B6
,
0x03B6E20C
,
0x74B1D29A
,
0xEAD54739
,
0x9DD277AF
,
0x04DB2615
,
0x73DC1683
,
0xE3630B12
,
0x94643B84
,
0x0D6D6A3E
,
0x7A6A5AA8
,
0xE40ECF0B
,
0x9309FF9D
,
0x0A00AE27
,
0x7D079EB1
,
0xF00F9344
,
0x8708A3D2
,
0x1E01F268
,
0x6906C2FE
,
0xF762575D
,
0x806567CB
,
0x196C3671
,
0x6E6B06E7
,
0xFED41B76
,
0x89D32BE0
,
0x10DA7A5A
,
0x67DD4ACC
,
0xF9B9DF6F
,
0x8EBEEFF9
,
0x17B7BE43
,
0x60B08ED5
,
0xD6D6A3E8
,
0xA1D1937E
,
0x38D8C2C4
,
0x4FDFF252
,
0xD1BB67F1
,
0xA6BC5767
,
0x3FB506DD
,
0x48B2364B
,
0xD80D2BDA
,
0xAF0A1B4C
,
0x36034AF6
,
0x41047A60
,
0xDF60EFC3
,
0xA867DF55
,
0x316E8EEF
,
0x4669BE79
,
0xCB61B38C
,
0xBC66831A
,
0x256FD2A0
,
0x5268E236
,
0xCC0C7795
,
0xBB0B4703
,
0x220216B9
,
0x5505262F
,
0xC5BA3BBE
,
0xB2BD0B28
,
0x2BB45A92
,
0x5CB36A04
,
0xC2D7FFA7
,
0xB5D0CF31
,
0x2CD99E8B
,
0x5BDEAE1D
,
0x9B64C2B0
,
0xEC63F226
,
0x756AA39C
,
0x026D930A
,
0x9C0906A9
,
0xEB0E363F
,
0x72076785
,
0x05005713
,
0x95BF4A82
,
0xE2B87A14
,
0x7BB12BAE
,
0x0CB61B38
,
0x92D28E9B
,
0xE5D5BE0D
,
0x7CDCEFB7
,
0x0BDBDF21
,
0x86D3D2D4
,
0xF1D4E242
,
0x68DDB3F8
,
0x1FDA836E
,
0x81BE16CD
,
0xF6B9265B
,
0x6FB077E1
,
0x18B74777
,
0x88085AE6
,
0xFF0F6A70
,
0x66063BCA
,
0x11010B5C
,
0x8F659EFF
,
0xF862AE69
,
0x616BFFD3
,
0x166CCF45
,
0xA00AE278
,
0xD70DD2EE
,
0x4E048354
,
0x3903B3C2
,
0xA7672661
,
0xD06016F7
,
0x4969474D
,
0x3E6E77DB
,
0xAED16A4A
,
0xD9D65ADC
,
0x40DF0B66
,
0x37D83BF0
,
0xA9BCAE53
,
0xDEBB9EC5
,
0x47B2CF7F
,
0x30B5FFE9
,
0xBDBDF21C
,
0xCABAC28A
,
0x53B39330
,
0x24B4A3A6
,
0xBAD03605
,
0xCDD70693
,
0x54DE5729
,
0x23D967BF
,
0xB3667A2E
,
0xC4614AB8
,
0x5D681B02
,
0x2A6F2B94
,
0xB40BBE37
,
0xC30C8EA1
,
0x5A05DF1B
,
0x2D02EF8D
};
unsigned
int
crc
=
~
0u
;
int
i
,
j
;
if
(
crc_table
[
1
]
==
0
)
for
(
i
=
0
;
i
<
256
;
i
++
)
for
(
crc_table
[
i
]
=
i
,
j
=
0
;
j
<
8
;
++
j
)
crc_table
[
i
]
=
(
crc_table
[
i
]
>>
1
)
^
(
crc_table
[
i
]
&
1
?
0xedb88320
:
0
);
int
i
;
for
(
i
=
0
;
i
<
len
;
++
i
)
crc
=
(
crc
>>
8
)
^
crc_table
[
buffer
[
i
]
^
(
crc
&
0xff
)];
return
~
crc
;
}
#define stbiw__wpng4(o,a,b,c,d) ((o)[0]=
(unsigned char)(a),(o)[1]=(unsigned char)(b),(o)[2]=(unsigned char)(c),(o)[3]=(unsigned char)
(d),(o)+=4)
#define stbiw__wpng4(o,a,b,c,d) ((o)[0]=
STBIW_UCHAR(a),(o)[1]=STBIW_UCHAR(b),(o)[2]=STBIW_UCHAR(c),(o)[3]=STBIW_UCHAR
(d),(o)+=4)
#define stbiw__wp32(data,v) stbiw__wpng4(data, (v)>>24,(v)>>16,(v)>>8,(v));
#define stbiw__wptag(data,s) stbiw__wpng4(data, s[0],s[1],s[2],s[3])
...
...
@@ -842,9 +889,9 @@ static void stbiw__wpcrc(unsigned char **data, int len)
static
unsigned
char
stbiw__paeth
(
int
a
,
int
b
,
int
c
)
{
int
p
=
a
+
b
-
c
,
pa
=
abs
(
p
-
a
),
pb
=
abs
(
p
-
b
),
pc
=
abs
(
p
-
c
);
if
(
pa
<=
pb
&&
pa
<=
pc
)
return
(
unsigned
char
)
a
;
if
(
pb
<=
pc
)
return
(
unsigned
char
)
b
;
return
(
unsigned
char
)
c
;
if
(
pa
<=
pb
&&
pa
<=
pc
)
return
STBIW_UCHAR
(
a
)
;
if
(
pb
<=
pc
)
return
STBIW_UCHAR
(
b
)
;
return
STBIW_UCHAR
(
c
)
;
}
unsigned
char
*
stbi_write_png_to_mem
(
unsigned
char
*
pixels
,
int
stride_bytes
,
int
x
,
int
y
,
int
n
,
int
*
out_len
)
...
...
@@ -917,7 +964,7 @@ unsigned char *stbi_write_png_to_mem(unsigned char *pixels, int stride_bytes, in
stbiw__wp32
(
o
,
x
);
stbiw__wp32
(
o
,
y
);
*
o
++
=
8
;
*
o
++
=
(
unsigned
char
)
ctype
[
n
]
;
*
o
++
=
STBIW_UCHAR
(
ctype
[
n
])
;
*
o
++
=
0
;
*
o
++
=
0
;
*
o
++
=
0
;
...
...
@@ -968,6 +1015,10 @@ STBIWDEF int stbi_write_png_to_func(stbi_write_func *func, void *context, int x,
#endif // STB_IMAGE_WRITE_IMPLEMENTATION
/* Revision history
1.01 (2016-01-16)
STBIW_REALLOC_SIZED: support allocators with no realloc support
avoid race-condition in crc initialization
minor compile issues
1.00 (2015-09-14)
installable file IO function
0.99 (2015-09-13)
...
...
stb_truetype.h
浏览文件 @
667d8408
// stb_truetype.h - v1.0
8
- public domain
// stb_truetype.h - v1.0
9
- public domain
// authored from 2009-2015 by Sean Barrett / RAD Game Tools
//
// This library processes TrueType files:
...
...
@@ -42,12 +42,15 @@
// Sergey Popov
// Giumo X. Clanjor
// Higor Euripedes
// Thomas Fields
// Derek Vinyard
//
// Misc other:
// Ryan Gordon
//
// VERSION HISTORY
//
// 1.09 (????-??-??) warning fix; avoid crash on outofmem
// 1.08 (2015-09-13) document stbtt_Rasterize(); fixes for vertical & horizontal edges
// 1.07 (2015-08-01) allow PackFontRanges to accept arrays of sparse codepoints;
// variant PackFontRanges to pack and render in separate phases;
...
...
@@ -1556,7 +1559,7 @@ STBTT_DEF void stbtt_FreeShape(const stbtt_fontinfo *info, stbtt_vertex *v)
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
)
{
int
x0
,
y0
,
x1
,
y1
;
int
x0
=
0
,
y0
=
0
,
x1
,
y1
;
// =0 suppresses compiler warning
if
(
!
stbtt_GetGlyphBox
(
font
,
glyph
,
&
x0
,
&
y0
,
&
x1
,
&
y1
))
{
// e.g. space character
if
(
ix0
)
*
ix0
=
0
;
...
...
@@ -1672,6 +1675,7 @@ static stbtt__active_edge *stbtt__new_active(stbtt__hheap *hh, stbtt__edge *e, i
{
stbtt__active_edge
*
z
=
(
stbtt__active_edge
*
)
stbtt__hheap_alloc
(
hh
,
sizeof
(
*
z
),
userdata
);
float
dxdy
=
(
e
->
x1
-
e
->
x0
)
/
(
e
->
y1
-
e
->
y0
);
STBTT_assert
(
z
!=
NULL
);
if
(
!
z
)
return
z
;
// round dx down to avoid overshooting
...
...
@@ -1693,6 +1697,7 @@ static stbtt__active_edge *stbtt__new_active(stbtt__hheap *hh, stbtt__edge *e, i
{
stbtt__active_edge
*
z
=
(
stbtt__active_edge
*
)
stbtt__hheap_alloc
(
hh
,
sizeof
(
*
z
),
userdata
);
float
dxdy
=
(
e
->
x1
-
e
->
x0
)
/
(
e
->
y1
-
e
->
y0
);
STBTT_assert
(
z
!=
NULL
);
//STBTT_assert(e->y0 <= start_point);
if
(
!
z
)
return
z
;
z
->
fdx
=
dxdy
;
...
...
@@ -1817,21 +1822,23 @@ static void stbtt__rasterize_sorted_edges(stbtt__bitmap *result, stbtt__edge *e,
while
(
e
->
y0
<=
scan_y
)
{
if
(
e
->
y1
>
scan_y
)
{
stbtt__active_edge
*
z
=
stbtt__new_active
(
&
hh
,
e
,
off_x
,
scan_y
,
userdata
);
// find insertion point
if
(
active
==
NULL
)
active
=
z
;
else
if
(
z
->
x
<
active
->
x
)
{
// insert at front
z
->
next
=
active
;
active
=
z
;
}
else
{
// find thing to insert AFTER
stbtt__active_edge
*
p
=
active
;
while
(
p
->
next
&&
p
->
next
->
x
<
z
->
x
)
p
=
p
->
next
;
// at this point, p->next->x is NOT < z->x
z
->
next
=
p
->
next
;
p
->
next
=
z
;
if
(
z
!=
NULL
)
{
// find insertion point
if
(
active
==
NULL
)
active
=
z
;
else
if
(
z
->
x
<
active
->
x
)
{
// insert at front
z
->
next
=
active
;
active
=
z
;
}
else
{
// find thing to insert AFTER
stbtt__active_edge
*
p
=
active
;
while
(
p
->
next
&&
p
->
next
->
x
<
z
->
x
)
p
=
p
->
next
;
// at this point, p->next->x is NOT < z->x
z
->
next
=
p
->
next
;
p
->
next
=
z
;
}
}
}
++
e
;
...
...
@@ -2101,10 +2108,12 @@ static void stbtt__rasterize_sorted_edges(stbtt__bitmap *result, stbtt__edge *e,
while
(
e
->
y0
<=
scan_y_bottom
)
{
if
(
e
->
y0
!=
e
->
y1
)
{
stbtt__active_edge
*
z
=
stbtt__new_active
(
&
hh
,
e
,
off_x
,
scan_y_top
,
userdata
);
STBTT_assert
(
z
->
ey
>=
scan_y_top
);
// insert at front
z
->
next
=
active
;
active
=
z
;
if
(
z
!=
NULL
)
{
STBTT_assert
(
z
->
ey
>=
scan_y_top
);
// insert at front
z
->
next
=
active
;
active
=
z
;
}
}
++
e
;
}
...
...
@@ -2706,6 +2715,7 @@ static void stbtt__h_prefilter(unsigned char *pixels, int w, int h, int stride_i
unsigned
char
buffer
[
STBTT_MAX_OVERSAMPLE
];
int
safe_w
=
w
-
kernel_width
;
int
j
;
STBTT_memset
(
buffer
,
0
,
STBTT_MAX_OVERSAMPLE
);
// suppress bogus warning from VS2013 -analyze
for
(
j
=
0
;
j
<
h
;
++
j
)
{
int
i
;
unsigned
int
total
;
...
...
@@ -2767,6 +2777,7 @@ static void stbtt__v_prefilter(unsigned char *pixels, int w, int h, int stride_i
unsigned
char
buffer
[
STBTT_MAX_OVERSAMPLE
];
int
safe_h
=
h
-
kernel_width
;
int
j
;
STBTT_memset
(
buffer
,
0
,
STBTT_MAX_OVERSAMPLE
);
// suppress bogus warning from VS2013 -analyze
for
(
j
=
0
;
j
<
w
;
++
j
)
{
int
i
;
unsigned
int
total
;
...
...
stb_vorbis.c
浏览文件 @
667d8408
此差异已折叠。
点击以展开。
tests/image_test.c
浏览文件 @
667d8408
...
...
@@ -7,7 +7,7 @@
#define STB_DEFINE
#include "stb.h"
#define PNGSUITE_PRIMARY
//
#define PNGSUITE_PRIMARY
#if 0
void test_ycbcr(void)
...
...
@@ -65,7 +65,7 @@ int main(int argc, char **argv)
int
w
,
h
;
//test_ycbcr();
#if
1
#if
0
// test hdr asserts
for (h=0; h < 100; h += 2)
for (w=0; w < 200; ++w)
...
...
@@ -81,15 +81,17 @@ int main(int argc, char **argv)
for
(
i
=
1
;
i
<
argc
;
++
i
)
{
int
res
;
int
w2
,
h2
,
n2
;
unsigned
char
*
data
;
printf
(
"%s
\n
"
,
argv
[
i
]);
res
=
stbi_info
(
argv
[
1
],
&
w
,
&
h
,
&
n
);
res
=
stbi_info
(
argv
[
1
],
&
w
2
,
&
h2
,
&
n2
);
data
=
stbi_load
(
argv
[
i
],
&
w
,
&
h
,
&
n
,
4
);
if
(
data
)
free
(
data
);
else
printf
(
"Failed &n
\n
"
);
data
=
stbi_load
(
argv
[
i
],
&
w
,
&
h
,
0
,
1
);
if
(
data
)
free
(
data
);
else
printf
(
"Failed 1
\n
"
);
data
=
stbi_load
(
argv
[
i
],
&
w
,
&
h
,
0
,
2
);
if
(
data
)
free
(
data
);
else
printf
(
"Failed 2
\n
"
);
data
=
stbi_load
(
argv
[
i
],
&
w
,
&
h
,
0
,
3
);
if
(
data
)
free
(
data
);
else
printf
(
"Failed 3
\n
"
);
data
=
stbi_load
(
argv
[
i
],
&
w
,
&
h
,
0
,
4
);
data
=
stbi_load
(
argv
[
i
],
&
w
,
&
h
,
&
n
,
4
);
assert
(
data
);
assert
(
w
==
w2
&&
h
==
h2
&&
n
==
n2
);
assert
(
res
);
if
(
data
)
{
char
fname
[
512
];
...
...
tests/stb.dsp
浏览文件 @
667d8408
...
...
@@ -130,6 +130,10 @@ SOURCE=..\stb_leakcheck.h
# End Source File
# Begin Source File
SOURCE=..\stb_malloc.h
# End Source File
# Begin Source File
SOURCE=..\stb_perlin.h
# End Source File
# Begin Source File
...
...
tests/test_vorbis.c
浏览文件 @
667d8408
...
...
@@ -8,10 +8,11 @@ extern void stb_vorbis_dumpmem(void);
int
main
(
int
argc
,
char
**
argv
)
{
size_t
memlen
;
unsigned
char
*
mem
=
stb_fileu
(
"c:/x/
theme_03
.ogg"
,
&
memlen
);
unsigned
char
*
mem
=
stb_fileu
(
"c:/x/
sketch008
.ogg"
,
&
memlen
);
int
chan
,
samplerate
;
short
*
output
;
int
samples
=
stb_vorbis_decode_memory
(
mem
,
memlen
,
&
chan
,
&
samplerate
,
&
output
);
stb_filewrite
(
"c:/x/sketch008.raw"
,
output
,
samples
*
4
);
return
0
;
}
#endif
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录