Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "src/djvulibre"]
path = src/djvulibre
url = https://github.com/barak/djvulibre
339 changes: 339 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

63 changes: 37 additions & 26 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,42 @@
#You should have received a copy of the GNU General Public License
#along with Simpledjvu. If not, see <http://www.gnu.org/licenses/>.


DJVULIBRE_PATH = /home/mihaild/djvulibre
CC = g++ -O3 -std=c++0x -MMD
INCLUDES=-I$(DJVULIBRE_PATH) -I$(DJVULIBRE_PATH)/libdjvu -I$(DJVULIBRE_PATH)/tools -I.
CXXFLAGS=$(INCLUDES) -DHAVE_CONFIG_H -pthread -DTHREADMODEL=POSIXTHREADS
LINK=g++ -O3

BIN_FILES = simpledjvu get_pgm_diff

all: $(BIN_FILES)

simpledjvu: build/simpledjvu.o build/hystogram_splitter.o build/normalize.o build/pgm2jb2.o build/jb2tune.o jb2cmp/libjb2cmp.a
$(LINK) -o simpledjvu $^ -DHAVE_CONFIG_H -ldjvulibre

get_pgm_diff: build/get_pgm_diff.o
$(LINK) -o get_pgm_diff $^ -DHAVE_CONFIG_H -ldjvulibre

build/%.o build/%.d: %.cpp
$(CC) $(CXXFLAGS) -c -o build/$*.o $*.cpp

jb2cmp/libjb2cmp.a:
cd jb2cmp && ${MAKE}
PROJECT = simpledjvu
DJVULIBRE_PATH = src/djvulibre
CXX = g++ -O3 -std=c++0x
INCLUDES = -I$(DJVULIBRE_PATH) -I$(DJVULIBRE_PATH)/libdjvu -I$(DJVULIBRE_PATH)/tools -Isrc
CXXFLAGS = $(INCLUDES) -DHAVE_CONFIG_H -pthread -DTHREADMODEL=POSIXTHREADS
LDFLAGS = -ldjvulibre
LN = $(CXX) -DHAVE_CONFIG_H
RM = rm -f

OBJ_FILES = \
src/hystogram_splitter.o \
src/normalize.o \
src/pgm2jb2.o \
src/djvulibre/tools/jb2tune.o \
src/djvulibre/tools/jb2cmp/classify.o \
src/djvulibre/tools/jb2cmp/cuts.o \
src/djvulibre/tools/jb2cmp/frames.o \
src/djvulibre/tools/jb2cmp/patterns.o \
src/simpledjvu.o
OBJ_FILE_PGM = src/get_pgm_diff.o
BIN_FILES = $(PROJECT) get_pgm_diff

all: djvulibre_config $(BIN_FILES)

$(PROJECT): $(OBJ_FILES)
$(LN) $^ $(LDFLAGS) -o $@

get_pgm_diff: $(OBJ_FILE_PGM)
$(LN) $^ $(LDFLAGS) -o $@

%.o: %.cpp
$(CXX) $(CXXFLAGS) -c $< -o $@

djvulibre_config:
cd src/djvulibre && ./autogen.sh

clean:
rm -f build/* $(BIN_FILES)
cd jb2cmp && ${MAKE} clean

-include $(wildcard build/*.d)
$(RM) $(OBJ_FILES) $(OBJ_FILE_PGM) $(BIN_FILES)
cd src/jb2cmp && ${MAKE} clean
31 changes: 24 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,33 @@ It uses [djvulibre](http://djvu.sourceforge.net/) for all technichal work and co
Really, the only one thing that it does itself is splitting the image to mask, background and foreground.

## Install
I am too stupid to understand, how does autoconf and other such tools work, so you have to change Makefile manually.

In usual case, set DJVULIBRE_PATH to right value is enough.
May be, you will need to change CXXFLAGS - just look with which flags djvulibre compiles on your machine and copy them.
I am too stupid to understand, how does autoconf and other such tools work, so you have to change `Makefile` manually.

### load submodules

submodules:

- [djvulibre](https://github.com/barak/djvulibre) -> [src](src)

```shell
$ git submodule init
$ git submodule update
```

### build

After it, just say `make` in project directory.

If you want, you can change your PATH variable or copy **simpledjvu** binary to any directory already included in your PATH.

You need g++ version supports c++0x standard flag.
You need `g++` version supports `c++0x` standard flag.

## Usage
`simpledjvu [options] **input.pgm** **output.djvu**`

```shell
simpledjvu [options] input.pgm output.djvu
```

where options =

Expand All @@ -27,6 +41,8 @@ where options =

**-mask_mul n** Multiplicate mask size n times.

**-dpi n** DPI output djvu.

**-use_normalized** Use normalized image (in which "almost black" and "almost white" colors are exactly black and white) for background and foreground except of original.

**-normalize_iters n** Use *n* normalization iterations for mask (see "Algorithm description").
Expand All @@ -39,9 +55,10 @@ where options =

**-slices_fg n1,n2,...** Use *n1,n2,...* as number of slices for c44 for foreground.

You can use imagemagick or any other similar tool to obtain pgm from other format.
You can use [Netpbm](https://sourceforge.net/projects/netpbm/) or any other similar tool to obtain `pgm` from other format.

## Algorithm description.

Algorithm is very simple, but it gives surprisingly good result for non-pathological images.
As usual, background and foreground are really white and black parts, not paper and letters.

Expand All @@ -51,4 +68,4 @@ Increase this images to original image size, and change the image: make absolute

Now we repeat this step many times, and result converges to almost black-and-white image, so we can do simple threshold to obtain the mask.

We use c44 for partially masked images using blurred mask for background, and blurred inverted mask for foreground.
We use `c44` for partially masked images using blurred mask for background, and blurred inverted mask for foreground.
109 changes: 0 additions & 109 deletions jb2cmp/Makefile

This file was deleted.

4 changes: 0 additions & 4 deletions jb2cmp/Makefile.dep

This file was deleted.

109 changes: 0 additions & 109 deletions jb2cmp/Makefile.in

This file was deleted.

3 changes: 0 additions & 3 deletions jb2cmp/README

This file was deleted.

Loading