Skip to content

Commit 1d26361

Browse files
committed
0.9.5
1 parent 1145cdf commit 1d26361

35 files changed

+3004
-2116
lines changed

ChangeLog

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
version 0.9.5:
2+
3+
- Added animation support.
4+
- added bpgview utility.
5+
- bpgenc: fixed support of some JPEG parameter combinations
6+
- fixed JS 8 bit only decoder and renamed it to bpgdec8.js
7+
- libbpg: added CMYK output format
8+
19
version 0.9.4:
210

311
- Modified alpha plane encoding to allow progressive display and

Makefile

+35-8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#USE_X265=y
99
# Enable the JCTVC code (best quality but slow) for the encoder
1010
USE_JCTVC=y
11+
# Compile bpgview (SDL and SDL_image libraries needed)
12+
USE_BPGVIEW=y
1113
# Enable it to use bit depths > 12 (need more tests to validate encoder)
1214
#USE_JCTVC_HIGH_BIT_DEPTH=y
1315
# Enable the cross compilation for Windows
@@ -45,7 +47,7 @@ CFLAGS+=-DRExt__HIGH_BIT_DEPTH_SUPPORT
4547
endif
4648

4749
# Emscriptem config
48-
EMLDFLAGS:=-s "EXPORTED_FUNCTIONS=['_bpg_decoder_open','_bpg_decoder_decode','_bpg_decoder_get_info','_bpg_decoder_start','_bpg_decoder_get_line','_bpg_decoder_close','_malloc','_free']"
50+
EMLDFLAGS:=-s "EXPORTED_FUNCTIONS=['_bpg_decoder_open','_bpg_decoder_decode','_bpg_decoder_get_info','_bpg_decoder_start','_bpg_decoder_get_frame_duration','_bpg_decoder_get_line','_bpg_decoder_close','_malloc','_free']"
4951
EMLDFLAGS+=-s NO_FILESYSTEM=1 -s NO_BROWSER=1
5052
#EMLDFLAGS+=-O1 --post-js post.js
5153
EMLDFLAGS+=-O3 --memory-init-file 0 --closure 1 --post-js post.js
@@ -61,29 +63,36 @@ CFLAGS+=-g
6163
CXXFLAGS=$(CFLAGS)
6264

6365
PROGS=bpgdec$(EXE) bpgenc$(EXE)
66+
ifdef USE_BPGVIEW
67+
PROGS+=bpgview$(EXE)
68+
endif
6469
ifdef USE_EMCC
65-
PROGS+=bpgdec.js bpgdec8b.js
70+
PROGS+=bpgdec.js bpgdec8.js bpgdec8a.js
6671
endif
6772

6873
all: $(PROGS)
6974

7075
LIBBPG_OBJS:=$(addprefix libavcodec/, \
7176
hevc_cabac.o hevc_filter.o hevc.o hevcpred.o hevc_refs.o\
7277
hevcdsp.o hevc_mvs.o hevc_ps.o hevc_sei.o\
73-
utils.o cabac.o golomb.o )
78+
utils.o cabac.o golomb.o videodsp.o )
7479
LIBBPG_OBJS+=$(addprefix libavutil/, mem.o buffer.o log2_tab.o frame.o pixdesc.o md5.o )
7580
LIBBPG_OBJS+=libbpg.o
7681

7782
LIBBPG_JS_OBJS:=$(patsubst %.o, %.js.o, $(LIBBPG_OBJS)) tmalloc.js.o
7883

7984
LIBBPG_JS8_OBJS:=$(patsubst %.o, %.js8.o, $(LIBBPG_OBJS)) tmalloc.js8.o
8085

81-
$(LIBBPG_OBJS): CFLAGS+=-D_ISOC99_SOURCE -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600 -DHAVE_AV_CONFIG_H -std=c99 -D_GNU_SOURCE=1 -DUSE_VAR_BIT_DEPTH
86+
LIBBPG_JS8A_OBJS:=$(patsubst %.o, %.js8a.o, $(LIBBPG_OBJS)) tmalloc.js8a.o
87+
88+
$(LIBBPG_OBJS): CFLAGS+=-D_ISOC99_SOURCE -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600 -DHAVE_AV_CONFIG_H -std=c99 -D_GNU_SOURCE=1 -DUSE_VAR_BIT_DEPTH -DUSE_PRED
8289

8390
$(LIBBPG_JS_OBJS): EMCFLAGS+=-D_ISOC99_SOURCE -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600 -DHAVE_AV_CONFIG_H -std=c99 -D_GNU_SOURCE=1 -DUSE_VAR_BIT_DEPTH
8491

8592
$(LIBBPG_JS8_OBJS): EMCFLAGS+=-D_ISOC99_SOURCE -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600 -DHAVE_AV_CONFIG_H -std=c99 -D_GNU_SOURCE=1
8693

94+
$(LIBBPG_JS8A_OBJS): EMCFLAGS+=-D_ISOC99_SOURCE -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600 -DHAVE_AV_CONFIG_H -std=c99 -D_GNU_SOURCE=1 -DUSE_PRED
95+
8796
BPGENC_OBJS:=bpgenc.o
8897
BPGENC_LIBS:=
8998

@@ -121,37 +130,52 @@ BPGENC_OBJS+=jctvc_glue.o jctvc/libjctvc.a
121130
bpgenc.o: CFLAGS+=-DUSE_JCTVC
122131
endif # USE_JCTVC
123132

133+
124134
ifdef CONFIG_WIN32
125-
LIBS:=-lz
135+
126136
LDFLAGS+=-static
137+
BPGDEC_LIBS:=-Wl,-dy -lpng -lz -Wl,-dn
138+
BPGENC_LIBS+=-Wl,-dy -lpng -ljpeg -lz -Wl,-dn
139+
BPGVIEW_LIBS:=-lmingw32 -lSDLmain -Wl,-dy -lSDL_image -lSDL -Wl,-dn -mwindows
140+
127141
else
142+
128143
ifdef CONFIG_APPLE
129144
LIBS:=
130145
else
131146
LIBS:=-lrt
132147
endif # !CONFIG_APPLE
133148
LIBS+=-lm -lpthread
134-
endif # !CONFIG_WIN32
135149

150+
BPGDEC_LIBS:=-lpng $(LIBS)
136151
BPGENC_LIBS+=-lpng -ljpeg $(LIBS)
152+
BPGVIEW_LIBS:=-lSDL_image -lSDL $(LIBS)
153+
154+
endif #!CONFIG_WIN32
137155

138156
bpgenc.o: CFLAGS+=-Wno-unused-but-set-variable
139157

140158
libbpg.a: $(LIBBPG_OBJS)
141159
$(AR) rcs $@ $^
142160

143161
bpgdec$(EXE): bpgdec.o libbpg.a
144-
$(CC) $(LDFLAGS) -o $@ $^ -lpng $(LIBS)
162+
$(CC) $(LDFLAGS) -o $@ $^ $(BPGDEC_LIBS)
145163

146164
bpgenc$(EXE): $(BPGENC_OBJS)
147165
$(CXX) $(LDFLAGS) -o $@ $^ $(BPGENC_LIBS)
148166

167+
bpgview$(EXE): bpgview.o libbpg.a
168+
$(CC) $(LDFLAGS) -o $@ $^ $(BPGVIEW_LIBS)
169+
149170
bpgdec.js: $(LIBBPG_JS_OBJS) post.js
150171
$(EMCC) $(EMLDFLAGS) -s TOTAL_MEMORY=33554432 -o $@ $(LIBBPG_JS_OBJS)
151172

152-
bpgdec8b.js: $(LIBBPG_JS8_OBJS) post.js
173+
bpgdec8.js: $(LIBBPG_JS8_OBJS) post.js
153174
$(EMCC) $(EMLDFLAGS) -s TOTAL_MEMORY=16777216 -o $@ $(LIBBPG_JS8_OBJS)
154175

176+
bpgdec8a.js: $(LIBBPG_JS8A_OBJS) post.js
177+
$(EMCC) $(EMLDFLAGS) -s TOTAL_MEMORY=16777216 -o $@ $(LIBBPG_JS8A_OBJS)
178+
155179
size:
156180
strip bpgdec
157181
size bpgdec libbpg.o libavcodec/*.o libavutil/*.o | sort -n
@@ -180,6 +204,9 @@ clean:
180204
%.js8.o: %.c
181205
$(EMCC) $(EMCFLAGS) -c -o $@ $<
182206

207+
%.js8a.o: %.c
208+
$(EMCC) $(EMCFLAGS) -c -o $@ $<
209+
183210
-include $(wildcard *.d)
184211
-include $(wildcard libavcodec/*.d)
185212
-include $(wildcard libavutil/*.d)

README

+66-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
BPG Image Encoder and Decoder
2-
-----------------------------
1+
BPG Image library and utilities
2+
-------------------------------
33

44
1) Quick introduction
55
---------------------
@@ -14,6 +14,9 @@ BPG Image Encoder and Decoder
1414
and does not support monochrome encoding yet (hence no alpha nor
1515
grayscale images can be encoded with it).
1616

17+
- bpgview: in order to compile it you need to install the SDL and
18+
SDL_image libraries.
19+
1720
- Emscripten usage: in order to generate the Javascript decoder, you
1821
must install Emscripten and enable its use in the Makefile.
1922

@@ -72,8 +75,7 @@ as input.
7275
* For JPEG input, the color space of the input image is not
7376
modified (it is YCbCr, RGB, YCbCrK or CMYK). The chroma is
7477
subsampled according to the preferred chroma format ('-f'
75-
option). Images with vertically subsampled chroma are currently
76-
not supported.
78+
option).
7779

7880
* For PNG input, the input image is converted to the preferred
7981
color space ('-c' option). Its chroma is then subsampled
@@ -87,6 +89,38 @@ as input.
8789
of a loss in the color components. This loss is not an issue if the
8890
image is not edited.
8991

92+
- Animations: with the '-a' option, animations can be encoded from a
93+
sequence of PNG or JPEG images, indexed from 1 or 0. For example:
94+
95+
./bpgenc -a anim%2d.png -fps 25 -loop 0 -o anim.bpg
96+
97+
generates an animation from anim01.png, anim02.png, etc... The frame
98+
rate is specified with '-fps' and the number of loops with '-loop'
99+
(0 = infinite). If a different delay per image is needed as in some
100+
animated GIFs, a text file can be specified with the '-delayfile'
101+
option. It contains one number per image giving its duration in
102+
centiseconds. All durations are rounded to a multiple of '1/fps', so
103+
it is important to set a consistent frame rate.
104+
105+
The necessary frames and delay file can be generated from animated
106+
GIFs with the ImageMagick tools:
107+
108+
convert -coalesce anim.gif anim%d.png
109+
110+
identify -format "%T\n" anim.gif > anim.txt
111+
112+
In order to reduce the file size, the frame rate can be choosen so
113+
that most frames have a frame period of 1 (hence if anim.txt
114+
contains only frame durations of 5 centiseconds, then choose a frame
115+
rate of 20 frames/s).
116+
117+
As GIFs use paletted colors and 1 bit transparency, it is always
118+
better to start from the source material (e.g. PNG files) to have
119+
the best quality.
120+
121+
A BPG decoder not supporting animations only displays the first
122+
frame.
123+
90124
- By default, bpgenc does not copy the metadata. You can copy them
91125
with the '-keepmetadata' option. For JPEG input, EXIF, ICCP and XMP
92126
are copied. For PNG input, ICCP is copied.
@@ -107,7 +141,15 @@ no decoded image is output).
107141
- The '-b' option selects the bit depth (8 or 16) of the PNG
108142
output. It is independent of the internal BPG bit depth.
109143

110-
4) BPG decoding library
144+
4) BPG viewer
145+
-------------
146+
147+
The BPG image viewer uses the SDL library to display BPG images and
148+
other image formats supported by the SDL_image library. The available
149+
keys are displayed by launching bpgview without parameters. bpgview
150+
supports BPG animations.
151+
152+
5) BPG decoding library
111153
-----------------------
112154

113155
BPG images can be decoded in any program with the libbpg
@@ -119,13 +161,19 @@ provided as a static one.
119161
Currently there is no similar library for encoding so you should
120162
invoke the bpgenc utility.
121163

122-
5) Javascript decoder
164+
6) Javascript decoder
123165
---------------------
124166

125-
bpgdec.js is a Javascript decoder supporting the BPG file
126-
format. bpgdec8b.js is a specialized version limited to BPG images
127-
using 8 bits per component. It is a little faster and consumes less
128-
memory (16 MB instead of 32 MB by default, you can change the memory
167+
The following Javascript decoders are available, sorted by increasing size:
168+
169+
> 8 bits animations
170+
bpgdec8.js no no
171+
bpgdec.js yes no
172+
bpgdec8a.js no yes
173+
174+
175+
The 8 bit only decoders are a little faster and consumes less memory
176+
(16 MB instead of 32 MB by default, you can change the memory
129177
configuration in the Makefile if you want to handle larger images).
130178

131179
The Javascript decoder substitutes all the <img> tags with a source
@@ -138,10 +186,14 @@ The image data is downloaded with the XMLHttpRequest object. So the
138186
BPG images and the BPG Javascript decoder must be in the same domain
139187
unless Cross-Origin Resource Sharing is used.
140188

189+
When animations are displayed, all the frames are stored in memory, so
190+
animations with a large number of frames and large resolutions should
191+
be avoided, as with animated GIFs.
192+
141193
asm.js gives an interesting speed boost, so we hope that more browsers
142194
will support this Javascript subset.
143195

144-
6) FFmpeg modifications
196+
7) FFmpeg modifications
145197
-----------------------
146198

147199
- Completed support of chroma_format_idc = 0 (monochrome mode).
@@ -156,7 +208,7 @@ will support this Javascript subset.
156208
14 are supported without code duplication but slower decoding.
157209

158210
- Added a modified SPS header to reduce the size of the BPG decoder
159-
(the solution instead is to generate standard VPS and SPS headers
211+
(an alternate solution is to generate standard VPS and SPS headers
160212
from the BPG header).
161213

162214
- Added defines to keep only the HEVC intra code and suppress the
@@ -165,10 +217,10 @@ will support this Javascript subset.
165217
- Stripped FFmpeg from all codecs except HEVC and the necessary
166218
support code.
167219

168-
7) Licensing
220+
8) Licensing
169221
------------
170222

171-
- libbpg and bpgenc are released under the LGPL license (the FFmpeg
223+
- libbpg and bpgdec are released under the LGPL license (the FFmpeg
172224
part is under the LGPL, the BPG specific part is released under the
173225
BSD license).
174226

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.9.4
1+
0.9.5

bpgdec.c

+6-4
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ static void ppm_save(BPGDecoderContext *img, const char *filename)
5151

5252
rgb_line = malloc(3 * w);
5353

54-
f = fopen(filename,"w");
54+
f = fopen(filename,"wb");
5555
if (!f) {
5656
fprintf(stderr, "%s: I/O error\n", filename);
5757
exit(1);
@@ -195,6 +195,7 @@ static void bpg_show_info(const char *filename, int show_extensions)
195195
"ICC profile",
196196
"XMP",
197197
"Thumbnail",
198+
"Animation control",
198199
};
199200

200201
f = fopen(filename, "rb");
@@ -232,16 +233,17 @@ static void bpg_show_info(const char *filename, int show_extensions)
232233
printf(" alpha=%d premul=%d",
233234
p->has_alpha, p->premultiplied_alpha);
234235
}
235-
printf(" format=%s limited_range=%d bit_depth=%d\n",
236+
printf(" format=%s limited_range=%d bit_depth=%d animation=%d\n",
236237
format_str[p->format],
237238
p->limited_range,
238-
p->bit_depth);
239+
p->bit_depth,
240+
p->has_animation);
239241

240242
if (first_md) {
241243
const char *tag_name;
242244
printf("Extension data:\n");
243245
for(md = first_md; md != NULL; md = md->next) {
244-
if (md->tag <= 4)
246+
if (md->tag <= 5)
245247
tag_name = extension_tag_str[md->tag];
246248
else
247249
tag_name = extension_tag_str[0];

0 commit comments

Comments
 (0)