Skip to content

Commit

Permalink
0.9.5
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-huet committed Jan 12, 2015
1 parent 1145cdf commit 1d26361
Show file tree
Hide file tree
Showing 35 changed files with 3,004 additions and 2,116 deletions.
8 changes: 8 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
version 0.9.5:

- Added animation support.
- added bpgview utility.
- bpgenc: fixed support of some JPEG parameter combinations
- fixed JS 8 bit only decoder and renamed it to bpgdec8.js
- libbpg: added CMYK output format

version 0.9.4:

- Modified alpha plane encoding to allow progressive display and
Expand Down
43 changes: 35 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#USE_X265=y
# Enable the JCTVC code (best quality but slow) for the encoder
USE_JCTVC=y
# Compile bpgview (SDL and SDL_image libraries needed)
USE_BPGVIEW=y
# Enable it to use bit depths > 12 (need more tests to validate encoder)
#USE_JCTVC_HIGH_BIT_DEPTH=y
# Enable the cross compilation for Windows
Expand Down Expand Up @@ -45,7 +47,7 @@ CFLAGS+=-DRExt__HIGH_BIT_DEPTH_SUPPORT
endif

# Emscriptem config
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']"
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']"
EMLDFLAGS+=-s NO_FILESYSTEM=1 -s NO_BROWSER=1
#EMLDFLAGS+=-O1 --post-js post.js
EMLDFLAGS+=-O3 --memory-init-file 0 --closure 1 --post-js post.js
Expand All @@ -61,29 +63,36 @@ CFLAGS+=-g
CXXFLAGS=$(CFLAGS)

PROGS=bpgdec$(EXE) bpgenc$(EXE)
ifdef USE_BPGVIEW
PROGS+=bpgview$(EXE)
endif
ifdef USE_EMCC
PROGS+=bpgdec.js bpgdec8b.js
PROGS+=bpgdec.js bpgdec8.js bpgdec8a.js
endif

all: $(PROGS)

LIBBPG_OBJS:=$(addprefix libavcodec/, \
hevc_cabac.o hevc_filter.o hevc.o hevcpred.o hevc_refs.o\
hevcdsp.o hevc_mvs.o hevc_ps.o hevc_sei.o\
utils.o cabac.o golomb.o )
utils.o cabac.o golomb.o videodsp.o )
LIBBPG_OBJS+=$(addprefix libavutil/, mem.o buffer.o log2_tab.o frame.o pixdesc.o md5.o )
LIBBPG_OBJS+=libbpg.o

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

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

$(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
LIBBPG_JS8A_OBJS:=$(patsubst %.o, %.js8a.o, $(LIBBPG_OBJS)) tmalloc.js8a.o

$(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

$(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

$(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

$(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

BPGENC_OBJS:=bpgenc.o
BPGENC_LIBS:=

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


ifdef CONFIG_WIN32
LIBS:=-lz

LDFLAGS+=-static
BPGDEC_LIBS:=-Wl,-dy -lpng -lz -Wl,-dn
BPGENC_LIBS+=-Wl,-dy -lpng -ljpeg -lz -Wl,-dn
BPGVIEW_LIBS:=-lmingw32 -lSDLmain -Wl,-dy -lSDL_image -lSDL -Wl,-dn -mwindows

else

ifdef CONFIG_APPLE
LIBS:=
else
LIBS:=-lrt
endif # !CONFIG_APPLE
LIBS+=-lm -lpthread
endif # !CONFIG_WIN32

BPGDEC_LIBS:=-lpng $(LIBS)
BPGENC_LIBS+=-lpng -ljpeg $(LIBS)
BPGVIEW_LIBS:=-lSDL_image -lSDL $(LIBS)

endif #!CONFIG_WIN32

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

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

bpgdec$(EXE): bpgdec.o libbpg.a
$(CC) $(LDFLAGS) -o $@ $^ -lpng $(LIBS)
$(CC) $(LDFLAGS) -o $@ $^ $(BPGDEC_LIBS)

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

bpgview$(EXE): bpgview.o libbpg.a
$(CC) $(LDFLAGS) -o $@ $^ $(BPGVIEW_LIBS)

bpgdec.js: $(LIBBPG_JS_OBJS) post.js
$(EMCC) $(EMLDFLAGS) -s TOTAL_MEMORY=33554432 -o $@ $(LIBBPG_JS_OBJS)

bpgdec8b.js: $(LIBBPG_JS8_OBJS) post.js
bpgdec8.js: $(LIBBPG_JS8_OBJS) post.js
$(EMCC) $(EMLDFLAGS) -s TOTAL_MEMORY=16777216 -o $@ $(LIBBPG_JS8_OBJS)

bpgdec8a.js: $(LIBBPG_JS8A_OBJS) post.js
$(EMCC) $(EMLDFLAGS) -s TOTAL_MEMORY=16777216 -o $@ $(LIBBPG_JS8A_OBJS)

size:
strip bpgdec
size bpgdec libbpg.o libavcodec/*.o libavutil/*.o | sort -n
Expand Down Expand Up @@ -180,6 +204,9 @@ clean:
%.js8.o: %.c
$(EMCC) $(EMCFLAGS) -c -o $@ $<

%.js8a.o: %.c
$(EMCC) $(EMCFLAGS) -c -o $@ $<

-include $(wildcard *.d)
-include $(wildcard libavcodec/*.d)
-include $(wildcard libavutil/*.d)
Expand Down
80 changes: 66 additions & 14 deletions README
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
BPG Image Encoder and Decoder
-----------------------------
BPG Image library and utilities
-------------------------------

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

- bpgview: in order to compile it you need to install the SDL and
SDL_image libraries.

- Emscripten usage: in order to generate the Javascript decoder, you
must install Emscripten and enable its use in the Makefile.

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

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

- Animations: with the '-a' option, animations can be encoded from a
sequence of PNG or JPEG images, indexed from 1 or 0. For example:

./bpgenc -a anim%2d.png -fps 25 -loop 0 -o anim.bpg

generates an animation from anim01.png, anim02.png, etc... The frame
rate is specified with '-fps' and the number of loops with '-loop'
(0 = infinite). If a different delay per image is needed as in some
animated GIFs, a text file can be specified with the '-delayfile'
option. It contains one number per image giving its duration in
centiseconds. All durations are rounded to a multiple of '1/fps', so
it is important to set a consistent frame rate.

The necessary frames and delay file can be generated from animated
GIFs with the ImageMagick tools:

convert -coalesce anim.gif anim%d.png

identify -format "%T\n" anim.gif > anim.txt

In order to reduce the file size, the frame rate can be choosen so
that most frames have a frame period of 1 (hence if anim.txt
contains only frame durations of 5 centiseconds, then choose a frame
rate of 20 frames/s).

As GIFs use paletted colors and 1 bit transparency, it is always
better to start from the source material (e.g. PNG files) to have
the best quality.

A BPG decoder not supporting animations only displays the first
frame.

- By default, bpgenc does not copy the metadata. You can copy them
with the '-keepmetadata' option. For JPEG input, EXIF, ICCP and XMP
are copied. For PNG input, ICCP is copied.
Expand All @@ -107,7 +141,15 @@ no decoded image is output).
- The '-b' option selects the bit depth (8 or 16) of the PNG
output. It is independent of the internal BPG bit depth.

4) BPG decoding library
4) BPG viewer
-------------

The BPG image viewer uses the SDL library to display BPG images and
other image formats supported by the SDL_image library. The available
keys are displayed by launching bpgview without parameters. bpgview
supports BPG animations.

5) BPG decoding library
-----------------------

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

5) Javascript decoder
6) Javascript decoder
---------------------

bpgdec.js is a Javascript decoder supporting the BPG file
format. bpgdec8b.js is a specialized version limited to BPG images
using 8 bits per component. It is a little faster and consumes less
memory (16 MB instead of 32 MB by default, you can change the memory
The following Javascript decoders are available, sorted by increasing size:

> 8 bits animations
bpgdec8.js no no
bpgdec.js yes no
bpgdec8a.js no yes


The 8 bit only decoders are a little faster and consumes less memory
(16 MB instead of 32 MB by default, you can change the memory
configuration in the Makefile if you want to handle larger images).

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

When animations are displayed, all the frames are stored in memory, so
animations with a large number of frames and large resolutions should
be avoided, as with animated GIFs.

asm.js gives an interesting speed boost, so we hope that more browsers
will support this Javascript subset.

6) FFmpeg modifications
7) FFmpeg modifications
-----------------------

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

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

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

7) Licensing
8) Licensing
------------

- libbpg and bpgenc are released under the LGPL license (the FFmpeg
- libbpg and bpgdec are released under the LGPL license (the FFmpeg
part is under the LGPL, the BPG specific part is released under the
BSD license).

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.9.4
0.9.5
10 changes: 6 additions & 4 deletions bpgdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static void ppm_save(BPGDecoderContext *img, const char *filename)

rgb_line = malloc(3 * w);

f = fopen(filename,"w");
f = fopen(filename,"wb");
if (!f) {
fprintf(stderr, "%s: I/O error\n", filename);
exit(1);
Expand Down Expand Up @@ -195,6 +195,7 @@ static void bpg_show_info(const char *filename, int show_extensions)
"ICC profile",
"XMP",
"Thumbnail",
"Animation control",
};

f = fopen(filename, "rb");
Expand Down Expand Up @@ -232,16 +233,17 @@ static void bpg_show_info(const char *filename, int show_extensions)
printf(" alpha=%d premul=%d",
p->has_alpha, p->premultiplied_alpha);
}
printf(" format=%s limited_range=%d bit_depth=%d\n",
printf(" format=%s limited_range=%d bit_depth=%d animation=%d\n",
format_str[p->format],
p->limited_range,
p->bit_depth);
p->bit_depth,
p->has_animation);

if (first_md) {
const char *tag_name;
printf("Extension data:\n");
for(md = first_md; md != NULL; md = md->next) {
if (md->tag <= 4)
if (md->tag <= 5)
tag_name = extension_tag_str[md->tag];
else
tag_name = extension_tag_str[0];
Expand Down
Loading

0 comments on commit 1d26361

Please sign in to comment.