Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
itdan3344
stb
提交
b056850e
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 搜索 >>
提交
b056850e
编写于
1月 29, 2018
作者:
S
Sean Barrett
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
stb_image_write can flip images vertically
上级
e371bd83
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
35 addition
and
9 deletion
+35
-9
stb_image_write.h
stb_image_write.h
+35
-9
未找到文件。
stb_image_write.h
浏览文件 @
b056850e
/* stb_image_write - v1.0
7
- public domain - http://nothings.org/stb/stb_image_write.h
/* stb_image_write - v1.0
8
- public domain - http://nothings.org/stb/stb_image_write.h
writes out PNG/BMP/TGA/JPEG/HDR images to C stdio - Sean Barrett 2010-2015
no warranty implied; use at your own risk
...
...
@@ -29,7 +29,7 @@ BUILDING:
USAGE:
There are f
our
functions, one for each image file format:
There are f
ive
functions, one for each image file format:
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);
...
...
@@ -37,7 +37,9 @@ USAGE:
int stbi_write_hdr(char const *filename, int w, int h, int comp, const float *data);
int stbi_write_jpg(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
void stbi_flip_vertically_on_write(int flag); // flag is non-zero to flip data vertically
There are also five equivalent functions that use an arbitrary write function. You are
expected to open/close your file-equivalent before and after calling these:
int stbi_write_png_to_func(stbi_write_func *func, void *context, int w, int h, int comp, const void *data, int stride_in_bytes);
...
...
@@ -151,6 +153,8 @@ STBIWDEF int stbi_write_tga_to_func(stbi_write_func *func, void *context, int w,
STBIWDEF
int
stbi_write_hdr_to_func
(
stbi_write_func
*
func
,
void
*
context
,
int
w
,
int
h
,
int
comp
,
const
float
*
data
);
STBIWDEF
int
stbi_write_jpg_to_func
(
stbi_write_func
*
func
,
void
*
context
,
int
x
,
int
y
,
int
comp
,
const
void
*
data
,
int
quality
);
extern
void
stbi_flip_vertically_on_write
(
int
flip_boolean
);
#ifdef __cplusplus
}
#endif
...
...
@@ -208,6 +212,13 @@ STBIWDEF int stbi_write_jpg_to_func(stbi_write_func *func, void *context, int x,
#define STBIW_UCHAR(x) (unsigned char) ((x) & 0xff)
int
stbi__flip_vertically_on_write
=
0
;
void
stbi_flip_vertically_on_write
(
int
flag
)
{
stbi__flip_vertically_on_write
=
flag
;
}
typedef
struct
{
stbi_write_func
*
func
;
...
...
@@ -341,6 +352,9 @@ static void stbiw__write_pixels(stbi__write_context *s, int rgb_dir, int vdir, i
if
(
y
<=
0
)
return
;
if
(
stbi__flip_vertically_on_write
)
vdir
*=
-
1
;
if
(
vdir
<
0
)
j_end
=
-
1
,
j
=
y
-
1
;
else
...
...
@@ -412,11 +426,21 @@ static int stbi_write_tga_core(stbi__write_context *s, int x, int y, int comp, v
"111 221 2222 11"
,
0
,
0
,
format
,
0
,
0
,
0
,
0
,
0
,
x
,
y
,
(
colorbytes
+
has_alpha
)
*
8
,
has_alpha
*
8
);
}
else
{
int
i
,
j
,
k
;
int
jend
,
jdir
;
stbiw__writef
(
s
,
"111 221 2222 11"
,
0
,
0
,
format
+
8
,
0
,
0
,
0
,
0
,
0
,
x
,
y
,
(
colorbytes
+
has_alpha
)
*
8
,
has_alpha
*
8
);
for
(
j
=
y
-
1
;
j
>=
0
;
--
j
)
{
unsigned
char
*
row
=
(
unsigned
char
*
)
data
+
j
*
x
*
comp
;
if
(
stbi__flip_vertically_on_write
)
{
j
=
0
;
jend
=
y
;
jdir
=
1
;
}
else
{
j
=
y
-
1
;
jend
=
-
1
;
jdir
=
-
1
;
}
for
(;
j
!=
jend
;
j
+=
jdir
)
{
unsigned
char
*
row
=
(
unsigned
char
*
)
data
+
j
*
x
*
comp
;
int
len
;
for
(
i
=
0
;
i
<
x
;
i
+=
len
)
{
...
...
@@ -630,7 +654,7 @@ static int stbi_write_hdr_core(stbi__write_context *s, int x, int y, int comp, f
s
->
func
(
s
->
context
,
buffer
,
len
);
for
(
i
=
0
;
i
<
y
;
i
++
)
stbiw__write_hdr_scanline
(
s
,
x
,
comp
,
scratch
,
data
+
comp
*
i
*
x
);
stbiw__write_hdr_scanline
(
s
,
x
,
comp
,
scratch
,
data
+
comp
*
x
*
(
stbi__flip_vertically_on_write
?
y
-
1
-
i
:
i
)
*
x
);
STBIW_FREE
(
scratch
);
return
1
;
}
...
...
@@ -932,7 +956,7 @@ unsigned char *stbi_write_png_to_mem(unsigned char *pixels, int stride_bytes, in
for
(
p
=
0
;
p
<
2
;
++
p
)
{
for
(
k
=
p
?
best
:
0
;
k
<
5
;
++
k
)
{
// @TODO: clarity: rewrite this to go 0..5, and 'continue' the unwanted ones during 2nd pass
int
type
=
mymap
[
k
],
est
=
0
;
unsigned
char
*
z
=
pixels
+
stride_bytes
*
j
;
unsigned
char
*
z
=
pixels
+
stride_bytes
*
(
stbi__flip_vertically_on_write
?
y
-
1
-
j
:
j
)
;
for
(
i
=
0
;
i
<
n
;
++
i
)
switch
(
type
)
{
case
0
:
line_buffer
[
i
]
=
z
[
i
];
break
;
...
...
@@ -954,7 +978,7 @@ unsigned char *stbi_write_png_to_mem(unsigned char *pixels, int stride_bytes, in
case
6
:
line_buffer
[
i
]
=
z
[
i
]
-
stbiw__paeth
(
z
[
i
-
n
],
0
,
0
);
break
;
}
}
if
(
p
)
break
;
if
(
p
!=
0
)
break
;
for
(
i
=
0
;
i
<
x
*
n
;
++
i
)
est
+=
abs
((
signed
char
)
line_buffer
[
i
]);
if
(
est
<
bestval
)
{
bestval
=
est
;
best
=
k
;
}
...
...
@@ -1318,7 +1342,7 @@ static int stbi_write_jpg_core(stbi__write_context *s, int width, int height, in
float
YDU
[
64
],
UDU
[
64
],
VDU
[
64
];
for
(
row
=
y
,
pos
=
0
;
row
<
y
+
8
;
++
row
)
{
for
(
col
=
x
;
col
<
x
+
8
;
++
col
,
++
pos
)
{
int
p
=
row
*
width
*
comp
+
col
*
comp
;
int
p
=
(
stbi__flip_vertically_on_write
?
height
-
1
-
row
:
row
)
*
width
*
comp
+
col
*
comp
;
float
r
,
g
,
b
;
if
(
row
>=
height
)
{
p
-=
width
*
comp
*
(
row
+
1
-
height
);
...
...
@@ -1377,6 +1401,8 @@ STBIWDEF int stbi_write_jpg(char const *filename, int x, int y, int comp, const
#endif // STB_IMAGE_WRITE_IMPLEMENTATION
/* Revision history
1.08 (2018-01-29)
add stbi__flip_vertically_on_write
1.07 (2017-07-24)
doc fix
1.06 (2017-07-23)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录