Subversion Repositories Kolibri OS

Compare Revisions

No changes between revisions

Regard whitespace Rev 8435 → Rev 8436

/contrib/media/updf/BuildUPDF.sh
File deleted
/contrib/media/updf/build.zip
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Deleted: svn:mime-type
-application/octet-stream
\ No newline at end of property
/contrib/media/updf/Makefile_2
File deleted
Property changes:
Deleted: svn:executable
-*
\ No newline at end of property
/contrib/media/updf/include/jmorecfg.h
File deleted
/contrib/media/updf/include/lispenvironment.h
File deleted
/contrib/media/updf/include/netdb.h
File deleted
/contrib/media/updf/include/tgt.h
File deleted
/contrib/media/updf/include/dwt.h
File deleted
/contrib/media/updf/include/standard.h
File deleted
/contrib/media/updf/include/lauxlib.h
File deleted
/contrib/media/updf/include/cctype
File deleted
/contrib/media/updf/include/scripts/menuetos_app_v01.ld
File deleted
/contrib/media/updf/include/scripts/menuetos_dll.ld
File deleted
/contrib/media/updf/include/genericobject.h
File deleted
/contrib/media/updf/include/std/cstdlib
File deleted
/contrib/media/updf/include/std/queue
File deleted
/contrib/media/updf/include/std/cctype
File deleted
/contrib/media/updf/include/std/streambuf
File deleted
/contrib/media/updf/include/std/cerrno
File deleted
/contrib/media/updf/include/std/iterator
File deleted
/contrib/media/updf/include/std/bitset
File deleted
/contrib/media/updf/include/std/ios
File deleted
/contrib/media/updf/include/std/iosfwd
File deleted
/contrib/media/updf/include/std/set
File deleted
/contrib/media/updf/include/std/cmath
File deleted
/contrib/media/updf/include/std/ctime
File deleted
/contrib/media/updf/include/std/limits
File deleted
/contrib/media/updf/include/std/fstream
File deleted
/contrib/media/updf/include/std/clocale
File deleted
/contrib/media/updf/include/std/functional
File deleted
/contrib/media/updf/include/std/cassert
File deleted
/contrib/media/updf/include/std/istream
File deleted
/contrib/media/updf/include/std/csetjmp
File deleted
/contrib/media/updf/include/std/stack
File deleted
/contrib/media/updf/include/std/string
File deleted
/contrib/media/updf/include/std/complex
File deleted
/contrib/media/updf/include/std/cfloat
File deleted
/contrib/media/updf/include/std/ostream
File deleted
/contrib/media/updf/include/std/sstream
File deleted
/contrib/media/updf/include/std/csignal
File deleted
/contrib/media/updf/include/std/valarray
File deleted
/contrib/media/updf/include/std/iostream
File deleted
/contrib/media/updf/include/std/cstdio
File deleted
/contrib/media/updf/include/std/algorithm
File deleted
/contrib/media/updf/include/std/cstdarg
File deleted
/contrib/media/updf/include/std/iomanip
File deleted
/contrib/media/updf/include/std/ciso646
File deleted
/contrib/media/updf/include/std/locale
File deleted
/contrib/media/updf/include/std/numeric
File deleted
/contrib/media/updf/include/std/vector
File deleted
/contrib/media/updf/include/std/stdexcept
File deleted
/contrib/media/updf/include/std/utility
File deleted
/contrib/media/updf/include/std/deque
File deleted
/contrib/media/updf/include/std/climits
File deleted
/contrib/media/updf/include/std/cwchar
File deleted
/contrib/media/updf/include/std/memory
File deleted
/contrib/media/updf/include/std/cstring
File deleted
/contrib/media/updf/include/std/list
File deleted
/contrib/media/updf/include/std/cstddef
File deleted
/contrib/media/updf/include/std/map
File deleted
/contrib/media/updf/include/std/cwctype
File deleted
/contrib/media/updf/include/exception
File deleted
/contrib/media/updf/include/iAVLTree.h
File deleted
/contrib/media/updf/include/lzio.h
File deleted
/contrib/media/updf/include/stdexcept
File deleted
/contrib/media/updf/include/floatingpoint.h
File deleted
/contrib/media/updf/include/zconf.h
File deleted
/contrib/media/updf/include/cfloat
File deleted
/contrib/media/updf/include/ansidecl.h
File deleted
/contrib/media/updf/include/t2.h
File deleted
/contrib/media/updf/include/cstddef
File deleted
/contrib/media/updf/include/map
File deleted
/contrib/media/updf/include/mpeg.h
File deleted
/contrib/media/updf/include/pngconf.h
File deleted
/contrib/media/updf/include/iostream
File deleted
/contrib/media/updf/include/endian.h
File deleted
/contrib/media/updf/include/share.h
File deleted
/contrib/media/updf/include/extern.h
File deleted
/contrib/media/updf/include/set
File deleted
/contrib/media/updf/include/conio.h
File deleted
/contrib/media/updf/include/openjpeg.h
File deleted
/contrib/media/updf/include/mf_common.h
File deleted
/contrib/media/updf/include/mathcommands.h
File deleted
/contrib/media/updf/include/gppconio.h
File deleted
/contrib/media/updf/include/dir.h
File deleted
/contrib/media/updf/include/fnmatch.h
File deleted
/contrib/media/updf/include/corefunctions.h
File deleted
/contrib/media/updf/include/ostream
File deleted
/contrib/media/updf/include/console.c
File deleted
/contrib/media/updf/include/lispstring.h
File deleted
/contrib/media/updf/include/locale.h
File deleted
/contrib/media/updf/include/cursos2.h
File deleted
/contrib/media/updf/include/patterns.h
File deleted
/contrib/media/updf/include/cerrno
File deleted
/contrib/media/updf/include/evalfunc.h
File deleted
/contrib/media/updf/include/gnu/stubs.h
File deleted
/contrib/media/updf/include/curses.h
File deleted
Property changes:
Deleted: svn:executable
-*
\ No newline at end of property
/contrib/media/updf/include/fcntl.h
File deleted
/contrib/media/updf/include/libelf/config.h
File deleted
/contrib/media/updf/include/libelf/elf_repl.h
File deleted
/contrib/media/updf/include/libelf/nlist.h
File deleted
/contrib/media/updf/include/libelf/private.h
File deleted
/contrib/media/updf/include/libelf/errors.h
File deleted
/contrib/media/updf/include/libelf/libelf.h
File deleted
/contrib/media/updf/include/libelf/byteswap.h
File deleted
/contrib/media/updf/include/libelf/ext_types.h
File deleted
/contrib/media/updf/include/libelf/sys_elf.h
File deleted
/contrib/media/updf/include/all.h
File deleted
/contrib/media/updf/include/memory.h
File deleted
/contrib/media/updf/include/bits/endian.h
File deleted
/contrib/media/updf/include/bits/std_algorithm.h
File deleted
/contrib/media/updf/include/bits/std_iterator.h
File deleted
/contrib/media/updf/include/bits/std_bitset.h
File deleted
/contrib/media/updf/include/bits/wchar.h
File deleted
/contrib/media/updf/include/bits/stl_algo.h
File deleted
/contrib/media/updf/include/bits/wordsize.h
File deleted
/contrib/media/updf/include/bits/std_iomanip.h
File deleted
/contrib/media/updf/include/bits/gslice.h
File deleted
/contrib/media/updf/include/bits/stl_construct.h
File deleted
/contrib/media/updf/include/bits/stl_iterator.h
File deleted
/contrib/media/updf/include/bits/std_numeric.h
File deleted
/contrib/media/updf/include/bits/stl_threads.h
File deleted
/contrib/media/updf/include/bits/std_functional.h
File deleted
/contrib/media/updf/include/bits/basic_ios.tcc
File deleted
/contrib/media/updf/include/bits/basic_file.h
File deleted
/contrib/media/updf/include/bits/container_concepts.h
File deleted
/contrib/media/updf/include/bits/std_string.h
File deleted
/contrib/media/updf/include/bits/fstream.tcc
File deleted
/contrib/media/updf/include/bits/stl_numeric.h
File deleted
/contrib/media/updf/include/bits/codecvt.h
File deleted
/contrib/media/updf/include/bits/valarray_meta.h
File deleted
/contrib/media/updf/include/bits/std_valarray.h
File deleted
/contrib/media/updf/include/bits/basic_ios.h
File deleted
/contrib/media/updf/include/bits/slice_array.h
File deleted
/contrib/media/updf/include/bits/std_queue.h
File deleted
/contrib/media/updf/include/bits/boost_concept_check.h
File deleted
/contrib/media/updf/include/bits/indirect_array.h
File deleted
/contrib/media/updf/include/bits/slice.h
File deleted
/contrib/media/updf/include/bits/localefwd.h
File deleted
/contrib/media/updf/include/bits/std_streambuf.h
File deleted
/contrib/media/updf/include/bits/stl_iterator_base_funcs.h
File deleted
/contrib/media/updf/include/bits/char_traits.h
File deleted
/contrib/media/updf/include/bits/stl_queue.h
File deleted
/contrib/media/updf/include/bits/sequence_concepts.h
File deleted
/contrib/media/updf/include/bits/stl_function.h
File deleted
/contrib/media/updf/include/bits/c++config
File deleted
/contrib/media/updf/include/bits/concept_checks.h
File deleted
/contrib/media/updf/include/bits/std_fstream.h
File deleted
/contrib/media/updf/include/bits/std_vector.h
File deleted
/contrib/media/updf/include/bits/stl_alloc.h
File deleted
/contrib/media/updf/include/bits/std_istream.h
File deleted
/contrib/media/updf/include/bits/std_stack.h
File deleted
/contrib/media/updf/include/bits/stl_tree.h
File deleted
/contrib/media/updf/include/bits/generic_shadow.h
File deleted
/contrib/media/updf/include/bits/sbuf_iter.h
File deleted
/contrib/media/updf/include/bits/stl_pthread_alloc.h
File deleted
/contrib/media/updf/include/bits/stl_tempbuf.h
File deleted
/contrib/media/updf/include/bits/stl_vector.h
File deleted
/contrib/media/updf/include/bits/std_ostream.h
File deleted
/contrib/media/updf/include/bits/locale_facets.h
File deleted
/contrib/media/updf/include/bits/std_list.h
File deleted
/contrib/media/updf/include/bits/stl_bvector.h
File deleted
/contrib/media/updf/include/bits/stl_stack.h
File deleted
/contrib/media/updf/include/bits/std_sstream.h
File deleted
/contrib/media/updf/include/bits/mask_array.h
File deleted
/contrib/media/updf/include/bits/stl_list.h
File deleted
/contrib/media/updf/include/bits/limits_generic.h
File deleted
/contrib/media/updf/include/bits/stl_algobase.h
File deleted
/contrib/media/updf/include/bits/valarray_array.tcc
File deleted
/contrib/media/updf/include/bits/gslice_array.h
File deleted
/contrib/media/updf/include/bits/stl_iterator_base.h
File deleted
/contrib/media/updf/include/bits/std_iosfwd.h
File deleted
/contrib/media/updf/include/bits/poll.h
File deleted
/contrib/media/updf/include/bits/type_traits.h
File deleted
/contrib/media/updf/include/bits/cpp_type_traits.h
File deleted
/contrib/media/updf/include/bits/streambuf.tcc
File deleted
/contrib/media/updf/include/bits/std_stdexcept.h
File deleted
/contrib/media/updf/include/bits/std_utility.h
File deleted
/contrib/media/updf/include/bits/std_deque.h
File deleted
/contrib/media/updf/include/bits/valarray_array.h
File deleted
/contrib/media/updf/include/bits/stl_deque.h
File deleted
/contrib/media/updf/include/bits/istream.tcc
File deleted
/contrib/media/updf/include/bits/stl_config.h
File deleted
/contrib/media/updf/include/bits/std_map.h
File deleted
/contrib/media/updf/include/bits/functexcept.h
File deleted
/contrib/media/updf/include/bits/basic_string.tcc
File deleted
/contrib/media/updf/include/bits/stl_uninitialized.h
File deleted
/contrib/media/updf/include/bits/ostream.tcc
File deleted
/contrib/media/updf/include/bits/std_iostream.h
File deleted
/contrib/media/updf/include/bits/stl_heap.h
File deleted
/contrib/media/updf/include/bits/stl_map.h
File deleted
/contrib/media/updf/include/bits/sstream.tcc
File deleted
/contrib/media/updf/include/bits/std_ios.h
File deleted
/contrib/media/updf/include/bits/std_set.h
File deleted
/contrib/media/updf/include/bits/locale_facets.tcc
File deleted
/contrib/media/updf/include/bits/basic_string.h
File deleted
/contrib/media/updf/include/bits/fpos.h
File deleted
/contrib/media/updf/include/bits/stringfwd.h
File deleted
/contrib/media/updf/include/bits/std_locale.h
File deleted
/contrib/media/updf/include/bits/stl_multimap.h
File deleted
/contrib/media/updf/include/bits/stl_pair.h
File deleted
/contrib/media/updf/include/bits/stl_set.h
File deleted
/contrib/media/updf/include/bits/std_complex.h
File deleted
/contrib/media/updf/include/bits/std_memory.h
File deleted
/contrib/media/updf/include/bits/stdio.h
File deleted
/contrib/media/updf/include/bits/stl_raw_storage_iter.h
File deleted
/contrib/media/updf/include/bits/pthread_allocimpl.h
File deleted
/contrib/media/updf/include/bits/ios_base.h
File deleted
/contrib/media/updf/include/bits/stl_relops.h
File deleted
/contrib/media/updf/include/bits/concept_check.h
File deleted
/contrib/media/updf/include/bits/stl_multiset.h
File deleted
/contrib/media/updf/include/bits/stl_iterator_base_types.h
File deleted
/contrib/media/updf/include/lisphash.h
File deleted
/contrib/media/updf/include/file.h
File deleted
/contrib/media/updf/include/stdio.h
File deleted
/contrib/media/updf/include/jbig2_arith.h
File deleted
/contrib/media/updf/include/parametrized.h
File deleted
/contrib/media/updf/include/term_entry.h
File deleted
/contrib/media/updf/include/std.h
File deleted
/contrib/media/updf/include/valarray
File deleted
/contrib/media/updf/include/termcap.h
File deleted
/contrib/media/updf/include/efmt.h
File deleted
/contrib/media/updf/include/jpt.h
File deleted
/contrib/media/updf/include/inout.h
File deleted
/contrib/media/updf/include/yacas.h
File deleted
/contrib/media/updf/include/wchar.h
File deleted
/contrib/media/updf/include/malloc.h
File deleted
/contrib/media/updf/include/lparser.h
File deleted
/contrib/media/updf/include/linux/byteorder/swabb.h
File deleted
/contrib/media/updf/include/linux/byteorder/big_endian.h
File deleted
/contrib/media/updf/include/linux/byteorder/pdp_endian.h
File deleted
/contrib/media/updf/include/linux/byteorder/little_endian.h
File deleted
/contrib/media/updf/include/linux/byteorder/generic.h
File deleted
/contrib/media/updf/include/linux/byteorder/swab.h
File deleted
/contrib/media/updf/include/bio.h
File deleted
/contrib/media/updf/include/regex.h
File deleted
/contrib/media/updf/include/tcd.h
File deleted
/contrib/media/updf/include/substitute.h
File deleted
/contrib/media/updf/include/jpeglib.h
File deleted
/contrib/media/updf/include/stack
File deleted
/contrib/media/updf/include/tic.h
File deleted
/contrib/media/updf/include/stdio_.h
File deleted
/contrib/media/updf/include/lua.h
File deleted
/contrib/media/updf/include/stdlib.h
File deleted
/contrib/media/updf/include/memory
File deleted
/contrib/media/updf/include/math.h
File deleted
/contrib/media/updf/include/bfd.h
File deleted
/contrib/media/updf/include/bios.h
File deleted
/contrib/media/updf/include/jbig2.h
File deleted
/contrib/media/updf/include/zlib.h
File deleted
/contrib/media/updf/include/iomanip
File deleted
/contrib/media/updf/include/pi.h
File deleted
/contrib/media/updf/include/crt0.h
File deleted
/contrib/media/updf/include/direct.h
File deleted
/contrib/media/updf/include/platmath.h
File deleted
/contrib/media/updf/include/lispglobals.h
File deleted
/contrib/media/updf/include/limits
File deleted
/contrib/media/updf/include/numeric
File deleted
/contrib/media/updf/include/crc32.h
File deleted
/contrib/media/updf/include/signal.h
File deleted
/contrib/media/updf/include/defines.h
File deleted
/contrib/media/updf/include/hashsize.h
File deleted
/contrib/media/updf/include/random.h
File deleted
/contrib/media/updf/include/eti.h
File deleted
/contrib/media/updf/include/lapi.h
File deleted
/contrib/media/updf/include/patcher.h
File deleted
/contrib/media/updf/include/j2k.h
File deleted
/contrib/media/updf/include/prototypes.h
File deleted
/contrib/media/updf/include/grp.h
File deleted
/contrib/media/updf/include/strings.h
File deleted
/contrib/media/updf/include/unixcommandline.h
File deleted
/contrib/media/updf/include/xmltokenizer.h
File deleted
/contrib/media/updf/include/jbig2_priv.h
File deleted
/contrib/media/updf/include/cstdlib
File deleted
/contrib/media/updf/include/ftw.h
File deleted
/contrib/media/updf/include/pnginfo.h
File deleted
/contrib/media/updf/include/stdcommandline.h
File deleted
/contrib/media/updf/include/limits.h
File deleted
/contrib/media/updf/include/jbig2_huffman.h
File deleted
/contrib/media/updf/include/streambuf
File deleted
/contrib/media/updf/include/menuet/net.h
File deleted
/contrib/media/updf/include/menuet/thread.h
File deleted
/contrib/media/updf/include/menuet/mash.h
File deleted
/contrib/media/updf/include/menuet/network.hpp
File deleted
/contrib/media/updf/include/menuet/ipc.h
File deleted
/contrib/media/updf/include/menuet/font8x8.h
File deleted
/contrib/media/updf/include/menuet/os.h
File deleted
/contrib/media/updf/include/menuet/console.h
File deleted
/contrib/media/updf/include/menuet/sem.h
File deleted
/contrib/media/updf/include/menuet/textcon.h
File deleted
/contrib/media/updf/include/menuet/gui.h
File deleted
/contrib/media/updf/include/locale
File deleted
/contrib/media/updf/include/lzoconf.h
File deleted
/contrib/media/updf/include/errors.h
File deleted
/contrib/media/updf/include/mystring.h
File deleted
/contrib/media/updf/include/llimits.h
File deleted
/contrib/media/updf/include/nomacros.h
File deleted
/contrib/media/updf/include/event.h
File deleted
/contrib/media/updf/include/complex
File deleted
/contrib/media/updf/include/lispuserfunc.h
File deleted
/contrib/media/updf/include/dirent.h
File deleted
/contrib/media/updf/include/dos.h
File deleted
/contrib/media/updf/include/fix.h
File deleted
/contrib/media/updf/include/table.h
File deleted
/contrib/media/updf/include/sys/wait.h
File deleted
/contrib/media/updf/include/sys/config.h
File deleted
/contrib/media/updf/include/sys/poll.h
File deleted
/contrib/media/updf/include/sys/exceptn.h
File deleted
/contrib/media/updf/include/sys/stat.h
File deleted
/contrib/media/updf/include/sys/nearptr.h
File deleted
/contrib/media/updf/include/sys/utsname.h
File deleted
/contrib/media/updf/include/sys/user.h
File deleted
/contrib/media/updf/include/sys/dir.h
File deleted
/contrib/media/updf/include/sys/bitypes.h
File deleted
/contrib/media/updf/include/sys/times.h
File deleted
/contrib/media/updf/include/sys/sysmacros.h
File deleted
/contrib/media/updf/include/sys/system.h
File deleted
/contrib/media/updf/include/sys/errno.h
File deleted
/contrib/media/updf/include/sys/version.h
File deleted
/contrib/media/updf/include/sys/segments.h
File deleted
/contrib/media/updf/include/sys/resource.h
File deleted
/contrib/media/updf/include/sys/farptr.h
File deleted
/contrib/media/updf/include/sys/time.h
File deleted
/contrib/media/updf/include/sys/types.h
File deleted
/contrib/media/updf/include/sys/fcntl.h
File deleted
/contrib/media/updf/include/sys/mono.h
File deleted
/contrib/media/updf/include/sys/ioctl.h
File deleted
/contrib/media/updf/include/sys/file.h
File deleted
/contrib/media/updf/include/sys/dxe.h
File deleted
/contrib/media/updf/include/sys/djtypes.h
File deleted
/contrib/media/updf/include/sys/cdefs.h
File deleted
/contrib/media/updf/include/sys/mman.h
File deleted
/contrib/media/updf/include/sys/socket.h
File deleted
/contrib/media/updf/include/sys/fsext.h
File deleted
/contrib/media/updf/include/sys/vfs.h
File deleted
/contrib/media/updf/include/sys/param.h
File deleted
/contrib/media/updf/include/sys/movedata.h
File deleted
/contrib/media/updf/include/sys/timeb.h
File deleted
/contrib/media/updf/include/t1_luts.h
File deleted
/contrib/media/updf/include/lispio.h
File deleted
/contrib/media/updf/include/ncurses_cfg.h
File deleted
/contrib/media/updf/include/patternclass.h
File deleted
/contrib/media/updf/include/elf.h
File deleted
/contrib/media/updf/include/climits
File deleted
/contrib/media/updf/include/nc_panel.h
File deleted
/contrib/media/updf/include/lib/libc.a
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Deleted: svn:mime-type
-application/octet-stream
\ No newline at end of property
/contrib/media/updf/include/lib/libpng.a
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Deleted: svn:mime-type
-application/octet-stream
\ No newline at end of property
/contrib/media/updf/include/lib/libjpeg.a
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Deleted: svn:mime-type
-application/octet-stream
\ No newline at end of property
/contrib/media/updf/include/lib/libfreetype2.a
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Deleted: svn:mime-type
-application/octet-stream
\ No newline at end of property
/contrib/media/updf/include/lib/libopenjpeg.a
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Deleted: svn:mime-type
-application/octet-stream
\ No newline at end of property
/contrib/media/updf/include/lib/libjbig2dec.a
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Deleted: svn:mime-type
-application/octet-stream
\ No newline at end of property
/contrib/media/updf/include/lib/libz.a
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Deleted: svn:mime-type
-application/octet-stream
\ No newline at end of property
/contrib/media/updf/include/lib/libmupdf.a
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Deleted: svn:mime-type
-application/octet-stream
\ No newline at end of property
/contrib/media/updf/include/lib/libm.a
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Deleted: svn:mime-type
-application/octet-stream
\ No newline at end of property
/contrib/media/updf/include/glob.h
File deleted
/contrib/media/updf/include/cwctype
File deleted
/contrib/media/updf/include/panel.h
File deleted
Property changes:
Deleted: svn:executable
-*
\ No newline at end of property
/contrib/media/updf/include/ios
File deleted
/contrib/media/updf/include/mcoff/mcoff.h
File deleted
/contrib/media/updf/include/mcoff/_coff.h
File deleted
/contrib/media/updf/include/lispcleanupstack.h
File deleted
/contrib/media/updf/include/string.h
File deleted
/contrib/media/updf/include/jbig2_mmr.h
File deleted
/contrib/media/updf/include/nc_alloc.h
File deleted
/contrib/media/updf/include/cio.h
File deleted
/contrib/media/updf/include/clocale
File deleted
/contrib/media/updf/include/curspriv.h
File deleted
/contrib/media/updf/include/features.h
File deleted
/contrib/media/updf/include/lisperror.h
File deleted
/contrib/media/updf/include/ftheader.h
File deleted
/contrib/media/updf/include/lstring.h
File deleted
/contrib/media/updf/include/hash.h
File deleted
/contrib/media/updf/include/mct.h
File deleted
/contrib/media/updf/include/ctype.h
File deleted
/contrib/media/updf/include/libiberty.h
File deleted
/contrib/media/updf/include/os_layer/os_layer.h
File deleted
/contrib/media/updf/include/os_layer/queue.h
File deleted
/contrib/media/updf/include/anumber.h
File deleted
/contrib/media/updf/include/pngstruct.h
File deleted
/contrib/media/updf/include/infixparser.h
File deleted
/contrib/media/updf/include/lstate.h
File deleted
/contrib/media/updf/include/cstdarg
File deleted
/contrib/media/updf/include/pc.h
File deleted
/contrib/media/updf/include/unistd.h
File deleted
/contrib/media/updf/include/unctrl.h
File deleted
/contrib/media/updf/include/ext/stl_hash_fun.h
File deleted
/contrib/media/updf/include/ext/stl_hashtable.h
File deleted
/contrib/media/updf/include/ext/bvector
File deleted
/contrib/media/updf/include/ext/rope
File deleted
/contrib/media/updf/include/ext/stl_bvector.h
File deleted
/contrib/media/updf/include/ext/ropeimpl.h
File deleted
/contrib/media/updf/include/ext/stl_rope.h
File deleted
/contrib/media/updf/include/ext/hash_set
File deleted
/contrib/media/updf/include/ext/slist
File deleted
/contrib/media/updf/include/ext/tree
File deleted
/contrib/media/updf/include/ext/hash_map
File deleted
/contrib/media/updf/include/utility
File deleted
/contrib/media/updf/include/opj_includes.h
File deleted
/contrib/media/updf/include/itc.h
File deleted
/contrib/media/updf/include/minilzo.h
File deleted
/contrib/media/updf/include/lispassert.h
File deleted
/contrib/media/updf/include/GPL_stuff.h
File deleted
/contrib/media/updf/include/filescanner.h
File deleted
/contrib/media/updf/include/int.h
File deleted
/contrib/media/updf/include/yacasprivate.h
File deleted
/contrib/media/updf/include/yacasbase.h
File deleted
/contrib/media/updf/include/jbig2_hufftab.h
File deleted
/contrib/media/updf/include/ltm.h
File deleted
/contrib/media/updf/include/freetype/ttinterp.h
File deleted
Property changes:
Deleted: svn:executable
-*
\ No newline at end of property
/contrib/media/updf/include/freetype/ttcalc.h
File deleted
Property changes:
Deleted: svn:executable
-*
\ No newline at end of property
/contrib/media/updf/include/freetype/ftgxval.h
File deleted
/contrib/media/updf/include/freetype/ftimage.h
File deleted
/contrib/media/updf/include/freetype/ttconfig.h
File deleted
Property changes:
Deleted: svn:executable
-*
\ No newline at end of property
/contrib/media/updf/include/freetype/ttengine.h
File deleted
Property changes:
Deleted: svn:executable
-*
\ No newline at end of property
/contrib/media/updf/include/freetype/ftsystem.h
File deleted
/contrib/media/updf/include/freetype/ftotval.h
File deleted
/contrib/media/updf/include/freetype/ftbbox.h
File deleted
/contrib/media/updf/include/freetype/ftadvanc.h
File deleted
/contrib/media/updf/include/freetype/ftlcdfil.h
File deleted
/contrib/media/updf/include/freetype/header.h
File deleted
Property changes:
Deleted: svn:executable
-*
\ No newline at end of property
/contrib/media/updf/include/freetype/ftmac.h
File deleted
/contrib/media/updf/include/freetype/ttdebug.h
File deleted
Property changes:
Deleted: svn:executable
-*
\ No newline at end of property
/contrib/media/updf/include/freetype/ftchapters.h
File deleted
/contrib/media/updf/include/freetype/ftlzw.h
File deleted
/contrib/media/updf/include/freetype/ttraster.h
File deleted
Property changes:
Deleted: svn:executable
-*
\ No newline at end of property
/contrib/media/updf/include/freetype/ftrender.h
File deleted
/contrib/media/updf/include/freetype/ft2build.h
File deleted
/contrib/media/updf/include/freetype/ftglyph.h
File deleted
/contrib/media/updf/include/freetype/ft_conf.h
File deleted
Property changes:
Deleted: svn:executable
-*
\ No newline at end of property
/contrib/media/updf/include/freetype/t1tables.h
File deleted
/contrib/media/updf/include/freetype/ttmemory.h
File deleted
Property changes:
Deleted: svn:executable
-*
\ No newline at end of property
/contrib/media/updf/include/freetype/ftheader.h
File deleted
/contrib/media/updf/include/freetype/ftgasp.h
File deleted
/contrib/media/updf/include/freetype/internal/psaux.h
File deleted
/contrib/media/updf/include/freetype/internal/ftmemory.h
File deleted
/contrib/media/updf/include/freetype/internal/ftgloadr.h
File deleted
/contrib/media/updf/include/freetype/internal/ftpic.h
File deleted
/contrib/media/updf/include/freetype/internal/ftserv.h
File deleted
/contrib/media/updf/include/freetype/internal/t1types.h
File deleted
/contrib/media/updf/include/freetype/internal/sfnt.h
File deleted
/contrib/media/updf/include/freetype/internal/internal.h
File deleted
/contrib/media/updf/include/freetype/internal/tttypes.h
File deleted
/contrib/media/updf/include/freetype/internal/ftrfork.h
File deleted
/contrib/media/updf/include/freetype/internal/ftdebug.h
File deleted
/contrib/media/updf/include/freetype/internal/ftstream.h
File deleted
/contrib/media/updf/include/freetype/internal/ftdriver.h
File deleted
/contrib/media/updf/include/freetype/internal/ftobjs.h
File deleted
/contrib/media/updf/include/freetype/internal/pshints.h
File deleted
/contrib/media/updf/include/freetype/internal/fttrace.h
File deleted
/contrib/media/updf/include/freetype/internal/ftvalid.h
File deleted
/contrib/media/updf/include/freetype/internal/autohint.h
File deleted
/contrib/media/updf/include/freetype/internal/ftcalc.h
File deleted
/contrib/media/updf/include/freetype/internal/services/svpostnm.h
File deleted
/contrib/media/updf/include/freetype/internal/services/svgxval.h
File deleted
/contrib/media/updf/include/freetype/internal/services/svtteng.h
File deleted
/contrib/media/updf/include/freetype/internal/services/svpscmap.h
File deleted
/contrib/media/updf/include/freetype/internal/services/svotval.h
File deleted
/contrib/media/updf/include/freetype/internal/services/svxf86nm.h
File deleted
/contrib/media/updf/include/freetype/internal/services/svpfr.h
File deleted
/contrib/media/updf/include/freetype/internal/services/svttcmap.h
File deleted
/contrib/media/updf/include/freetype/internal/services/svbdf.h
File deleted
/contrib/media/updf/include/freetype/internal/services/svpsinfo.h
File deleted
/contrib/media/updf/include/freetype/internal/services/svcid.h
File deleted
/contrib/media/updf/include/freetype/internal/services/svkern.h
File deleted
/contrib/media/updf/include/freetype/internal/services/svwinfnt.h
File deleted
/contrib/media/updf/include/freetype/internal/services/svgldict.h
File deleted
/contrib/media/updf/include/freetype/internal/services/svttglyf.h
File deleted
/contrib/media/updf/include/freetype/internal/services/svmm.h
File deleted
/contrib/media/updf/include/freetype/internal/services/svsfnt.h
File deleted
/contrib/media/updf/include/freetype/internal/pcftypes.h
File deleted
/contrib/media/updf/include/freetype/ttcmap.h
File deleted
Property changes:
Deleted: svn:executable
-*
\ No newline at end of property
/contrib/media/updf/include/freetype/fttypes.h
File deleted
/contrib/media/updf/include/freetype/fterrid.h
File deleted
Property changes:
Deleted: svn:executable
-*
\ No newline at end of property
/contrib/media/updf/include/freetype/ttnameid.h
File deleted
/contrib/media/updf/include/freetype/fterrors.h
File deleted
/contrib/media/updf/include/freetype/ttmutex.h
File deleted
Property changes:
Deleted: svn:executable
-*
\ No newline at end of property
/contrib/media/updf/include/freetype/tttypes.h
File deleted
Property changes:
Deleted: svn:executable
-*
\ No newline at end of property
/contrib/media/updf/include/freetype/config/ftstdlib.h
File deleted
/contrib/media/updf/include/freetype/config/ftmodule.h
File deleted
/contrib/media/updf/include/freetype/config/ftconfig.h
File deleted
/contrib/media/updf/include/freetype/config/ftheader.h
File deleted
/contrib/media/updf/include/freetype/config/ftoption.h
File deleted
/contrib/media/updf/include/freetype/ftpfr.h
File deleted
/contrib/media/updf/include/freetype/ftxf86.h
File deleted
/contrib/media/updf/include/freetype/ttload.h
File deleted
Property changes:
Deleted: svn:executable
-*
\ No newline at end of property
/contrib/media/updf/include/freetype/ftcid.h
File deleted
/contrib/media/updf/include/freetype/ftoutln.h
File deleted
/contrib/media/updf/include/freetype/fttrigon.h
File deleted
/contrib/media/updf/include/freetype/ftcache.h
File deleted
/contrib/media/updf/include/freetype/ftsynth.h
File deleted
/contrib/media/updf/include/freetype/ttunpat.h
File deleted
/contrib/media/updf/include/freetype/ftstroke.h
File deleted
/contrib/media/updf/include/freetype/ftmodapi.h
File deleted
/contrib/media/updf/include/freetype/ttobjs.h
File deleted
Property changes:
Deleted: svn:executable
-*
\ No newline at end of property
/contrib/media/updf/include/freetype/ftlist.h
File deleted
/contrib/media/updf/include/freetype/ftbitmap.h
File deleted
/contrib/media/updf/include/freetype/tttags.h
File deleted
/contrib/media/updf/include/freetype/ftincrem.h
File deleted
/contrib/media/updf/include/freetype/ttcache.h
File deleted
Property changes:
Deleted: svn:executable
-*
\ No newline at end of property
/contrib/media/updf/include/freetype/ftsnames.h
File deleted
/contrib/media/updf/include/freetype/ftmoderr.h
File deleted
/contrib/media/updf/include/freetype/tttables.h
File deleted
/contrib/media/updf/include/freetype/freetype.h
File deleted
/contrib/media/updf/include/freetype/ftbdf.h
File deleted
/contrib/media/updf/include/freetype/ftsizes.h
File deleted
/contrib/media/updf/include/freetype/ttfile.h
File deleted
Property changes:
Deleted: svn:executable
-*
\ No newline at end of property
/contrib/media/updf/include/freetype/ftnameid.h
File deleted
Property changes:
Deleted: svn:executable
-*
\ No newline at end of property
/contrib/media/updf/include/freetype/ttgload.h
File deleted
Property changes:
Deleted: svn:executable
-*
\ No newline at end of property
/contrib/media/updf/include/freetype/ttextend.h
File deleted
Property changes:
Deleted: svn:executable
-*
\ No newline at end of property
/contrib/media/updf/include/freetype/ftwinfnt.h
File deleted
/contrib/media/updf/include/freetype/fterrdef.h
File deleted
/contrib/media/updf/include/freetype/ftmm.h
File deleted
/contrib/media/updf/include/freetype/ftgzip.h
File deleted
/contrib/media/updf/include/queue
File deleted
/contrib/media/updf/include/jbig2_arith_int.h
File deleted
/contrib/media/updf/include/values.h
File deleted
/contrib/media/updf/include/ring.h
File deleted
/contrib/media/updf/include/ar.h
File deleted
/contrib/media/updf/include/config.h
File deleted
/contrib/media/updf/include/c_std/bits/std_cstdlib.h
File deleted
/contrib/media/updf/include/c_std/bits/std_cstdio.h
File deleted
/contrib/media/updf/include/c_std/bits/std_cctype.h
File deleted
/contrib/media/updf/include/c_std/bits/std_cstdarg.h
File deleted
/contrib/media/updf/include/c_std/bits/std_cerrno.h
File deleted
/contrib/media/updf/include/c_std/bits/std_cmath.h
File deleted
/contrib/media/updf/include/c_std/bits/std_ctime.h
File deleted
/contrib/media/updf/include/c_std/bits/std_clocale.h
File deleted
/contrib/media/updf/include/c_std/bits/cmath.tcc
File deleted
/contrib/media/updf/include/c_std/bits/std_cassert.h
File deleted
/contrib/media/updf/include/c_std/bits/std_climits.h
File deleted
/contrib/media/updf/include/c_std/bits/std_csetjmp.h
File deleted
/contrib/media/updf/include/c_std/bits/std_cwchar.h
File deleted
/contrib/media/updf/include/c_std/bits/std_cfloat.h
File deleted
/contrib/media/updf/include/c_std/bits/std_cstring.h
File deleted
/contrib/media/updf/include/c_std/bits/std_cstddef.h
File deleted
/contrib/media/updf/include/c_std/bits/std_cwctype.h
File deleted
/contrib/media/updf/include/c_std/bits/std_csignal.h
File deleted
/contrib/media/updf/include/lualib.h
File deleted
/contrib/media/updf/include/osfcn.h
File deleted
/contrib/media/updf/include/wctype.h
File deleted
/contrib/media/updf/include/vector
File deleted
/contrib/media/updf/include/jconfig.h
File deleted
/contrib/media/updf/include/csetjmp
File deleted
/contrib/media/updf/include/lispeval.h
File deleted
/contrib/media/updf/include/mathutil.h
File deleted
/contrib/media/updf/include/lispatom.h
File deleted
/contrib/media/updf/include/sstream
File deleted
/contrib/media/updf/include/kolibri.h
File deleted
/contrib/media/updf/include/zAVLTree.h
File deleted
/contrib/media/updf/include/lispobject.h
File deleted
/contrib/media/updf/include/deffile.h
File deleted
/contrib/media/updf/include/rpc/types.h
File deleted
/contrib/media/updf/include/rpc/auth_unix.h
File deleted
/contrib/media/updf/include/rpc/svc_auth.h
File deleted
/contrib/media/updf/include/rpc/pmap_clnt.h
File deleted
/contrib/media/updf/include/rpc/pmap_rmt.h
File deleted
/contrib/media/updf/include/rpc/rpc_des.h
File deleted
/contrib/media/updf/include/rpc/rpc.h
File deleted
/contrib/media/updf/include/rpc/rpc_msg.h
File deleted
/contrib/media/updf/include/rpc/svc.h
File deleted
/contrib/media/updf/include/rpc/des_crypt.h
File deleted
/contrib/media/updf/include/rpc/key_prot.h
File deleted
/contrib/media/updf/include/rpc/auth_des.h
File deleted
/contrib/media/updf/include/rpc/netdb.h
File deleted
/contrib/media/updf/include/rpc/xdr.h
File deleted
/contrib/media/updf/include/rpc/clnt.h
File deleted
/contrib/media/updf/include/rpc/auth.h
File deleted
/contrib/media/updf/include/rpc/pmap_prot.h
File deleted
/contrib/media/updf/include/stubs.h
File deleted
/contrib/media/updf/include/ftp_var.h
File deleted
/contrib/media/updf/include/setjmp.h
File deleted
/contrib/media/updf/include/ltable.h
File deleted
/contrib/media/updf/include/archiver.h
File deleted
/contrib/media/updf/include/iterator
File deleted
/contrib/media/updf/include/genericstructs.h
File deleted
/contrib/media/updf/include/float.h
File deleted
/contrib/media/updf/include/ciso646
File deleted
/contrib/media/updf/include/lopcodes.h
File deleted
/contrib/media/updf/include/jbig2_arith_iaid.h
File deleted
/contrib/media/updf/include/utime.h
File deleted
/contrib/media/updf/include/lundump.h
File deleted
/contrib/media/updf/include/png.h
File deleted
/contrib/media/updf/include/commandline.h
File deleted
/contrib/media/updf/include/asm/types.h
File deleted
/contrib/media/updf/include/asm/byteorder.h
File deleted
/contrib/media/updf/include/pngdebug.h
File deleted
/contrib/media/updf/include/y_tab.h
File deleted
/contrib/media/updf/include/stdint.h
File deleted
/contrib/media/updf/include/grower.h
File deleted
/contrib/media/updf/include/stdbool.h
File deleted
/contrib/media/updf/include/io.h
File deleted
/contrib/media/updf/include/term.h
File deleted
/contrib/media/updf/include/tokenizer.h
File deleted
/contrib/media/updf/include/ft2build.h
File deleted
/contrib/media/updf/include/fstream
File deleted
/contrib/media/updf/include/j2k_lib.h
File deleted
/contrib/media/updf/include/coff.h
File deleted
/contrib/media/updf/include/choices.h
File deleted
/contrib/media/updf/include/opj_malloc.h
File deleted
/contrib/media/updf/include/cwchar
File deleted
/contrib/media/updf/include/pnglibconf.h
File deleted
/contrib/media/updf/include/termios.h
File deleted
/contrib/media/updf/include/errno.h
File deleted
/contrib/media/updf/include/refcount.h
File deleted
/contrib/media/updf/include/debugmem.h
File deleted
/contrib/media/updf/include/lcode.h
File deleted
/contrib/media/updf/include/glib/glib.h
File deleted
/contrib/media/updf/include/glib/glibconfig.h
File deleted
/contrib/media/updf/include/raw.h
File deleted
/contrib/media/updf/include/lmem.h
File deleted
/contrib/media/updf/include/tzfile.h
File deleted
/contrib/media/updf/include/glview.h
File deleted
/contrib/media/updf/include/time.h
File deleted
/contrib/media/updf/include/jbig2_image.h
File deleted
/contrib/media/updf/include/lctype.h
File deleted
/contrib/media/updf/include/algorithm
File deleted
/contrib/media/updf/include/menu.h
File deleted
/contrib/media/updf/include/bitset
File deleted
/contrib/media/updf/include/iosfwd
File deleted
/contrib/media/updf/include/search.h
File deleted
/contrib/media/updf/include/functional
File deleted
/contrib/media/updf/include/deque
File deleted
/contrib/media/updf/include/ldo.h
File deleted
/contrib/media/updf/include/inttypes.h
File deleted
/contrib/media/updf/include/string
File deleted
/contrib/media/updf/include/image.h
File deleted
/contrib/media/updf/include/stdarg.h
File deleted
/contrib/media/updf/include/jbig2_symbol_dict.h
File deleted
/contrib/media/updf/include/stub/crt0_elf.asm
File deleted
/contrib/media/updf/include/stub/Makefile
File deleted
/contrib/media/updf/include/stub/crt0__nounderscores.asm
File deleted
Property changes:
Deleted: svn:executable
-*
\ No newline at end of property
/contrib/media/updf/include/stub/crt0_coff.asm
File deleted
/contrib/media/updf/include/stub/crt0.asm
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Deleted: svn:mime-type
-application/octet-stream
\ No newline at end of property
/contrib/media/updf/include/jp2.h
File deleted
/contrib/media/updf/include/arpa/ftp.h
File deleted
/contrib/media/updf/include/arpa/nameser.h
File deleted
/contrib/media/updf/include/arpa/telnet.h
File deleted
/contrib/media/updf/include/arpa/tftp.h
File deleted
/contrib/media/updf/include/arpa/inet.h
File deleted
/contrib/media/updf/include/getpages.h
File deleted
/contrib/media/updf/include/ldebug.h
File deleted
/contrib/media/updf/include/form.h
File deleted
/contrib/media/updf/include/mathuserfunc.h
File deleted
/contrib/media/updf/include/mntent.h
File deleted
/contrib/media/updf/include/lgc.h
File deleted
/contrib/media/updf/include/lfunc.h
File deleted
/contrib/media/updf/include/opcode.h
File deleted
/contrib/media/updf/include/ctime
File deleted
/contrib/media/updf/include/machine/endian.h
File deleted
/contrib/media/updf/include/machine/asm.h
File deleted
/contrib/media/updf/include/istream
File deleted
/contrib/media/updf/include/mathenvironment.h
File deleted
/contrib/media/updf/include/log.h
File deleted
/contrib/media/updf/include/libc/asmdefs.h
File deleted
/contrib/media/updf/include/libc/version.h
File deleted
/contrib/media/updf/include/libc/bss.h
File deleted
/contrib/media/updf/include/libc/Makefile
File deleted
/contrib/media/updf/include/libc/farptrgs.h
File deleted
/contrib/media/updf/include/libc/unconst.h
File deleted
/contrib/media/updf/include/libc/dosexec.h
File deleted
/contrib/media/updf/include/libc/local.h
File deleted
/contrib/media/updf/include/libc/ttyprvt.h
File deleted
/contrib/media/updf/include/libc/atexit.h
File deleted
/contrib/media/updf/include/libc/stubs.h
File deleted
/contrib/media/updf/include/libc/stdiohk.h
File deleted
/contrib/media/updf/include/libc/ieee.h
File deleted
/contrib/media/updf/include/libc/mkfargs.bat
File deleted
/contrib/media/updf/include/libc/internal.h
File deleted
/contrib/media/updf/include/libc/dosio.h
File deleted
/contrib/media/updf/include/libc/file.h
File deleted
/contrib/media/updf/include/libc/environ.h
File deleted
/contrib/media/updf/include/libc/asm.h
File deleted
/contrib/media/updf/include/lispparser.h
File deleted
/contrib/media/updf/include/luaconf.h
File deleted
/contrib/media/updf/include/libmgfx.h
File deleted
/contrib/media/updf/include/externs.h
File deleted
/contrib/media/updf/include/jbig2_generic.h
File deleted
/contrib/media/updf/include/csignal
File deleted
/contrib/media/updf/include/emu_layer/fs.h
File deleted
/contrib/media/updf/include/emu_layer/layer.h
File deleted
/contrib/media/updf/include/libm/math.h
File deleted
/contrib/media/updf/include/debug/wild.h
File deleted
/contrib/media/updf/include/debug/redir.h
File deleted
/contrib/media/updf/include/debug/v2load.h
File deleted
/contrib/media/updf/include/debug/tss.h
File deleted
/contrib/media/updf/include/debug/stab.h
File deleted
/contrib/media/updf/include/debug/dbgcom.h
File deleted
/contrib/media/updf/include/debug/syms.h
File deleted
/contrib/media/updf/include/jbig2_text.h
File deleted
/contrib/media/updf/include/assert.h
File deleted
/contrib/media/updf/include/types.h
File deleted
/contrib/media/updf/include/arrayclass.h
File deleted
/contrib/media/updf/include/llex.h
File deleted
/contrib/media/updf/include/fdset.h
File deleted
/contrib/media/updf/include/general.h
File deleted
/contrib/media/updf/include/process.h
File deleted
/contrib/media/updf/include/t1.h
File deleted
/contrib/media/updf/include/arggetter.h
File deleted
/contrib/media/updf/include/backward/function.h
File deleted
/contrib/media/updf/include/backward/multimap.h
File deleted
/contrib/media/updf/include/backward/stream.h
File deleted
/contrib/media/updf/include/backward/pair.h
File deleted
/contrib/media/updf/include/backward/iomanip.h
File deleted
/contrib/media/updf/include/backward/slist.h
File deleted
/contrib/media/updf/include/backward/strstream
File deleted
/contrib/media/updf/include/backward/tree.h
File deleted
/contrib/media/updf/include/backward/vector.h
File deleted
/contrib/media/updf/include/backward/deque.h
File deleted
/contrib/media/updf/include/backward/backward_warning.h
File deleted
/contrib/media/updf/include/backward/multiset.h
File deleted
/contrib/media/updf/include/backward/defalloc.h
File deleted
/contrib/media/updf/include/backward/list.h
File deleted
/contrib/media/updf/include/backward/map.h
File deleted
/contrib/media/updf/include/backward/algobase.h
File deleted
/contrib/media/updf/include/backward/hash_map.h
File deleted
/contrib/media/updf/include/backward/algo.h
File deleted
/contrib/media/updf/include/backward/strstream.h
File deleted
/contrib/media/updf/include/backward/queue.h
File deleted
/contrib/media/updf/include/backward/streambuf.h
File deleted
/contrib/media/updf/include/backward/new.h
File deleted
/contrib/media/updf/include/backward/iterator.h
File deleted
/contrib/media/updf/include/backward/alloc.h
File deleted
/contrib/media/updf/include/backward/set.h
File deleted
/contrib/media/updf/include/backward/hashtable.h
File deleted
/contrib/media/updf/include/backward/hash_set.h
File deleted
/contrib/media/updf/include/backward/fstream.h
File deleted
/contrib/media/updf/include/backward/tempbuf.h
File deleted
/contrib/media/updf/include/backward/istream.h
File deleted
/contrib/media/updf/include/backward/bvector.h
File deleted
/contrib/media/updf/include/backward/rope.h
File deleted
/contrib/media/updf/include/backward/stack.h
File deleted
/contrib/media/updf/include/backward/complex.h
File deleted
/contrib/media/updf/include/backward/ostream.h
File deleted
/contrib/media/updf/include/backward/heap.h
File deleted
/contrib/media/updf/include/backward/iostream.h
File deleted
/contrib/media/updf/include/ieeefp.h
File deleted
/contrib/media/updf/include/jbig2_metadata.h
File deleted
/contrib/media/updf/include/lvm.h
File deleted
/contrib/media/updf/include/stringio.h
File deleted
/contrib/media/updf/include/cstdio
File deleted
/contrib/media/updf/include/varargs.h
File deleted
/contrib/media/updf/include/stddef.h
File deleted
/contrib/media/updf/include/keys.h
File deleted
/contrib/media/updf/include/numbers.h
File deleted
/contrib/media/updf/include/inlines/pc.h
File deleted
/contrib/media/updf/include/inlines/ctype.ha
File deleted
/contrib/media/updf/include/inlines/ctype.hd
File deleted
/contrib/media/updf/include/mgtk/slider.h
File deleted
/contrib/media/updf/include/mgtk/mgtk.h
File deleted
/contrib/media/updf/include/mgtk/pen.h
File deleted
/contrib/media/updf/include/mgtk/widget.h
File deleted
/contrib/media/updf/include/mgtk/types.h
File deleted
/contrib/media/updf/include/mgtk/text.h
File deleted
/contrib/media/updf/include/mgtk/string.h
File deleted
/contrib/media/updf/include/mgtk/editor.h
File deleted
/contrib/media/updf/include/mgtk/button.h
File deleted
/contrib/media/updf/include/mgtk/terminal.h
File deleted
/contrib/media/updf/include/mgtk/bitmap.h
File deleted
/contrib/media/updf/include/mgtk/app.h
File deleted
/contrib/media/updf/include/mgtk/event.h
File deleted
/contrib/media/updf/include/core_yacasmain.h
File deleted
/contrib/media/updf/include/mem.h
File deleted
/contrib/media/updf/include/cassert
File deleted
/contrib/media/updf/include/mqc.h
File deleted
/contrib/media/updf/include/lobject.h
File deleted
/contrib/media/updf/include/stdfileio.h
File deleted
/contrib/media/updf/include/lispevalhash.h
File deleted
/contrib/media/updf/include/pngpriv.h
File deleted
/contrib/media/updf/include/version.h
File deleted
/contrib/media/updf/include/list
File deleted
/contrib/media/updf/include/compressedfiles.h
File deleted
/contrib/media/updf/include/pwd.h
File deleted
/contrib/media/updf/include/configure
File deleted
Property changes:
Deleted: svn:executable
-*
\ No newline at end of property
/contrib/media/updf/build2.sh
File deleted
Property changes:
Deleted: svn:executable
-*
\ No newline at end of property
/contrib/media/updf/Makefile
File deleted
/contrib/media/updf/SYSCALL/src/Makefile
0,0 → 1,22
CC = kos32-gcc
LD = kos32-ld
 
SDK_DIR = $(abspath ../../../../sdk)
 
CFLAGS = -c -fno-ident -O2 -fomit-frame-pointer -fno-ident -U__WIN32__ -U_Win32 -U_WIN32 -U__MINGW32__ -UWIN32
 
INCLUDES = -I ../include -I $(SDK_DIR)/sources/newlib/libc/include
 
SYSCALL_SRC := $(notdir $(wildcard *.c))
OBJECTS = $(patsubst %.c, %.o, $(SYSCALL_SRC))
 
default: $(patsubst %.c,%.o,$(SYSCALL_SRC))
ar rcs libsyscall.a *.o
rm *.o
mv libsyscall.a ../../lib
 
%.o : %.c Makefile $(SYSCALL_SRC)
$(CC) $(CFLAGS) $(INCLUDES) -o $@ $<
 
clean:
rm *.o
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/SYSCALL/src/backgr.c
0,0 → 1,26
#include<menuet/os.h>
 
void __menuet__set_background_size(__u32 xsz,__u32 ysz)
{
__asm__ __volatile__("int $0x40"::"a"(15),"b"(1),"c"(xsz),"d"(ysz));
}
 
void __menuet__write_background_mem(__u32 pos,__u32 color)
{
__asm__ __volatile__("int $0x40"::"a"(15),"b"(2),"c"(pos),"d"(color));
}
 
void __menuet__draw_background(void)
{
__asm__ __volatile__("int $0x40"::"a"(15),"b"(3));
}
 
void __menuet__set_background_draw_type(int type)
{
__asm__ __volatile__("int $0x40"::"a"(15),"b"(3),"c"(type));
}
 
void __menuet__background_blockmove(char * src_ptr,__u32 bgr_dst,__u32 count)
{
__asm__ __volatile__("int $0x40"::"a"(15),"b"(3),"c"(src_ptr),"d"(bgr_dst),"S"(count));
}
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/SYSCALL/src/bar.c
0,0 → 1,9
#include<menuet/os.h>
 
void __menuet__bar(__u16 x1,__u16 y1,__u16 xsize,__u16 ysize,__u32 color)
{
__u32 a,b;
a=(x1<<16)|xsize;
b=(y1<<16)|ysize;
__asm__ __volatile__("int $0x40"::"a"(13),"b"(a),"c"(b),"d"(color));
}
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/SYSCALL/src/button.c
0,0 → 1,17
#include<menuet/os.h>
 
void __menuet__make_button(__u16 x1,__u16 y1,__u16 xsize,__u16 ysize,
int id,__u32 color)
{
__u32 a,b;
a=(x1<<16)|xsize;
b=(y1<<16)|ysize;
__asm__ __volatile__("int $0x40"::"a"(8),"b"(a),"c"(b),"d"(id),"S"(color));
}
 
int __menuet__get_button_id(void)
{
__u16 __ret;
__asm__ __volatile__("int $0x40":"=a"(__ret):"0"(17));
if((__ret & 0xFF)==0) return (__ret>>8)&0xFF; else return -1;
}
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/SYSCALL/src/clock.c
0,0 → 1,8
#include<menuet/os.h>
 
__u32 __menuet__getsystemclock(void)
{
__u32 __ret;
__asm__ __volatile__("int $0x40":"=a"(__ret):"0"(3));
return __ret;
}
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/SYSCALL/src/cofflib.c
0,0 → 1,15
#include <menuet/os.h>
#include <stdio.h>
#include <string.h>
 
IMP_TABLE __kolibri__cofflib_load(const char* name){
__asm__ __volatile__("int $0x40"::"a"(68L),"b"(19L),"c"((__u32)name));
}
 
__u32 __kolibri__cofflib_getproc(IMP_TABLE lib, const char* name){
if(!name || !name[0]) return 0;
int i;
for(i = 0; lib[i].name && strcmp(name, lib[i].name); i++);
if(lib[i].name) return (__u32)lib[i].pointer;
else return 0;
}
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/SYSCALL/src/date.c
0,0 → 1,8
#include<menuet/os.h>
 
__u32 __menuet__get_date(void)
{
__u32 __ret;
__asm__ __volatile__("int $0x40":"=a"(__ret):"0"(29));
return __ret;
}
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/SYSCALL/src/debug.c
0,0 → 1,5
#include <menuet/os.h>
void __menuet__debug_out(const char* str){
while(*str)
__menuet__debug_out_byte(*str++);
}
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/SYSCALL/src/delay.c
0,0 → 1,11
#include<menuet/os.h>
 
void __menuet__delay100(int m)
{
__asm__ __volatile__("int $0x40"::"a"(5),"b"(m));
}
 
void __menuet__idle(void)
{
__menuet__delay100(10);
}
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/SYSCALL/src/dga.c
0,0 → 1,19
#include<menuet/os.h>
 
void __menuet__dga_get_caps(int * xres,int * yres,int * bpp,int * bpscan)
{
int p;
__asm__ __volatile__("int $0x40":"=a"(p):"0"(61),"b"(1));
if(xres) *xres=(p>>16)&0xFFFF;
if(yres) *yres=p & 0xFFFF;
if(bpp)
{
__asm__ __volatile__("int $0x40":"=a"(p):"0"(61),"b"(2));
*bpp=p;
}
if(bpscan)
{
__asm__ __volatile__("int $0x40":"=a"(p):"0"(61),"b"(3));
*bpscan=p;
}
}
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/SYSCALL/src/event.c
0,0 → 1,20
#include<menuet/os.h>
 
int __menuet__wait_for_event(void)
{
__u32 __ret;
__asm__ __volatile__("int $0x40":"=a"(__ret):"0"(10));
return __ret;
}
 
int __menuet__check_for_event(void)
{
__u32 __ret;
__asm__ __volatile__("int $0x40":"=a"(__ret):"0"(11));
return __ret;
}
 
void __menuet__set_bitfield_for_wanted_events(__u32 ev)
{
__asm__ __volatile__("int $0x40"::"a"(40),"b"(ev));
}
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/SYSCALL/src/exit.c
0,0 → 1,6
#include<menuet/os.h>
 
void __menuet__sys_exit(void)
{
__asm__ __volatile__("int $0x40"::"a"(0xFFFFFFFF));
}
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/SYSCALL/src/file.c
0,0 → 1,45
#include<menuet/os.h>
#include<stdio.h>
#include<stdarg.h>
#include<string.h>
 
__u32 __menuet__open(char * name,char * data)
{
__u32 __ret;
__asm__ __volatile__("int $0x40":"=a"(__ret):"0"(6),"b"((__u32)name),"c"(0),"d"(0xFFFFFFFF),"S"((__u32)data));
return __ret;
}
 
void __menuet__save(char * name,char * data,__u32 count)
{
__asm__ __volatile__("int $0x40"::"a"(33),"b"((__u32)name),"c"((__u32)data),"d"(count),"S"(0));
}
 
void __menuet__exec_ramdisk(char * filename,char * args,...)
{
va_list argz;
char buffer[1024];
memset(buffer,0,1024);
if(args)
{
va_start(argz,args);
vsprintf(buffer,args,argz);
}
va_end(argz);
__asm__ __volatile__("int $0x40"::"a"(19),"b"(filename),"c"((args ? buffer : NULL)));
}
 
void __menuet__exec_hd(char * filename,char * args,...)
{
va_list argz;
char buffer[1024];
char work_area[0xFFFF];
memset(buffer,0,1024);
if(args)
{
va_start(argz,args);
vsprintf(buffer,args,argz);
}
va_end(argz);
__asm__ __volatile__("int $0x40"::"a"(19),"b"(filename),"c"(args ? buffer : NULL),"d"(work_area));
}
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/SYSCALL/src/image.c
0,0 → 1,9
#include<menuet/os.h>
 
void __menuet__putimage(__u16 x1,__u16 y1,__u16 xsize,__u16 ysize,char * image)
{
__u32 a,b;
a=(xsize<<16)|ysize;
b=(x1<<16)|y1;
__asm__ __volatile__("int $0x40"::"a"(7),"b"(image),"c"(a),"d"(b));
}
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/SYSCALL/src/ipc.c
0,0 → 1,11
#include<menuet/os.h>
 
void send_message(int pid,void * msg_ptr,int message_size)
{
__asm__ __volatile__("int $0x40"::"a"(60),"b"(2),"c"(pid),"d"(msg_ptr),"S"(message_size));
}
 
void define_receive_area(msgrcva_t * rcva_ptr,int size)
{
__asm__ __volatile__("int $0x40"::"a"(60),"b"(1),"c"(rcva_ptr),"d"(size));
}
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/SYSCALL/src/irq.c
0,0 → 1,62
#include<menuet/os.h>
 
__u32 __menuet__get_irq_owner(__u32 irq)
{
__u32 __ret;
__asm__ __volatile__("int $0x40":"=a"(__ret):"0"(41),"b"(irq));
return __ret;
}
 
int __menuet__get_data_read_by_irq(__u32 irq,__u32 * num_bytes_in_buf,__u8 * data)
{
__u32 a,b,c;
__asm__ __volatile__("int $0x40":"=a"(a),"=b"(b),"=c"(c):"0"(42),"1"(irq));
if(num_bytes_in_buf) *num_bytes_in_buf=a;
if(data) *data=b & 0xFF;
return c;
}
 
int __menuet__send_data_to_device(__u16 port,__u8 val)
{
int __ret;
__asm__ __volatile__("int $0x40":"=a"(__ret):"0"(43),"b"(port),"c"(val));
return __ret;
}
 
void __menuet__program_irq(void * intr_table,__u32 irq_num)
{
__asm__ __volatile__("int $0x40"::"a"(44),"b"(intr_table),"c"(irq_num));
}
 
int __menuet__reserve_irq(int irqno)
{
int __ret;
__asm__ __volatile__("int $0x40":"=a"(__ret):"0"(45),"b"(0),"c"(irqno));
return __ret;
}
 
int __menuet__free_irq(int irqno)
{
int __ret;
__asm__ __volatile__("int $0x40":"=a"(__ret):"0"(45),"b"(1),"c"(irqno));
return __ret;
}
 
int __menuet__reserve_port_area(__u32 start,__u32 end)
{
int __ret;
__asm__("int $0x40":"=a"(__ret):"a"(45),"b"(0),"c"(start),"d"(end));
return __ret;
}
 
int __menuet__free_port_area(__u32 start,__u32 end)
{
int __ret;
__asm__("int $0x40":"=a"(__ret):"a"(45),"b"(1),"c"(start),"d"(end));
return __ret;
}
 
void __menuet__define_app_internal_intrs(void * intr_table)
{
__asm__("int $0x40"::"a"(49),"b"(0),"c"(intr_table));
}
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/SYSCALL/src/keyb.c
0,0 → 1,8
#include<menuet/os.h>
 
int __menuet__getkey(void)
{
__u16 __ret;
__asm__ __volatile__("int $0x40":"=a"(__ret):"0"(2));
if(!(__ret & 0xFF)) return (__ret>>8)&0xFF; else return 0;
}
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/SYSCALL/src/line.c
0,0 → 1,9
#include<menuet/os.h>
 
void __menuet__line(__u16 x1,__u16 y1,__u16 x2,__u16 y2,__u32 color)
{
__u32 b,c;
b=(x1<<16)|x1;
c=(y1<<16)|y2;
__asm__ __volatile__("int $0x40"::"a"(38),"b"(b),"c"(c),"d"(color));
}
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/SYSCALL/src/mpu401.c
0,0 → 1,11
#include<menuet/os.h>
 
void __menuet__reset_mpu401(void)
{
__asm__ __volatile__("int $0x40"::"a"(20),"b"(1));
}
 
void __menuet__write_mpu401(__u8 d)
{
__asm__ __volatile__("int $0x40"::"a"(20),"b"(2),"c"(d));
}
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/SYSCALL/src/param.c
0,0 → 1,7
#include<menuet/os.h>
 
#define APP_PARAM_SZ (1024)
#define APP_PATH_SZ (1024)
 
char __menuet__app_param_area[APP_PARAM_SZ];
char __menuet__app_path_area[APP_PATH_SZ];
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/SYSCALL/src/pci.c
0,0 → 1,50
#include<menuet/os.h>
 
#define PCI_FN 62
 
void get_pci_version(__u8 * major,__u8 * minor)
{
int r;
__asm__ __volatile__("int $0x40":"=a"(r):"0"(PCI_FN),"b"(0));
*minor=r&0xFF;
*major=(r>>8)&0xFF;
}
 
void pci_get_last_bus(__u8 * last_bus)
{
__asm__ __volatile__("int $0x40":"=a"(*last_bus):"0"(PCI_FN),"b"(1));
}
 
void get_pci_access_mechanism(__u8 * mechanism)
{
__asm__ __volatile__("int $0x40":"=a"(*mechanism):"0"(PCI_FN),"b"(2));
}
 
#define read_config(x,c,bits) \
__u##bits pci_read_config_##x (__u8 bus,__u8 dev,__u8 fn,__u8 reg) \
{ \
__u##bits __ret; \
__u16 cx; \
__u16 bx; \
cx=(((fn&7)|(((dev)&~7)<<3))<<8)|reg; \
bx=(bus<<8)|(c); \
__asm__ __volatile__("int $0x40":"=a"(__ret):"0"(PCI_FN),"b"(bx),"c"(cx)); \
return __ret; \
}
 
#define write_config(x,c,bits) \
void pci_write_config_##x (__u8 bus,__u8 dev,__u8 fn,__u8 reg,__u##bits val) \
{ \
__u16 cx,bx; \
cx=(((fn&7)|(((dev)&~7)<<3))<<8)|reg; \
bx=(bus<<8)|(c); \
__asm__ __volatile__("int $0x40"::"a"(PCI_FN),"b"(bx),"c"(cx),"d"(val)); \
}
 
#define rw_config(x,c,bits) \
read_config(x,4+c,bits) \
write_config(x,7+c,bits)
rw_config(byte,0,8)
rw_config(word,1,16)
rw_config(dword,2,32)
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/SYSCALL/src/pixel.c
0,0 → 1,6
#include<menuet/os.h>
 
void __menuet__putpixel(__u32 x,__u32 y,__u32 color)
{
__asm__ __volatile__("int $0x40"::"a"(1),"b"(x),"c"(y),"d"(color));
}
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/SYSCALL/src/process.c
0,0 → 1,8
#include<menuet/os.h>
 
int __menuet__get_process_table(struct process_table_entry * proctab,int pid)
{
int __ret;
__asm__ __volatile__("int $0x40":"=a"(__ret):"0"(9),"b"((__u32)proctab),"c"(pid));
return __ret;
}
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/SYSCALL/src/screen.c
0,0 → 1,9
#include<menuet/os.h>
 
void __menuet__get_screen_max(__u16 * x,__u16 * y)
{
__u32 v;
__asm__ __volatile__("int $0x40":"=a"(v):"0"(14));
if(x) *x=v>>16;
if(y) *y=v & 0xFFFF;
}
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/SYSCALL/src/sound.c
0,0 → 1,11
#include<menuet/os.h>
 
void __menuet__sound_load_block(char * blockptr)
{
__asm__ __volatile__("int $0x40"::"a"(55),"b"(0),"c"(blockptr));
}
 
void __menuet__sound_play_block(void)
{
__asm__ __volatile__("int $0x40"::"a"(55),"b"(1));
}
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/SYSCALL/src/systree.c
0,0 → 1,16
#include<menuet/os.h>
 
int __kolibri__system_tree_access(struct systree_info * info)
{
int __ret;
int d0;
__asm__ __volatile__("int $0x40":"=a"(__ret),"=&b"(d0):"0"(70),"1"((__u32)info));
return __ret;
}
int __kolibri__system_tree_access2(struct systree_info2 * info)
{
int __ret;
int d0;
__asm__ __volatile__("int $0x40":"=a"(__ret),"=&b"(d0):"0"(70),"1"((__u32)info));
return __ret;
}
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/SYSCALL/src/text.c
0,0 → 1,6
#include<menuet/os.h>
 
void __menuet__write_text(__u16 x,__u16 y,__u32 color,char * text,int len)
{
__asm__ __volatile__("int $0x40"::"a"(4),"b"((x<<16)|y),"c"(color),"d"((__u32)text),"S"(len));
}
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/SYSCALL/src/thread.c
0,0 → 1,12
#include<menuet/os.h>
#include<stdio.h>
#include<stdlib.h>
 
void * __menuet__exec_thread(void (* func_ptr)(void),__u32 stack_size,int * retp)
{
void * __stk, * __ret;
__ret=__stk=malloc(stack_size);
__stk+=stack_size-1;
__asm__ __volatile__("int $0x40":"=a"(*retp):"0"(51L),"b"(1L),"c"((__u32)func_ptr),"d"((__u32)__stk));
return __ret;
}
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/SYSCALL/src/window.c
0,0 → 1,16
#include<menuet/os.h>
 
void __menuet__define_window(__u16 x1,__u16 y1,__u16 xsize,__u16 ysize,
__u32 body_color,__u32 grab_color,__u32 frame_color)
{
__u32 a,b;
a=(x1<<16)|xsize;
b=(y1<<16)|ysize;
__asm__ __volatile__("int $0x40"::"a"(0),"b"(a),"c"(b),"d"(body_color),"S"(grab_color),
"D"(frame_color));
}
 
void __menuet__window_redraw(int status)
{
__asm__ __volatile__("int $0x40"::"a"(12),"b"(status));
}
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/apps/Makefile
0,0 → 1,25
CC = kos32-gcc
LD = kos32-ld
 
SDK_DIR = $(abspath ../../../sdk)
LDFLAGS = -static -nostdlib -T $(SDK_DIR)/sources/newlib/app.lds --image-base 0
 
CFLAGS = -c -fno-ident -O2 -fomit-frame-pointer -fno-ident -U__WIN32__ -U_Win32 -U_WIN32 -U__MINGW32__ -UWIN32
 
INCLUDES = -I ../SYSCALL/include -I $(SDK_DIR)/sources/newlib/libc/include -I $(SDK_DIR)/sources/freetype/include -I $(SDK_DIR)/sources/zlib -I ../fitz -I ../pdf
LIBPATH = -L $(SDK_DIR)/lib -L /home/autobuild/tools/win32/mingw32/lib -L ../lib
 
APPS_SRC := $(notdir $(wildcard *.c))
 
default: $(patsubst %.c,%.o,$(APPS_SRC))
$(LD) $(LDFLAGS) $(LIBPATH) -o updf kolibri.o pdfapp.o kos_main.o -lmupdf -lfreetype -lfitz -lgcc -lfitz -ldraw -ljpeg -ljbig2dec -lfreetype -lc.dll -lopenjpeg -lz -lc -lsyscall --subsystem native
# yet not work
# $(LD) $(LDFLAGS) $(LIBPATH) -o pdfdraw kolibri.o pdfapp.o pdfdraw.o -lmupdf -lfreetype -lfitz -lgcc -lfitz -ldraw -ljpeg -ljbig2dec -lfreetype -lc.dll -lopenjpeg -lz -lc -lsyscall --subsystem native
objcopy updf -O binary
 
 
%.o : %.c Makefile $(APPS_SRC)
$(CC) $(CFLAGS) $(INCLUDES) -o $@ $<
 
clean:
rm *.o
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/apps/kolibri.c
1,5 → 1,6
#include "kolibri.h"
#include "string.h"
#include <stdlib.h>
 
 
extern char KOL_PATH[256];
469,7 → 470,7
void kos_blit(int dstx, int dsty, int w, int h, int srcx,
int srcy,int srcw, int srch, int stride, char *d)
{
struct blit_call image;
volatile struct blit_call image;
image.dstx=dstx;
image.dsty=dsty;
image.w=w;
481,5 → 482,6
image.stride=stride;
image.d=d;
asm ("int $0x40"::"a"(73),"b"(0),"c"(&image));
}
 
/contrib/media/updf/apps/kolibri.h
1,5 → 1,7
 
#ifndef NULL
#define NULL ((void*)0)
#endif
 
#define SHM_OPEN 0
#define SHM_OPEN_ALWAYS 0x04
46,7 → 48,7
{
unsigned p00;
unsigned p04;
unsigned p08;
char *p08;
unsigned p12;
unsigned p16;
char p20;
143,3 → 145,6
char* kol_clip_get(int n);
int kol_clip_set(int n, char buffer[]);
 
void kos_blit(int dstx, int dsty, int w, int h, int srcx,
int srcy,int srcw, int srch, int stride, char *d);
int kos_random(int num);
/contrib/media/updf/apps/kos_main.c
1,10 → 1,12
// getrusage
#include "resource.h"
 
#include <menuet/os.h>
#define _WIN32
#include "fitz.h"
#include "mupdf.h"
#include "pdfapp.h"
#include "icons/allbtns.h"
#include "kolibri.c"
#include "kolibri.h"
 
void run_app()
{
53,6 → 55,13
};
 
/*==== CODE ====*/
// Prototypes //
void RunApp(char app[], char param[]);
void winblit(pdfapp_t *app);
void DrawPagination(void);
void HandleNewPageNumber(unsigned char key);
void ApplyNewPageNumber(void);
void DrawWindow(void);
 
 
// not implemented yet
101,12 → 110,14
void winclose(pdfapp_t *app)
{
pdfapp_close(&gapp);
__menuet__sys_exit();
exit(0);
}
 
void RunOpenApp()
void RunOpenApp(char name[])
{
RunApp("/sys/lod", "*pdf* /kolibrios/media/updf");
char cmd[250] = "*pdf* ";
strcat(cmd, name);
RunApp("/sys/lod", cmd);
}
 
 
353,18 → 364,17
DrawPageSides();
}
 
int main (void)
int main (int argc, char* argv[])
{
char ii, mouse_wheels_state;
char* original_command_line = *(char**)0x1C;
if (*original_command_line == 0) {
if (argc == 1) {
kol_board_puts("uPDF: no param set, showing OpenDialog");
RunOpenApp();
__menuet__sys_exit();
RunOpenApp(argv[0]);
exit(0);
}
 
kol_board_puts(original_command_line);
kol_board_puts(argv[1]);
kol_board_puts("\n");
char buf[128];
378,7 → 388,7
gapp.resolution = resolution;
gapp.pageno = pageno;
kol_board_puts("PDF Open\n");
pdfapp_open(&gapp, original_command_line, 0, 0);
pdfapp_open(&gapp, argv[1], 0, 0);
kol_board_puts("PDF Opened\n");
wintitle(&gapp, 0);
390,7 → 400,6
 
for(;;)
{
 
switch(__menuet__wait_for_event())
{
case evReDraw:
430,8 → 439,8
 
case evButton:
butt = __menuet__get_button_id();
if(butt==1) __menuet__sys_exit();
if(butt==10) RunOpenApp();
if(butt==1) exit(0);
if(butt==10) RunOpenApp(argv[0]);
if(butt==11) PageZoomOut(); //magnify -
if(butt==12) PageZoomIn(); //magnify +
if(butt==13) //show help
/contrib/media/updf/apps/pdfapp.c
1,6 → 1,7
#include "fitz.h"
#include "mupdf.h"
#include "pdfapp.h"
#include "kolibri.h"
 
#include <ctype.h> /* for tolower() */
 
109,12 → 110,12
/*
* Open PDF and load xref table
*/
__menuet__debug_out("FZ OPEN\n");
kol_board_puts("FZ OPEN\n");
//file = fz_open_fd(fd);
__menuet__debug_out("FZ ready\n");
kol_board_puts("FZ ready\n");
error = pdf_open_xref(&app->xref, filename, NULL);
if (error){
__menuet__debug_out("FZ can't open\n");
kol_board_puts("FZ can't open\n");
pdfapp_error(app, fz_rethrow(error, "cannot open document '%s'", filename));}
fz_close(file);
 
160,16 → 161,16
/*
* Start at first page
*/
__menuet__debug_out("Start at first page\n");
kol_board_puts("Start at first page\n");
 
error = pdf_load_page_tree(app->xref);
if (error) {
__menuet__debug_out("Can't load tree\n");
kol_board_puts("Can't load tree\n");
pdfapp_error(app, fz_rethrow(error, "cannot load page tree"));}
 
__menuet__debug_out("Page counter\n");
kol_board_puts("Page counter\n");
app->pagecount = pdf_count_pages(app->xref);
__menuet__debug_out("All is set!\n");
kol_board_puts("All is set!\n");
}
 
void pdfapp_open(pdfapp_t *app, char *filename, int fd, int reload)
375,7 → 376,7
 
if (app->shrinkwrap)
{
__menuet__debug_out ("SHRINK\n");
kol_board_puts ("SHRINK\n");
int w = app->image->w;
int h = app->image->h;
if (app->winw == w)
/contrib/media/updf/apps/resource.h
0,0 → 1,23
#include <time.h>
 
struct rusage {
struct timeval ru_utime; /* user time used */
struct timeval ru_stime; /* system time used */
long ru_maxrss; /* integral max resident set size */
long ru_ixrss; /* integral shared text memory size */
long ru_idrss; /* integral unshared data size */
long ru_isrss; /* integral unshared stack size */
long ru_minflt; /* page reclaims */
long ru_majflt; /* page faults */
long ru_nswap; /* swaps */
long ru_inblock; /* block input operations */
long ru_oublock; /* block output operations */
long ru_msgsnd; /* messages sent */
long ru_msgrcv; /* messages received */
long ru_nsignals; /* signals received */
long ru_nvcsw; /* voluntary context switches */
long ru_nivcsw; /* involuntary context switches */
};
 
/// STUB ///
int getrusage(int _who, struct rusage *_rusage) {};
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/build_libs.sh
0,0 → 1,29
# BUILD ONLY LIBRARIES
 
mkdir lib
 
cd SYSCALL/src
make
cd ../..
 
cd fitz
make
cd ..
 
cd pdf
make
cd ..
 
cd libopenjpeg
make
cd ..
 
cd libjbig2dec
make
cd ..
 
cd draw
make
cd ..
 
sleep 100
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/draw/Makefile
0,0 → 1,19
CC = kos32-gcc
LD = kos32-ld
 
SDK_DIR = $(abspath ../../../sdk)
 
CFLAGS = -c -fno-ident -O2 -fomit-frame-pointer -fno-ident -U__WIN32__ -U_Win32 -U_WIN32 -U__MINGW32__ -UWIN32
 
INCLUDES = -I $(SDK_DIR)/sources/newlib/libc/include -I ../fitz
 
DRAW_SRC := $(notdir $(wildcard *.c))
OBJECTS = $(patsubst %.c, %.o, $(DRAW_SRC))
 
default: $(patsubst %.c,%.o,$(DRAW_SRC))
ar rcs libdraw.a $(OBJECTS)
rm *.o
mv libdraw.a ../lib
 
%.o : %.c Makefile $(DRAW_SRC)
$(CC) $(CFLAGS) $(INCLUDES) -o $@ $<
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/fitz/Makefile
0,0 → 1,19
CC = kos32-gcc
LD = kos32-ld
 
SDK_DIR = $(abspath ../../../sdk)
 
CFLAGS = -c -fno-ident -O2 -fomit-frame-pointer -fno-ident -U__WIN32__ -U_Win32 -U_WIN32 -U__MINGW32__ -UWIN32
 
INCLUDES = -I $(SDK_DIR)/sources/newlib/libc/include -I $(SDK_DIR)/sources/freetype/include -I $(SDK_DIR)/sources/libjpeg -I $(SDK_DIR)/sources/zlib -I ../libopenjpeg -I ../libjbig2dec
 
FITZ_SRC := $(notdir $(wildcard *.c))
OBJECTS = $(patsubst %.c, %.o, $(FITZ_SRC))
 
default: $(patsubst %.c,%.o,$(FITZ_SRC))
ar rcs libfitz.a *.o
rm *.o
mv libfitz.a ../lib
 
%.o : %.c Makefile $(FITZ_SRC)
$(CC) $(CFLAGS) $(INCLUDES) -o $@ $<
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/fitz/lrintf.c
1,5 → 1,5
#include <math.h>
 
/*
long long int lrintf(float x) {
return floor(x);
}
}*/
/contrib/media/updf/libjbig2dec/Makefile
0,0 → 1,18
CC = kos32-gcc
LD = kos32-ld
 
SDK_DIR = /media/maxim/E22406D62406AE1B/SVNKOS/contrib/sdk
CFLAGS = -c -fno-ident -O2 -fomit-frame-pointer -fno-ident -U__WIN32__ -U_Win32 -U_WIN32 -U__MINGW32__ -UWIN32
 
INCLUDES = -I $(SDK_DIR)/sources/newlib/libc/include -I $(SDK_DIR)/sources/freetype/include -I $(SDK_DIR)/sources/libpng -I $(SDK_DIR)/sources/zlib -I .
 
SRC := $(notdir $(wildcard *.c))
OBJECTS = $(patsubst %.c, %.o, $(SRC))
 
default: $(patsubst %.c,%.o,$(SRC))
ar rcs libjbig2dec.a *.o
rm *.o
mv libjbig2dec.a ../lib
 
%.o : %.c Makefile $(SRC)
$(CC) $(CFLAGS) -DHAVE_CONFIG_H $(INCLUDES) -o $@ $<
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libjbig2dec/config.h
0,0 → 1,120
/* config.h. Generated from config.h.in by configure. */
/* config.h.in. Generated from configure.ac by autoheader. */
 
/* Define if building universal (internal helper macro) */
/* #undef AC_APPLE_UNIVERSAL_BUILD */
 
/* Define to 1 if you have the <dlfcn.h> header file. */
#define HAVE_DLFCN_H 1
 
/* Define if the local libc includes getopt_long() */
#define HAVE_GETOPT_LONG /**/
 
/* Define to 1 if you have the <inttypes.h> header file. */
#define HAVE_INTTYPES_H 1
 
/* Define to 1 if you have the <libintl.h> header file. */
#define HAVE_LIBINTL_H 1
 
/* Define if libpng is available (-lpng) */
#define HAVE_LIBPNG 1
 
/* Define to 1 if you have the <memory.h> header file. */
#define HAVE_MEMORY_H 1
 
/* Define to 1 if you have the `memset' function. */
#define HAVE_MEMSET 1
 
/* Define to 1 if you have the `snprintf' function. */
#define HAVE_SNPRINTF 1
 
/* Define to 1 if you have the <stddef.h> header file. */
#define HAVE_STDDEF_H 1
 
/* Define to 1 if you have the <stdint.h> header file. */
#define HAVE_STDINT_H 1
 
/* Define to 1 if you have the <stdlib.h> header file. */
#define HAVE_STDLIB_H 1
 
/* Define to 1 if you have the `strdup' function. */
#define HAVE_STRDUP 1
 
/* Define to 1 if you have the <strings.h> header file. */
#define HAVE_STRINGS_H 1
 
/* Define to 1 if you have the <string.h> header file. */
#define HAVE_STRING_H 1
 
/* Define to 1 if you have the <sys/stat.h> header file. */
#define HAVE_SYS_STAT_H 1
 
/* Define to 1 if you have the <sys/types.h> header file. */
#define HAVE_SYS_TYPES_H 1
 
/* Define to 1 if you have the <unistd.h> header file. */
#define HAVE_UNISTD_H 1
 
/* set by configure if an alternate header with the stdint.h types is found */
/* #undef JBIG2_REPLACE_STDINT_H */
 
/* Define to the sub-directory in which libtool stores uninstalled libraries.
*/
#define LT_OBJDIR ".libs/"
 
/* Define to 1 if your C compiler doesn't accept -c and -o together. */
/* #undef NO_MINUS_C_MINUS_O */
 
/* Name of package */
#define PACKAGE "jbig2dec"
 
/* Define to the address where bug reports for this package should be sent. */
#define PACKAGE_BUGREPORT "jbig2-dev@ghostscript.com"
 
/* Define to the full name of this package. */
#define PACKAGE_NAME "jbig2dec"
 
/* Define to the full name and version of this package. */
#define PACKAGE_STRING "jbig2dec 0.11"
 
/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "jbig2dec"
 
/* Define to the version of this package. */
#define PACKAGE_VERSION "0.11"
 
/* The size of `char', as computed by sizeof. */
#define SIZEOF_CHAR 1
 
/* The size of `int', as computed by sizeof. */
#define SIZEOF_INT 4
 
/* The size of `long', as computed by sizeof. */
#define SIZEOF_LONG 4
 
/* The size of `short', as computed by sizeof. */
#define SIZEOF_SHORT 2
 
/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1
 
/* Version number of package */
#define VERSION "0.11"
 
/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
significant byte first (like Motorola and SPARC, unlike Intel). */
#if defined AC_APPLE_UNIVERSAL_BUILD
# if defined __BIG_ENDIAN__
# define WORDS_BIGENDIAN 1
# endif
#else
# ifndef WORDS_BIGENDIAN
/* # undef WORDS_BIGENDIAN */
# endif
#endif
 
/* Define to empty if `const' does not conform to ANSI C. */
/* #undef const */
 
/* Define to `unsigned int' if <sys/types.h> does not define. */
/* #undef size_t */
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libjbig2dec/config_types.h
0,0 → 1,19
/*
generated header with missing types for the
jbig2dec program and library. include this
after config.h, within the HAVE_CONFIG_H
ifdef
*/
 
#ifndef HAVE_STDINT_H
# ifdef JBIG2_REPLACE_STDINT_H
# include <no_replacement_found>
# else
typedef unsigned int uint32_t;
typedef unsigned short uint16_t;
typedef unsigned char uint8_t;
typedef signed int int32_t;
typedef signed short int16_t;
typedef signed char int8_t;
# endif /* JBIG2_REPLACE_STDINT */
#endif /* HAVE_STDINT_H */
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libjbig2dec/config_win32.h
0,0 → 1,41
/*
jbig2dec
 
Copyright (C) 2002-2003 Artifex Software, Inc.
 
This software is distributed under license and may not
be copied, modified or distributed except as expressly
authorized under the terms of the license contained in
the file LICENSE in this distribution.
 
For further licensing information refer to http://artifex.com/ or
contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
San Rafael, CA 94903, U.S.A., +1(415)492-9861.
*/
 
/* configuration header file for compiling under Microsoft Windows */
 
/* update package version here */
#define PACKAGE "jbig2dec"
#define VERSION "0.3"
 
#if defined(_MSC_VER) || (defined(__BORLANDC__) && defined(__WIN32__))
/* Microsoft Visual C++ or Borland C++ */
typedef signed char int8_t;
typedef short int int16_t;
typedef int int32_t;
typedef __int64 int64_t;
 
typedef unsigned char uint8_t;
typedef unsigned short int uint16_t;
typedef unsigned int uint32_t;
/* no uint64_t */
 
# if defined(_MSC_VER)
# if _MSC_VER < 1500 /* VS 2008 has vsnprintf */
# define vsnprintf _vsnprintf
# endif
# endif
# define snprintf _snprintf
 
#endif /* _MSC_VER */
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libjbig2dec/getopt.h
0,0 → 1,180
/* Declarations for getopt.
Copyright (C) 1989-1994, 1996-1999, 2001 Free Software Foundation, Inc.
This file is part of the GNU C Library.
 
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
 
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
 
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
 
#ifndef _GETOPT_H
 
#ifndef __need_getopt
# define _GETOPT_H 1
#endif
 
/* If __GNU_LIBRARY__ is not already defined, either we are being used
standalone, or this is the first header included in the source file.
If we are being used with glibc, we need to include <features.h>, but
that does not exist if we are standalone. So: if __GNU_LIBRARY__ is
not defined, include <ctype.h>, which will pull in <features.h> for us
if it's from glibc. (Why ctype.h? It's guaranteed to exist and it
doesn't flood the namespace with stuff the way some other headers do.) */
#if !defined __GNU_LIBRARY__
# include <ctype.h>
#endif
 
#ifdef __cplusplus
extern "C" {
#endif
 
/* For communication from `getopt' to the caller.
When `getopt' finds an option that takes an argument,
the argument value is returned here.
Also, when `ordering' is RETURN_IN_ORDER,
each non-option ARGV-element is returned here. */
 
extern char *optarg;
 
/* Index in ARGV of the next element to be scanned.
This is used for communication to and from the caller
and for communication between successive calls to `getopt'.
 
On entry to `getopt', zero means this is the first call; initialize.
 
When `getopt' returns -1, this is the index of the first of the
non-option elements that the caller should itself scan.
 
Otherwise, `optind' communicates from one call to the next
how much of ARGV has been scanned so far. */
 
extern int optind;
 
/* Callers store zero here to inhibit the error message `getopt' prints
for unrecognized options. */
 
extern int opterr;
 
/* Set to an option character which was unrecognized. */
 
extern int optopt;
 
#ifndef __need_getopt
/* Describe the long-named options requested by the application.
The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
of `struct option' terminated by an element containing a name which is
zero.
 
The field `has_arg' is:
no_argument (or 0) if the option does not take an argument,
required_argument (or 1) if the option requires an argument,
optional_argument (or 2) if the option takes an optional argument.
 
If the field `flag' is not NULL, it points to a variable that is set
to the value given in the field `val' when the option is found, but
left unchanged if the option is not found.
 
To have a long-named option do something other than set an `int' to
a compiled-in constant, such as set a value from `optarg', set the
option's `flag' field to zero and its `val' field to a nonzero
value (the equivalent single-letter option character, if there is
one). For long options that have a zero `flag' field, `getopt'
returns the contents of the `val' field. */
 
struct option
{
# if (defined __STDC__ && __STDC__) || defined __cplusplus
const char *name;
# else
char *name;
# endif
/* has_arg can't be an enum because some compilers complain about
type mismatches in all the code that assumes it is an int. */
int has_arg;
int *flag;
int val;
};
 
/* Names for the values of the `has_arg' field of `struct option'. */
 
# define no_argument 0
# define required_argument 1
# define optional_argument 2
#endif /* need getopt */
 
 
/* Get definitions and prototypes for functions to process the
arguments in ARGV (ARGC of them, minus the program name) for
options given in OPTS.
 
Return the option character from OPTS just read. Return -1 when
there are no more options. For unrecognized options, or options
missing arguments, `optopt' is set to the option letter, and '?' is
returned.
 
The OPTS string is a list of characters which are recognized option
letters, optionally followed by colons, specifying that that letter
takes an argument, to be placed in `optarg'.
 
If a letter in OPTS is followed by two colons, its argument is
optional. This behavior is specific to the GNU `getopt'.
 
The argument `--' causes premature termination of argument
scanning, explicitly telling `getopt' that there are no more
options.
 
If OPTS begins with `--', then non-option arguments are treated as
arguments to the option '\0'. This behavior is specific to the GNU
`getopt'. */
 
#if (defined __STDC__ && __STDC__) || defined __cplusplus
# ifdef __GNU_LIBRARY__
/* Many other libraries have conflicting prototypes for getopt, with
differences in the consts, in stdlib.h. To avoid compilation
errors, only prototype getopt for the GNU C library. */
extern int getopt (int __argc, char *const *__argv, const char *__shortopts);
# else /* not __GNU_LIBRARY__ */
extern int getopt ();
# endif /* __GNU_LIBRARY__ */
 
# ifndef __need_getopt
extern int getopt_long (int __argc, char *const *__argv, const char *__shortopts,
const struct option *__longopts, int *__longind);
extern int getopt_long_only (int __argc, char *const *__argv,
const char *__shortopts,
const struct option *__longopts, int *__longind);
 
/* Internal only. Users should not call this directly. */
extern int _getopt_internal (int __argc, char *const *__argv,
const char *__shortopts,
const struct option *__longopts, int *__longind,
int __long_only);
# endif
#else /* not __STDC__ */
extern int getopt ();
# ifndef __need_getopt
extern int getopt_long ();
extern int getopt_long_only ();
 
extern int _getopt_internal ();
# endif
#endif /* __STDC__ */
 
#ifdef __cplusplus
}
#endif
 
/* Make sure we later can get all the definitions and declarations. */
#undef __need_getopt
 
#endif /* getopt.h */
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libjbig2dec/jbig2.c
0,0 → 1,428
/*
jbig2dec
 
Copyright (C) 2002-2005 Artifex Software, Inc.
 
This software is provided AS-IS with no warranty,
either express or implied.
 
This software is distributed under license and may not
be copied, modified or distributed except as expressly
authorized under the terms of the license contained in
the file LICENSE in this distribution.
 
For further licensing information refer to http://artifex.com/ or
contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
San Rafael, CA 94903, U.S.A., +1(415)492-9861.
*/
 
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "os_types.h"
 
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
 
#include "jbig2.h"
#include "jbig2_priv.h"
 
static void *
jbig2_default_alloc (Jbig2Allocator *allocator, size_t size)
{
return malloc (size);
}
 
static void
jbig2_default_free (Jbig2Allocator *allocator, void *p)
{
free (p);
}
 
static void *
jbig2_default_realloc (Jbig2Allocator *allocator, void *p, size_t size)
{
return realloc (p, size);
}
 
static Jbig2Allocator jbig2_default_allocator =
{
jbig2_default_alloc,
jbig2_default_free,
jbig2_default_realloc
};
 
void *
jbig2_alloc (Jbig2Allocator *allocator, size_t size)
{
return allocator->alloc (allocator, size);
}
 
void
jbig2_free (Jbig2Allocator *allocator, void *p)
{
allocator->free (allocator, p);
}
 
void *
jbig2_realloc (Jbig2Allocator *allocator, void *p, size_t size)
{
return allocator->realloc (allocator, p, size);
}
 
static int
jbig2_default_error(void *data, const char *msg,
Jbig2Severity severity, int32_t seg_idx)
{
/* report only fatal errors by default */
if (severity == JBIG2_SEVERITY_FATAL) {
fprintf(stderr, "jbig2 decoder FATAL ERROR: %s", msg);
if (seg_idx != -1) fprintf(stderr, " (segment 0x%02x)", seg_idx);
fprintf(stderr, "\n");
fflush(stderr);
}
 
return 0;
}
 
int
jbig2_error(Jbig2Ctx *ctx, Jbig2Severity severity, int32_t segment_number,
const char *fmt, ...)
{
char buf[1024];
va_list ap;
int n;
int code;
 
va_start (ap, fmt);
n = vsnprintf (buf, sizeof(buf), fmt, ap);
va_end (ap);
if (n < 0 || n == sizeof(buf))
strncpy (buf, "jbig2_error: error in generating error string", sizeof(buf));
code = ctx->error_callback (ctx->error_callback_data, buf, severity, segment_number);
if (severity == JBIG2_SEVERITY_FATAL)
code = -1;
return code;
}
 
Jbig2Ctx *
jbig2_ctx_new (Jbig2Allocator *allocator,
Jbig2Options options,
Jbig2GlobalCtx *global_ctx,
Jbig2ErrorCallback error_callback,
void *error_callback_data)
{
Jbig2Ctx *result;
 
if (allocator == NULL)
allocator = &jbig2_default_allocator;
if (error_callback == NULL)
error_callback = &jbig2_default_error;
 
result = (Jbig2Ctx *)jbig2_alloc(allocator, sizeof(Jbig2Ctx));
if (result == NULL) {
error_callback(error_callback_data, "initial context allocation failed!",
JBIG2_SEVERITY_FATAL, -1);
return result;
}
 
result->allocator = allocator;
result->options = options;
result->global_ctx = (const Jbig2Ctx *)global_ctx;
result->error_callback = error_callback;
result->error_callback_data = error_callback_data;
 
result->state = (options & JBIG2_OPTIONS_EMBEDDED) ?
JBIG2_FILE_SEQUENTIAL_HEADER :
JBIG2_FILE_HEADER;
 
result->buf = NULL;
 
result->n_segments = 0;
result->n_segments_max = 16;
result->segments = (Jbig2Segment **)jbig2_alloc(allocator, result->n_segments_max * sizeof(Jbig2Segment *));
result->segment_index = 0;
 
result->current_page = 0;
result->max_page_index = 4;
result->pages = (Jbig2Page *)jbig2_alloc(allocator, result->max_page_index * sizeof(Jbig2Page));
{
int index;
for (index = 0; index < result->max_page_index; index++) {
result->pages[index].state = JBIG2_PAGE_FREE;
result->pages[index].number = 0;
result->pages[index].image = NULL;
}
}
 
return result;
}
 
int32_t
jbig2_get_int32 (const byte *buf)
{
return (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
}
 
int16_t
jbig2_get_int16 (const byte *buf)
{
return (buf[0] << 8) | buf[1];
}
 
 
/**
* jbig2_data_in: submit data for decoding
* @ctx: The jbig2dec decoder context
* @data: a pointer to the data buffer
* @size: the size of the data buffer in bytes
*
* Copies the specified data into internal storage and attempts
* to (continue to) parse it as part of a jbig2 data stream.
*
* Return code: 0 on success
* -1 if there is a parsing error, or whatever
* the error handling callback returns
**/
int
jbig2_data_in (Jbig2Ctx *ctx, const unsigned char *data, size_t size)
{
const size_t initial_buf_size = 1024;
 
if (ctx->buf == NULL)
{
size_t buf_size = initial_buf_size;
 
do
buf_size <<= 1;
while (buf_size < size);
ctx->buf = (byte *)jbig2_alloc(ctx->allocator, buf_size);
ctx->buf_size = buf_size;
ctx->buf_rd_ix = 0;
ctx->buf_wr_ix = 0;
}
else if (ctx->buf_wr_ix + size > ctx->buf_size)
{
if (ctx->buf_rd_ix <= (ctx->buf_size >> 1) &&
ctx->buf_wr_ix - ctx->buf_rd_ix + size <= ctx->buf_size)
{
memmove(ctx->buf, ctx->buf + ctx->buf_rd_ix,
ctx->buf_wr_ix - ctx->buf_rd_ix);
}
else
{
byte *buf;
size_t buf_size = initial_buf_size;
 
do
buf_size <<= 1;
while (buf_size < ctx->buf_wr_ix - ctx->buf_rd_ix + size);
buf = (byte *)jbig2_alloc(ctx->allocator, buf_size);
memcpy(buf, ctx->buf + ctx->buf_rd_ix,
ctx->buf_wr_ix - ctx->buf_rd_ix);
jbig2_free(ctx->allocator, ctx->buf);
ctx->buf = buf;
ctx->buf_size = buf_size;
}
ctx->buf_wr_ix -= ctx->buf_rd_ix;
ctx->buf_rd_ix = 0;
}
memcpy(ctx->buf + ctx->buf_wr_ix, data, size);
ctx->buf_wr_ix += size;
 
/* data has now been added to buffer */
 
for (;;)
{
const byte jbig2_id_string[8] = { 0x97, 0x4a, 0x42, 0x32, 0x0d, 0x0a, 0x1a, 0x0a };
Jbig2Segment *segment;
size_t header_size;
int code;
 
switch (ctx->state)
{
case JBIG2_FILE_HEADER:
/* D.4.1 */
if (ctx->buf_wr_ix - ctx->buf_rd_ix < 9)
return 0;
if (memcmp(ctx->buf + ctx->buf_rd_ix, jbig2_id_string, 8))
return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1,
"Not a JBIG2 file header");
/* D.4.2 */
ctx->file_header_flags = ctx->buf[ctx->buf_rd_ix + 8];
if (ctx->file_header_flags & 0xFC) {
jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1,
"reserved bits (2-7) of file header flags are not zero (0x%02x)", ctx->file_header_flags);
}
/* D.4.3 */
if (!(ctx->file_header_flags & 2)) /* number of pages is known */
{
if (ctx->buf_wr_ix - ctx->buf_rd_ix < 13)
return 0;
ctx->n_pages = jbig2_get_int32(ctx->buf + ctx->buf_rd_ix + 9);
ctx->buf_rd_ix += 13;
if (ctx->n_pages == 1)
jbig2_error(ctx, JBIG2_SEVERITY_INFO, -1, "file header indicates a single page document");
else
jbig2_error(ctx, JBIG2_SEVERITY_INFO, -1, "file header indicates a %d page document", ctx->n_pages);
}
else /* number of pages not known */
{
ctx->n_pages=0;
ctx->buf_rd_ix += 9;
}
/* determine the file organization based on the flags - D.4.2 again */
if (ctx->file_header_flags & 1)
{
ctx->state = JBIG2_FILE_SEQUENTIAL_HEADER;
jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, -1, "file header indicates sequential organization");
}
else
{
ctx->state = JBIG2_FILE_RANDOM_HEADERS;
jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, -1, "file header indicates random-access organization");
 
}
break;
case JBIG2_FILE_SEQUENTIAL_HEADER:
case JBIG2_FILE_RANDOM_HEADERS:
segment = jbig2_parse_segment_header(ctx, ctx->buf + ctx->buf_rd_ix,
ctx->buf_wr_ix - ctx->buf_rd_ix,
&header_size);
if (segment == NULL)
return 0; /* need more data */
ctx->buf_rd_ix += header_size;
 
if (ctx->n_segments == ctx->n_segments_max)
ctx->segments = (Jbig2Segment **)jbig2_realloc(ctx->allocator,
ctx->segments, (ctx->n_segments_max <<= 2) * sizeof(Jbig2Segment *));
 
ctx->segments[ctx->n_segments++] = segment;
if (ctx->state == JBIG2_FILE_RANDOM_HEADERS)
{
if ((segment->flags & 63) == 51) /* end of file */
ctx->state = JBIG2_FILE_RANDOM_BODIES;
}
else /* JBIG2_FILE_SEQUENTIAL_HEADER */
ctx->state = JBIG2_FILE_SEQUENTIAL_BODY;
break;
case JBIG2_FILE_SEQUENTIAL_BODY:
case JBIG2_FILE_RANDOM_BODIES:
segment = ctx->segments[ctx->segment_index];
if (segment->data_length > ctx->buf_wr_ix - ctx->buf_rd_ix)
return 0; /* need more data */
code = jbig2_parse_segment(ctx, segment, ctx->buf + ctx->buf_rd_ix);
ctx->buf_rd_ix += segment->data_length;
ctx->segment_index++;
if (ctx->state == JBIG2_FILE_RANDOM_BODIES)
{
if (ctx->segment_index == ctx->n_segments)
ctx->state = JBIG2_FILE_EOF;
}
else /* JBIG2_FILE_SEQUENCIAL_BODY */
{
ctx->state = JBIG2_FILE_SEQUENTIAL_HEADER;
}
if (code < 0)
{
ctx->state = JBIG2_FILE_EOF;
return code;
}
break;
case JBIG2_FILE_EOF:
if (ctx->buf_rd_ix == ctx->buf_wr_ix)
return 0;
return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1,
"Garbage beyond end of file");
}
}
return 0;
}
 
void
jbig2_ctx_free (Jbig2Ctx *ctx)
{
Jbig2Allocator *ca = ctx->allocator;
int i;
 
jbig2_free(ca, ctx->buf);
if (ctx->segments != NULL) {
for (i = 0; i < ctx->n_segments; i++)
jbig2_free_segment(ctx, ctx->segments[i]);
jbig2_free(ca, ctx->segments);
}
 
if (ctx->pages != NULL) {
for (i = 0; i <= ctx->current_page; i++)
if (ctx->pages[i].image != NULL)
jbig2_image_release(ctx, ctx->pages[i].image);
jbig2_free(ca, ctx->pages);
}
 
jbig2_free(ca, ctx);
}
 
Jbig2GlobalCtx *jbig2_make_global_ctx (Jbig2Ctx *ctx)
{
return (Jbig2GlobalCtx *)ctx;
}
 
void jbig2_global_ctx_free(Jbig2GlobalCtx *global_ctx)
{
jbig2_ctx_free((Jbig2Ctx *)global_ctx);
}
 
 
/* I'm not committed to keeping the word stream interface. It's handy
when you think you may be streaming your input, but if you're not
(as is currently the case), it just adds complexity.
*/
 
typedef struct {
Jbig2WordStream super;
const byte *data;
size_t size;
} Jbig2WordStreamBuf;
 
static uint32_t
jbig2_word_stream_buf_get_next_word(Jbig2WordStream *self, int offset)
{
Jbig2WordStreamBuf *z = (Jbig2WordStreamBuf *)self;
const byte *data = z->data;
uint32_t result;
 
if (offset + 4 < z->size)
result = (data[offset] << 24) | (data[offset + 1] << 16) |
(data[offset + 2] << 8) | data[offset + 3];
else if (offset >= z->size)
return 0;
else
{
int i;
 
result = 0;
for (i = 0; i < z->size - offset; i++)
result |= data[offset + i] << ((3 - i) << 3);
}
return result;
}
 
Jbig2WordStream *
jbig2_word_stream_buf_new(Jbig2Ctx *ctx, const byte *data, size_t size)
{
Jbig2WordStreamBuf *result = (Jbig2WordStreamBuf *)jbig2_alloc(ctx->allocator, sizeof(Jbig2WordStreamBuf));
 
result->super.get_next_word = jbig2_word_stream_buf_get_next_word;
result->data = data;
result->size = size;
 
return &result->super;
}
 
void
jbig2_word_stream_buf_free(Jbig2Ctx *ctx, Jbig2WordStream *ws)
{
jbig2_free(ctx->allocator, ws);
}
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libjbig2dec/jbig2.h
0,0 → 1,135
/*
jbig2dec
 
Copyright (C) 2002-2005 Artifex Software, Inc.
 
This software is distributed under license and may not
be copied, modified or distributed except as expressly
authorized under the terms of the license contained in
the file LICENSE in this distribution.
 
For further licensing information refer to http://artifex.com/ or
contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
San Rafael, CA 94903, U.S.A., +1(415)492-9861.
*/
 
#ifdef __cplusplus
extern "C" {
#endif
 
#ifndef _JBIG2_H
#define _JBIG2_H
 
/* warning levels */
typedef enum {
JBIG2_SEVERITY_DEBUG,
JBIG2_SEVERITY_INFO,
JBIG2_SEVERITY_WARNING,
JBIG2_SEVERITY_FATAL
} Jbig2Severity;
 
typedef enum {
JBIG2_OPTIONS_EMBEDDED = 1
} Jbig2Options;
 
/* forward public structure declarations */
typedef struct _Jbig2Allocator Jbig2Allocator;
typedef struct _Jbig2Ctx Jbig2Ctx;
typedef struct _Jbig2GlobalCtx Jbig2GlobalCtx;
typedef struct _Jbig2Segment Jbig2Segment;
typedef struct _Jbig2Image Jbig2Image;
 
/* private structures */
typedef struct _Jbig2Page Jbig2Page;
typedef struct _Jbig2SymbolDictionary Jbig2SymbolDictionary;
 
/*
this is the general image structure used by the jbig2dec library
images are 1 bpp, packed into rows a byte at a time. stride gives
the byte offset to the next row, while width and height define
the size of the image area in pixels.
*/
 
struct _Jbig2Image {
int width, height, stride;
uint8_t *data;
int refcount;
};
 
Jbig2Image* jbig2_image_new(Jbig2Ctx *ctx, int width, int height);
Jbig2Image* jbig2_image_clone(Jbig2Ctx *ctx, Jbig2Image *image);
void jbig2_image_release(Jbig2Ctx *ctx, Jbig2Image *image);
void jbig2_image_free(Jbig2Ctx *ctx, Jbig2Image *image);
void jbig2_image_clear(Jbig2Ctx *ctx, Jbig2Image *image, int value);
Jbig2Image *jbig2_image_resize(Jbig2Ctx *ctx, Jbig2Image *image,
int width, int height);
 
/* errors are returned from the library via a callback. If no callback
is provided (a NULL argument is passed ot jbig2_ctx_new) a default
handler is used which prints fatal errors to the stderr stream. */
 
/* error callback */
typedef int (*Jbig2ErrorCallback) (void *data,
const char *msg, Jbig2Severity severity,
int32_t seg_idx);
 
/* memory allocation is likewise done via a set of callbacks so that
clients can better control memory usage. If a NULL is passed for
this argumennt of jbig2_ctx_new, a default allocator based on malloc()
is used. */
 
/* dynamic memory callbacks */
struct _Jbig2Allocator {
void *(*alloc) (Jbig2Allocator *allocator, size_t size);
void (*free) (Jbig2Allocator *allocator, void *p);
void *(*realloc) (Jbig2Allocator *allocator, void *p, size_t size);
};
 
/* decoder context */
Jbig2Ctx *jbig2_ctx_new (Jbig2Allocator *allocator,
Jbig2Options options,
Jbig2GlobalCtx *global_ctx,
Jbig2ErrorCallback error_callback,
void *error_callback_data);
void jbig2_ctx_free (Jbig2Ctx *ctx);
 
/* global context for embedded streams */
Jbig2GlobalCtx *jbig2_make_global_ctx (Jbig2Ctx *ctx);
void jbig2_global_ctx_free (Jbig2GlobalCtx *global_ctx);
 
/* submit data to the decoder */
int jbig2_data_in (Jbig2Ctx *ctx, const unsigned char *data, size_t size);
 
/* get the next available decoded page image. NULL means there isn't one. */
Jbig2Image *jbig2_page_out (Jbig2Ctx *ctx);
/* mark a returned page image as no longer needed. */
int jbig2_release_page (Jbig2Ctx *ctx, Jbig2Image *image);
/* mark the current page as complete, simulating an end-of-page segment (for broken streams) */
int jbig2_complete_page (Jbig2Ctx *ctx);
 
 
/* segment header routines */
 
struct _Jbig2Segment {
uint32_t number;
uint8_t flags;
uint32_t page_association;
size_t data_length;
int referred_to_segment_count;
uint32_t *referred_to_segments;
void *result;
};
 
Jbig2Segment *jbig2_parse_segment_header (Jbig2Ctx *ctx, uint8_t *buf, size_t buf_size,
size_t *p_header_size);
int jbig2_parse_segment (Jbig2Ctx *ctx, Jbig2Segment *segment,
const uint8_t *segment_data);
void jbig2_free_segment (Jbig2Ctx *ctx, Jbig2Segment *segment);
 
Jbig2Segment *jbig2_find_segment(Jbig2Ctx *ctx, uint32_t number);
 
#endif /* _JBIG2_H */
 
#ifdef __cplusplus
}
#endif
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libjbig2dec/jbig2_arith.c
0,0 → 1,394
/*
jbig2dec
 
Copyright (C) 2001-2005 Artifex Software, Inc.
 
This software is provided AS-IS with no warranty,
either express or implied.
 
This software is distributed under license and may not
be copied, modified or distributed except as expressly
authorized under the terms of the license contained in
the file LICENSE in this distribution.
 
For further licensing information refer to http://artifex.com/ or
contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
San Rafael, CA 94903, U.S.A., +1(415)492-9861.
*/
 
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "os_types.h"
 
#include <stdio.h>
#include <stdlib.h>
 
#include "jbig2.h"
#include "jbig2_priv.h"
#include "jbig2_arith.h"
 
#ifdef JBIG2_DEBUG
#include <stdio.h>
#endif
 
struct _Jbig2ArithState {
uint32_t C;
int A;
 
int CT;
 
uint32_t next_word;
int next_word_bytes;
 
Jbig2WordStream *ws;
int offset;
};
 
#undef SOFTWARE_CONVENTION
 
/*
A note on the "software conventions".
 
Previously, I had misinterpreted the spec, and had thought that the
spec's description of the "software convention" was wrong. Now I
believe that this code is both correct and matches the spec, with
SOFTWARE_CONVENTION defined or not. Thanks to William Rucklidge for
the clarification.
 
In any case, my benchmarking indicates no speed difference at all.
Therefore, for now we will just use the normative version.
 
*/
 
static void
jbig2_arith_bytein (Jbig2ArithState *as)
{
byte B;
 
/* invariant: as->next_word_bytes > 0 */
 
/* Figure G.3 */
B = (byte)((as->next_word >> 24) & 0xFF);
if (B == 0xFF)
{
byte B1;
if (as->next_word_bytes == 1)
{
Jbig2WordStream *ws = as->ws;
as->next_word = ws->get_next_word (ws, as->offset);
as->offset += 4;
B1 = (byte)((as->next_word >> 24) & 0xFF);
if (B1 > 0x8F)
{
#ifdef JBIG2_DEBUG_ARITH
fprintf(stderr, "read %02x (aa)\n", B);
#endif
#ifndef SOFTWARE_CONVENTION
as->C += 0xFF00;
#endif
as->CT = 8;
as->next_word = (0xFF00 | B1) << 16;
as->next_word_bytes = 2;
}
else
{
#ifdef JBIG2_DEBUG_ARITH
fprintf(stderr, "read %02x (a)\n", B);
#endif
#ifdef SOFTWARE_CONVENTION
as->C += 0xFE00 - (B1 << 9);
#else
as->C += B1 << 9;
#endif
as->CT = 7;
as->next_word_bytes = 4;
}
}
else
{
B1 = (byte)((as->next_word >> 16) & 0xFF);
if (B1 > 0x8F)
{
#ifdef JBIG2_DEBUG_ARITH
fprintf(stderr, "read %02x (ba)\n", B);
#endif
#ifndef SOFTWARE_CONVENTION
as->C += 0xFF00;
#endif
as->CT = 8;
}
else
{
as->next_word_bytes--;
as->next_word <<= 8;
#ifdef JBIG2_DEBUG_ARITH
fprintf(stderr, "read %02x (b)\n", B);
#endif
 
#ifdef SOFTWARE_CONVENTION
as->C += 0xFE00 - (B1 << 9);
#else
as->C += (B1 << 9);
#endif
as->CT = 7;
}
}
}
else
{
#ifdef JBIG2_DEBUG_ARITH
fprintf(stderr, "read %02x\n", B);
#endif
as->CT = 8;
as->next_word <<= 8;
as->next_word_bytes--;
if (as->next_word_bytes == 0)
{
Jbig2WordStream *ws = as->ws;
 
as->next_word = ws->get_next_word (ws, as->offset);
as->offset += 4;
as->next_word_bytes = 4;
}
B = (byte)((as->next_word >> 24) & 0xFF);
#ifdef SOFTWARE_CONVENTION
as->C += 0xFF00 - (B << 8);
#else
as->C += (B << 8);
#endif
}
}
 
#if defined(JBIG2_DEBUG) || defined(JBIG2_DEBUG_ARITH)
#include <stdio.h>
 
static void
jbig2_arith_trace (Jbig2ArithState *as, Jbig2ArithCx cx)
{
fprintf(stderr, "I = %2d, MPS = %d, A = %04x, CT = %2d, C = %08x\n",
cx & 0x7f, cx >> 7, as->A, as->CT, as->C);
}
#endif
 
/** Allocate and initialize a new arithmetic coding state
* the returned pointer can simply be freed; this does
* not affect the associated Jbig2WordStream.
*/
Jbig2ArithState *
jbig2_arith_new (Jbig2Ctx *ctx, Jbig2WordStream *ws)
{
Jbig2ArithState *result;
 
result = (Jbig2ArithState *)jbig2_alloc(ctx->allocator,
sizeof(Jbig2ArithState));
 
result->ws = ws;
 
result->next_word = ws->get_next_word (ws, 0);
result->next_word_bytes = 4;
result->offset = 4;
 
/* Figure G.1 */
#ifdef SOFTWARE_CONVENTION
result->C = (~(result->next_word >> 8)) & 0xFF0000;
#else
result->C = (result->next_word >> 8) & 0xFF0000;
#endif
 
jbig2_arith_bytein (result);
result->C <<= 7;
result->CT -= 7;
result->A = 0x8000;
 
return result;
}
 
/* could put bit fields in to minimize memory usage */
typedef struct {
unsigned short Qe;
byte mps_xor; /* mps_xor = index ^ NMPS */
byte lps_xor; /* lps_xor = index ^ NLPS ^ (SWITCH << 7) */
} Jbig2ArithQe;
 
const Jbig2ArithQe jbig2_arith_Qe[] = {
{ 0x5601, 1 ^ 0, 1 ^ 0 ^ 0x80 },
{ 0x3401, 2 ^ 1, 6 ^ 1 },
{ 0x1801, 3 ^ 2, 9 ^ 2 },
{ 0x0AC1, 4 ^ 3, 12 ^ 3 },
{ 0x0521, 5 ^ 4, 29 ^ 4 },
{ 0x0221, 38 ^ 5, 33 ^ 5 },
{ 0x5601, 7 ^ 6, 6 ^ 6 ^ 0x80 },
{ 0x5401, 8 ^ 7, 14 ^ 7 },
{ 0x4801, 9 ^ 8, 14 ^ 8 },
{ 0x3801, 10 ^ 9, 14 ^ 9 },
{ 0x3001, 11 ^ 10, 17 ^ 10 },
{ 0x2401, 12 ^ 11, 18 ^ 11 },
{ 0x1C01, 13 ^ 12, 20 ^ 12 },
{ 0x1601, 29 ^ 13, 21 ^ 13 },
{ 0x5601, 15 ^ 14, 14 ^ 14 ^ 0x80 },
{ 0x5401, 16 ^ 15, 14 ^ 15 },
{ 0x5101, 17 ^ 16, 15 ^ 16 },
{ 0x4801, 18 ^ 17, 16 ^ 17 },
{ 0x3801, 19 ^ 18, 17 ^ 18 },
{ 0x3401, 20 ^ 19, 18 ^ 19 },
{ 0x3001, 21 ^ 20, 19 ^ 20 },
{ 0x2801, 22 ^ 21, 19 ^ 21 },
{ 0x2401, 23 ^ 22, 20 ^ 22 },
{ 0x2201, 24 ^ 23, 21 ^ 23 },
{ 0x1C01, 25 ^ 24, 22 ^ 24 },
{ 0x1801, 26 ^ 25, 23 ^ 25 },
{ 0x1601, 27 ^ 26, 24 ^ 26 },
{ 0x1401, 28 ^ 27, 25 ^ 27 },
{ 0x1201, 29 ^ 28, 26 ^ 28 },
{ 0x1101, 30 ^ 29, 27 ^ 29 },
{ 0x0AC1, 31 ^ 30, 28 ^ 30 },
{ 0x09C1, 32 ^ 31, 29 ^ 31 },
{ 0x08A1, 33 ^ 32, 30 ^ 32 },
{ 0x0521, 34 ^ 33, 31 ^ 33 },
{ 0x0441, 35 ^ 34, 32 ^ 34 },
{ 0x02A1, 36 ^ 35, 33 ^ 35 },
{ 0x0221, 37 ^ 36, 34 ^ 36 },
{ 0x0141, 38 ^ 37, 35 ^ 37 },
{ 0x0111, 39 ^ 38, 36 ^ 38 },
{ 0x0085, 40 ^ 39, 37 ^ 39 },
{ 0x0049, 41 ^ 40, 38 ^ 40 },
{ 0x0025, 42 ^ 41, 39 ^ 41 },
{ 0x0015, 43 ^ 42, 40 ^ 42 },
{ 0x0009, 44 ^ 43, 41 ^ 43 },
{ 0x0005, 45 ^ 44, 42 ^ 44 },
{ 0x0001, 45 ^ 45, 43 ^ 45 },
{ 0x5601, 46 ^ 46, 46 ^ 46 }
};
 
static void
jbig2_arith_renormd (Jbig2ArithState *as)
{
/* Figure E.18 */
do
{
if (as->CT == 0)
jbig2_arith_bytein (as);
as->A <<= 1;
as->C <<= 1;
as->CT--;
}
while ((as->A & 0x8000) == 0);
}
 
bool
jbig2_arith_decode (Jbig2ArithState *as, Jbig2ArithCx *pcx)
{
Jbig2ArithCx cx = *pcx;
const Jbig2ArithQe *pqe = &jbig2_arith_Qe[cx & 0x7f];
bool D;
 
/* Figure G.2 */
as->A -= pqe->Qe;
if (
#ifdef SOFTWARE_CONVENTION
/* Note: I do not think this is correct. See above. */
(as->C >> 16) < as->A
#else
!((as->C >> 16) < pqe->Qe)
#endif
)
{
#ifndef SOFTWARE_CONVENTION
as->C -= pqe->Qe << 16;
#endif
if ((as->A & 0x8000) == 0)
{
/* MPS_EXCHANGE, Figure E.16 */
if (as->A < pqe->Qe)
{
D = 1 - (cx >> 7);
*pcx ^= pqe->lps_xor;
}
else
{
D = cx >> 7;
*pcx ^= pqe->mps_xor;
}
jbig2_arith_renormd (as);
return D;
}
else
return cx >> 7;
}
else
{
#ifdef SOFTWARE_CONVENTION
as->C -= (as->A) << 16;
#endif
/* LPS_EXCHANGE, Figure E.17 */
if (as->A < pqe->Qe)
{
as->A = pqe->Qe;
D = cx >> 7;
*pcx ^= pqe->mps_xor;
}
else
{
as->A = pqe->Qe;
D = 1 - (cx >> 7);
*pcx ^= pqe->lps_xor;
}
jbig2_arith_renormd (as);
return D;
}
}
 
#ifdef TEST
 
static uint32_t
test_get_word (Jbig2WordStream *self, int offset)
{
byte stream[] = {
0x84, 0xC7, 0x3B, 0xFC, 0xE1, 0xA1, 0x43, 0x04, 0x02, 0x20, 0x00, 0x00,
0x41, 0x0D, 0xBB, 0x86, 0xF4, 0x31, 0x7F, 0xFF, 0x88, 0xFF, 0x37, 0x47,
0x1A, 0xDB, 0x6A, 0xDF, 0xFF, 0xAC,
0x00, 0x00
};
if (offset >= sizeof(stream))
return 0;
else
return (stream[offset] << 24) | (stream[offset + 1] << 16) |
(stream[offset + 2] << 8) | stream[offset + 3];
}
 
int
main (int argc, char **argv)
{
Jbig2Ctx *ctx;
Jbig2WordStream ws;
Jbig2ArithState *as;
int i;
Jbig2ArithCx cx = 0;
 
ctx = jbig2_ctx_new(NULL, 0, NULL, NULL, NULL);
 
ws.get_next_word = test_get_word;
as = jbig2_arith_new (ctx, &ws);
#ifdef JBIG2_DEBUG_ARITH
jbig2_arith_trace (as, cx);
#endif
 
for (i = 0; i < 256; i++)
{
bool D;
 
D = jbig2_arith_decode (as, &cx);
#ifdef JBIG2_DEBUG_ARITH
fprintf(stderr, "%3d: D = %d, ", i, D);
jbig2_arith_trace (as, cx);
#endif
}
 
jbig2_free(ctx->allocator, as);
 
jbig2_ctx_free(ctx);
 
return 0;
}
#endif
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libjbig2dec/jbig2_arith.h
0,0 → 1,31
/*
jbig2dec
 
Copyright (C) 2001 Artifex Software, Inc.
 
This software is distributed under license and may not
be copied, modified or distributed except as expressly
authorized under the terms of the license contained in
the file LICENSE in this distribution.
 
For further licensing information refer to http://artifex.com/ or
contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
San Rafael, CA 94903, U.S.A., +1(415)492-9861.
*/
 
typedef struct _Jbig2ArithState Jbig2ArithState;
 
/* An arithmetic coding context is stored as a single byte, with the
index in the low order 7 bits (actually only 6 are used), and the
MPS in the top bit. */
typedef unsigned char Jbig2ArithCx;
 
/* allocate and initialize a new arithmetic coding state */
Jbig2ArithState *
jbig2_arith_new (Jbig2Ctx *ctx, Jbig2WordStream *ws);
 
/* decode a bit */
bool
jbig2_arith_decode (Jbig2ArithState *as, Jbig2ArithCx *pcx);
 
 
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libjbig2dec/jbig2_arith_iaid.c
0,0 → 1,91
/*
jbig2dec
 
Copyright (C) 2001 Artifex Software, Inc.
 
This software is provided AS-IS with no warranty,
either express or implied.
 
This software is distributed under license and may not
be copied, modified or distributed except as expressly
authorized under the terms of the license contained in
the file LICENSE in this distribution.
 
For further licensing information refer to http://artifex.com/ or
contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
San Rafael, CA 94903, U.S.A., +1(415)492-9861.
*/
 
/* Annex A.3 */
 
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "os_types.h"
 
#include <stddef.h>
#include <string.h> /* memset() */
 
#ifdef VERBOSE
#include <stdio.h> /* for debug printing only */
#endif
 
#include "jbig2.h"
#include "jbig2_priv.h"
#include "jbig2_arith.h"
#include "jbig2_arith_iaid.h"
 
struct _Jbig2ArithIaidCtx {
int SBSYMCODELEN;
Jbig2ArithCx *IAIDx;
};
 
Jbig2ArithIaidCtx *
jbig2_arith_iaid_ctx_new(Jbig2Ctx *ctx, int SBSYMCODELEN)
{
Jbig2ArithIaidCtx *result = jbig2_new(ctx, Jbig2ArithIaidCtx, 1);
int ctx_size = 1 << SBSYMCODELEN;
 
result->SBSYMCODELEN = SBSYMCODELEN;
result->IAIDx = jbig2_alloc(ctx->allocator, ctx_size);
memset(result->IAIDx, 0, ctx_size);
 
return result;
}
 
/* A.3 */
/* Return value: -1 on error, 0 on normal value */
int
jbig2_arith_iaid_decode(Jbig2ArithIaidCtx *ctx, Jbig2ArithState *as,
int32_t *p_result)
{
Jbig2ArithCx *IAIDx = ctx->IAIDx;
int SBSYMCODELEN = ctx->SBSYMCODELEN;
int PREV = 1;
int D;
int i;
 
/* A.3 (2) */
for (i = 0; i < SBSYMCODELEN; i++)
{
D = jbig2_arith_decode(as, &IAIDx[PREV]);
#ifdef VERBOSE
fprintf(stderr, "IAID%x: D = %d\n", PREV, D);
#endif
PREV = (PREV << 1) | D;
}
/* A.3 (3) */
PREV -= 1 << SBSYMCODELEN;
#ifdef VERBOSE
fprintf(stderr, "IAID result: %d\n", PREV);
#endif
*p_result = PREV;
return 0;
}
 
void
jbig2_arith_iaid_ctx_free(Jbig2Ctx *ctx, Jbig2ArithIaidCtx *iax)
{
jbig2_free(ctx->allocator, iax->IAIDx);
jbig2_free(ctx->allocator, iax);
}
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libjbig2dec/jbig2_arith_iaid.h
0,0 → 1,26
/*
jbig2dec
 
Copyright (C) 2001 Artifex Software, Inc.
 
This software is distributed under license and may not
be copied, modified or distributed except as expressly
authorized under the terms of the license contained in
the file LICENSE in this distribution.
 
For further licensing information refer to http://artifex.com/ or
contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
San Rafael, CA 94903, U.S.A., +1(415)492-9861.
*/
 
typedef struct _Jbig2ArithIaidCtx Jbig2ArithIaidCtx;
 
Jbig2ArithIaidCtx *
jbig2_arith_iaid_ctx_new(Jbig2Ctx *ctx, int SBSYMCODELEN);
 
int
jbig2_arith_iaid_decode(Jbig2ArithIaidCtx *ctx, Jbig2ArithState *as,
int32_t *p_result);
 
void
jbig2_arith_iaid_ctx_free(Jbig2Ctx *ctx, Jbig2ArithIaidCtx *iax);
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libjbig2dec/jbig2_arith_int.c
0,0 → 1,139
/*
jbig2dec
 
Copyright (C) 2001 Artifex Software, Inc.
 
This software is provided AS-IS with no warranty,
either express or implied.
 
This software is distributed under license and may not
be copied, modified or distributed except as expressly
authorized under the terms of the license contained in
the file LICENSE in this distribution.
 
For further licensing information refer to http://artifex.com/ or
contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
San Rafael, CA 94903, U.S.A., +1(415)492-9861.
*/
 
/* Annex A */
 
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "os_types.h"
 
#include <stddef.h>
#include <string.h> /* memset() */
 
#include "jbig2.h"
#include "jbig2_priv.h"
#include "jbig2_arith.h"
#include "jbig2_arith_int.h"
 
struct _Jbig2ArithIntCtx {
Jbig2ArithCx IAx[512];
};
 
Jbig2ArithIntCtx *
jbig2_arith_int_ctx_new(Jbig2Ctx *ctx)
{
Jbig2ArithIntCtx *result = jbig2_new(ctx, Jbig2ArithIntCtx, 1);
 
memset(result->IAx, 0, sizeof(result->IAx));
 
return result;
}
 
/* A.2 */
/* Return value: -1 on error, 0 on normal value, 1 on OOB return. */
int
jbig2_arith_int_decode(Jbig2ArithIntCtx *ctx, Jbig2ArithState *as,
int32_t *p_result)
{
Jbig2ArithCx *IAx = ctx->IAx;
int PREV = 1;
int S, V;
int bit;
int n_tail, offset;
int i;
 
S = jbig2_arith_decode(as, &IAx[PREV]);
PREV = (PREV << 1) | S;
 
bit = jbig2_arith_decode(as, &IAx[PREV]);
PREV = (PREV << 1) | bit;
if (bit)
{
bit = jbig2_arith_decode(as, &IAx[PREV]);
PREV = (PREV << 1) | bit;
 
if (bit)
{
bit = jbig2_arith_decode(as, &IAx[PREV]);
PREV = (PREV << 1) | bit;
 
if (bit)
{
bit = jbig2_arith_decode(as, &IAx[PREV]);
PREV = (PREV << 1) | bit;
 
if (bit)
{
bit = jbig2_arith_decode(as, &IAx[PREV]);
PREV = (PREV << 1) | bit;
 
if (bit)
{
n_tail = 32;
offset = 4436;
}
else
{
n_tail = 12;
offset = 340;
}
}
else
{
n_tail = 8;
offset = 84;
}
}
else
{
n_tail = 6;
offset = 20;
}
}
else
{
n_tail = 4;
offset = 4;
}
}
else
{
n_tail = 2;
offset = 0;
}
 
V = 0;
for (i = 0; i < n_tail; i++)
{
bit = jbig2_arith_decode(as, &IAx[PREV]);
PREV = ((PREV << 1) & 511) | (PREV & 256) | bit;
V = (V << 1) | bit;
}
 
V += offset;
V = S ? -V : V;
*p_result = V;
return S && V == 0 ? 1 : 0;
}
 
void
jbig2_arith_int_ctx_free(Jbig2Ctx *ctx, Jbig2ArithIntCtx *iax)
{
jbig2_free(ctx->allocator, iax);
}
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libjbig2dec/jbig2_arith_int.h
0,0 → 1,26
/*
jbig2dec
 
Copyright (C) 2001 Artifex Software, Inc.
 
This software is distributed under license and may not
be copied, modified or distributed except as expressly
authorized under the terms of the license contained in
the file LICENSE in this distribution.
 
For further licensing information refer to http://artifex.com/ or
contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
San Rafael, CA 94903, U.S.A., +1(415)492-9861.
*/
 
typedef struct _Jbig2ArithIntCtx Jbig2ArithIntCtx;
 
Jbig2ArithIntCtx *
jbig2_arith_int_ctx_new(Jbig2Ctx *ctx);
 
int
jbig2_arith_int_decode(Jbig2ArithIntCtx *ctx, Jbig2ArithState *as,
int32_t *p_result);
 
void
jbig2_arith_int_ctx_free(Jbig2Ctx *ctx, Jbig2ArithIntCtx *iax);
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libjbig2dec/jbig2_generic.c
0,0 → 1,854
/*
jbig2dec
 
Copyright (C) 2002-2005 Artifex Software, Inc.
 
This software is provided AS-IS with no warranty,
either express or implied.
 
This software is distributed under license and may not
be copied, modified or distributed except as expressly
authorized under the terms of the license contained in
the file LICENSE in this distribution.
 
For further licensing information refer to http://artifex.com/ or
contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
San Rafael, CA 94903, U.S.A., +1(415)492-9861.
*/
 
/**
* Generic region handlers.
**/
 
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "os_types.h"
 
#include <stddef.h>
#include <string.h> /* memcpy(), memset() */
 
#ifdef OUTPUT_PBM
#include <stdio.h>
#endif
 
#include "jbig2.h"
#include "jbig2_priv.h"
#include "jbig2_image.h"
#include "jbig2_arith.h"
#include "jbig2_generic.h"
#include "jbig2_mmr.h"
 
/* return the appropriate context size for the given template */
int
jbig2_generic_stats_size(Jbig2Ctx *ctx, int template)
{
int stats_size = template == 0 ? 1 << 16 :
template == 1 ? 1 << 1 << 13 : 1 << 10;
return stats_size;
}
 
 
static int
jbig2_decode_generic_template0(Jbig2Ctx *ctx,
Jbig2Segment *segment,
const Jbig2GenericRegionParams *params,
Jbig2ArithState *as,
Jbig2Image *image,
Jbig2ArithCx *GB_stats)
{
const int GBW = image->width;
const int GBH = image->height;
const int rowstride = image->stride;
int x, y;
byte *gbreg_line = (byte *)image->data;
 
/* todo: currently we only handle the nominal gbat location */
 
#ifdef OUTPUT_PBM
printf("P4\n%d %d\n", GBW, GBH);
#endif
 
for (y = 0; y < GBH; y++)
{
uint32_t CONTEXT;
uint32_t line_m1;
uint32_t line_m2;
int padded_width = (GBW + 7) & -8;
 
line_m1 = (y >= 1) ? gbreg_line[-rowstride] : 0;
line_m2 = (y >= 2) ? gbreg_line[-(rowstride << 1)] << 6 : 0;
CONTEXT = (line_m1 & 0x7f0) | (line_m2 & 0xf800);
 
/* 6.2.5.7 3d */
for (x = 0; x < padded_width; x += 8)
{
byte result = 0;
int x_minor;
int minor_width = GBW - x > 8 ? 8 : GBW - x;
 
if (y >= 1)
line_m1 = (line_m1 << 8) |
(x + 8 < GBW ? gbreg_line[-rowstride + (x >> 3) + 1] : 0);
 
if (y >= 2)
line_m2 = (line_m2 << 8) |
(x + 8 < GBW ? gbreg_line[-(rowstride << 1) + (x >> 3) + 1] << 6: 0);
 
/* This is the speed-critical inner loop. */
for (x_minor = 0; x_minor < minor_width; x_minor++)
{
bool bit;
 
bit = jbig2_arith_decode(as, &GB_stats[CONTEXT]);
result |= bit << (7 - x_minor);
CONTEXT = ((CONTEXT & 0x7bf7) << 1) | bit |
((line_m1 >> (7 - x_minor)) & 0x10) |
((line_m2 >> (7 - x_minor)) & 0x800);
}
gbreg_line[x >> 3] = result;
}
#ifdef OUTPUT_PBM
fwrite(gbreg_line, 1, rowstride, stdout);
#endif
gbreg_line += rowstride;
}
 
return 0;
}
 
static int
jbig2_decode_generic_template0_unopt(Jbig2Ctx *ctx,
Jbig2Segment *segment,
const Jbig2GenericRegionParams *params,
Jbig2ArithState *as,
Jbig2Image *image,
Jbig2ArithCx *GB_stats)
{
const int GBW = image->width;
const int GBH = image->height;
uint32_t CONTEXT;
int x,y;
bool bit;
 
/* this version is generic and easy to understand, but very slow */
 
for (y = 0; y < GBH; y++) {
for (x = 0; x < GBW; x++) {
CONTEXT = 0;
CONTEXT |= jbig2_image_get_pixel(image, x - 1, y) << 0;
CONTEXT |= jbig2_image_get_pixel(image, x - 2, y) << 1;
CONTEXT |= jbig2_image_get_pixel(image, x - 3, y) << 2;
CONTEXT |= jbig2_image_get_pixel(image, x - 4, y) << 3;
CONTEXT |= jbig2_image_get_pixel(image, x + params->gbat[0],
y + params->gbat[1]) << 4;
CONTEXT |= jbig2_image_get_pixel(image, x + 2, y - 1) << 5;
CONTEXT |= jbig2_image_get_pixel(image, x + 1, y - 1) << 6;
CONTEXT |= jbig2_image_get_pixel(image, x + 0, y - 1) << 7;
CONTEXT |= jbig2_image_get_pixel(image, x - 1, y - 1) << 8;
CONTEXT |= jbig2_image_get_pixel(image, x - 2, y - 1) << 9;
CONTEXT |= jbig2_image_get_pixel(image, x + params->gbat[2],
y + params->gbat[3]) << 10;
CONTEXT |= jbig2_image_get_pixel(image, x + params->gbat[4],
y + params->gbat[5]) << 11;
CONTEXT |= jbig2_image_get_pixel(image, x + 1, y - 2) << 12;
CONTEXT |= jbig2_image_get_pixel(image, x + 0, y - 2) << 13;
CONTEXT |= jbig2_image_get_pixel(image, x - 1, y - 2) << 14;
CONTEXT |= jbig2_image_get_pixel(image, x + params->gbat[6],
y + params->gbat[7]) << 15;
bit = jbig2_arith_decode(as, &GB_stats[CONTEXT]);
jbig2_image_set_pixel(image, x, y, bit);
}
}
return 0;
}
 
static int
jbig2_decode_generic_template1(Jbig2Ctx *ctx,
Jbig2Segment *segment,
const Jbig2GenericRegionParams *params,
Jbig2ArithState *as,
Jbig2Image *image,
Jbig2ArithCx *GB_stats)
{
const int GBW = image->width;
const int GBH = image->height;
const int rowstride = image->stride;
int x, y;
byte *gbreg_line = (byte *)image->data;
 
/* todo: currently we only handle the nominal gbat location */
 
#ifdef OUTPUT_PBM
printf("P4\n%d %d\n", GBW, GBH);
#endif
 
for (y = 0; y < GBH; y++)
{
uint32_t CONTEXT;
uint32_t line_m1;
uint32_t line_m2;
int padded_width = (GBW + 7) & -8;
 
line_m1 = (y >= 1) ? gbreg_line[-rowstride] : 0;
line_m2 = (y >= 2) ? gbreg_line[-(rowstride << 1)] << 5 : 0;
CONTEXT = ((line_m1 >> 1) & 0x1f8) | ((line_m2 >> 1) & 0x1e00);
 
/* 6.2.5.7 3d */
for (x = 0; x < padded_width; x += 8)
{
byte result = 0;
int x_minor;
int minor_width = GBW - x > 8 ? 8 : GBW - x;
 
if (y >= 1)
line_m1 = (line_m1 << 8) |
(x + 8 < GBW ? gbreg_line[-rowstride + (x >> 3) + 1] : 0);
 
if (y >= 2)
line_m2 = (line_m2 << 8) |
(x + 8 < GBW ? gbreg_line[-(rowstride << 1) + (x >> 3) + 1] << 5: 0);
 
/* This is the speed-critical inner loop. */
for (x_minor = 0; x_minor < minor_width; x_minor++)
{
bool bit;
 
bit = jbig2_arith_decode(as, &GB_stats[CONTEXT]);
result |= bit << (7 - x_minor);
CONTEXT = ((CONTEXT & 0xefb) << 1) | bit |
((line_m1 >> (8 - x_minor)) & 0x8) |
((line_m2 >> (8 - x_minor)) & 0x200);
}
gbreg_line[x >> 3] = result;
}
#ifdef OUTPUT_PBM
fwrite(gbreg_line, 1, rowstride, stdout);
#endif
gbreg_line += rowstride;
}
 
return 0;
}
 
static int
jbig2_decode_generic_template2(Jbig2Ctx *ctx,
Jbig2Segment *segment,
const Jbig2GenericRegionParams *params,
Jbig2ArithState *as,
Jbig2Image *image,
Jbig2ArithCx *GB_stats)
{
const int GBW = image->width;
const int GBH = image->height;
const int rowstride = image->stride;
int x, y;
byte *gbreg_line = (byte *)image->data;
 
/* todo: currently we only handle the nominal gbat location */
 
#ifdef OUTPUT_PBM
printf("P4\n%d %d\n", GBW, GBH);
#endif
 
for (y = 0; y < GBH; y++)
{
uint32_t CONTEXT;
uint32_t line_m1;
uint32_t line_m2;
int padded_width = (GBW + 7) & -8;
 
line_m1 = (y >= 1) ? gbreg_line[-rowstride] : 0;
line_m2 = (y >= 2) ? gbreg_line[-(rowstride << 1)] << 4 : 0;
CONTEXT = ((line_m1 >> 3) & 0x7c) | ((line_m2 >> 3) & 0x380);
 
/* 6.2.5.7 3d */
for (x = 0; x < padded_width; x += 8)
{
byte result = 0;
int x_minor;
int minor_width = GBW - x > 8 ? 8 : GBW - x;
 
if (y >= 1)
line_m1 = (line_m1 << 8) |
(x + 8 < GBW ? gbreg_line[-rowstride + (x >> 3) + 1] : 0);
 
if (y >= 2)
line_m2 = (line_m2 << 8) |
(x + 8 < GBW ? gbreg_line[-(rowstride << 1) + (x >> 3) + 1] << 4: 0);
 
/* This is the speed-critical inner loop. */
for (x_minor = 0; x_minor < minor_width; x_minor++)
{
bool bit;
 
bit = jbig2_arith_decode(as, &GB_stats[CONTEXT]);
result |= bit << (7 - x_minor);
CONTEXT = ((CONTEXT & 0x1bd) << 1) | bit |
((line_m1 >> (10 - x_minor)) & 0x4) |
((line_m2 >> (10 - x_minor)) & 0x80);
}
gbreg_line[x >> 3] = result;
}
#ifdef OUTPUT_PBM
fwrite(gbreg_line, 1, rowstride, stdout);
#endif
gbreg_line += rowstride;
}
 
return 0;
}
 
static int
jbig2_decode_generic_template2a(Jbig2Ctx *ctx,
Jbig2Segment *segment,
const Jbig2GenericRegionParams *params,
Jbig2ArithState *as,
Jbig2Image *image,
Jbig2ArithCx *GB_stats)
{
const int GBW = image->width;
const int GBH = image->height;
const int rowstride = image->stride;
int x, y;
byte *gbreg_line = (byte *)image->data;
 
/* This is a special case for GBATX1 = 3, GBATY1 = -1 */
 
#ifdef OUTPUT_PBM
printf("P4\n%d %d\n", GBW, GBH);
#endif
 
for (y = 0; y < GBH; y++)
{
uint32_t CONTEXT;
uint32_t line_m1;
uint32_t line_m2;
int padded_width = (GBW + 7) & -8;
 
line_m1 = (y >= 1) ? gbreg_line[-rowstride] : 0;
line_m2 = (y >= 2) ? gbreg_line[-(rowstride << 1)] << 4 : 0;
CONTEXT = ((line_m1 >> 3) & 0x78) | ((line_m1 >> 2) & 0x4) | ((line_m2 >> 3) & 0x380);
 
/* 6.2.5.7 3d */
for (x = 0; x < padded_width; x += 8)
{
byte result = 0;
int x_minor;
int minor_width = GBW - x > 8 ? 8 : GBW - x;
 
if (y >= 1)
line_m1 = (line_m1 << 8) |
(x + 8 < GBW ? gbreg_line[-rowstride + (x >> 3) + 1] : 0);
 
if (y >= 2)
line_m2 = (line_m2 << 8) |
(x + 8 < GBW ? gbreg_line[-(rowstride << 1) + (x >> 3) + 1] << 4: 0);
 
/* This is the speed-critical inner loop. */
for (x_minor = 0; x_minor < minor_width; x_minor++)
{
bool bit;
 
bit = jbig2_arith_decode(as, &GB_stats[CONTEXT]);
result |= bit << (7 - x_minor);
CONTEXT = ((CONTEXT & 0x1b9) << 1) | bit |
((line_m1 >> (10 - x_minor)) & 0x8) |
((line_m1 >> (9 - x_minor)) & 0x4) |
((line_m2 >> (10 - x_minor)) & 0x80);
}
gbreg_line[x >> 3] = result;
}
#ifdef OUTPUT_PBM
fwrite(gbreg_line, 1, rowstride, stdout);
#endif
gbreg_line += rowstride;
}
 
return 0;
}
 
static int
jbig2_decode_generic_template3(Jbig2Ctx *ctx,
Jbig2Segment *segment,
const Jbig2GenericRegionParams *params,
Jbig2ArithState *as,
Jbig2Image *image,
Jbig2ArithCx *GB_stats)
{
const int GBW = image->width;
const int GBH = image->height;
const int rowstride = image->stride;
byte *gbreg_line = (byte *)image->data;
int x, y;
 
/* this routine only handles the nominal AT location */
 
#ifdef OUTPUT_PBM
printf("P4\n%d %d\n", GBW, GBH);
#endif
 
for (y = 0; y < GBH; y++)
{
uint32_t CONTEXT;
uint32_t line_m1;
int padded_width = (GBW + 7) & -8;
 
line_m1 = (y >= 1) ? gbreg_line[-rowstride] : 0;
CONTEXT = (line_m1 >> 1) & 0x3f0;
 
/* 6.2.5.7 3d */
for (x = 0; x < padded_width; x += 8)
{
byte result = 0;
int x_minor;
int minor_width = GBW - x > 8 ? 8 : GBW - x;
 
if (y >= 1)
line_m1 = (line_m1 << 8) |
(x + 8 < GBW ? gbreg_line[-rowstride + (x >> 3) + 1] : 0);
 
/* This is the speed-critical inner loop. */
for (x_minor = 0; x_minor < minor_width; x_minor++)
{
bool bit;
 
bit = jbig2_arith_decode(as, &GB_stats[CONTEXT]);
result |= bit << (7 - x_minor);
CONTEXT = ((CONTEXT & 0x1f7) << 1) | bit |
((line_m1 >> (10 - x_minor)) & 0x010);
}
gbreg_line[x >> 3] = result;
}
#ifdef OUTPUT_PBM
fwrite(gbreg_line, 1, rowstride, stdout);
#endif
gbreg_line += rowstride;
}
 
return 0;
}
 
static int
jbig2_decode_generic_template3_unopt(Jbig2Ctx *ctx,
Jbig2Segment *segment,
const Jbig2GenericRegionParams *params,
Jbig2ArithState *as,
Jbig2Image *image,
Jbig2ArithCx *GB_stats)
{
const int GBW = image->width;
const int GBH = image->height;
uint32_t CONTEXT;
int x,y;
bool bit;
 
/* this version is generic and easy to understand, but very slow */
 
for (y = 0; y < GBH; y++) {
for (x = 0; x < GBW; x++) {
CONTEXT = 0;
CONTEXT |= jbig2_image_get_pixel(image, x - 1, y) << 0;
CONTEXT |= jbig2_image_get_pixel(image, x - 2, y) << 1;
CONTEXT |= jbig2_image_get_pixel(image, x - 3, y) << 2;
CONTEXT |= jbig2_image_get_pixel(image, x - 4, y) << 3;
CONTEXT |= jbig2_image_get_pixel(image, x + params->gbat[0],
y + params->gbat[1]) << 4;
CONTEXT |= jbig2_image_get_pixel(image, x + 1, y - 1) << 5;
CONTEXT |= jbig2_image_get_pixel(image, x + 0, y - 1) << 6;
CONTEXT |= jbig2_image_get_pixel(image, x - 1, y - 1) << 7;
CONTEXT |= jbig2_image_get_pixel(image, x - 2, y - 1) << 8;
CONTEXT |= jbig2_image_get_pixel(image, x - 3, y - 1) << 9;
bit = jbig2_arith_decode(as, &GB_stats[CONTEXT]);
jbig2_image_set_pixel(image, x, y, bit);
}
}
return 0;
}
 
static void
copy_prev_row(Jbig2Image *image, int row)
{
if (!row) {
/* no previous row */
memset( image->data, 0, image->stride );
} else {
/* duplicate data from the previous row */
uint8_t *src = image->data + (row - 1) * image->stride;
memcpy( src + image->stride, src, image->stride );
}
}
 
static int
jbig2_decode_generic_template0_TPGDON(Jbig2Ctx *ctx,
Jbig2Segment *segment,
const Jbig2GenericRegionParams *params,
Jbig2ArithState *as,
Jbig2Image *image,
Jbig2ArithCx *GB_stats)
{
const int GBW = image->width;
const int GBH = image->height;
uint32_t CONTEXT;
int x, y;
bool bit;
int LTP = 0;
 
for (y = 0; y < GBH; y++)
{
LTP ^= jbig2_arith_decode(as, &GB_stats[0x9B25]);
if (!LTP) {
for (x = 0; x < GBW; x++) {
CONTEXT = jbig2_image_get_pixel(image, x - 1, y);
CONTEXT |= jbig2_image_get_pixel(image, x - 2, y) << 1;
CONTEXT |= jbig2_image_get_pixel(image, x - 3, y) << 2;
CONTEXT |= jbig2_image_get_pixel(image, x - 4, y) << 3;
CONTEXT |= jbig2_image_get_pixel(image, x + params->gbat[0],
y + params->gbat[1]) << 4;
CONTEXT |= jbig2_image_get_pixel(image, x + 2, y - 1) << 5;
CONTEXT |= jbig2_image_get_pixel(image, x + 1, y - 1) << 6;
CONTEXT |= jbig2_image_get_pixel(image, x , y - 1) << 7;
CONTEXT |= jbig2_image_get_pixel(image, x - 1, y - 1) << 8;
CONTEXT |= jbig2_image_get_pixel(image, x - 2, y - 1) << 9;
CONTEXT |= jbig2_image_get_pixel(image, x + params->gbat[2],
y + params->gbat[3]) << 10;
CONTEXT |= jbig2_image_get_pixel(image, x + params->gbat[4],
y + params->gbat[5]) << 11;
CONTEXT |= jbig2_image_get_pixel(image, x + 1, y - 2) << 12;
CONTEXT |= jbig2_image_get_pixel(image, x , y - 2) << 13;
CONTEXT |= jbig2_image_get_pixel(image, x - 1, y - 2) << 14;
CONTEXT |= jbig2_image_get_pixel(image, x + params->gbat[6],
y + params->gbat[7]) << 15;
bit = jbig2_arith_decode(as, &GB_stats[CONTEXT]);
jbig2_image_set_pixel(image, x, y, bit);
}
} else {
copy_prev_row(image, y);
}
}
 
return 0;
}
 
static int
jbig2_decode_generic_template1_TPGDON(Jbig2Ctx *ctx,
Jbig2Segment *segment,
const Jbig2GenericRegionParams *params,
Jbig2ArithState *as,
Jbig2Image *image,
Jbig2ArithCx *GB_stats)
{
const int GBW = image->width;
const int GBH = image->height;
uint32_t CONTEXT;
int x, y;
bool bit;
int LTP = 0;
 
for (y = 0; y < GBH; y++) {
LTP ^= jbig2_arith_decode(as, &GB_stats[0x0795]);
if (!LTP) {
for (x = 0; x < GBW; x++) {
CONTEXT = jbig2_image_get_pixel(image, x - 1, y);
CONTEXT |= jbig2_image_get_pixel(image, x - 2, y) << 1;
CONTEXT |= jbig2_image_get_pixel(image, x - 3, y) << 2;
CONTEXT |= jbig2_image_get_pixel(image, x + params->gbat[0],
y + params->gbat[1]) << 3;
CONTEXT |= jbig2_image_get_pixel(image, x + 2, y - 1) << 4;
CONTEXT |= jbig2_image_get_pixel(image, x + 1, y - 1) << 5;
CONTEXT |= jbig2_image_get_pixel(image, x , y - 1) << 6;
CONTEXT |= jbig2_image_get_pixel(image, x - 1, y - 1) << 7;
CONTEXT |= jbig2_image_get_pixel(image, x - 2, y - 1) << 8;
CONTEXT |= jbig2_image_get_pixel(image, x + 2, y - 2) << 9;
CONTEXT |= jbig2_image_get_pixel(image, x + 1, y - 2) << 10;
CONTEXT |= jbig2_image_get_pixel(image, x , y - 2) << 11;
CONTEXT |= jbig2_image_get_pixel(image, x - 1, y - 2) << 12;
bit = jbig2_arith_decode(as, &GB_stats[CONTEXT]);
jbig2_image_set_pixel(image, x, y, bit);
}
} else {
copy_prev_row(image, y);
}
}
 
return 0;
}
 
static int
jbig2_decode_generic_template2_TPGDON(Jbig2Ctx *ctx,
Jbig2Segment *segment,
const Jbig2GenericRegionParams *params,
Jbig2ArithState *as,
Jbig2Image *image,
Jbig2ArithCx *GB_stats)
{
const int GBW = image->width;
const int GBH = image->height;
uint32_t CONTEXT;
int x, y;
bool bit;
int LTP = 0;
 
for (y = 0; y < GBH; y++) {
LTP ^= jbig2_arith_decode(as, &GB_stats[0xE5]);
if (!LTP) {
for (x = 0; x < GBW; x++) {
CONTEXT = jbig2_image_get_pixel(image, x - 1, y);
CONTEXT |= jbig2_image_get_pixel(image, x - 2, y) << 1;
CONTEXT |= jbig2_image_get_pixel(image, x + params->gbat[0],
y + params->gbat[1]) << 2;
CONTEXT |= jbig2_image_get_pixel(image, x + 1, y - 1) << 3;
CONTEXT |= jbig2_image_get_pixel(image, x , y - 1) << 4;
CONTEXT |= jbig2_image_get_pixel(image, x - 1, y - 1) << 5;
CONTEXT |= jbig2_image_get_pixel(image, x - 2, y - 1) << 6;
CONTEXT |= jbig2_image_get_pixel(image, x + 1, y - 2) << 7;
CONTEXT |= jbig2_image_get_pixel(image, x , y - 2) << 8;
CONTEXT |= jbig2_image_get_pixel(image, x - 1, y - 2) << 9;
bit = jbig2_arith_decode(as, &GB_stats[CONTEXT]);
jbig2_image_set_pixel(image, x, y, bit);
}
} else {
copy_prev_row(image, y);
}
}
 
return 0;
}
 
static int
jbig2_decode_generic_template3_TPGDON(Jbig2Ctx *ctx,
Jbig2Segment *segment,
const Jbig2GenericRegionParams *params,
Jbig2ArithState *as,
Jbig2Image *image,
Jbig2ArithCx *GB_stats)
{
const int GBW = image->width;
const int GBH = image->height;
uint32_t CONTEXT;
int x, y;
bool bit;
int LTP = 0;
 
for (y = 0; y < GBH; y++) {
LTP ^= jbig2_arith_decode(as, &GB_stats[0x0195]);
if (!LTP) {
for (x = 0; x < GBW; x++) {
CONTEXT = jbig2_image_get_pixel(image, x - 1, y);
CONTEXT |= jbig2_image_get_pixel(image, x - 2, y) << 1;
CONTEXT |= jbig2_image_get_pixel(image, x - 3, y) << 2;
CONTEXT |= jbig2_image_get_pixel(image, x - 4, y) << 3;
CONTEXT |= jbig2_image_get_pixel(image, x + params->gbat[0],
y + params->gbat[1]) << 4;
CONTEXT |= jbig2_image_get_pixel(image, x + 1, y - 1) << 5;
CONTEXT |= jbig2_image_get_pixel(image, x , y - 1) << 6;
CONTEXT |= jbig2_image_get_pixel(image, x - 1, y - 1) << 7;
CONTEXT |= jbig2_image_get_pixel(image, x - 2, y - 1) << 8;
CONTEXT |= jbig2_image_get_pixel(image, x - 3, y - 1) << 9;
bit = jbig2_arith_decode(as, &GB_stats[CONTEXT]);
jbig2_image_set_pixel(image, x, y, bit);
}
} else {
copy_prev_row(image, y);
}
}
 
return 0;
}
 
static int
jbig2_decode_generic_region_TPGDON(Jbig2Ctx *ctx,
Jbig2Segment *segment,
const Jbig2GenericRegionParams *params,
Jbig2ArithState *as,
Jbig2Image *image,
Jbig2ArithCx *GB_stats)
{
switch (params->GBTEMPLATE) {
case 0:
return jbig2_decode_generic_template0_TPGDON(ctx, segment,
params, as, image, GB_stats);
case 1:
return jbig2_decode_generic_template1_TPGDON(ctx, segment,
params, as, image, GB_stats);
case 2:
return jbig2_decode_generic_template2_TPGDON(ctx, segment,
params, as, image, GB_stats);
case 3:
return jbig2_decode_generic_template3_TPGDON(ctx, segment,
params, as, image, GB_stats);
}
 
return -1;
}
 
/**
* jbig2_decode_generic_region: Decode a generic region.
* @ctx: The context for allocation and error reporting.
* @segment: A segment reference for error reporting.
* @params: Decoding parameter set.
* @as: Arithmetic decoder state.
* @image: Where to store the decoded data.
* @GB_stats: Arithmetic stats.
*
* Decodes a generic region, according to section 6.2. The caller should
* pass an already allocated Jbig2Image object for @image
*
* Because this API is based on an arithmetic decoding state, it is
* not suitable for MMR decoding.
*
* Return code: 0 on success.
**/
int
jbig2_decode_generic_region(Jbig2Ctx *ctx,
Jbig2Segment *segment,
const Jbig2GenericRegionParams *params,
Jbig2ArithState *as,
Jbig2Image *image,
Jbig2ArithCx *GB_stats)
{
const int8_t *gbat = params->gbat;
 
if (!params->MMR && params->TPGDON)
return jbig2_decode_generic_region_TPGDON(ctx, segment, params,
as, image, GB_stats);
 
if (!params->MMR && params->GBTEMPLATE == 0) {
if (gbat[0] == +3 && gbat[1] == -1 &&
gbat[2] == -3 && gbat[3] == -1 &&
gbat[4] == +2 && gbat[5] == -2 &&
gbat[6] == -2 && gbat[7] == -2)
return jbig2_decode_generic_template0(ctx, segment, params,
as, image, GB_stats);
else
return jbig2_decode_generic_template0_unopt(ctx, segment, params,
as, image, GB_stats);
} else if (!params->MMR && params->GBTEMPLATE == 1)
return jbig2_decode_generic_template1(ctx, segment, params,
as, image, GB_stats);
else if (!params->MMR && params->GBTEMPLATE == 2)
{
if (gbat[0] == 3 && gbat[1] == -1)
return jbig2_decode_generic_template2a(ctx, segment, params,
as, image, GB_stats);
else
return jbig2_decode_generic_template2(ctx, segment, params,
as, image, GB_stats);
}
else if (!params->MMR && params->GBTEMPLATE == 3) {
if (gbat[0] == 2 && gbat[1] == -1)
return jbig2_decode_generic_template3_unopt(ctx, segment, params,
as, image, GB_stats);
else
return jbig2_decode_generic_template3_unopt(ctx, segment, params,
as, image, GB_stats);
}
 
{
int i;
for (i = 0; i < 8; i++)
jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
"gbat[%d] = %d", i, params->gbat[i]);
}
jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
"decode_generic_region: MMR=%d, GBTEMPLATE=%d NYI",
params->MMR, params->GBTEMPLATE);
return -1;
}
 
/**
* Handler for immediate generic region segments
*/
int
jbig2_immediate_generic_region(Jbig2Ctx *ctx, Jbig2Segment *segment,
const byte *segment_data)
{
Jbig2RegionSegmentInfo rsi;
byte seg_flags;
int8_t gbat[8];
int offset;
int gbat_bytes = 0;
Jbig2GenericRegionParams params;
int code;
Jbig2Image *image;
Jbig2WordStream *ws;
Jbig2ArithState *as;
Jbig2ArithCx *GB_stats = NULL;
 
/* 7.4.6 */
if (segment->data_length < 18)
return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"Segment too short");
 
jbig2_get_region_segment_info(&rsi, segment_data);
jbig2_error(ctx, JBIG2_SEVERITY_INFO, segment->number,
"generic region: %d x %d @ (%d, %d), flags = %02x",
rsi.width, rsi.height, rsi.x, rsi.y, rsi.flags);
 
/* 7.4.6.2 */
seg_flags = segment_data[17];
jbig2_error(ctx, JBIG2_SEVERITY_INFO, segment->number,
"segment flags = %02x", seg_flags);
if ((seg_flags & 1) && (seg_flags & 6))
jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
"MMR is 1, but GBTEMPLATE is not 0");
 
/* 7.4.6.3 */
if (!(seg_flags & 1))
{
gbat_bytes = (seg_flags & 6) ? 2 : 8;
if (18 + gbat_bytes > segment->data_length)
return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"Segment too short");
memcpy(gbat, segment_data + 18, gbat_bytes);
jbig2_error(ctx, JBIG2_SEVERITY_INFO, segment->number,
"gbat: %d, %d", gbat[0], gbat[1]);
}
 
offset = 18 + gbat_bytes;
 
/* Table 34 */
params.MMR = seg_flags & 1;
params.GBTEMPLATE = (seg_flags & 6) >> 1;
params.TPGDON = (seg_flags & 8) >> 3;
params.USESKIP = 0;
memcpy (params.gbat, gbat, gbat_bytes);
 
image = jbig2_image_new(ctx, rsi.width, rsi.height);
if (image == NULL)
return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"unable to allocate generic image");
jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
"allocated %d x %d image buffer for region decode results",
rsi.width, rsi.height);
 
if (params.MMR)
{
code = jbig2_decode_generic_mmr(ctx, segment, &params,
segment_data + offset, segment->data_length - offset,
image);
}
else
{
int stats_size = jbig2_generic_stats_size(ctx, params.GBTEMPLATE);
GB_stats = jbig2_alloc(ctx->allocator, stats_size);
memset(GB_stats, 0, stats_size);
 
ws = jbig2_word_stream_buf_new(ctx,
segment_data + offset,
segment->data_length - offset);
as = jbig2_arith_new(ctx, ws);
code = jbig2_decode_generic_region(ctx, segment, &params,
as, image, GB_stats);
jbig2_free(ctx->allocator, as);
jbig2_word_stream_buf_free(ctx, ws);
 
jbig2_free(ctx->allocator, GB_stats);
}
 
jbig2_page_add_result(ctx, &ctx->pages[ctx->current_page],
image, rsi.x, rsi.y, JBIG2_COMPOSE_OR);
jbig2_image_release(ctx, image);
 
return code;
}
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libjbig2dec/jbig2_generic.h
0,0 → 1,62
/*
jbig2dec
 
Copyright (C) 2002-2004 Artifex Software, Inc.
 
This software is distributed under license and may not
be copied, modified or distributed except as expressly
authorized under the terms of the license contained in
the file LICENSE in this distribution.
 
For further licensing information refer to http://artifex.com/ or
contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
San Rafael, CA 94903, U.S.A., +1(415)492-9861.
*/
 
/**
* Headers for Generic and Generic Refinement region handling
**/
 
/* 6.4 Table 2 */
typedef struct {
bool MMR;
/* GBW */
/* GBH */
int GBTEMPLATE;
bool TPGDON;
bool USESKIP;
/* SKIP */
int8_t gbat[8];
} Jbig2GenericRegionParams;
 
/* return the appropriate context size for the given template */
int
jbig2_generic_stats_size(Jbig2Ctx *ctx, int template);
 
int
jbig2_decode_generic_region(Jbig2Ctx *ctx,
Jbig2Segment *segment,
const Jbig2GenericRegionParams *params,
Jbig2ArithState *as,
Jbig2Image *image,
Jbig2ArithCx *GB_stats);
 
 
/* 6.3 Table 6 */
typedef struct {
/* GRW */
/* GRH */
bool GRTEMPLATE;
Jbig2Image *reference;
int32_t DX, DY;
bool TPGRON;
int8_t grat[4];
} Jbig2RefinementRegionParams;
 
int
jbig2_decode_refinement_region(Jbig2Ctx *ctx,
Jbig2Segment *segment,
const Jbig2RefinementRegionParams *params,
Jbig2ArithState *as,
Jbig2Image *image,
Jbig2ArithCx *GB_stats);
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libjbig2dec/jbig2_halftone.c
0,0 → 1,372
/*
jbig2dec
 
Copyright (C) 2005 Artifex Software, Inc.
 
This software is distributed under license and may not
be copied, modified or distributed except as expressly
authorized under the terms of the license contained in
the file LICENSE in this distribution.
 
For further licensing information refer to http://artifex.com/ or
contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
San Rafael, CA 94903, U.S.A., +1(415)492-9861.
*/
 
/* JBIG2 Pattern Dictionary and Halftone Region decoding */
 
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "os_types.h"
 
#include <string.h> /* memset() */
 
#include "jbig2.h"
#include "jbig2_priv.h"
#include "jbig2_arith.h"
#include "jbig2_generic.h"
#include "jbig2_mmr.h"
 
typedef struct {
int n_patterns;
Jbig2Image **patterns;
int HPW, HPH;
} Jbig2PatternDict;
 
/* Table 24 */
typedef struct {
bool HDMMR;
uint32_t HDPW;
uint32_t HDPH;
uint32_t GRAYMAX;
int HDTEMPLATE;
} Jbig2PatternDictParams;
 
/* Table 33 */
typedef struct {
byte flags;
uint32_t HGW;
uint32_t HGH;
int32_t HGX;
int32_t HGY;
uint16_t HRX;
uint16_t HRY;
bool HMMR;
int HTEMPLATE;
bool HENABLESKIP;
Jbig2ComposeOp op;
bool HDEFPIXEL;
} Jbig2HalftoneRegionParams;
 
 
/**
* jbig2_hd_new: create a new dictionary from a collective bitmap
*/
Jbig2PatternDict *
jbig2_hd_new(Jbig2Ctx *ctx,
const Jbig2PatternDictParams *params,
Jbig2Image *image)
{
Jbig2PatternDict *new;
const int N = params->GRAYMAX + 1;
const int HPW = params->HDPW;
const int HPH = params->HDPH;
int i;
 
/* allocate a new struct */
new = (Jbig2PatternDict *)jbig2_alloc(ctx->allocator,
sizeof(Jbig2PatternDict));
if (new != NULL) {
new->patterns = (Jbig2Image **)jbig2_alloc(ctx->allocator,
N*sizeof(Jbig2Image*));
if (new->patterns == NULL) {
jbig2_free(ctx->allocator, new);
return NULL;
}
new->n_patterns = N;
new->HPW = HPW;
new->HPH = HPH;
 
/* 6.7.5(4) - copy out the individual pattern images */
for (i = 0; i < N; i++) {
new->patterns[i] = jbig2_image_new(ctx, HPW, HPH);
if (new->patterns[i] == NULL) {
int j;
jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1,
"failed to allocate pattern element image");
for (j = 0; j < i; j++)
jbig2_free(ctx->allocator, new->patterns[j]);
jbig2_free(ctx->allocator, new);
return NULL;
}
/* compose with the REPLACE operator; the source
will be clipped to the destintion, selecting the
proper sub image */
jbig2_image_compose(ctx, new->patterns[i], image,
-i * HPW, 0, JBIG2_COMPOSE_REPLACE);
}
}
 
return new;
}
 
/**
* jbig2_hd_release: release a pattern dictionary
*/
void
jbig2_hd_release(Jbig2Ctx *ctx, Jbig2PatternDict *dict)
{
int i;
 
if (dict == NULL) return;
for (i = 0; i < dict->n_patterns; i++)
if (dict->patterns[i]) jbig2_image_release(ctx, dict->patterns[i]);
jbig2_free(ctx->allocator, dict->patterns);
jbig2_free(ctx->allocator, dict);
}
 
/**
* jbig2_decode_pattern_dict: decode pattern dictionary data
*
* @ctx: jbig2 decoder context
* @segment: jbig2 segment (header) structure
* @params: parameters from the pattern dictionary header
* @data: pointer to text region data to be decoded
* @size: length of text region data
* @GB_stats: artimetic coding context to use
*
* Implements the patten dictionary decoding proceedure
* described in section 6.7 of the JBIG2 spec.
*
* returns: a pointer to the resulting dictionary on success
* returns: 0 on failure
**/
static Jbig2PatternDict *
jbig2_decode_pattern_dict(Jbig2Ctx *ctx, Jbig2Segment *segment,
const Jbig2PatternDictParams *params,
const byte *data, const size_t size,
Jbig2ArithCx *GB_stats)
{
Jbig2PatternDict *hd = NULL;
Jbig2Image *image;
Jbig2GenericRegionParams rparams;
int code;
 
/* allocate the collective image */
image = jbig2_image_new(ctx,
params->HDPW * (params->GRAYMAX + 1), params->HDPH);
if (image == NULL) {
jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"failed to allocate collective bitmap for halftone dict!");
return NULL;
}
 
/* fill out the generic region decoder parameters */
rparams.MMR = params->HDMMR;
rparams.GBTEMPLATE = params->HDTEMPLATE;
rparams.TPGDON = 0; /* not used if HDMMR = 1 */
rparams.USESKIP = 0;
rparams.gbat[0] = -params->HDPW;
rparams.gbat[1] = 0;
rparams.gbat[2] = -3;
rparams.gbat[3] = -1;
rparams.gbat[4] = 2;
rparams.gbat[5] = -2;
rparams.gbat[6] = -2;
rparams.gbat[7] = -2;
 
if (params->HDMMR) {
code = jbig2_decode_generic_mmr(ctx, segment, &rparams,
data, size, image);
} else {
Jbig2WordStream *ws = jbig2_word_stream_buf_new(ctx, data, size);
Jbig2ArithState *as = jbig2_arith_new(ctx, ws);
 
code = jbig2_decode_generic_region(ctx, segment, &rparams,
as, image, GB_stats);
 
jbig2_free(ctx->allocator, as);
jbig2_word_stream_buf_free(ctx, ws);
}
if (code != 0) {
jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
"error decoding collective pattern dictionary bitmap!");
}
 
hd = jbig2_hd_new(ctx, params, image);
jbig2_image_release(ctx, image);
 
return hd;
}
 
/* 7.4.4 */
int
jbig2_pattern_dictionary(Jbig2Ctx *ctx, Jbig2Segment *segment,
const byte *segment_data)
{
Jbig2PatternDictParams params;
Jbig2ArithCx *GB_stats = NULL;
byte flags;
int offset = 0;
 
/* 7.4.4.1 - Data header */
if (segment->data_length < 7) {
return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"Segment too short");
}
flags = segment_data[0];
params.HDMMR = flags & 1;
params.HDTEMPLATE = (flags & 6) >> 1;
params.HDPW = segment_data[1];
params.HDPH = segment_data[2];
params.GRAYMAX = jbig2_get_int32(segment_data + 3);
offset += 7;
 
jbig2_error(ctx, JBIG2_SEVERITY_INFO, segment->number,
"pattern dictionary, flags=%02x, %d grays (%dx%d cell)",
flags, params.GRAYMAX + 1, params.HDPW, params.HDPH);
 
if (params.HDMMR && params.HDTEMPLATE) {
jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
"HDTEMPLATE is %d when HDMMR is %d, contrary to spec",
params.HDTEMPLATE, params.HDMMR);
}
if (flags & 0xf8) {
jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
"Reserved flag bits non-zero");
}
 
/* 7.4.4.2 */
if (!params.HDMMR) {
/* allocate and zero arithmetic coding stats */
int stats_size = jbig2_generic_stats_size(ctx, params.HDTEMPLATE);
GB_stats = jbig2_alloc(ctx->allocator, stats_size);
memset(GB_stats, 0, stats_size);
}
 
segment->result = jbig2_decode_pattern_dict(ctx, segment, &params,
segment_data + offset,
segment->data_length - offset, GB_stats);
 
/* todo: retain GB_stats? */
if (!params.HDMMR) {
jbig2_free(ctx->allocator, GB_stats);
}
 
return (segment->result != NULL) ? 0 : 1;
}
 
 
 
/**
* jbig2_decode_halftone_region: decode a halftone region
**/
int
jbig2_decode_halftone_region(Jbig2Ctx *ctx, Jbig2Segment *segment,
Jbig2HalftoneRegionParams *params,
const byte *data, const size_t size,
Jbig2Image *image,
Jbig2ArithCx *GB_stats)
{
int code = 0;
 
/* todo: implement */
return code;
}
 
/**
* jbig2_halftone_region: read a halftone region segment header
**/
int
jbig2_halftone_region(Jbig2Ctx *ctx, Jbig2Segment *segment, const byte *segment_data)
{
int offset = 0;
Jbig2RegionSegmentInfo region_info;
Jbig2HalftoneRegionParams params;
Jbig2Image *image;
Jbig2ArithCx *GB_stats;
int code;
 
/* 7.4.5.1 */
if (segment->data_length < 17) goto too_short;
jbig2_get_region_segment_info(&region_info, segment_data);
offset += 17;
 
if (segment->data_length < 18) goto too_short;
 
/* 7.4.5.1.1 */
params.flags = segment_data[offset];
params.HMMR = params.flags & 1;
params.HTEMPLATE = (params.flags & 6) >> 1;
params.HENABLESKIP = (params.flags & 8) >> 3;
params.op = (params.flags & 0x70) >> 4;
params.HDEFPIXEL = (params.flags &0x80) >> 7;
offset += 1;
 
jbig2_error(ctx, JBIG2_SEVERITY_INFO, segment->number,
"halftone region: %d x %d @ (%x,%d) flags=%02x",
region_info.width, region_info.height,
region_info.x, region_info.y, params.flags);
 
if (params.HMMR && params.HTEMPLATE) {
jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
"HTEMPLATE is %d when HMMR is %d, contrary to spec",
params.HTEMPLATE, params.HMMR);
}
if (params.HMMR && params.HENABLESKIP) {
jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
"HENABLESKIP is %d when HMMR is %d, contrary to spec",
params.HENABLESKIP, params.HMMR);
}
 
/* Figure 43 */
if (segment->data_length - offset < 16) goto too_short;
params.HGW = jbig2_get_int32(segment_data + offset);
params.HGH = jbig2_get_int32(segment_data + offset + 4);
params.HGX = jbig2_get_int32(segment_data + offset + 8);
params.HGY = jbig2_get_int32(segment_data + offset + 12);
offset += 16;
 
/* Figure 44 */
if (segment->data_length - offset < 4) goto too_short;
params.HRX = jbig2_get_int16(segment_data + offset);
params.HRY = jbig2_get_int16(segment_data + offset + 2);
offset += 4;
 
jbig2_error(ctx, JBIG2_SEVERITY_INFO, segment->number,
" grid %d x %d @ (%d.%d,%d.%d) vector (%d.%d,%d.%d)",
params.HGW, params.HGH,
params.HGX >> 8, params.HGX & 0xff,
params.HGY >> 8, params.HGY & 0xff,
params.HRX >> 8, params.HRX & 0xff,
params.HRY >> 8, params.HRY & 0xff);
 
/* 7.4.5.2.2 */
if (!params.HMMR) {
/* allocate and zero arithmetic coding stats */
int stats_size = jbig2_generic_stats_size(ctx, params.HTEMPLATE);
GB_stats = jbig2_alloc(ctx->allocator, stats_size);
memset(GB_stats, 0, stats_size);
}
 
image = jbig2_image_new(ctx, region_info.width, region_info.height);
if (image == NULL)
return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"unable to allocate halftone image");
 
code = jbig2_decode_halftone_region(ctx, segment, &params,
segment_data + offset, segment->data_length - offset,
image, GB_stats);
 
/* todo: retain GB_stats? */
if (!params.HMMR) {
jbig2_free(ctx->allocator, GB_stats);
}
 
return code;
 
too_short:
return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"Segment too short");
}
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libjbig2dec/jbig2_huffman.c
0,0 → 1,480
/*
jbig2dec
 
Copyright (C) 2001-2005 Artifex Software, Inc.
 
This software is distributed under license and may not
be copied, modified or distributed except as expressly
authorized under the terms of the license contained in
the file LICENSE in this distribution.
 
For further licensing information refer to http://artifex.com/ or
contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
San Rafael, CA 94903, U.S.A., +1(415)492-9861.
*/
 
/* Huffman table decoding procedures
-- See Annex B of the JBIG2 specification */
 
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "os_types.h"
 
#include <stdlib.h>
#include <string.h>
 
#ifdef JBIG2_DEBUG
#include <stdio.h>
#endif
 
#include "jbig2.h"
#include "jbig2_priv.h"
#include "jbig2_huffman.h"
#include "jbig2_hufftab.h"
 
#define JBIG2_HUFFMAN_FLAGS_ISOOB 1
#define JBIG2_HUFFMAN_FLAGS_ISLOW 2
#define JBIG2_HUFFMAN_FLAGS_ISEXT 4
 
 
 
struct _Jbig2HuffmanState {
/* The current bit offset is equal to (offset * 8) + offset_bits.
The MSB of this_word is the current bit offset. The MSB of next_word
is (offset + 4) * 8. */
uint32_t this_word;
uint32_t next_word;
int offset_bits;
int offset;
 
Jbig2WordStream *ws;
};
 
 
/** Allocate and initialize a new huffman coding state
* the returned pointer can simply be freed; this does
* not affect the associated Jbig2WordStream.
*/
Jbig2HuffmanState *
jbig2_huffman_new (Jbig2Ctx *ctx, Jbig2WordStream *ws)
{
Jbig2HuffmanState *result;
 
result = (Jbig2HuffmanState *)jbig2_alloc(ctx->allocator,
sizeof(Jbig2HuffmanState));
 
if (result != NULL) {
result->offset = 0;
result->offset_bits = 0;
result->this_word = ws->get_next_word (ws, 0);
result->next_word = ws->get_next_word (ws, 4);
 
result->ws = ws;
}
 
return result;
}
 
/** Free an allocated huffman coding state.
* This just calls jbig2_free() if the pointer is not NULL
*/
void
jbig2_huffman_free (Jbig2Ctx *ctx, Jbig2HuffmanState *hs)
{
if (hs != NULL) free(hs);
return;
}
 
/** debug routines **/
#ifdef JBIG2_DEBUG
 
/** print current huffman state */
void jbig2_dump_huffman_state(Jbig2HuffmanState *hs) {
fprintf(stderr, "huffman state %08x %08x offset %d.%d\n",
hs->this_word, hs->next_word, hs->offset, hs->offset_bits);
}
 
/** print the binary string we're reading from */
void jbig2_dump_huffman_binary(Jbig2HuffmanState *hs)
{
const uint32_t word = hs->this_word;
int i;
 
fprintf(stderr, "huffman binary ");
for (i = 31; i >= 0; i--)
fprintf(stderr, ((word >> i) & 1) ? "1" : "0");
fprintf(stderr, "\n");
}
 
#endif /* JBIG2_DEBUG */
 
/** Skip bits up to the next byte boundary
*/
void
jbig2_huffman_skip(Jbig2HuffmanState *hs)
{
int bits = hs->offset_bits & 7;
 
if (bits) {
bits = 8 - bits;
hs->offset_bits += bits;
hs->this_word = (hs->this_word << bits) |
(hs->next_word >> (32 - hs->offset_bits));
}
 
if (hs->offset_bits >= 32) {
Jbig2WordStream *ws = hs->ws;
hs->this_word = hs->next_word;
hs->offset += 4;
hs->next_word = ws->get_next_word (ws, hs->offset + 4);
hs->offset_bits -= 32;
if (hs->offset_bits) {
hs->this_word = (hs->this_word << hs->offset_bits) |
(hs->next_word >> (32 - hs->offset_bits));
}
}
}
 
/* skip ahead a specified number of bytes in the word stream
*/
void jbig2_huffman_advance(Jbig2HuffmanState *hs, int offset)
{
Jbig2WordStream *ws = hs->ws;
 
hs->offset += offset & ~3;
hs->offset_bits += (offset & 3) << 3;
if (hs->offset_bits >= 32) {
hs->offset += 4;
hs->offset_bits -= 32;
}
hs->this_word = ws->get_next_word (ws, hs->offset);
hs->next_word = ws->get_next_word (ws, hs->offset + 4);
if (hs->offset_bits > 0)
hs->this_word = (hs->this_word << hs->offset_bits) |
(hs->next_word >> (32 - hs->offset_bits));
}
 
/* return the offset of the huffman decode pointer (in bytes)
* from the beginning of the WordStream
*/
int
jbig2_huffman_offset(Jbig2HuffmanState *hs)
{
return hs->offset + (hs->offset_bits >> 3);
}
 
/* read a number of bits directly from the huffman state
* without decoding against a table
*/
int32_t
jbig2_huffman_get_bits (Jbig2HuffmanState *hs, const int bits)
{
uint32_t this_word = hs->this_word;
int32_t result;
 
result = this_word >> (32 - bits);
hs->offset_bits += bits;
if (hs->offset_bits >= 32) {
hs->offset += 4;
hs->offset_bits -= 32;
hs->this_word = hs->next_word;
hs->next_word = hs->ws->get_next_word(hs->ws, hs->offset + 4);
if (hs->offset_bits) {
hs->this_word = (hs->this_word << hs->offset_bits) |
(hs->next_word >> (32 - hs->offset_bits));
} else {
hs->this_word = (hs->this_word << hs->offset_bits);
}
} else {
hs->this_word = (this_word << bits) |
(hs->next_word >> (32 - hs->offset_bits));
}
 
return result;
}
 
int32_t
jbig2_huffman_get (Jbig2HuffmanState *hs,
const Jbig2HuffmanTable *table, bool *oob)
{
Jbig2HuffmanEntry *entry;
byte flags;
int offset_bits = hs->offset_bits;
uint32_t this_word = hs->this_word;
uint32_t next_word;
int RANGELEN;
int32_t result;
 
for (;;)
{
int log_table_size = table->log_table_size;
int PREFLEN;
 
entry = &table->entries[this_word >> (32 - log_table_size)];
flags = entry->flags;
PREFLEN = entry->PREFLEN;
 
next_word = hs->next_word;
offset_bits += PREFLEN;
if (offset_bits >= 32)
{
Jbig2WordStream *ws = hs->ws;
this_word = next_word;
hs->offset += 4;
next_word = ws->get_next_word (ws, hs->offset + 4);
offset_bits -= 32;
hs->next_word = next_word;
PREFLEN = offset_bits;
}
if (PREFLEN)
this_word = (this_word << PREFLEN) |
(next_word >> (32 - offset_bits));
if (flags & JBIG2_HUFFMAN_FLAGS_ISEXT)
{
table = entry->u.ext_table;
}
else
break;
}
result = entry->u.RANGELOW;
RANGELEN = entry->RANGELEN;
if (RANGELEN > 0)
{
int32_t HTOFFSET;
 
HTOFFSET = this_word >> (32 - RANGELEN);
if (flags & JBIG2_HUFFMAN_FLAGS_ISLOW)
result -= HTOFFSET;
else
result += HTOFFSET;
 
offset_bits += RANGELEN;
if (offset_bits >= 32)
{
Jbig2WordStream *ws = hs->ws;
this_word = next_word;
hs->offset += 4;
next_word = ws->get_next_word (ws, hs->offset + 4);
offset_bits -= 32;
hs->next_word = next_word;
RANGELEN = offset_bits;
}
if (RANGELEN)
this_word = (this_word << RANGELEN) |
(next_word >> (32 - offset_bits));
}
 
hs->this_word = this_word;
hs->offset_bits = offset_bits;
 
if (oob != NULL)
*oob = (flags & JBIG2_HUFFMAN_FLAGS_ISOOB);
 
return result;
}
 
/* TODO: more than 8 bits here is wasteful of memory. We have support
for sub-trees in jbig2_huffman_get() above, but don't use it here.
We should, and then revert to 8 bits */
#define LOG_TABLE_SIZE_MAX 16
 
/** Build an in-memory representation of a Huffman table from the
* set of template params provided by the spec or a table segment
*/
Jbig2HuffmanTable *
jbig2_build_huffman_table (Jbig2Ctx *ctx, const Jbig2HuffmanParams *params)
{
int *LENCOUNT;
int LENMAX = -1;
const int lencountsize = 256 * sizeof(*LENCOUNT);
const Jbig2HuffmanLine *lines = params->lines;
int n_lines = params->n_lines;
int i, j;
int max_j;
int log_table_size = 0;
Jbig2HuffmanTable *result;
Jbig2HuffmanEntry *entries;
int CURLEN;
int firstcode = 0;
int CURCODE;
int CURTEMP;
 
LENCOUNT = jbig2_alloc(ctx->allocator, lencountsize);
if (LENCOUNT == NULL) {
jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1,
"couldn't allocate storage for huffman histogram");
return NULL;
}
memset(LENCOUNT, 0, lencountsize);
 
/* B.3, 1. */
for (i = 0; i < params->n_lines; i++)
{
int PREFLEN = lines[i].PREFLEN;
int lts;
 
if (PREFLEN > LENMAX)
{
for (j = LENMAX + 1; j < PREFLEN + 1; j++)
LENCOUNT[j] = 0;
LENMAX = PREFLEN;
}
LENCOUNT[PREFLEN]++;
 
lts = PREFLEN + lines[i].RANGELEN;
if (lts > LOG_TABLE_SIZE_MAX)
lts = PREFLEN;
if (lts <= LOG_TABLE_SIZE_MAX && log_table_size < lts)
log_table_size = lts;
}
jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, -1,
"constructing huffman table log size %d", log_table_size);
max_j = 1 << log_table_size;
 
result = (Jbig2HuffmanTable *)jbig2_alloc(ctx->allocator, sizeof(Jbig2HuffmanTable));
result->log_table_size = log_table_size;
entries = (Jbig2HuffmanEntry *)jbig2_alloc(ctx->allocator, max_j * sizeof(Jbig2HuffmanEntry));
result->entries = entries;
 
LENCOUNT[0] = 0;
 
for (CURLEN = 1; CURLEN <= LENMAX; CURLEN++)
{
int shift = log_table_size - CURLEN;
 
/* B.3 3.(a) */
firstcode = (firstcode + LENCOUNT[CURLEN - 1]) << 1;
CURCODE = firstcode;
/* B.3 3.(b) */
for (CURTEMP = 0; CURTEMP < n_lines; CURTEMP++)
{
int PREFLEN = lines[CURTEMP].PREFLEN;
if (PREFLEN == CURLEN)
{
int RANGELEN = lines[CURTEMP].RANGELEN;
int start_j = CURCODE << shift;
int end_j = (CURCODE + 1) << shift;
byte eflags = 0;
 
if (end_j > max_j) {
jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1,
"ran off the end of the entries table! (%d >= %d)",
end_j, max_j);
jbig2_free(ctx->allocator, result->entries);
jbig2_free(ctx->allocator, result);
jbig2_free(ctx->allocator, LENCOUNT);
return NULL;
}
/* todo: build extension tables */
if (params->HTOOB && CURTEMP == n_lines - 1)
eflags |= JBIG2_HUFFMAN_FLAGS_ISOOB;
if (CURTEMP == n_lines - (params->HTOOB ? 3 : 2))
eflags |= JBIG2_HUFFMAN_FLAGS_ISLOW;
if (PREFLEN + RANGELEN > LOG_TABLE_SIZE_MAX) {
for (j = start_j; j < end_j; j++) {
entries[j].u.RANGELOW = lines[CURTEMP].RANGELOW;
entries[j].PREFLEN = PREFLEN;
entries[j].RANGELEN = RANGELEN;
entries[j].flags = eflags;
}
} else {
for (j = start_j; j < end_j; j++) {
int32_t HTOFFSET = (j >> (shift - RANGELEN)) &
((1 << RANGELEN) - 1);
if (eflags & JBIG2_HUFFMAN_FLAGS_ISLOW)
entries[j].u.RANGELOW = lines[CURTEMP].RANGELOW -
HTOFFSET;
else
entries[j].u.RANGELOW = lines[CURTEMP].RANGELOW +
HTOFFSET;
entries[j].PREFLEN = PREFLEN + RANGELEN;
entries[j].RANGELEN = 0;
entries[j].flags = eflags;
}
}
CURCODE++;
}
}
}
 
jbig2_free(ctx->allocator, LENCOUNT);
 
return result;
}
 
/** Free the memory associated with the representation of table */
void
jbig2_release_huffman_table (Jbig2Ctx *ctx, Jbig2HuffmanTable *table)
{
if (table != NULL) {
jbig2_free(ctx->allocator, table->entries);
jbig2_free(ctx->allocator, table);
}
return;
}
 
#ifdef TEST
#include <stdio.h>
 
/* a test bitstream, and a list of the table indicies
to use in decoding it. 1 = table B.1 (A), 2 = table B.2 (B), and so on */
/* this test stream should decode to { 8, 5, oob, 8 } */
 
const byte test_stream[] = { 0xe9, 0xcb, 0xf4, 0x00 };
const byte test_tabindex[] = { 4, 2, 2, 1 };
 
static uint32_t
test_get_word (Jbig2WordStream *self, int offset)
{
/* assume test_stream[] is at least 4 bytes */
if (offset+3 > sizeof(test_stream))
return 0;
else
return ( (test_stream[offset] << 24) |
(test_stream[offset+1] << 16) |
(test_stream[offset+2] << 8) |
(test_stream[offset+3]) );
}
 
int
main (int argc, char **argv)
{
Jbig2Ctx *ctx;
Jbig2HuffmanTable *tables[5];
Jbig2HuffmanState *hs;
Jbig2WordStream ws;
bool oob;
int32_t code;
 
ctx = jbig2_ctx_new(NULL, 0, NULL, NULL, NULL);
 
tables[0] = NULL;
tables[1] = jbig2_build_huffman_table (ctx, &jbig2_huffman_params_A);
tables[2] = jbig2_build_huffman_table (ctx, &jbig2_huffman_params_B);
tables[3] = NULL;
tables[4] = jbig2_build_huffman_table (ctx, &jbig2_huffman_params_D);
ws.get_next_word = test_get_word;
hs = jbig2_huffman_new (ctx, &ws);
 
printf("testing jbig2 huffmann decoding...");
printf("\t(should be 8 5 (oob) 8)\n");
 
{
int i;
int sequence_length = sizeof(test_tabindex);
 
for (i = 0; i < sequence_length; i++) {
code = jbig2_huffman_get (hs, tables[test_tabindex[i]], &oob);
if (oob) printf("(oob) ");
else printf("%d ", code);
}
}
 
printf("\n");
 
jbig2_ctx_free(ctx);
 
return 0;
}
#endif
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libjbig2dec/jbig2_huffman.h
0,0 → 1,105
/*
jbig2dec
 
Copyright (C) 2001-2005 Artifex Software, Inc.
 
This software is distributed under license and may not
be copied, modified or distributed except as expressly
authorized under the terms of the license contained in
the file LICENSE in this distribution.
 
For further licensing information refer to http://artifex.com/ or
contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
San Rafael, CA 94903, U.S.A., +1(415)492-9861.
*/
 
#ifndef JBIG2_HUFFMAN_H
#define JBIG2_HUFFMAN_H
 
/* Huffman coder interface */
 
typedef struct _Jbig2HuffmanEntry Jbig2HuffmanEntry;
typedef struct _Jbig2HuffmanState Jbig2HuffmanState;
typedef struct _Jbig2HuffmanTable Jbig2HuffmanTable;
typedef struct _Jbig2HuffmanParams Jbig2HuffmanParams;
 
struct _Jbig2HuffmanEntry {
union {
int32_t RANGELOW;
Jbig2HuffmanTable *ext_table;
} u;
byte PREFLEN;
byte RANGELEN;
byte flags;
};
 
struct _Jbig2HuffmanTable {
int log_table_size;
Jbig2HuffmanEntry *entries;
};
 
typedef struct _Jbig2HuffmanLine Jbig2HuffmanLine;
 
struct _Jbig2HuffmanLine {
int PREFLEN;
int RANGELEN;
int RANGELOW;
};
 
struct _Jbig2HuffmanParams {
bool HTOOB;
int n_lines;
const Jbig2HuffmanLine *lines;
};
 
Jbig2HuffmanState *
jbig2_huffman_new (Jbig2Ctx *ctx, Jbig2WordStream *ws);
 
void
jbig2_huffman_free (Jbig2Ctx *ctx, Jbig2HuffmanState *hs);
 
void
jbig2_huffman_skip(Jbig2HuffmanState *hs);
 
void jbig2_huffman_advance(Jbig2HuffmanState *hs, int offset);
 
int
jbig2_huffman_offset(Jbig2HuffmanState *hs);
 
int32_t
jbig2_huffman_get (Jbig2HuffmanState *hs,
const Jbig2HuffmanTable *table, bool *oob);
 
int32_t
jbig2_huffman_get_bits (Jbig2HuffmanState *hs, const int bits);
 
#ifdef JBIG2_DEBUG
void jbig2_dump_huffman_state(Jbig2HuffmanState *hs);
void jbig2_dump_huffman_binary(Jbig2HuffmanState *hs);
#endif
 
Jbig2HuffmanTable *
jbig2_build_huffman_table (Jbig2Ctx *ctx, const Jbig2HuffmanParams *params);
 
void
jbig2_release_huffman_table (Jbig2Ctx *ctx, Jbig2HuffmanTable *table);
 
/* standard Huffman templates defined by the specification */
extern const Jbig2HuffmanParams jbig2_huffman_params_A; /* Table B.1 */
extern const Jbig2HuffmanParams jbig2_huffman_params_B; /* Table B.2 */
extern const Jbig2HuffmanParams jbig2_huffman_params_C; /* Table B.3 */
extern const Jbig2HuffmanParams jbig2_huffman_params_D; /* Table B.4 */
extern const Jbig2HuffmanParams jbig2_huffman_params_E; /* Table B.5 */
extern const Jbig2HuffmanParams jbig2_huffman_params_F; /* Table B.6 */
extern const Jbig2HuffmanParams jbig2_huffman_params_G; /* Table B.7 */
extern const Jbig2HuffmanParams jbig2_huffman_params_H; /* Table B.8 */
extern const Jbig2HuffmanParams jbig2_huffman_params_I; /* Table B.9 */
extern const Jbig2HuffmanParams jbig2_huffman_params_J; /* Table B.10 */
extern const Jbig2HuffmanParams jbig2_huffman_params_K; /* Table B.11 */
extern const Jbig2HuffmanParams jbig2_huffman_params_L; /* Table B.12 */
extern const Jbig2HuffmanParams jbig2_huffman_params_M; /* Table B.13 */
extern const Jbig2HuffmanParams jbig2_huffman_params_N; /* Table B.14 */
extern const Jbig2HuffmanParams jbig2_huffman_params_O; /* Table B.15 */
 
 
#endif /* JBIG2_HUFFMAN_H */
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libjbig2dec/jbig2_hufftab.h
0,0 → 1,335
/*
jbig2dec
 
Copyright (C) 2001-2005 Artifex Software, Inc.
 
This software is distributed under license and may not
be copied, modified or distributed except as expressly
authorized under the terms of the license contained in
the file LICENSE in this distribution.
 
For further licensing information refer to http://artifex.com/ or
contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
San Rafael, CA 94903, U.S.A., +1(415)492-9861.
*/
 
/* predefined Huffman table definitions
-- See Annex B of the JBIG2 specification */
 
#ifndef JBIG2_HUFFTAB_H
#define JBIG2_HUFFTAB_H
 
/* types are in jbig2_huffman.h, you must include that first */
 
 
/* Table B.1 */
const Jbig2HuffmanLine
jbig2_huffman_lines_A[] = {
{ 1, 4, 0 },
{ 2, 8, 16 },
{ 3, 16, 272 },
{ 0, 32, -1 }, /* low */
{ 3, 32, 65808 } /* high */
};
 
const Jbig2HuffmanParams
jbig2_huffman_params_A = { FALSE, 5, jbig2_huffman_lines_A };
 
/* Table B.2 */
const Jbig2HuffmanLine
jbig2_huffman_lines_B[] = {
{ 1, 0, 0 },
{ 2, 0, 1 },
{ 3, 0, 2 },
{ 4, 3, 3 },
{ 5, 6, 11 },
{ 0, 32, -1 }, /* low */
{ 6, 32, 75 }, /* high */
{ 6, 0, 0 }
};
 
const Jbig2HuffmanParams
jbig2_huffman_params_B = { TRUE, 8, jbig2_huffman_lines_B };
 
/* Table B.3 */
const Jbig2HuffmanLine
jbig2_huffman_lines_C[] = {
{ 8, 8, -256 },
{ 1, 0, 0 },
{ 2, 0, 1 },
{ 3, 0, 2 },
{ 4, 3, 3 },
{ 5, 6, 11 },
{ 8, 32, -257 }, /* low */
{ 7, 32, 75 }, /* high */
{ 6, 0, 0 } /* OOB */
};
 
const Jbig2HuffmanParams
jbig2_huffman_params_C = { TRUE, 9, jbig2_huffman_lines_C };
 
/* Table B.4 */
const Jbig2HuffmanLine
jbig2_huffman_lines_D[] = {
{ 1, 0, 1 },
{ 2, 0, 2 },
{ 3, 0, 3 },
{ 4, 3, 4 },
{ 5, 6, 12 },
{ 0, 32, -1 }, /* low */
{ 5, 32, 76 }, /* high */
};
 
const Jbig2HuffmanParams
jbig2_huffman_params_D = { FALSE, 7, jbig2_huffman_lines_D };
 
/* Table B.5 */
const Jbig2HuffmanLine
jbig2_huffman_lines_E[] = {
{7, 8, -255},
{1, 0, 1},
{2, 0, 2},
{3, 0, 3},
{4, 3, 4},
{5, 6, 12},
{7, 32, -256}, /* low */
{6, 32, 76} /* high */
};
 
const Jbig2HuffmanParams
jbig2_huffman_params_E = { FALSE, 8, jbig2_huffman_lines_E };
 
/* Table B.6 */
const Jbig2HuffmanLine
jbig2_huffman_lines_F[] = {
{5, 10, -2048},
{4, 9, -1024},
{4, 8, -512},
{4, 7, -256},
{5, 6, -128},
{5, 5, -64},
{4, 5, -32},
{2, 7, 0},
{3, 7, 128},
{3, 8, 256},
{4, 9, 512},
{4, 10, 1024},
{6, 32, -2049}, /* low */
{6, 32, 2048} /* high */
};
 
const Jbig2HuffmanParams
jbig2_huffman_params_F = { FALSE, 14, jbig2_huffman_lines_F };
 
/* Table B.7 */
const Jbig2HuffmanLine
jbig2_huffman_lines_G[] = {
{4, 9, -1024},
{3, 8, -512},
{4, 7, -256},
{5, 6, -128},
{5, 5, -64},
{4, 5, -32},
{4, 5, 0},
{5, 5, 32},
{5, 6, 64},
{4, 7, 128},
{3, 8, 256},
{3, 9, 512},
{3, 10, 1024},
{5, 32, -1025}, /* low */
{5, 32, 2048} /* high */
};
 
const Jbig2HuffmanParams
jbig2_huffman_params_G = { FALSE, 15, jbig2_huffman_lines_G };
 
/* Table B.8 */
const Jbig2HuffmanLine
jbig2_huffman_lines_H[] = {
{8, 3, -15},
{9, 1, -7},
{8, 1, -5},
{9, 0, -3},
{7, 0, -2},
{4, 0, -1},
{2, 1, 0},
{5, 0, 2},
{6, 0, 3},
{3, 4, 4},
{6, 1, 20},
{4, 4, 22},
{4, 5, 38},
{5, 6, 70},
{5, 7, 134},
{6, 7, 262},
{7, 8, 390},
{6, 10, 646},
{9, 32, -16}, /* low */
{9, 32, 1670}, /* high */
{2, 0, 0} /* OOB */
};
 
const Jbig2HuffmanParams
jbig2_huffman_params_H = { TRUE, 21, jbig2_huffman_lines_H };
 
/* Table B.9 */
const Jbig2HuffmanLine
jbig2_huffman_lines_I[] = {
{8, 4, -31},
{9, 2, -15},
{8, 2, -11},
{9, 1, -7},
{7, 1, -5},
{4, 1, -3},
{3, 1, -1},
{3, 1, 1},
{5, 1, 3},
{6, 1, 5},
{3, 5, 7},
{6, 2, 39},
{4, 5, 43},
{4, 6, 75},
{5, 7, 139},
{5, 8, 267},
{6, 8, 523},
{7, 9, 779},
{6, 11, 1291},
{9, 32, -32}, /* low */
{9, 32, 3339}, /* high */
{2, 0, 0} /* OOB */
};
 
const Jbig2HuffmanParams
jbig2_huffman_params_I = { TRUE, 22, jbig2_huffman_lines_I };
 
/* Table B.10 */
const Jbig2HuffmanLine
jbig2_huffman_lines_J[] = {
{7, 4, -21},
{8, 0, -5},
{7, 0, -4},
{5, 0, -3},
{2, 2, -2},
{5, 0, 2},
{6, 0, 3},
{7, 0, 4},
{8, 0, 5},
{2, 6, 6},
{5, 5, 70},
{6, 5, 102},
{6, 6, 134},
{6, 7, 198},
{6, 8, 326},
{6, 9, 582},
{6, 10, 1094},
{7, 11, 2118},
{8, 32, -22}, /* low */
{8, 32, 4166}, /* high */
{2, 0, 0} /* OOB */
};
 
const Jbig2HuffmanParams
jbig2_huffman_params_J = { TRUE, 21, jbig2_huffman_lines_J };
 
/* Table B.11 */
const Jbig2HuffmanLine
jbig2_huffman_lines_K[] = {
{1, 0, 1},
{2, 1, 2},
{4, 0, 3},
{4, 1, 5},
{5, 1, 7},
{5, 2, 9},
{6, 2, 13},
{7, 2, 17},
{7, 3, 21},
{7, 4, 29},
{7, 5, 45},
{7, 6, 77},
{7, 32, 141} /* high */
};
 
const Jbig2HuffmanParams
jbig2_huffman_params_K = { FALSE, 13, jbig2_huffman_lines_K };
 
/* Table B.12 */
const Jbig2HuffmanLine
jbig2_huffman_lines_L[] = {
{1, 0, 1},
{2, 0, 2},
{3, 1, 3},
{5, 0, 5},
{5, 1, 6},
{6, 1, 8},
{7, 0, 10},
{7, 1, 11},
{7, 2, 13},
{7, 3, 17},
{7, 4, 25},
{8, 5, 41},
{8, 32, 73}
};
 
const Jbig2HuffmanParams
jbig2_huffman_params_L = { FALSE, 13, jbig2_huffman_lines_L };
 
 
/* Table B.13 */
const Jbig2HuffmanLine
jbig2_huffman_lines_M[] = {
{1, 0, 1},
{3, 0, 2},
{4, 0, 3},
{5, 0, 4},
{4, 1, 5},
{3, 3, 7},
{6, 1, 15},
{6, 2, 17},
{6, 3, 21},
{6, 4, 29},
{6, 5, 45},
{7, 6, 77},
{7, 32, 141} /* high */
};
 
const Jbig2HuffmanParams
jbig2_huffman_params_M = { FALSE, 13, jbig2_huffman_lines_M };
 
/* Table B.14 */
const Jbig2HuffmanLine
jbig2_huffman_lines_N[] = {
{ 3, 0, -2 },
{ 3, 0, -1 },
{ 1, 0, 0 },
{ 3, 3, 1 },
{ 3, 6, 2 },
{ 0, 32, -1 }, /* low */
{ 0, 32, 3 }, /* high */
};
 
const Jbig2HuffmanParams
jbig2_huffman_params_N = { FALSE, 7, jbig2_huffman_lines_N };
 
/* Table B.15 */
const Jbig2HuffmanLine
jbig2_huffman_lines_O[] = {
{7, 4, -24},
{6, 2, -8},
{5, 1, -4},
{4, 0, -2},
{3, 0, -1},
{1, 0, 0},
{3, 0, 1},
{4, 0, 2},
{5, 1, 3},
{6, 2, 5},
{7, 4, 9},
{7, 32, -25}, /* low */
{7, 32, 25} /* high */
};
 
const Jbig2HuffmanParams
jbig2_huffman_params_O = { FALSE, 13, jbig2_huffman_lines_O };
 
#endif /* JBIG2_HUFFTAB_H */
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libjbig2dec/jbig2_image.c
0,0 → 1,313
/*
jbig2dec
 
Copyright (C) 2001-2005 Artifex Software, Inc.
 
This software is distributed under license and may not
be copied, modified or distributed except as expressly
authorized under the terms of the license contained in
the file LICENSE in this distribution.
 
For further licensing information refer to http://artifex.com/ or
contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
San Rafael, CA 94903, U.S.A., +1(415)492-9861.
*/
 
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "os_types.h"
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h> /* memcpy() */
 
#include "jbig2.h"
#include "jbig2_priv.h"
#include "jbig2_image.h"
 
 
/* allocate a Jbig2Image structure and its associated bitmap */
Jbig2Image* jbig2_image_new(Jbig2Ctx *ctx, int width, int height)
{
Jbig2Image *image;
int stride;
 
image = (Jbig2Image *)jbig2_alloc(ctx->allocator, sizeof(*image));
if (image == NULL) {
jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1,
"could not allocate image structure");
return NULL;
}
 
stride = ((width - 1) >> 3) + 1; /* generate a byte-aligned stride */
image->data = (uint8_t *)jbig2_alloc(ctx->allocator, stride*height);
if (image->data == NULL) {
jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1,
"could not allocate image data buffer! [%d bytes]\n", stride*height);
jbig2_free(ctx->allocator, image);
return NULL;
}
 
image->width = width;
image->height = height;
image->stride = stride;
image->refcount = 1;
 
return image;
}
 
/* clone an image pointer by bumping its reference count */
Jbig2Image* jbig2_image_clone(Jbig2Ctx *ctx, Jbig2Image *image)
{
image->refcount++;
return image;
}
 
/* release an image pointer, freeing it it appropriate */
void jbig2_image_release(Jbig2Ctx *ctx, Jbig2Image *image)
{
image->refcount--;
if (!image->refcount) jbig2_image_free(ctx, image);
}
 
/* free a Jbig2Image structure and its associated memory */
void jbig2_image_free(Jbig2Ctx *ctx, Jbig2Image *image)
{
jbig2_free(ctx->allocator, image->data);
jbig2_free(ctx->allocator, image);
}
 
/* resize a Jbig2Image */
Jbig2Image *jbig2_image_resize(Jbig2Ctx *ctx, Jbig2Image *image,
int width, int height)
{
if (width == image->width) {
/* use the same stride, just change the length */
image->data = jbig2_realloc(ctx->allocator,
image->data, image->stride*height);
if (image->data == NULL) {
jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1,
"could not resize image buffer!");
return NULL;
}
if (height > image->height) {
memset(image->data + image->height*image->stride,
0, (height - image->height)*image->stride);
}
image->height = height;
 
} else {
/* we must allocate a new image buffer and copy */
jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1,
"jbig2_image_resize called with a different width (NYI)");
}
 
return NULL;
}
 
/* composite one jbig2_image onto another
slow but general version */
int jbig2_image_compose_unopt(Jbig2Ctx *ctx,
Jbig2Image *dst, Jbig2Image *src,
int x, int y, Jbig2ComposeOp op)
{
int i, j;
int sw = src->width;
int sh = src->height;
int sx = 0;
int sy = 0;
 
/* clip to the dst image boundaries */
if (x < 0) { sx += -x; sw -= -x; x = 0; }
if (y < 0) { sy += -y; sh -= -y; y = 0; }
if (x + sw >= dst->width) sw = dst->width - x;
if (y + sh >= dst->height) sh = dst->height - y;
 
switch (op) {
case JBIG2_COMPOSE_OR:
for (j = 0; j < sh; j++) {
for (i = 0; i < sw; i++) {
jbig2_image_set_pixel(dst, i+x, j+y,
jbig2_image_get_pixel(src, i+sx, j+sy) |
jbig2_image_get_pixel(dst, i+x, j+y));
}
}
break;
case JBIG2_COMPOSE_AND:
for (j = 0; j < sh; j++) {
for (i = 0; i < sw; i++) {
jbig2_image_set_pixel(dst, i+x, j+y,
jbig2_image_get_pixel(src, i+sx, j+sy) &
jbig2_image_get_pixel(dst, i+x, j+y));
}
}
break;
case JBIG2_COMPOSE_XOR:
for (j = 0; j < sh; j++) {
for (i = 0; i < sw; i++) {
jbig2_image_set_pixel(dst, i+x, j+y,
jbig2_image_get_pixel(src, i+sx, j+sy) ^
jbig2_image_get_pixel(dst, i+x, j+y));
}
}
break;
case JBIG2_COMPOSE_XNOR:
for (j = 0; j < sh; j++) {
for (i = 0; i < sw; i++) {
jbig2_image_set_pixel(dst, i+x, j+y,
~(jbig2_image_get_pixel(src, i+sx, j+sy) ^
jbig2_image_get_pixel(dst, i+x, j+y)));
}
}
break;
case JBIG2_COMPOSE_REPLACE:
for (j = 0; j < sh; j++) {
for (i = 0; i < sw; i++) {
jbig2_image_set_pixel(dst, i+x, j+y,
jbig2_image_get_pixel(src, i+sx, j+sy));
}
}
break;
}
 
return 0;
}
 
/* composite one jbig2_image onto another */
int jbig2_image_compose(Jbig2Ctx *ctx, Jbig2Image *dst, Jbig2Image *src,
int x, int y, Jbig2ComposeOp op)
{
int i, j;
int w, h;
int leftbyte, rightbyte;
int shift;
uint8_t *s, *ss;
uint8_t *d, *dd;
uint8_t mask, rightmask;
 
if (op != JBIG2_COMPOSE_OR) {
/* hand off the the general routine */
return jbig2_image_compose_unopt(ctx, dst, src, x, y, op);
}
 
/* clip */
w = src->width;
h = src->height;
ss = src->data;
/* FIXME: this isn't sufficient for the < 0 cases */
if (x < 0) { w += x; x = 0; }
if (y < 0) { h += y; y = 0; }
w = (x + w < dst->width) ? w : dst->width - x;
h = (y + h < dst->height) ? h : dst->height - y;
#ifdef JBIG2_DEBUG
jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, -1,
"compositing %dx%d at (%d, %d) after clipping\n",
w, h, x, y);
#endif
 
#if 0
/* special case complete/strip replacement */
/* disabled because it's only safe to do when the destination
buffer is all-blank. */
if ((x == 0) && (w == src->width)) {
memcpy(dst->data + y*dst->stride, src->data, h*src->stride);
return 0;
}
#endif
 
leftbyte = x >> 3;
rightbyte = (x + w - 1) >> 3;
shift = x & 7;
 
/* general OR case */
s = ss;
d = dd = dst->data + y*dst->stride + leftbyte;
if (leftbyte == rightbyte) {
mask = 0x100 - (0x100 >> w);
for (j = 0; j < h; j++) {
*d |= (*s & mask) >> shift;
d += dst->stride;
s += src->stride;
}
} else if (shift == 0) {
rightmask = (w & 7) ? 0x100 - (1 << (8 - (w & 7))) : 0xFF;
for (j = 0; j < h; j++) {
for (i = leftbyte; i < rightbyte; i++)
*d++ |= *s++;
*d |= *s & rightmask;
d = (dd += dst->stride);
s = (ss += src->stride);
}
} else {
bool overlap = (((w + 7) >> 3) < ((x + w + 7) >> 3) - (x >> 3));
mask = 0x100 - (1 << shift);
if (overlap)
rightmask = (0x100 - (0x100 >> ((x + w) & 7))) >> (8 - shift);
else
rightmask = 0x100 - (0x100 >> (w & 7));
for (j = 0; j < h; j++) {
*d++ |= (*s & mask) >> shift;
for(i = leftbyte; i < rightbyte - 1; i++) {
*d |= ((*s++ & ~mask) << (8 - shift));
*d++ |= ((*s & mask) >> shift);
}
if (overlap)
*d |= (*s & rightmask) << (8 - shift);
else
*d |= ((s[0] & ~mask) << (8 - shift)) |
((s[1] & rightmask) >> shift);
d = (dd += dst->stride);
s = (ss += src->stride);
}
}
 
return 0;
}
 
 
/* initialize an image bitmap to a constant value */
void jbig2_image_clear(Jbig2Ctx *ctx, Jbig2Image *image, int value)
{
const uint8_t fill = value ? 0xFF : 0x00;
 
memset(image->data, fill, image->stride*image->height);
}
 
/* look up a pixel value in an image.
returns 0 outside the image frame for the convenience of
the template code
*/
int jbig2_image_get_pixel(Jbig2Image *image, int x, int y)
{
const int w = image->width;
const int h = image->height;
const int byte = (x >> 3) + y*image->stride;
const int bit = 7 - (x & 7);
 
if ((x < 0) || (x >= w)) return 0;
if ((y < 0) || (y >= h)) return 0;
 
return ((image->data[byte]>>bit) & 1);
}
 
/* set an individual pixel value in an image */
int jbig2_image_set_pixel(Jbig2Image *image, int x, int y, bool value)
{
const int w = image->width;
const int h = image->height;
int scratch, mask;
int bit, byte;
 
if ((x < 0) || (x >= w)) return 0;
if ((y < 0) || (y >= h)) return 0;
 
byte = (x >> 3) + y*image->stride;
bit = 7 - (x & 7);
mask = (1 << bit) ^ 0xff;
 
scratch = image->data[byte] & mask;
image->data[byte] = scratch | (value << bit);
 
return 1;
}
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libjbig2dec/jbig2_image.h
0,0 → 1,38
/*
jbig2dec
 
Copyright (C) 2001-2002 Artifex Software, Inc.
 
This software is distributed under license and may not
be copied, modified or distributed except as expressly
authorized under the terms of the license contained in
the file LICENSE in this distribution.
 
For further licensing information refer to http://artifex.com/ or
contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
San Rafael, CA 94903, U.S.A., +1(415)492-9861.
*/
 
 
#ifndef _JBIG2_IMAGE_H
#define _JBIG2_IMAGE_H
 
int jbig2_image_get_pixel(Jbig2Image *image, int x, int y);
int jbig2_image_set_pixel(Jbig2Image *image, int x, int y, int value);
 
/* routines for dumping the image data in various formats */
/* FIXME: should these be in the client instead? */
 
#include <stdio.h>
 
int jbig2_image_write_pbm_file(Jbig2Image *image, char *filename);
int jbig2_image_write_pbm(Jbig2Image *image, FILE *out);
Jbig2Image *jbig2_image_read_pbm_file(Jbig2Ctx *ctx, char *filename);
Jbig2Image *jbig2_image_read_pbm(Jbig2Ctx *ctx, FILE *in);
 
#ifdef HAVE_LIBPNG
int jbig2_image_write_png_file(Jbig2Image *image, char *filename);
int jbig2_image_write_png(Jbig2Image *image, FILE *out);
#endif
 
#endif /* _JBIG2_IMAGE_H */
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libjbig2dec/jbig2_image_pbm.c
0,0 → 1,150
/*
jbig2dec
 
Copyright (C) 2009 Artifex Software, Inc.
 
This software is distributed under license and may not
be copied, modified or distributed except as expressly
authorized under the terms of the license contained in
the file LICENSE in this distribution.
 
For further licensing information refer to http://artifex.com/ or
contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
San Rafael, CA 94903, U.S.A., +1(415)492-9861.
*/
 
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "os_types.h"
 
#include <stdio.h>
#include <ctype.h>
 
#include "jbig2.h"
#include "jbig2_image.h"
 
/* take an image structure and write it to a file in pbm format */
 
int jbig2_image_write_pbm_file(Jbig2Image *image, char *filename)
{
FILE *out;
int error;
 
if ((out = fopen(filename, "wb")) == NULL) {
fprintf(stderr, "unable to open '%s' for writing", filename);
return 1;
}
 
error = jbig2_image_write_pbm(image, out);
 
fclose(out);
return (error);
}
 
/* write out an image struct as a pbm stream to an open file pointer */
 
int jbig2_image_write_pbm(Jbig2Image *image, FILE *out)
{
/* pbm header */
fprintf(out, "P4\n%d %d\n", image->width, image->height);
 
/* pbm format pads to a byte boundary, so we can
just write out the whole data buffer
NB: this assumes minimal stride for the width */
fwrite(image->data, 1, image->height*image->stride, out);
 
/* success */
return 0;
}
 
/* take an image from a file in pbm format */
Jbig2Image *jbig2_image_read_pbm_file(Jbig2Ctx *ctx, char *filename)
{
FILE *in;
Jbig2Image *image;
 
if ((in = fopen(filename, "rb")) == NULL) {
fprintf(stderr, "unable to open '%s' for reading\n", filename);
return NULL;
}
 
image = jbig2_image_read_pbm(ctx, in);
 
fclose(in);
 
return (image);
}
 
/* FIXME: should handle multi-image files */
Jbig2Image *jbig2_image_read_pbm(Jbig2Ctx *ctx, FILE *in)
{
int i, dim[2];
int done;
Jbig2Image *image;
int c;
char buf[32];
 
/* look for 'P4' magic */
while ((c = fgetc(in)) != 'P') {
if (feof(in)) return NULL;
}
if ((c = fgetc(in)) != '4') {
fprintf(stderr, "not a binary pbm file.\n");
return NULL;
}
/* read size. we must find two decimal numbers representing
the image dimensions. 'done' will index whether we're
looking for the width or the height and 'i' will be our
array index for copying strings into our buffer */
done = 0;
i = 0;
while (done < 2) {
c = fgetc(in);
/* skip whitespace */
if (c == ' ' || c == '\t' || c == '\r' || c == '\n') continue;
/* skip comments */
if (c == '#') {
while ((c = fgetc(in)) != '\n');
continue;
}
/* report unexpected eof */
if (c == EOF) {
fprintf(stderr, "end-of-file parsing pbm header\n");
return NULL;
}
if (isdigit(c)) {
buf[i++] = c;
while (isdigit(c = fgetc(in))) {
if (i >= 32) {
fprintf(stderr, "pbm parsing error\n");
return NULL;
}
buf[i++] = c;
}
buf[i] = '\0';
if (sscanf(buf, "%d", &dim[done]) != 1) {
fprintf(stderr, "couldn't read pbm image dimensions\n");
return NULL;
}
i = 0;
done++;
}
}
/* allocate image structure */
image = jbig2_image_new(ctx, dim[0], dim[1]);
if (image == NULL) {
fprintf(stderr, "could not allocate %dx%d image for pbm file\n", dim[0], dim[1]);
return NULL;
}
/* the pbm data is byte-aligned, so we can
do a simple block read */
fread(image->data, 1, image->height*image->stride, in);
if (feof(in)) {
fprintf(stderr, "unexpected end of pbm file.\n");
jbig2_image_release(ctx, image);
return NULL;
}
/* success */
return image;
}
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libjbig2dec/jbig2_metadata.c
0,0 → 1,155
/*
jbig2dec
 
Copyright (C) 2003 Artifex Software, Inc.
 
This software is distributed under license and may not
be copied, modified or distributed except as expressly
authorized under the terms of the license contained in
the file LICENSE in this distribution.
 
For further licensing information refer to http://artifex.com/ or
contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
San Rafael, CA 94903, U.S.A., +1(415)492-9861.
*/
 
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "os_types.h"
 
#include <stdlib.h>
#include <string.h>
 
#include "jbig2.h"
#include "jbig2_priv.h"
#include "jbig2_metadata.h"
 
/* metadata key,value list object */
Jbig2Metadata *jbig2_metadata_new(Jbig2Ctx *ctx, Jbig2Encoding encoding)
{
Jbig2Metadata *md = jbig2_alloc(ctx->allocator, sizeof(Jbig2Metadata));
 
if (md != NULL) {
md->encoding = encoding;
md->entries = 0;
md->max_entries = 4;
md->keys = jbig2_alloc(ctx->allocator, md->max_entries*sizeof(char*));
md->values = jbig2_alloc(ctx->allocator, md->max_entries*sizeof(char*));
if (md->keys == NULL || md->values == NULL) {
jbig2_metadata_free(ctx, md);
md = NULL;
}
}
return md;
}
 
void jbig2_metadata_free(Jbig2Ctx *ctx, Jbig2Metadata *md)
{
int i;
 
if (md->keys) {
/* assume we own the pointers */
for (i = 0; i < md->entries; i++)
jbig2_free(ctx->allocator, md->keys[i]);
jbig2_free(ctx->allocator, md->keys);
}
if (md->values) {
for (i = 0; i < md->entries; i++)
jbig2_free(ctx->allocator, md->values[i]);
jbig2_free(ctx->allocator, md->values);
}
jbig2_free(ctx->allocator, md);
}
 
static char *jbig2_strndup(Jbig2Ctx *ctx, const char *c, const int len)
{
char *s = jbig2_alloc(ctx->allocator, len*sizeof(char));
if (s == NULL) {
jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1,
"unable to duplicate comment string");
} else {
memcpy(s, c, len);
}
return s;
}
 
int jbig2_metadata_add(Jbig2Ctx *ctx, Jbig2Metadata *md,
const char *key, const int key_length,
const char *value, const int value_length)
{
char **keys, **values;
 
/* grow the array if necessary */
if (md->entries == md->max_entries) {
md->max_entries >>= 2;
keys = jbig2_realloc(ctx->allocator, md->keys, md->max_entries);
values = jbig2_realloc(ctx->allocator, md->values, md->max_entries);
if (keys == NULL || values == NULL) {
jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1,
"unable to resize metadata structure");
return -1;
}
md->keys = keys;
md->values = values;
}
 
/* copy the passed key,value pair */
md->keys[md->entries] = jbig2_strndup(ctx, key, key_length);
md->values[md->entries] = jbig2_strndup(ctx, value, value_length);
md->entries++;
 
return 0;
}
 
 
/* decode an ascii comment segment 7.4.15.1 */
int jbig2_comment_ascii(Jbig2Ctx *ctx, Jbig2Segment *segment,
const uint8_t *segment_data)
{
char *s = (char *)(segment_data + 4);
char *end = (char *)(segment_data + segment->data_length);
Jbig2Metadata *comment;
char *key, *value;
int key_length, value_length;
 
jbig2_error(ctx, JBIG2_SEVERITY_INFO, segment->number,
"ASCII comment data");
 
comment = jbig2_metadata_new(ctx, JBIG2_ENCODING_ASCII);
if (comment == NULL) {
jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
"unable to allocate comment structure");
return -1;
}
/* loop over the segment data pulling out the key,value pairs */
while(*s && s < end) {
key_length = strlen(s) + 1;
key = s; s += key_length;
if (s >= end) goto too_short;
value_length = strlen(s) + 1;
value = s; s += value_length;
if (s >= end) goto too_short;
jbig2_metadata_add(ctx, comment, key, key_length, value, value_length);
jbig2_error(ctx, JBIG2_SEVERITY_INFO, segment->number,
"'%s'\t'%s'", key, value);
}
 
/* TODO: associate with ctx, page, or referred-to segment(s) */
segment->result = comment;
 
return 0;
 
too_short:
jbig2_metadata_free(ctx, comment);
return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
"unexpected end of comment segment");
}
 
/* decode a UCS-16 comment segement 7.4.15.2 */
int jbig2_comment_unicode(Jbig2Ctx *ctx, Jbig2Segment *segment,
const uint8_t *segment_data)
{
return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
"unhandled unicode comment segment");
}
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libjbig2dec/jbig2_metadata.h
0,0 → 1,48
/*
jbig2dec
 
Copyright (C) 2003 Artifex Software, Inc.
 
This software is distributed under license and may not
be copied, modified or distributed except as expressly
authorized under the terms of the license contained in
the file LICENSE in this distribution.
 
For further licensing information refer to http://artifex.com/ or
contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
San Rafael, CA 94903, U.S.A., +1(415)492-9861.
*/
 
 
#ifndef _JBIG2_METADATA_H
#define _JBIG2_METADATA_H
 
/* metadata from extension segments */
 
/* these bits should be moved to jbig2.h for public access */
typedef enum {
JBIG2_ENCODING_ASCII,
JBIG2_ENCODING_UCS16
} Jbig2Encoding;
 
typedef struct _Jbig2Metadata Jbig2Metadata;
 
Jbig2Metadata *jbig2_metadata_new(Jbig2Ctx *ctx, Jbig2Encoding encoding);
void jbig2_metadata_free(Jbig2Ctx *ctx, Jbig2Metadata *md);
int jbig2_metadata_add(Jbig2Ctx *ctx, Jbig2Metadata *md,
const char *key, const int key_length,
const char *value, const int value_length);
 
struct _Jbig2Metadata {
Jbig2Encoding encoding;
char **keys, **values;
int entries, max_entries;
};
 
/* these bits can go to jbig2_priv.h */
int jbig2_comment_ascii(Jbig2Ctx *ctx, Jbig2Segment *segment,
const uint8_t *segment_data);
int jbig2_comment_unicode(Jbig2Ctx *ctx, Jbig2Segment *segment,
const uint8_t *segment_data);
 
#endif /* _JBIG2_METADATA_H */
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libjbig2dec/jbig2_mmr.c
0,0 → 1,998
/*
jbig2dec
 
Copyright (C) 2001-2002 Artifex Software, Inc.
 
This software is provided AS-IS with no warranty,
either express or implied.
 
This software is distributed under license and may not
be copied, modified or distributed except as expressly
authorized under the terms of the license contained in
the file LICENSE in this distribution.
 
For further licensing information refer to http://artifex.com/ or
contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
San Rafael, CA 94903, U.S.A., +1(415)492-9861.
*/
 
/* An implementation of MMR decoding. This is based on the
implementation in Fitz, which in turn is based on the one
in Ghostscript.
*/
 
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "os_types.h"
 
#include <stddef.h>
#include <stdio.h>
#include <string.h>
 
#include "jbig2.h"
#include "jbig2_priv.h"
#include "jbig2_arith.h"
#include "jbig2_generic.h"
#include "jbig2_mmr.h"
 
typedef struct {
int width;
int height;
const byte *data;
size_t size;
int data_index;
int bit_index;
uint32_t word;
} Jbig2MmrCtx;
 
 
static void
jbig2_decode_mmr_init(Jbig2MmrCtx *mmr, int width, int height, const byte *data, size_t size)
{
int i;
uint32_t word = 0;
 
mmr->width = width;
mmr->height = height;
mmr->data = data;
mmr->size = size;
mmr->data_index = 0;
mmr->bit_index = 0;
 
for (i = 0; i < size && i < 4; i++)
word |= (data[i] << ((3 - i) << 3));
mmr->word = word;
}
 
static void
jbig2_decode_mmr_consume(Jbig2MmrCtx *mmr, int n_bits)
{
mmr->word <<= n_bits;
mmr->bit_index += n_bits;
while (mmr->bit_index >= 8) {
mmr->bit_index -= 8;
if (mmr->data_index + 4 < mmr->size)
mmr->word |= (mmr->data[mmr->data_index + 4] << mmr->bit_index);
mmr->data_index++;
}
}
 
/*
<raph> the first 2^(initialbits) entries map bit patterns to decodes
<raph> let's say initial_bits is 8 for the sake of example
<raph> and that the code is 1001
<raph> that means that entries 0x90 .. 0x9f have the entry { val, 4 }
<raph> because those are all the bytes that start with the code
<raph> and the 4 is the length of the code
... if (n_bits > initial_bits) ...
<raph> anyway, in that case, it basically points to a mini table
<raph> the n_bits is the maximum length of all codes beginning with that byte
<raph> so 2^(n_bits - initial_bits) is the size of the mini-table
<raph> peter came up with this, and it makes sense
*/
 
typedef struct {
short val;
short n_bits;
} mmr_table_node;
 
/* white decode table (runlength huffman codes) */
const mmr_table_node jbig2_mmr_white_decode[] = {
{ 256, 12 },
{ 272, 12 },
{ 29, 8 },
{ 30, 8 },
{ 45, 8 },
{ 46, 8 },
{ 22, 7 },
{ 22, 7 },
{ 23, 7 },
{ 23, 7 },
{ 47, 8 },
{ 48, 8 },
{ 13, 6 },
{ 13, 6 },
{ 13, 6 },
{ 13, 6 },
{ 20, 7 },
{ 20, 7 },
{ 33, 8 },
{ 34, 8 },
{ 35, 8 },
{ 36, 8 },
{ 37, 8 },
{ 38, 8 },
{ 19, 7 },
{ 19, 7 },
{ 31, 8 },
{ 32, 8 },
{ 1, 6 },
{ 1, 6 },
{ 1, 6 },
{ 1, 6 },
{ 12, 6 },
{ 12, 6 },
{ 12, 6 },
{ 12, 6 },
{ 53, 8 },
{ 54, 8 },
{ 26, 7 },
{ 26, 7 },
{ 39, 8 },
{ 40, 8 },
{ 41, 8 },
{ 42, 8 },
{ 43, 8 },
{ 44, 8 },
{ 21, 7 },
{ 21, 7 },
{ 28, 7 },
{ 28, 7 },
{ 61, 8 },
{ 62, 8 },
{ 63, 8 },
{ 0, 8 },
{ 320, 8 },
{ 384, 8 },
{ 10, 5 },
{ 10, 5 },
{ 10, 5 },
{ 10, 5 },
{ 10, 5 },
{ 10, 5 },
{ 10, 5 },
{ 10, 5 },
{ 11, 5 },
{ 11, 5 },
{ 11, 5 },
{ 11, 5 },
{ 11, 5 },
{ 11, 5 },
{ 11, 5 },
{ 11, 5 },
{ 27, 7 },
{ 27, 7 },
{ 59, 8 },
{ 60, 8 },
{ 288, 9 },
{ 290, 9 },
{ 18, 7 },
{ 18, 7 },
{ 24, 7 },
{ 24, 7 },
{ 49, 8 },
{ 50, 8 },
{ 51, 8 },
{ 52, 8 },
{ 25, 7 },
{ 25, 7 },
{ 55, 8 },
{ 56, 8 },
{ 57, 8 },
{ 58, 8 },
{ 192, 6 },
{ 192, 6 },
{ 192, 6 },
{ 192, 6 },
{ 1664, 6 },
{ 1664, 6 },
{ 1664, 6 },
{ 1664, 6 },
{ 448, 8 },
{ 512, 8 },
{ 292, 9 },
{ 640, 8 },
{ 576, 8 },
{ 294, 9 },
{ 296, 9 },
{ 298, 9 },
{ 300, 9 },
{ 302, 9 },
{ 256, 7 },
{ 256, 7 },
{ 2, 4 },
{ 2, 4 },
{ 2, 4 },
{ 2, 4 },
{ 2, 4 },
{ 2, 4 },
{ 2, 4 },
{ 2, 4 },
{ 2, 4 },
{ 2, 4 },
{ 2, 4 },
{ 2, 4 },
{ 2, 4 },
{ 2, 4 },
{ 2, 4 },
{ 2, 4 },
{ 3, 4 },
{ 3, 4 },
{ 3, 4 },
{ 3, 4 },
{ 3, 4 },
{ 3, 4 },
{ 3, 4 },
{ 3, 4 },
{ 3, 4 },
{ 3, 4 },
{ 3, 4 },
{ 3, 4 },
{ 3, 4 },
{ 3, 4 },
{ 3, 4 },
{ 3, 4 },
{ 128, 5 },
{ 128, 5 },
{ 128, 5 },
{ 128, 5 },
{ 128, 5 },
{ 128, 5 },
{ 128, 5 },
{ 128, 5 },
{ 8, 5 },
{ 8, 5 },
{ 8, 5 },
{ 8, 5 },
{ 8, 5 },
{ 8, 5 },
{ 8, 5 },
{ 8, 5 },
{ 9, 5 },
{ 9, 5 },
{ 9, 5 },
{ 9, 5 },
{ 9, 5 },
{ 9, 5 },
{ 9, 5 },
{ 9, 5 },
{ 16, 6 },
{ 16, 6 },
{ 16, 6 },
{ 16, 6 },
{ 17, 6 },
{ 17, 6 },
{ 17, 6 },
{ 17, 6 },
{ 4, 4 },
{ 4, 4 },
{ 4, 4 },
{ 4, 4 },
{ 4, 4 },
{ 4, 4 },
{ 4, 4 },
{ 4, 4 },
{ 4, 4 },
{ 4, 4 },
{ 4, 4 },
{ 4, 4 },
{ 4, 4 },
{ 4, 4 },
{ 4, 4 },
{ 4, 4 },
{ 5, 4 },
{ 5, 4 },
{ 5, 4 },
{ 5, 4 },
{ 5, 4 },
{ 5, 4 },
{ 5, 4 },
{ 5, 4 },
{ 5, 4 },
{ 5, 4 },
{ 5, 4 },
{ 5, 4 },
{ 5, 4 },
{ 5, 4 },
{ 5, 4 },
{ 5, 4 },
{ 14, 6 },
{ 14, 6 },
{ 14, 6 },
{ 14, 6 },
{ 15, 6 },
{ 15, 6 },
{ 15, 6 },
{ 15, 6 },
{ 64, 5 },
{ 64, 5 },
{ 64, 5 },
{ 64, 5 },
{ 64, 5 },
{ 64, 5 },
{ 64, 5 },
{ 64, 5 },
{ 6, 4 },
{ 6, 4 },
{ 6, 4 },
{ 6, 4 },
{ 6, 4 },
{ 6, 4 },
{ 6, 4 },
{ 6, 4 },
{ 6, 4 },
{ 6, 4 },
{ 6, 4 },
{ 6, 4 },
{ 6, 4 },
{ 6, 4 },
{ 6, 4 },
{ 6, 4 },
{ 7, 4 },
{ 7, 4 },
{ 7, 4 },
{ 7, 4 },
{ 7, 4 },
{ 7, 4 },
{ 7, 4 },
{ 7, 4 },
{ 7, 4 },
{ 7, 4 },
{ 7, 4 },
{ 7, 4 },
{ 7, 4 },
{ 7, 4 },
{ 7, 4 },
{ 7, 4 },
{ -2, 3 },
{ -2, 3 },
{ -1, 0 },
{ -1, 0 },
{ -1, 0 },
{ -1, 0 },
{ -1, 0 },
{ -1, 0 },
{ -1, 0 },
{ -1, 0 },
{ -1, 0 },
{ -1, 0 },
{ -1, 0 },
{ -1, 0 },
{ -1, 0 },
{ -3, 4 },
{ 1792, 3 },
{ 1792, 3 },
{ 1984, 4 },
{ 2048, 4 },
{ 2112, 4 },
{ 2176, 4 },
{ 2240, 4 },
{ 2304, 4 },
{ 1856, 3 },
{ 1856, 3 },
{ 1920, 3 },
{ 1920, 3 },
{ 2368, 4 },
{ 2432, 4 },
{ 2496, 4 },
{ 2560, 4 },
{ 1472, 1 },
{ 1536, 1 },
{ 1600, 1 },
{ 1728, 1 },
{ 704, 1 },
{ 768, 1 },
{ 832, 1 },
{ 896, 1 },
{ 960, 1 },
{ 1024, 1 },
{ 1088, 1 },
{ 1152, 1 },
{ 1216, 1 },
{ 1280, 1 },
{ 1344, 1 },
{ 1408, 1 }
};
 
/* black decode table (runlength huffman codes) */
const mmr_table_node jbig2_mmr_black_decode[] = {
{ 128, 12 },
{ 160, 13 },
{ 224, 12 },
{ 256, 12 },
{ 10, 7 },
{ 11, 7 },
{ 288, 12 },
{ 12, 7 },
{ 9, 6 },
{ 9, 6 },
{ 8, 6 },
{ 8, 6 },
{ 7, 5 },
{ 7, 5 },
{ 7, 5 },
{ 7, 5 },
{ 6, 4 },
{ 6, 4 },
{ 6, 4 },
{ 6, 4 },
{ 6, 4 },
{ 6, 4 },
{ 6, 4 },
{ 6, 4 },
{ 5, 4 },
{ 5, 4 },
{ 5, 4 },
{ 5, 4 },
{ 5, 4 },
{ 5, 4 },
{ 5, 4 },
{ 5, 4 },
{ 1, 3 },
{ 1, 3 },
{ 1, 3 },
{ 1, 3 },
{ 1, 3 },
{ 1, 3 },
{ 1, 3 },
{ 1, 3 },
{ 1, 3 },
{ 1, 3 },
{ 1, 3 },
{ 1, 3 },
{ 1, 3 },
{ 1, 3 },
{ 1, 3 },
{ 1, 3 },
{ 4, 3 },
{ 4, 3 },
{ 4, 3 },
{ 4, 3 },
{ 4, 3 },
{ 4, 3 },
{ 4, 3 },
{ 4, 3 },
{ 4, 3 },
{ 4, 3 },
{ 4, 3 },
{ 4, 3 },
{ 4, 3 },
{ 4, 3 },
{ 4, 3 },
{ 4, 3 },
{ 3, 2 },
{ 3, 2 },
{ 3, 2 },
{ 3, 2 },
{ 3, 2 },
{ 3, 2 },
{ 3, 2 },
{ 3, 2 },
{ 3, 2 },
{ 3, 2 },
{ 3, 2 },
{ 3, 2 },
{ 3, 2 },
{ 3, 2 },
{ 3, 2 },
{ 3, 2 },
{ 3, 2 },
{ 3, 2 },
{ 3, 2 },
{ 3, 2 },
{ 3, 2 },
{ 3, 2 },
{ 3, 2 },
{ 3, 2 },
{ 3, 2 },
{ 3, 2 },
{ 3, 2 },
{ 3, 2 },
{ 3, 2 },
{ 3, 2 },
{ 3, 2 },
{ 3, 2 },
{ 2, 2 },
{ 2, 2 },
{ 2, 2 },
{ 2, 2 },
{ 2, 2 },
{ 2, 2 },
{ 2, 2 },
{ 2, 2 },
{ 2, 2 },
{ 2, 2 },
{ 2, 2 },
{ 2, 2 },
{ 2, 2 },
{ 2, 2 },
{ 2, 2 },
{ 2, 2 },
{ 2, 2 },
{ 2, 2 },
{ 2, 2 },
{ 2, 2 },
{ 2, 2 },
{ 2, 2 },
{ 2, 2 },
{ 2, 2 },
{ 2, 2 },
{ 2, 2 },
{ 2, 2 },
{ 2, 2 },
{ 2, 2 },
{ 2, 2 },
{ 2, 2 },
{ 2, 2 },
{ -2, 4 },
{ -2, 4 },
{ -1, 0 },
{ -1, 0 },
{ -1, 0 },
{ -1, 0 },
{ -1, 0 },
{ -1, 0 },
{ -1, 0 },
{ -1, 0 },
{ -1, 0 },
{ -1, 0 },
{ -1, 0 },
{ -1, 0 },
{ -1, 0 },
{ -3, 5 },
{ 1792, 4 },
{ 1792, 4 },
{ 1984, 5 },
{ 2048, 5 },
{ 2112, 5 },
{ 2176, 5 },
{ 2240, 5 },
{ 2304, 5 },
{ 1856, 4 },
{ 1856, 4 },
{ 1920, 4 },
{ 1920, 4 },
{ 2368, 5 },
{ 2432, 5 },
{ 2496, 5 },
{ 2560, 5 },
{ 18, 3 },
{ 18, 3 },
{ 18, 3 },
{ 18, 3 },
{ 18, 3 },
{ 18, 3 },
{ 18, 3 },
{ 18, 3 },
{ 52, 5 },
{ 52, 5 },
{ 640, 6 },
{ 704, 6 },
{ 768, 6 },
{ 832, 6 },
{ 55, 5 },
{ 55, 5 },
{ 56, 5 },
{ 56, 5 },
{ 1280, 6 },
{ 1344, 6 },
{ 1408, 6 },
{ 1472, 6 },
{ 59, 5 },
{ 59, 5 },
{ 60, 5 },
{ 60, 5 },
{ 1536, 6 },
{ 1600, 6 },
{ 24, 4 },
{ 24, 4 },
{ 24, 4 },
{ 24, 4 },
{ 25, 4 },
{ 25, 4 },
{ 25, 4 },
{ 25, 4 },
{ 1664, 6 },
{ 1728, 6 },
{ 320, 5 },
{ 320, 5 },
{ 384, 5 },
{ 384, 5 },
{ 448, 5 },
{ 448, 5 },
{ 512, 6 },
{ 576, 6 },
{ 53, 5 },
{ 53, 5 },
{ 54, 5 },
{ 54, 5 },
{ 896, 6 },
{ 960, 6 },
{ 1024, 6 },
{ 1088, 6 },
{ 1152, 6 },
{ 1216, 6 },
{ 64, 3 },
{ 64, 3 },
{ 64, 3 },
{ 64, 3 },
{ 64, 3 },
{ 64, 3 },
{ 64, 3 },
{ 64, 3 },
{ 13, 1 },
{ 13, 1 },
{ 13, 1 },
{ 13, 1 },
{ 13, 1 },
{ 13, 1 },
{ 13, 1 },
{ 13, 1 },
{ 13, 1 },
{ 13, 1 },
{ 13, 1 },
{ 13, 1 },
{ 13, 1 },
{ 13, 1 },
{ 13, 1 },
{ 13, 1 },
{ 23, 4 },
{ 23, 4 },
{ 50, 5 },
{ 51, 5 },
{ 44, 5 },
{ 45, 5 },
{ 46, 5 },
{ 47, 5 },
{ 57, 5 },
{ 58, 5 },
{ 61, 5 },
{ 256, 5 },
{ 16, 3 },
{ 16, 3 },
{ 16, 3 },
{ 16, 3 },
{ 17, 3 },
{ 17, 3 },
{ 17, 3 },
{ 17, 3 },
{ 48, 5 },
{ 49, 5 },
{ 62, 5 },
{ 63, 5 },
{ 30, 5 },
{ 31, 5 },
{ 32, 5 },
{ 33, 5 },
{ 40, 5 },
{ 41, 5 },
{ 22, 4 },
{ 22, 4 },
{ 14, 1 },
{ 14, 1 },
{ 14, 1 },
{ 14, 1 },
{ 14, 1 },
{ 14, 1 },
{ 14, 1 },
{ 14, 1 },
{ 14, 1 },
{ 14, 1 },
{ 14, 1 },
{ 14, 1 },
{ 14, 1 },
{ 14, 1 },
{ 14, 1 },
{ 14, 1 },
{ 15, 2 },
{ 15, 2 },
{ 15, 2 },
{ 15, 2 },
{ 15, 2 },
{ 15, 2 },
{ 15, 2 },
{ 15, 2 },
{ 128, 5 },
{ 192, 5 },
{ 26, 5 },
{ 27, 5 },
{ 28, 5 },
{ 29, 5 },
{ 19, 4 },
{ 19, 4 },
{ 20, 4 },
{ 20, 4 },
{ 34, 5 },
{ 35, 5 },
{ 36, 5 },
{ 37, 5 },
{ 38, 5 },
{ 39, 5 },
{ 21, 4 },
{ 21, 4 },
{ 42, 5 },
{ 43, 5 },
{ 0, 3 },
{ 0, 3 },
{ 0, 3 },
{ 0, 3 }
};
 
#define getbit(buf, x) ( ( buf[x >> 3] >> ( 7 - (x & 7) ) ) & 1 )
 
static int
jbig2_find_changing_element(const byte *line, int x, int w)
{
int a, b;
 
if (line == 0)
return w;
 
if (x == -1) {
a = 0;
x = 0;
}
else {
a = getbit(line, x);
x ++;
}
 
while (x < w) {
b = getbit(line, x);
if (a != b)
break;
x++;
}
 
return x;
}
 
static int
jbig2_find_changing_element_of_color(const byte *line, int x, int w, int color)
{
if (line == 0)
return w;
x = jbig2_find_changing_element(line, x, w);
if (x < w && getbit(line, x) != color)
x = jbig2_find_changing_element(line, x, w);
return x;
}
 
static const byte lm[8] = { 0xFF, 0x7F, 0x3F, 0x1F, 0x0F, 0x07, 0x03, 0x01 };
static const byte rm[8] = { 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE };
 
static void
jbig2_set_bits(byte *line, int x0, int x1)
{
int a0, a1, b0, b1, a;
 
a0 = x0 >> 3;
a1 = x1 >> 3;
 
b0 = x0 & 7;
b1 = x1 & 7;
 
if (a0 == a1) {
line[a0] |= lm[b0] & rm[b1];
}
else {
line[a0] |= lm[b0];
for (a = a0 + 1; a < a1; a++)
line[a] = 0xFF;
line[a1] |= rm[b1];
}
}
 
 
static int
jbig2_decode_get_code(Jbig2MmrCtx *mmr, const mmr_table_node *table, int initial_bits)
{
uint32_t word = mmr->word;
int table_ix = word >> (32 - initial_bits);
int val = table[table_ix].val;
int n_bits = table[table_ix].n_bits;
 
if (n_bits > initial_bits) {
int mask = (1 << (32 - initial_bits)) - 1;
table_ix = val + ((word & mask) >> (32 - n_bits));
val = table[table_ix].val;
n_bits = initial_bits + table[table_ix].n_bits;
}
 
jbig2_decode_mmr_consume(mmr, n_bits);
 
return val;
}
 
static int
jbig2_decode_get_run(Jbig2MmrCtx *mmr, const mmr_table_node *table, int initial_bits)
{
int result = 0;
int val;
 
do {
val = jbig2_decode_get_code(mmr, table, initial_bits);
result += val;
} while (val >= 64);
 
return result;
}
 
static void
jbig2_decode_mmr_line(Jbig2MmrCtx *mmr, const byte *ref, byte *dst)
{
int a0, a1, a2, b1, b2;
int c;
 
a0 = -1;
c = 0; /* 0 is white, black is 1 */
 
while (1)
{
uint32_t word = mmr->word;
/* printf ("%08x\n", word); */
 
if (a0 >= mmr->width)
break;
 
if ((word >> (32 - 3)) == 1)
{
int white_run, black_run;
 
jbig2_decode_mmr_consume(mmr, 3);
 
if (a0 == -1)
a0 = 0;
 
if (c == 0) {
white_run = jbig2_decode_get_run(mmr, jbig2_mmr_white_decode, 8);
black_run = jbig2_decode_get_run(mmr, jbig2_mmr_black_decode, 7);
a1 = a0 + white_run;
a2 = a1 + black_run;
if (a1 > mmr->width) a1 = mmr->width;
if (a2 > mmr->width) a2 = mmr->width;
jbig2_set_bits(dst, a1, a2);
a0 = a2;
/* printf ("H %d %d\n", white_run, black_run); */
}
else
{
black_run = jbig2_decode_get_run(mmr, jbig2_mmr_black_decode, 7);
white_run = jbig2_decode_get_run(mmr, jbig2_mmr_white_decode, 8);
a1 = a0 + black_run;
a2 = a1 + white_run;
if (a1 > mmr->width) a1 = mmr->width;
if (a2 > mmr->width) a2 = mmr->width;
jbig2_set_bits(dst, a0, a1);
a0 = a2;
/* printf ("H %d %d\n", black_run, white_run); */
}
}
 
else if ((word >> (32 - 4)) == 1)
{
/* printf ("P\n"); */
jbig2_decode_mmr_consume(mmr, 4);
b1 = jbig2_find_changing_element_of_color(ref, a0, mmr->width, !c);
b2 = jbig2_find_changing_element(ref, b1, mmr->width);
if (c) jbig2_set_bits(dst, a0, b2);
a0 = b2;
}
 
else if ((word >> (32 - 1)) == 1)
{
/* printf ("V(0)\n"); */
jbig2_decode_mmr_consume(mmr, 1);
b1 = jbig2_find_changing_element_of_color(ref, a0, mmr->width, !c);
if (c) jbig2_set_bits(dst, a0, b1);
a0 = b1;
c = !c;
}
 
else if ((word >> (32 - 3)) == 3)
{
/* printf ("VR(1)\n"); */
jbig2_decode_mmr_consume(mmr, 3);
b1 = jbig2_find_changing_element_of_color(ref, a0, mmr->width, !c);
if (b1 + 1 > mmr->width) break;
if (c) jbig2_set_bits(dst, a0, b1 + 1);
a0 = b1 + 1;
c = !c;
}
 
else if ((word >> (32 - 6)) == 3)
{
/* printf ("VR(2)\n"); */
jbig2_decode_mmr_consume(mmr, 6);
b1 = jbig2_find_changing_element_of_color(ref, a0, mmr->width, !c);
if (b1 + 2 > mmr->width) break;
if (c) jbig2_set_bits(dst, a0, b1 + 2);
a0 = b1 + 2;
c = !c;
}
 
else if ((word >> (32 - 7)) == 3)
{
/* printf ("VR(3)\n"); */
jbig2_decode_mmr_consume(mmr, 7);
b1 = jbig2_find_changing_element_of_color(ref, a0, mmr->width, !c);
if (b1 + 3 > mmr->width) break;
if (c) jbig2_set_bits(dst, a0, b1 + 3);
a0 = b1 + 3;
c = !c;
}
 
else if ((word >> (32 - 3)) == 2)
{
/* printf ("VL(1)\n"); */
jbig2_decode_mmr_consume(mmr, 3);
b1 = jbig2_find_changing_element_of_color(ref, a0, mmr->width, !c);
if (b1 - 1 < 0) break;
if (c) jbig2_set_bits(dst, a0, b1 - 1);
a0 = b1 - 1;
c = !c;
}
 
else if ((word >> (32 - 6)) == 2)
{
/* printf ("VL(2)\n"); */
jbig2_decode_mmr_consume(mmr, 6);
b1 = jbig2_find_changing_element_of_color(ref, a0, mmr->width, !c);
if (b1 - 2 < 0) break;
if (c) jbig2_set_bits(dst, a0, b1 - 2);
a0 = b1 - 2;
c = !c;
}
 
else if ((word >> (32 - 7)) == 2)
{
/* printf ("VL(3)\n"); */
jbig2_decode_mmr_consume(mmr, 7);
b1 = jbig2_find_changing_element_of_color(ref, a0, mmr->width, !c);
if (b1 - 3 < 0) break;
if (c) jbig2_set_bits(dst, a0, b1 - 3);
a0 = b1 - 3;
c = !c;
}
 
else
break;
}
}
 
int
jbig2_decode_generic_mmr(Jbig2Ctx *ctx,
Jbig2Segment *segment,
const Jbig2GenericRegionParams *params,
const byte *data, size_t size,
Jbig2Image *image)
{
Jbig2MmrCtx mmr;
const int rowstride = image->stride;
byte *dst = image->data;
byte *ref = NULL;
int y;
 
jbig2_decode_mmr_init(&mmr, image->width, image->height, data, size);
 
for (y = 0; y < image->height; y++) {
memset(dst, 0, rowstride);
jbig2_decode_mmr_line(&mmr, ref, dst);
ref = dst;
dst += rowstride;
}
 
return 0;
}
 
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libjbig2dec/jbig2_mmr.h
0,0 → 1,22
/*
jbig2dec
 
Copyright (C) 2001 Artifex Software, Inc.
 
This software is distributed under license and may not
be copied, modified or distributed except as expressly
authorized under the terms of the license contained in
the file LICENSE in this distribution.
 
For further licensing information refer to http://artifex.com/ or
contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
San Rafael, CA 94903, U.S.A., +1(415)492-9861.
*/
 
int
jbig2_decode_generic_mmr(Jbig2Ctx *ctx,
Jbig2Segment *segment,
const Jbig2GenericRegionParams *params,
const byte *data, size_t size,
Jbig2Image *image);
 
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libjbig2dec/jbig2_page.c
0,0 → 1,327
/*
jbig2dec
 
Copyright (C) 2001-2005 Artifex Software, Inc.
 
This software is distributed under license and may not
be copied, modified or distributed except as expressly
authorized under the terms of the license contained in
the file LICENSE in this distribution.
 
For further licensing information refer to http://artifex.com/ or
contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
San Rafael, CA 94903, U.S.A., +1(415)492-9861.
*/
 
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "os_types.h"
 
#include <stdlib.h>
 
#include "jbig2.h"
#include "jbig2_priv.h"
 
#ifdef OUTPUT_PBM
#include <stdio.h>
#include "jbig2_image.h"
#endif
 
/* dump the page struct info */
static void
dump_page_info(Jbig2Ctx *ctx, Jbig2Segment *segment, Jbig2Page *page)
{
if (page->x_resolution == 0) {
jbig2_error(ctx, JBIG2_SEVERITY_INFO, segment->number,
"page %d image is %dx%d (unknown res)", page->number,
page->width, page->height);
} else if (page->x_resolution == page->y_resolution) {
jbig2_error(ctx, JBIG2_SEVERITY_INFO, segment->number,
"page %d image is %dx%d (%d ppm)", page->number,
page->width, page->height,
page->x_resolution);
} else {
jbig2_error(ctx, JBIG2_SEVERITY_INFO, segment->number,
"page %d image is %dx%d (%dx%d ppm)", page->number,
page->width, page->height,
page->x_resolution, page->y_resolution);
}
if (page->striped) {
jbig2_error(ctx, JBIG2_SEVERITY_INFO, segment->number,
"\tmaximum stripe size: %d", page->stripe_size);
}
}
 
/**
* jbig2_page_info: parse page info segment
*
* Parse the page info segment data and fill out a corresponding
* Jbig2Page struct and ready it for subsequent rendered data,
* including allocating an image buffer for the page (or the first stripe)
**/
int
jbig2_page_info (Jbig2Ctx *ctx, Jbig2Segment *segment, const uint8_t *segment_data)
{
Jbig2Page *page;
 
/* a new page info segment implies the previous page is finished */
page = &(ctx->pages[ctx->current_page]);
if ((page->number != 0) &&
((page->state == JBIG2_PAGE_NEW) || (page->state == JBIG2_PAGE_FREE))) {
page->state = JBIG2_PAGE_COMPLETE;
jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
"unexpected page info segment, marking previous page finished");
}
 
/* find a free page */
{
int index, j;
index = ctx->current_page;
while (ctx->pages[index].state != JBIG2_PAGE_FREE) {
index++;
if (index >= ctx->max_page_index) {
/* grow the list */
ctx->pages = jbig2_realloc(ctx->allocator, ctx->pages,
(ctx->max_page_index <<= 2) * sizeof(Jbig2Page));
for (j=index; j < ctx->max_page_index; j++) {
ctx->pages[j].state = JBIG2_PAGE_FREE;
ctx->pages[j].number = 0;
ctx->pages[j].image = NULL;
 
}
}
}
page = &(ctx->pages[index]);
ctx->current_page = index;
page->state = JBIG2_PAGE_NEW;
page->number = segment->page_association;
}
 
/* FIXME: would be nice if we tried to work around this */
if (segment->data_length < 19) {
return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"segment too short");
}
 
/* 7.4.8.x */
page->width = jbig2_get_int32(segment_data);
page->height = jbig2_get_int32(segment_data + 4);
 
page->x_resolution = jbig2_get_int32(segment_data + 8);
page->y_resolution = jbig2_get_int32(segment_data + 12);
page->flags = segment_data[16];
 
/* 7.4.8.6 */
{
int16_t striping = jbig2_get_int16(segment_data +17);
if (striping & 0x8000) {
page->striped = TRUE;
page->stripe_size = striping & 0x7FFF;
} else {
page->striped = FALSE;
page->stripe_size = 0; /* would page->height be better? */
}
}
if (page->height == 0xFFFFFFFF && page->striped == FALSE) {
jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
"height is unspecified but page is not markes as striped");
page->striped = TRUE;
}
page->end_row = 0;
 
if (segment->data_length > 19) {
jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
"extra data in segment");
}
 
dump_page_info(ctx, segment, page);
 
/* allocate an approprate page image buffer */
/* 7.4.8.2 */
if (page->height == 0xFFFFFFFF) {
page->image = jbig2_image_new(ctx, page->width, page->stripe_size);
} else {
page->image = jbig2_image_new(ctx, page->width, page->height);
}
if (page->image == NULL) {
return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"failed to allocate buffer for page image");
} else {
/* 8.2 (3) fill the page with the default pixel value */
jbig2_image_clear(ctx, page->image, (page->flags & 4));
jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
"allocated %dx%d page image (%d bytes)",
page->image->width, page->image->height,
page->image->stride*page->image->height);
}
 
return 0;
}
 
/**
* jbig2_end_of_stripe: parse and implement an end of stripe segment
**/
int
jbig2_end_of_stripe(Jbig2Ctx *ctx, Jbig2Segment *segment, const uint8_t *segment_data)
{
Jbig2Page page = ctx->pages[ctx->current_page];
int end_row;
 
end_row = jbig2_get_int32(segment_data);
if (end_row < page.end_row) {
jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
"end of stripe segment with non-positive end row advance"
" (new end row %d vs current end row %d)",
end_row, page.end_row);
} else {
jbig2_error(ctx, JBIG2_SEVERITY_INFO, segment->number,
"end of stripe: advancing end row to %d", end_row);
}
 
page.end_row = end_row;
 
return 0;
}
 
/**
* jbig2_complete_page: complete a page image
*
* called upon seeing an 'end of page' segment, this routine
* marks a page as completed so it can be returned.
* compositing will have already happened in the previous
* segment handlers.
**/
int
jbig2_complete_page (Jbig2Ctx *ctx)
{
 
/* check for unfinished segments */
if (ctx->segment_index != ctx->n_segments) {
Jbig2Segment *segment = ctx->segments[ctx->segment_index];
int code = 0;
/* Some versions of Xerox Workcentre generate PDF files
with the segment data length field of the last segment
set to -1. Try to cope with this here. */
if ((segment->data_length & 0xffffffff) == 0xffffffff) {
jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
"File has an invalid segment data length!"
" Trying to decode using the available data.");
segment->data_length = ctx->buf_wr_ix - ctx->buf_rd_ix;
code = jbig2_parse_segment(ctx, segment, ctx->buf + ctx->buf_rd_ix);
ctx->buf_rd_ix += segment->data_length;
ctx->segment_index++;
}
}
ctx->pages[ctx->current_page].state = JBIG2_PAGE_COMPLETE;
 
return 0;
}
 
/**
* jbig2_end_of_page: parse and implement an end of page segment
**/
int
jbig2_end_of_page(Jbig2Ctx *ctx, Jbig2Segment *segment, const uint8_t *segment_data)
{
uint32_t page_number = ctx->pages[ctx->current_page].number;
 
if (segment->page_association != page_number) {
jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
"end of page marker for page %d doesn't match current page number %d",
segment->page_association, page_number);
}
 
jbig2_error(ctx, JBIG2_SEVERITY_INFO, segment->number,
"end of page %d", page_number);
 
jbig2_complete_page(ctx);
 
#ifdef OUTPUT_PBM
jbig2_image_write_pbm(ctx->pages[ctx->current_page].image, stdout);
#endif
 
return 0;
}
 
/**
* jbig2_add_page_result: composite a decoding result onto a page
*
* this is called to add the results of segment decode (when it
* is an image) to a page image buffer
**/
int
jbig2_page_add_result(Jbig2Ctx *ctx, Jbig2Page *page, Jbig2Image *image,
int x, int y, Jbig2ComposeOp op)
{
/* grow the page to accomodate a new stripe if necessary */
if (page->striped) {
int new_height = y + image->height + page->end_row;
if (page->image->height < new_height) {
jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, -1,
"growing page buffer to %d rows "
"to accomodate new stripe", new_height);
jbig2_image_resize(ctx, page->image,
page->image->width, new_height);
}
}
 
jbig2_image_compose(ctx, page->image, image,
x, y + page->end_row, JBIG2_COMPOSE_OR);
 
return 0;
}
 
/**
* jbig2_get_page: return the next available page image buffer
*
* the client can call this at any time to check if any pages
* have been decoded. If so, it returns the first available
* one. The client should then call jbig2_release_page() when
* it no longer needs to refer to the image buffer.
*
* since this is a public routine for the library clients, we
* return an image structure pointer, even though the function
* name refers to a page; the page structure is private.
**/
Jbig2Image *jbig2_page_out(Jbig2Ctx *ctx)
{
int index;
 
/* search for a completed page */
for (index=0; index < ctx->max_page_index; index++) {
if (ctx->pages[index].state == JBIG2_PAGE_COMPLETE) {
ctx->pages[index].state = JBIG2_PAGE_RETURNED;
jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, -1,
"page %d returned to the client", ctx->pages[index].number);
return jbig2_image_clone(ctx, ctx->pages[index].image);
}
}
 
/* no pages available */
return NULL;
}
 
/**
* jbig2_release_page: tell the library a page can be freed
**/
int jbig2_release_page(Jbig2Ctx *ctx, Jbig2Image *image)
{
int index;
 
/* find the matching page struct and mark it released */
for (index = 0; index < ctx->max_page_index; index++) {
if (ctx->pages[index].image == image) {
jbig2_image_release(ctx, image);
ctx->pages[index].state = JBIG2_PAGE_RELEASED;
jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, -1,
"page %d released by the client", ctx->pages[index].number);
return 0;
}
}
 
/* no matching pages */
jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1,
"jbig2_release_page called on unknown page");
return 1;
}
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libjbig2dec/jbig2_priv.h
0,0 → 1,177
/*
jbig2dec
 
Copyright (C) 2002 Artifex Software, Inc.
 
This software is distributed under license and may not
be copied, modified or distributed except as expressly
authorized under the terms of the license contained in
the file LICENSE in this distribution.
 
For further licensing information refer to http://artifex.com/ or
contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
San Rafael, CA 94903, U.S.A., +1(415)492-9861.
*/
 
/* library internals */
 
typedef uint8_t byte;
typedef int bool;
 
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
 
#ifndef NULL
#define NULL ((void*)0)
#endif
 
typedef enum {
JBIG2_FILE_HEADER,
JBIG2_FILE_SEQUENTIAL_HEADER,
JBIG2_FILE_SEQUENTIAL_BODY,
JBIG2_FILE_RANDOM_HEADERS,
JBIG2_FILE_RANDOM_BODIES,
JBIG2_FILE_EOF
} Jbig2FileState;
 
struct _Jbig2Ctx {
Jbig2Allocator *allocator;
Jbig2Options options;
const Jbig2Ctx *global_ctx;
Jbig2ErrorCallback error_callback;
void *error_callback_data;
 
byte *buf;
size_t buf_size;
unsigned int buf_rd_ix;
unsigned int buf_wr_ix;
 
Jbig2FileState state;
 
uint8_t file_header_flags;
int32_t n_pages;
 
int n_segments_max;
Jbig2Segment **segments;
int n_segments; /* index of last segment header parsed */
int segment_index; /* index of last segment body parsed */
 
/* list of decoded pages, including the one in progress,
currently stored as a contiguous, 0-indexed array. */
int current_page;
int max_page_index;
Jbig2Page *pages;
};
 
int32_t
jbig2_get_int32 (const byte *buf);
 
int16_t
jbig2_get_int16 (const byte *buf);
 
/* dynamic memory management */
void *
jbig2_alloc (Jbig2Allocator *allocator, size_t size);
 
void
jbig2_free (Jbig2Allocator *allocator, void *p);
 
void *
jbig2_realloc (Jbig2Allocator *allocator, void *p, size_t size);
 
#define jbig2_new(ctx, t, size) ((t *)jbig2_alloc(ctx->allocator, (size) * sizeof(t)))
 
#define jbig2_renew(ctx, p, t, size) ((t *)jbig2_realloc(ctx->allocator, (p), (size) * sizeof(t)))
 
int
jbig2_error (Jbig2Ctx *ctx, Jbig2Severity severity, int32_t seg_idx,
const char *fmt, ...);
 
/* the page structure handles decoded page
results. it's allocated by a 'page info'
segement and marked complete by an 'end of page'
segment.
*/
typedef enum {
JBIG2_PAGE_FREE,
JBIG2_PAGE_NEW,
JBIG2_PAGE_COMPLETE,
JBIG2_PAGE_RETURNED,
JBIG2_PAGE_RELEASED
} Jbig2PageState;
 
struct _Jbig2Page {
Jbig2PageState state;
uint32_t number;
uint32_t height, width; /* in pixels */
uint32_t x_resolution,
y_resolution; /* in pixels per meter */
uint16_t stripe_size;
bool striped;
int end_row;
uint8_t flags;
Jbig2Image *image;
};
 
int jbig2_page_info (Jbig2Ctx *ctx, Jbig2Segment *segment, const uint8_t *segment_data);
int jbig2_end_of_stripe(Jbig2Ctx *ctx, Jbig2Segment *segment, const uint8_t *segment_data);
int jbig2_end_of_page(Jbig2Ctx *ctx, Jbig2Segment *segment, const uint8_t *segment_data);
int jbig2_extension_segment(Jbig2Ctx *ctx, Jbig2Segment *segment, const uint8_t *segment_data);
 
typedef enum {
JBIG2_COMPOSE_OR = 0,
JBIG2_COMPOSE_AND = 1,
JBIG2_COMPOSE_XOR = 2,
JBIG2_COMPOSE_XNOR = 3,
JBIG2_COMPOSE_REPLACE = 4
} Jbig2ComposeOp;
 
int jbig2_image_compose(Jbig2Ctx *ctx, Jbig2Image *dst, Jbig2Image *src, int x, int y, Jbig2ComposeOp op);
int jbig2_page_add_result(Jbig2Ctx *ctx, Jbig2Page *page, Jbig2Image *src, int x, int y, Jbig2ComposeOp op);
 
/* region segment info */
 
typedef struct {
int32_t width;
int32_t height;
int32_t x;
int32_t y;
Jbig2ComposeOp op;
uint8_t flags;
} Jbig2RegionSegmentInfo;
 
void jbig2_get_region_segment_info(Jbig2RegionSegmentInfo *info, const uint8_t *segment_data);
int jbig2_text_region(Jbig2Ctx *ctx, Jbig2Segment *segment, const uint8_t *segment_data);
 
/* 7.4 */
int jbig2_immediate_generic_region(Jbig2Ctx *ctx, Jbig2Segment *segment,
const uint8_t *segment_data);
int jbig2_refinement_region(Jbig2Ctx *ctx, Jbig2Segment *segment,
const byte *segment_data);
 
int jbig2_pattern_dictionary(Jbig2Ctx *ctx, Jbig2Segment *segment,
const byte *segment_data);
int jbig2_halftone_region(Jbig2Ctx *ctx, Jbig2Segment *segment,
const byte *segment_data);
 
 
/* The word stream design is a compromise between simplicity and
trying to amortize the number of method calls. Each ::get_next_word
invocation pulls 4 bytes from the stream, packed big-endian into a
32 bit word. The offset argument is provided as a convenience. It
begins at 0 and increments by 4 for each successive invocation. */
typedef struct _Jbig2WordStream Jbig2WordStream;
 
struct _Jbig2WordStream {
uint32_t (*get_next_word) (Jbig2WordStream *self, int offset);
};
 
Jbig2WordStream *
jbig2_word_stream_buf_new(Jbig2Ctx *ctx, const byte *data, size_t size);
 
void
jbig2_word_stream_buf_free(Jbig2Ctx *ctx, Jbig2WordStream *ws);
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libjbig2dec/jbig2_refinement.c
0,0 → 1,440
/*
jbig2dec
 
Copyright (C) 2004 Artifex Software, Inc.
 
This software is provided AS-IS with no warranty,
either express or implied.
 
This software is distributed under license and may not
be copied, modified or distributed except as expressly
authorized under the terms of the license contained in
the file LICENSE in this distribution.
 
For further licensing information refer to http://artifex.com/ or
contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
San Rafael, CA 94903, U.S.A., +1(415)492-9861.
*/
 
/**
* Generic Refinement region handlers.
**/
 
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "os_types.h"
 
#include <stddef.h>
#include <string.h> /* memcpy(), memset() */
 
#include <stdio.h>
 
#include "jbig2.h"
#include "jbig2_priv.h"
#include "jbig2_arith.h"
#include "jbig2_generic.h"
#include "jbig2_image.h"
 
static int
jbig2_decode_refinement_template0(Jbig2Ctx *ctx,
Jbig2Segment *segment,
const Jbig2RefinementRegionParams *params,
Jbig2ArithState *as,
Jbig2Image *image,
Jbig2ArithCx *GR_stats)
{
return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"refinement region template 0 NYI");
}
 
static int
jbig2_decode_refinement_template0_unopt(Jbig2Ctx *ctx,
Jbig2Segment *segment,
const Jbig2RefinementRegionParams *params,
Jbig2ArithState *as,
Jbig2Image *image,
Jbig2ArithCx *GR_stats)
{
const int GRW = image->width;
const int GRH = image->height;
const int dx = params->DX;
const int dy = params->DY;
Jbig2Image *ref = params->reference;
uint32_t CONTEXT;
int x,y;
bool bit;
 
for (y = 0; y < GRH; y++) {
for (x = 0; x < GRW; x++) {
CONTEXT = 0;
CONTEXT |= jbig2_image_get_pixel(image, x - 1, y + 0) << 0;
CONTEXT |= jbig2_image_get_pixel(image, x + 1, y - 1) << 1;
CONTEXT |= jbig2_image_get_pixel(image, x + 0, y - 1) << 2;
CONTEXT |= jbig2_image_get_pixel(image, x + params->grat[0],
y + params->grat[1]) << 3;
CONTEXT |= jbig2_image_get_pixel(ref, x-dx+1, y-dy+1) << 4;
CONTEXT |= jbig2_image_get_pixel(ref, x-dx+0, y-dy+1) << 5;
CONTEXT |= jbig2_image_get_pixel(ref, x-dx-1, y-dy+1) << 6;
CONTEXT |= jbig2_image_get_pixel(ref, x-dx+1, y-dy+0) << 7;
CONTEXT |= jbig2_image_get_pixel(ref, x-dx+0, y-dy+0) << 8;
CONTEXT |= jbig2_image_get_pixel(ref, x-dx-1, y-dy+0) << 9;
CONTEXT |= jbig2_image_get_pixel(ref, x-dx+1, y-dy-1) << 10;
CONTEXT |= jbig2_image_get_pixel(ref, x-dx+0, y-dy-1) << 11;
CONTEXT |= jbig2_image_get_pixel(ref, x-dx+params->grat[2],
y-dy+params->grat[3]) << 12;
bit = jbig2_arith_decode(as, &GR_stats[CONTEXT]);
jbig2_image_set_pixel(image, x, y, bit);
}
}
#ifdef JBIG2_DEBUG_DUMP
{
static count = 0;
char name[32];
snprintf(name, 32, "refin-%d.pbm", count);
jbig2_image_write_pbm_file(ref, name);
snprintf(name, 32, "refout-%d.pbm", count);
jbig2_image_write_pbm_file(image, name);
count++;
}
#endif
 
return 0;
}
 
 
static int
jbig2_decode_refinement_template1_unopt(Jbig2Ctx *ctx,
Jbig2Segment *segment,
const Jbig2RefinementRegionParams *params,
Jbig2ArithState *as,
Jbig2Image *image,
Jbig2ArithCx *GR_stats)
{
const int GRW = image->width;
const int GRH = image->height;
const int dx = params->DX;
const int dy = params->DY;
Jbig2Image *ref = params->reference;
uint32_t CONTEXT;
int x,y;
bool bit;
 
for (y = 0; y < GRH; y++) {
for (x = 0; x < GRW; x++) {
CONTEXT = 0;
CONTEXT |= jbig2_image_get_pixel(image, x - 1, y + 0) << 0;
CONTEXT |= jbig2_image_get_pixel(image, x + 1, y - 1) << 1;
CONTEXT |= jbig2_image_get_pixel(image, x + 0, y - 1) << 2;
CONTEXT |= jbig2_image_get_pixel(image, x - 1, y - 1) << 3;
CONTEXT |= jbig2_image_get_pixel(ref, x-dx+1, y-dy+1) << 4;
CONTEXT |= jbig2_image_get_pixel(ref, x-dx+0, y-dy+1) << 5;
CONTEXT |= jbig2_image_get_pixel(ref, x-dx+1, y-dy+0) << 6;
CONTEXT |= jbig2_image_get_pixel(ref, x-dx+0, y-dy+0) << 7;
CONTEXT |= jbig2_image_get_pixel(ref, x-dx-1, y-dy+0) << 8;
CONTEXT |= jbig2_image_get_pixel(ref, x-dx+0, y-dy-1) << 9;
bit = jbig2_arith_decode(as, &GR_stats[CONTEXT]);
jbig2_image_set_pixel(image, x, y, bit);
}
}
 
#ifdef JBIG2_DEBUG_DUMP
{
static count = 0;
char name[32];
snprintf(name, 32, "refin-%d.pbm", count);
jbig2_image_write_pbm_file(ref, name);
snprintf(name, 32, "refout-%d.pbm", count);
jbig2_image_write_pbm_file(image, name);
count++;
}
#endif
 
return 0;
}
 
static int
jbig2_decode_refinement_template1(Jbig2Ctx *ctx,
Jbig2Segment *segment,
const Jbig2RefinementRegionParams *params,
Jbig2ArithState *as,
Jbig2Image *image,
Jbig2ArithCx *GR_stats)
{
const int GRW = image->width;
const int GRH = image->height;
const int stride = image->stride;
const int refstride = params->reference->stride;
const int dy = params->DY;
byte *grreg_line = (byte *)image->data;
byte *grref_line = (byte *)params->reference->data;
int x,y;
 
for (y = 0; y < GRH; y++) {
const int padded_width = (GRW + 7) & -8;
uint32_t CONTEXT;
uint32_t refline_m1; /* previous line of the reference bitmap */
uint32_t refline_0; /* current line of the reference bitmap */
uint32_t refline_1; /* next line of the reference bitmap */
uint32_t line_m1; /* previous line of the decoded bitmap */
 
line_m1 = (y >= 1) ? grreg_line[-stride] : 0;
refline_m1 = ((y-dy) >= 1) ? grref_line[(-1-dy)*stride] << 2: 0;
refline_0 = (((y-dy) > 0) && ((y-dy) < GRH)) ? grref_line[(0-dy)*stride] << 4 : 0;
refline_1 = (y < GRH - 1) ? grref_line[(+1-dy)*stride] << 7 : 0;
CONTEXT = ((line_m1 >> 5) & 0x00e) |
((refline_1 >> 5) & 0x030) |
((refline_0 >> 5) & 0x1c0) |
((refline_m1 >> 5) & 0x200);
 
for (x = 0; x < padded_width; x += 8) {
byte result = 0;
int x_minor;
const int minor_width = GRW - x > 8 ? 8 : GRW - x;
 
if (y >= 1) {
line_m1 = (line_m1 << 8) |
(x + 8 < GRW ? grreg_line[-stride + (x >> 3) + 1] : 0);
refline_m1 = (refline_m1 << 8) |
(x + 8 < GRW ? grref_line[-refstride + (x >> 3) + 1] << 2 : 0);
}
 
refline_0 = (refline_0 << 8) |
(x + 8 < GRW ? grref_line[(x >> 3) + 1] << 4 : 0);
 
if (y < GRH - 1)
refline_1 = (refline_1 << 8) |
(x + 8 < GRW ? grref_line[+refstride + (x >> 3) + 1] << 7 : 0);
else
refline_1 = 0;
 
/* this is the speed critical inner-loop */
for (x_minor = 0; x_minor < minor_width; x_minor++) {
bool bit;
 
bit = jbig2_arith_decode(as, &GR_stats[CONTEXT]);
result |= bit << (7 - x_minor);
CONTEXT = ((CONTEXT & 0x0d6) << 1) | bit |
((line_m1 >> (9 - x_minor)) & 0x002) |
((refline_1 >> (9 - x_minor)) & 0x010) |
((refline_0 >> (9 - x_minor)) & 0x040) |
((refline_m1 >> (9 - x_minor)) & 0x200);
}
 
grreg_line[x>>3] = result;
 
}
 
grreg_line += stride;
grref_line += refstride;
 
}
 
return 0;
 
}
 
 
/**
* jbig2_decode_refinement_region: Decode a generic refinement region.
* @ctx: The context for allocation and error reporting.
* @segment: A segment reference for error reporting.
* @params: Decoding parameter set.
* @as: Arithmetic decoder state.
* @image: Where to store the decoded image.
* @GR_stats: Arithmetic stats.
*
* Decodes a generic refinement region, according to section 6.3.
* an already allocated Jbig2Image object in @image for the result.
*
* Because this API is based on an arithmetic decoding state, it is
* not suitable for MMR decoding.
*
* Return code: 0 on success.
**/
int
jbig2_decode_refinement_region(Jbig2Ctx *ctx,
Jbig2Segment *segment,
const Jbig2RefinementRegionParams *params,
Jbig2ArithState *as,
Jbig2Image *image,
Jbig2ArithCx *GR_stats)
{
{
jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
"decoding generic refinement region with offset %d,%x,\n"
" GRTEMPLATE=%d, TPGRON=%d, RA1=(%d,%d) RA2=(%d,%d)\n",
params->DX, params->DY, params->GRTEMPLATE, params->TPGRON,
params->grat[0], params->grat[1], params->grat[2], params->grat[3]);
}
if (params->TPGRON)
return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
"decode_refinement_region: typical prediction coding NYI");
if (params->GRTEMPLATE)
return jbig2_decode_refinement_template1_unopt(ctx, segment, params,
as, image, GR_stats);
else
return jbig2_decode_refinement_template0_unopt(ctx, segment, params,
as, image, GR_stats);
}
 
/**
* Find the first referred-to intermediate region segment
* with a non-NULL result for use as a reference image
*/
Jbig2Segment *
jbig2_region_find_referred(Jbig2Ctx *ctx,Jbig2Segment *segment)
{
const int nsegments = segment->referred_to_segment_count;
Jbig2Segment *rsegment;
int index;
 
for (index = 0; index < nsegments; index++) {
rsegment = jbig2_find_segment(ctx,
segment->referred_to_segments[index]);
if (rsegment == NULL) {
jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
"could not find referred to segment %d",
segment->referred_to_segments[index]);
continue;
}
switch (rsegment->flags & 63) {
case 4: /* intermediate text region */
case 20: /* intermediate halftone region */
case 36: /* intermediate generic region */
case 40: /* intermediate generic refinement region */
if (rsegment->result) return rsegment;
break;
default: /* keep looking */
break;
}
}
/* no appropriate reference was found. */
return NULL;
}
 
/**
* Handler for generic refinement region segments
*/
int
jbig2_refinement_region(Jbig2Ctx *ctx, Jbig2Segment *segment,
const byte *segment_data)
{
Jbig2RefinementRegionParams params;
Jbig2RegionSegmentInfo rsi;
int offset = 0;
byte seg_flags;
 
/* 7.4.7 */
if (segment->data_length < 18)
return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"Segment too short");
 
jbig2_get_region_segment_info(&rsi, segment_data);
jbig2_error(ctx, JBIG2_SEVERITY_INFO, segment->number,
"generic region: %d x %d @ (%d, %d), flags = %02x",
rsi.width, rsi.height, rsi.x, rsi.y, rsi.flags);
 
/* 7.4.7.2 */
seg_flags = segment_data[17];
params.GRTEMPLATE = seg_flags & 0x01;
params.TPGRON = seg_flags & 0x02 ? 1 : 0;
jbig2_error(ctx, JBIG2_SEVERITY_INFO, segment->number,
"segment flags = %02x %s%s", seg_flags,
params.GRTEMPLATE ? " GRTEMPLATE" :"",
params.TPGRON ? " TPGRON" : "" );
if (seg_flags & 0xFC)
jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
"reserved segment flag bits are non-zero");
offset += 18;
 
/* 7.4.7.3 */
if (!params.GRTEMPLATE) {
if (segment->data_length < 22)
return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"Segment too short");
params.grat[0] = segment_data[offset + 0];
params.grat[1] = segment_data[offset + 1];
params.grat[2] = segment_data[offset + 2];
params.grat[3] = segment_data[offset + 3];
jbig2_error(ctx, JBIG2_SEVERITY_INFO, segment->number,
"grat1: (%d, %d) grat2: (%d, %d)",
params.grat[0], params.grat[1],
params.grat[2], params.grat[3]);
offset += 4;
}
 
/* 7.4.7.4 - set up the reference image */
if (segment->referred_to_segment_count) {
Jbig2Segment *ref;
 
ref = jbig2_region_find_referred(ctx, segment);
if (ref == NULL)
return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"could not find reference bitmap!");
/* the reference bitmap is the result of a previous
intermediate region segment; the reference selection
rules say to use the first one available, and not to
reuse any intermediate result, so we simply clone it
and free the original to keep track of this. */
params.reference = jbig2_image_clone(ctx, ref->result);
jbig2_image_release(ctx, ref->result);
ref->result = NULL;
jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
"found reference bitmap in segment %d", ref->number);
} else {
/* the reference is just (a subset of) the page buffer */
params.reference = jbig2_image_clone(ctx,
ctx->pages[ctx->current_page].image);
/* TODO: subset the image if appropriate */
}
 
/* 7.4.7.5 */
params.DX = 0;
params.DY = 0;
{
Jbig2WordStream *ws;
Jbig2ArithState *as;
Jbig2ArithCx *GR_stats = NULL;
int stats_size;
Jbig2Image *image;
int code;
 
image = jbig2_image_new(ctx, rsi.width, rsi.height);
if (image == NULL)
return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"unable to allocate refinement image");
jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
"allocated %d x %d image buffer for region decode results",
rsi.width, rsi.height);
 
stats_size = params.GRTEMPLATE ? 1 << 10 : 1 << 13;
GR_stats = jbig2_alloc(ctx->allocator, stats_size);
memset(GR_stats, 0, stats_size);
 
ws = jbig2_word_stream_buf_new(ctx, segment_data + offset,
segment->data_length - offset);
as = jbig2_arith_new(ctx, ws);
code = jbig2_decode_refinement_region(ctx, segment, &params,
as, image, GR_stats);
 
jbig2_free(ctx->allocator, as);
jbig2_word_stream_buf_free(ctx, ws);
jbig2_free(ctx->allocator, GR_stats);
 
if ((segment->flags & 63) == 40) {
/* intermediate region. save the result for later */
segment->result = image;
} else {
/* immediate region. composite onto the page */
jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
"composing %dx%d decoded refinement region onto page at (%d, %d)",
rsi.width, rsi.height, rsi.x, rsi.y);
jbig2_page_add_result(ctx, &ctx->pages[ctx->current_page],
image, rsi.x, rsi.y, rsi.op);
jbig2_image_release(ctx, image);
}
}
 
return 0;
}
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libjbig2dec/jbig2_segment.c
0,0 → 1,295
/*
jbig2dec
 
Copyright (C) 2002-2005 Artifex Software, Inc.
 
This software is distributed under license and may not
be copied, modified or distributed except as expressly
authorized under the terms of the license contained in
the file LICENSE in this distribution.
 
For further licensing information refer to http://artifex.com/ or
contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
San Rafael, CA 94903, U.S.A., +1(415)492-9861.
*/
 
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "os_types.h"
 
#include <stddef.h> /* size_t */
 
#include "jbig2.h"
#include "jbig2_priv.h"
#include "jbig2_symbol_dict.h"
#include "jbig2_metadata.h"
 
Jbig2Segment *
jbig2_parse_segment_header (Jbig2Ctx *ctx, uint8_t *buf, size_t buf_size,
size_t *p_header_size)
{
Jbig2Segment *result;
uint8_t rtscarf;
uint32_t rtscarf_long;
uint32_t *referred_to_segments;
int referred_to_segment_count;
int referred_to_segment_size;
int pa_size;
int offset;
 
/* minimum possible size of a jbig2 segment header */
if (buf_size < 11)
return NULL;
 
result = (Jbig2Segment *)jbig2_alloc(ctx->allocator,
sizeof(Jbig2Segment));
 
/* 7.2.2 */
result->number = jbig2_get_int32(buf);
 
/* 7.2.3 */
result->flags = buf[4];
 
/* 7.2.4 referred-to segments */
rtscarf = buf[5];
if ((rtscarf & 0xe0) == 0xe0)
{
rtscarf_long = jbig2_get_int32(buf + 5);
referred_to_segment_count = rtscarf_long & 0x1fffffff;
offset = 5 + 4 + (referred_to_segment_count + 1) / 8;
}
else
{
referred_to_segment_count = (rtscarf >> 5);
offset = 5 + 1;
}
result->referred_to_segment_count = referred_to_segment_count;
 
/* we now have enough information to compute the full header length */
referred_to_segment_size = result->number <= 256 ? 1:
result->number <= 65536 ? 2 : 4; /* 7.2.5 */
pa_size = result->flags & 0x40 ? 4 : 1; /* 7.2.6 */
if (offset + referred_to_segment_count*referred_to_segment_size + pa_size + 4 > buf_size)
{
jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, result->number,
"jbig2_parse_segment_header() called with insufficient data", -1);
jbig2_free (ctx->allocator, result);
return NULL;
}
 
/* 7.2.5 */
if (referred_to_segment_count)
{
int i;
 
referred_to_segments = jbig2_alloc(ctx->allocator, referred_to_segment_count * referred_to_segment_size * sizeof(uint32_t));
 
for (i = 0; i < referred_to_segment_count; i++) {
referred_to_segments[i] =
(referred_to_segment_size == 1) ? buf[offset] :
(referred_to_segment_size == 2) ? jbig2_get_int16(buf+offset) :
jbig2_get_int32(buf + offset);
offset += referred_to_segment_size;
jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, result->number,
"segment %d refers to segment %d",
result->number, referred_to_segments[i]);
}
result->referred_to_segments = referred_to_segments;
}
else /* no referred-to segments */
{
result->referred_to_segments = NULL;
}
 
/* 7.2.6 */
if (result->flags & 0x40) {
result->page_association = jbig2_get_int32(buf + offset);
offset += 4;
} else {
result->page_association = buf[offset++];
}
jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, result->number,
"segment %d is associated with page %d",
result->number, result->page_association);
 
/* 7.2.7 */
result->data_length = jbig2_get_int32(buf + offset);
*p_header_size = offset + 4;
 
/* no body parsing results yet */
result->result = NULL;
 
return result;
}
 
void
jbig2_free_segment (Jbig2Ctx *ctx, Jbig2Segment *segment)
{
if (segment->referred_to_segments != NULL) {
jbig2_free(ctx->allocator, segment->referred_to_segments);
}
/* todo: we need either some separate fields or
a more complex result object rather than this
brittle special casing */
switch (segment->flags & 63) {
case 0: /* symbol dictionary */
if (segment->result != NULL)
jbig2_sd_release(ctx, segment->result);
break;
case 4: /* intermediate text region */
case 40: /* intermediate refinement region */
if (segment->result != NULL)
jbig2_image_release(ctx, segment->result);
break;
case 62:
if (segment->result != NULL)
jbig2_metadata_free(ctx, segment->result);
break;
default:
/* anything else is probably an undefined pointer */
break;
}
jbig2_free (ctx->allocator, segment);
}
 
/* find a segment by number */
Jbig2Segment *
jbig2_find_segment(Jbig2Ctx *ctx, uint32_t number)
{
int index, index_max = ctx->segment_index - 1;
const Jbig2Ctx *global_ctx = ctx->global_ctx;
 
/* FIXME: binary search would be better */
for (index = index_max; index >= 0; index--)
if (ctx->segments[index]->number == number)
return (ctx->segments[index]);
 
if (global_ctx)
for (index = global_ctx->segment_index - 1; index >= 0; index--)
if (global_ctx->segments[index]->number == number)
return (global_ctx->segments[index]);
 
/* didn't find a match */
return NULL;
}
 
/* parse the generic portion of a region segment data header */
void
jbig2_get_region_segment_info(Jbig2RegionSegmentInfo *info,
const uint8_t *segment_data)
{
/* 7.4.1 */
info->width = jbig2_get_int32(segment_data);
info->height = jbig2_get_int32(segment_data + 4);
info->x = jbig2_get_int32(segment_data + 8);
info->y = jbig2_get_int32(segment_data + 12);
info->flags = segment_data[16];
info->op = info->flags & 0x7;
}
 
/* dispatch code for extension segment parsing */
int jbig2_parse_extension_segment(Jbig2Ctx *ctx, Jbig2Segment *segment,
const uint8_t *segment_data)
{
uint32_t type;
bool reserved, dependent, necessary;
 
type = jbig2_get_int32(segment_data);
 
reserved = type & 0x20000000;
dependent = type & 0x40000000;
necessary = type & 0x80000000;
 
if (necessary && !reserved) {
jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
"extension segment is marked 'necessary' but not 'reservered' contrary to spec");
}
 
switch (type) {
case 0x20000000: return jbig2_comment_ascii(ctx, segment, segment_data);
case 0x20000002: return jbig2_comment_unicode(ctx, segment, segment_data);
default:
if (necessary) {
return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"unhandled necessary extension segment type 0x%08x", type);
} else {
return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
"unhandled extension segment");
}
}
 
return 0;
}
 
/* general segment parsing dispatch */
int jbig2_parse_segment (Jbig2Ctx *ctx, Jbig2Segment *segment,
const uint8_t *segment_data)
{
jbig2_error(ctx, JBIG2_SEVERITY_INFO, segment->number,
"Segment %d, flags=%x, type=%d, data_length=%d",
segment->number, segment->flags, segment->flags & 63,
segment->data_length);
switch (segment->flags & 63)
{
case 0:
return jbig2_symbol_dictionary(ctx, segment, segment_data);
case 4: /* intermediate text region */
case 6: /* immediate text region */
case 7: /* immediate lossless text region */
return jbig2_text_region(ctx, segment, segment_data);
#ifdef JBIG2_HALFTONE
case 16:
return jbig2_pattern_dictionary(ctx, segment, segment_data);
case 20: /* intermediate halftone region */
case 22: /* immediate halftone region */
case 23: /* immediate lossless halftone region */
return jbig2_halftone_region(ctx, segment, segment_data);
#else
case 16:
return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
"unhandled segment type 'pattern dictionary'");
case 20:
return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
"unhandled segment type 'intermediate halftone region'");
case 22:
return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
"unhandled segment type 'immediate halftone region'");
case 23:
return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
"unhandled segment type 'immediate lossless halftone region'");
#endif
case 36:
return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
"unhandled segment type 'intermediate generic region'");
case 38: /* immediate generic region */
case 39: /* immediate lossless generic region */
return jbig2_immediate_generic_region(ctx, segment, segment_data);
case 40: /* intermediate generic refinement region */
case 42: /* immediate generic refinement region */
case 43: /* immediate lossless generic refinement region */
return jbig2_refinement_region(ctx, segment, segment_data);
case 48:
return jbig2_page_info(ctx, segment, segment_data);
case 49:
return jbig2_end_of_page(ctx, segment, segment_data);
case 50:
return jbig2_end_of_stripe(ctx, segment, segment_data);
case 51:
ctx->state = JBIG2_FILE_EOF;
return jbig2_error(ctx, JBIG2_SEVERITY_INFO, segment->number,
"end of file");
case 52:
return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
"unhandled segment type 'profile'");
case 53:
return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
"unhandled table segment");
case 62:
return jbig2_parse_extension_segment(ctx, segment, segment_data);
default:
jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
"unknown segment type %d", segment->flags & 63);
}
return 0;
}
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libjbig2dec/jbig2_symbol_dict.c
0,0 → 1,937
/*
jbig2dec
 
Copyright (C) 2001-2005 Artifex Software, Inc.
 
This software is distributed under license and may not
be copied, modified or distributed except as expressly
authorized under the terms of the license contained in
the file LICENSE in this distribution.
 
For further licensing information refer to http://artifex.com/ or
contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
San Rafael, CA 94903, U.S.A., +1(415)492-9861.
*/
 
/* symbol dictionary segment decode and support */
 
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "os_types.h"
 
#include <stddef.h>
#include <string.h> /* memset() */
 
#include "jbig2.h"
#include "jbig2_priv.h"
#include "jbig2_arith.h"
#include "jbig2_arith_int.h"
#include "jbig2_arith_iaid.h"
#include "jbig2_huffman.h"
#include "jbig2_generic.h"
#include "jbig2_mmr.h"
#include "jbig2_symbol_dict.h"
#include "jbig2_text.h"
 
#if defined(OUTPUT_PBM) || defined(DUMP_SYMDICT)
#include <stdio.h>
#include "jbig2_image.h"
#endif
 
/* Table 13 */
typedef struct {
bool SDHUFF;
bool SDREFAGG;
int32_t SDNUMINSYMS;
Jbig2SymbolDict *SDINSYMS;
uint32_t SDNUMNEWSYMS;
uint32_t SDNUMEXSYMS;
Jbig2HuffmanTable *SDHUFFDH;
Jbig2HuffmanTable *SDHUFFDW;
Jbig2HuffmanTable *SDHUFFBMSIZE;
Jbig2HuffmanTable *SDHUFFAGGINST;
int SDTEMPLATE;
int8_t sdat[8];
bool SDRTEMPLATE;
int8_t sdrat[4];
} Jbig2SymbolDictParams;
 
 
/* Utility routines */
 
#ifdef DUMP_SYMDICT
void
jbig2_dump_symbol_dict(Jbig2Ctx *ctx, Jbig2Segment *segment)
{
Jbig2SymbolDict *dict = (Jbig2SymbolDict *)segment->result;
int index;
char filename[24];
 
if (dict == NULL) return;
jbig2_error(ctx, JBIG2_SEVERITY_INFO, segment->number,
"dumping symbol dict as %d individual png files\n", dict->n_symbols);
for (index = 0; index < dict->n_symbols; index++) {
snprintf(filename, sizeof(filename), "symbol_%02d-%04d.png",
segment->number, index);
jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
"dumping symbol %d/%d as '%s'", index, dict->n_symbols, filename);
#ifdef HAVE_LIBPNG
jbig2_image_write_png_file(dict->glyphs[index], filename);
#else
jbig2_image_write_pbm_file(dict->glyphs[index], filename);
#endif
}
}
#endif /* DUMP_SYMDICT */
 
/* return a new empty symbol dict */
Jbig2SymbolDict *
jbig2_sd_new(Jbig2Ctx *ctx, int n_symbols)
{
Jbig2SymbolDict *new = NULL;
 
new = (Jbig2SymbolDict *)jbig2_alloc(ctx->allocator,
sizeof(Jbig2SymbolDict));
if (new != NULL) {
new->glyphs = (Jbig2Image **)jbig2_alloc(ctx->allocator,
n_symbols*sizeof(Jbig2Image*));
new->n_symbols = n_symbols;
} else {
return NULL;
}
 
if (new->glyphs != NULL) {
memset(new->glyphs, 0, n_symbols*sizeof(Jbig2Image*));
} else {
jbig2_free(ctx->allocator, new);
return NULL;
}
 
return new;
}
 
/* release the memory associated with a symbol dict */
void
jbig2_sd_release(Jbig2Ctx *ctx, Jbig2SymbolDict *dict)
{
int i;
 
if (dict == NULL) return;
for (i = 0; i < dict->n_symbols; i++)
if (dict->glyphs[i]) jbig2_image_release(ctx, dict->glyphs[i]);
jbig2_free(ctx->allocator, dict->glyphs);
jbig2_free(ctx->allocator, dict);
}
 
/* get a particular glyph by index */
Jbig2Image *
jbig2_sd_glyph(Jbig2SymbolDict *dict, unsigned int id)
{
if (dict == NULL) return NULL;
return dict->glyphs[id];
}
 
/* count the number of dictionary segments referred to by the given segment */
int
jbig2_sd_count_referred(Jbig2Ctx *ctx, Jbig2Segment *segment)
{
int index;
Jbig2Segment *rsegment;
int n_dicts = 0;
 
for (index = 0; index < segment->referred_to_segment_count; index++) {
rsegment = jbig2_find_segment(ctx, segment->referred_to_segments[index]);
if (rsegment && ((rsegment->flags & 63) == 0)) n_dicts++;
}
 
return (n_dicts);
}
 
/* return an array of pointers to symbol dictionaries referred to by the given segment */
Jbig2SymbolDict **
jbig2_sd_list_referred(Jbig2Ctx *ctx, Jbig2Segment *segment)
{
int index;
Jbig2Segment *rsegment;
Jbig2SymbolDict **dicts;
int n_dicts = jbig2_sd_count_referred(ctx, segment);
int dindex = 0;
 
dicts = jbig2_alloc(ctx->allocator, sizeof(Jbig2SymbolDict *) * n_dicts);
for (index = 0; index < segment->referred_to_segment_count; index++) {
rsegment = jbig2_find_segment(ctx, segment->referred_to_segments[index]);
if (rsegment && ((rsegment->flags & 63) == 0)) {
/* add this referred to symbol dictionary */
dicts[dindex++] = (Jbig2SymbolDict *)rsegment->result;
}
}
 
if (dindex != n_dicts) {
/* should never happen */
jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"counted %d symbol dictionaries but build a list with %d.\n",
n_dicts, dindex);
}
 
return (dicts);
}
 
/* generate a new symbol dictionary by concatenating a list of
existing dictionaries */
Jbig2SymbolDict *
jbig2_sd_cat(Jbig2Ctx *ctx, int n_dicts, Jbig2SymbolDict **dicts)
{
int i,j,k, symbols;
Jbig2SymbolDict *new = NULL;
 
/* count the imported symbols and allocate a new array */
symbols = 0;
for(i = 0; i < n_dicts; i++)
symbols += dicts[i]->n_symbols;
 
/* fill a new array with cloned glyph pointers */
new = jbig2_sd_new(ctx, symbols);
if (new != NULL) {
k = 0;
for (i = 0; i < n_dicts; i++)
for (j = 0; j < dicts[i]->n_symbols; j++)
new->glyphs[k++] = jbig2_image_clone(ctx, dicts[i]->glyphs[j]);
}
 
return new;
}
 
 
/* Decoding routines */
 
/* 6.5 */
static Jbig2SymbolDict *
jbig2_decode_symbol_dict(Jbig2Ctx *ctx,
Jbig2Segment *segment,
const Jbig2SymbolDictParams *params,
const byte *data, size_t size,
Jbig2ArithCx *GB_stats,
Jbig2ArithCx *GR_stats)
{
Jbig2SymbolDict *SDNEWSYMS;
Jbig2SymbolDict *SDEXSYMS;
int32_t HCHEIGHT;
uint32_t NSYMSDECODED;
int32_t SYMWIDTH, TOTWIDTH;
uint32_t HCFIRSTSYM;
uint32_t *SDNEWSYMWIDTHS = NULL;
int SBSYMCODELEN = 0;
Jbig2WordStream *ws = NULL;
Jbig2HuffmanState *hs = NULL;
Jbig2HuffmanTable *SDHUFFRDX = NULL;
Jbig2ArithState *as = NULL;
Jbig2ArithIntCtx *IADH = NULL;
Jbig2ArithIntCtx *IADW = NULL;
Jbig2ArithIntCtx *IAEX = NULL;
Jbig2ArithIntCtx *IAAI = NULL;
Jbig2ArithIaidCtx *IAID = NULL;
Jbig2ArithIntCtx *IARDX = NULL;
Jbig2ArithIntCtx *IARDY = NULL;
int code = 0;
Jbig2SymbolDict **refagg_dicts;
int n_refagg_dicts = 1;
 
Jbig2TextRegionParams *tparams = NULL;
 
/* 6.5.5 (3) */
HCHEIGHT = 0;
NSYMSDECODED = 0;
 
ws = jbig2_word_stream_buf_new(ctx, data, size);
 
if (!params->SDHUFF) {
as = jbig2_arith_new(ctx, ws);
IADH = jbig2_arith_int_ctx_new(ctx);
IADW = jbig2_arith_int_ctx_new(ctx);
IAEX = jbig2_arith_int_ctx_new(ctx);
IAAI = jbig2_arith_int_ctx_new(ctx);
if (params->SDREFAGG) {
int tmp = params->SDINSYMS->n_symbols + params->SDNUMNEWSYMS;
for (SBSYMCODELEN = 0; (1 << SBSYMCODELEN) < tmp; SBSYMCODELEN++);
IAID = jbig2_arith_iaid_ctx_new(ctx, SBSYMCODELEN);
IARDX = jbig2_arith_int_ctx_new(ctx);
IARDY = jbig2_arith_int_ctx_new(ctx);
}
} else {
jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
"huffman coded symbol dictionary");
hs = jbig2_huffman_new(ctx, ws);
SDHUFFRDX = jbig2_build_huffman_table(ctx,
&jbig2_huffman_params_O);
if (!params->SDREFAGG) {
SDNEWSYMWIDTHS = jbig2_alloc(ctx->allocator,
sizeof(*SDNEWSYMWIDTHS)*params->SDNUMNEWSYMS);
if (SDNEWSYMWIDTHS == NULL) {
jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"could not allocate storage for symbol widths");
return NULL;
}
}
}
 
SDNEWSYMS = jbig2_sd_new(ctx, params->SDNUMNEWSYMS);
 
/* 6.5.5 (4a) */
while (NSYMSDECODED < params->SDNUMNEWSYMS) {
int32_t HCDH, DW;
 
/* 6.5.6 */
if (params->SDHUFF) {
HCDH = jbig2_huffman_get(hs, params->SDHUFFDH, &code);
} else {
code = jbig2_arith_int_decode(IADH, as, &HCDH);
}
 
if (code != 0) {
jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
"error or OOB decoding height class delta (%d)\n", code);
}
 
/* 6.5.5 (4b) */
HCHEIGHT = HCHEIGHT + HCDH;
SYMWIDTH = 0;
TOTWIDTH = 0;
HCFIRSTSYM = NSYMSDECODED;
 
if (HCHEIGHT < 0) {
/* todo: mem cleanup */
code = jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"Invalid HCHEIGHT value");
return NULL;
}
#ifdef JBIG2_DEBUG
jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
"HCHEIGHT = %d", HCHEIGHT);
#endif
jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
"decoding height class %d with %d syms decoded", HCHEIGHT, NSYMSDECODED);
 
for (;;) {
/* check for broken symbol table */
if (NSYMSDECODED > params->SDNUMNEWSYMS)
{
/* todo: mem cleanup? */
jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
"No OOB signalling end of height class %d", HCHEIGHT);
break;
}
/* 6.5.7 */
if (params->SDHUFF) {
DW = jbig2_huffman_get(hs, params->SDHUFFDW, &code);
} else {
code = jbig2_arith_int_decode(IADW, as, &DW);
}
 
/* 6.5.5 (4c.i) */
if (code == 1) {
jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
" OOB signals end of height class %d", HCHEIGHT);
break;
}
SYMWIDTH = SYMWIDTH + DW;
TOTWIDTH = TOTWIDTH + SYMWIDTH;
if (SYMWIDTH < 0) {
/* todo: mem cleanup */
code = jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"Invalid SYMWIDTH value (%d) at symbol %d", SYMWIDTH, NSYMSDECODED+1);
return NULL;
}
#ifdef JBIG2_DEBUG
jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
"SYMWIDTH = %d TOTWIDTH = %d", SYMWIDTH, TOTWIDTH);
#endif
/* 6.5.5 (4c.ii) */
if (!params->SDHUFF || params->SDREFAGG) {
#ifdef JBIG2_DEBUG
jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
"SDHUFF = %d; SDREFAGG = %d", params->SDHUFF, params->SDREFAGG);
#endif
/* 6.5.8 */
if (!params->SDREFAGG) {
Jbig2GenericRegionParams region_params;
int sdat_bytes;
Jbig2Image *image;
 
/* Table 16 */
region_params.MMR = 0;
region_params.GBTEMPLATE = params->SDTEMPLATE;
region_params.TPGDON = 0;
region_params.USESKIP = 0;
sdat_bytes = params->SDTEMPLATE == 0 ? 8 : 2;
memcpy(region_params.gbat, params->sdat, sdat_bytes);
 
image = jbig2_image_new(ctx, SYMWIDTH, HCHEIGHT);
 
code = jbig2_decode_generic_region(ctx, segment, &region_params,
as, image, GB_stats);
/* todo: handle errors */
 
SDNEWSYMS->glyphs[NSYMSDECODED] = image;
 
} else {
/* 6.5.8.2 refinement/aggregate symbol */
uint32_t REFAGGNINST;
 
if (params->SDHUFF) {
REFAGGNINST = jbig2_huffman_get(hs, params->SDHUFFAGGINST, &code);
} else {
code = jbig2_arith_int_decode(IAAI, as, (int32_t*)&REFAGGNINST);
}
if (code || (int32_t)REFAGGNINST <= 0) {
code = jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"invalid number of symbols or OOB in aggregate glyph");
return NULL;
}
 
jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
"aggregate symbol coding (%d instances)", REFAGGNINST);
 
if (REFAGGNINST > 1) {
Jbig2Image *image;
int i;
 
if (tparams == NULL)
{
/* First time through, we need to initialise the */
/* various tables for Huffman or adaptive encoding */
/* as well as the text region parameters structure */
refagg_dicts = jbig2_alloc(ctx->allocator, sizeof(Jbig2SymbolDict *) * n_refagg_dicts);
if (refagg_dicts == NULL) {
code = jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"Out of memory allocating dictionary array");
return NULL;
}
refagg_dicts[0] = jbig2_sd_new(ctx, params->SDNUMINSYMS + params->SDNUMNEWSYMS);
if (refagg_dicts[0] == NULL) {
code = jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"Out of memory allocating symbol dictionary");
jbig2_free(ctx->allocator, refagg_dicts);
return NULL;
}
refagg_dicts[0]->n_symbols = params->SDNUMINSYMS + params->SDNUMNEWSYMS;
for (i=0;i < params->SDNUMINSYMS;i++)
{
refagg_dicts[0]->glyphs[i] = jbig2_image_clone(ctx, params->SDINSYMS->glyphs[i]);
}
 
tparams = jbig2_alloc(ctx->allocator, sizeof(Jbig2TextRegionParams));
if (tparams == NULL) {
code = jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"Out of memory creating text region params");
jbig2_sd_release(ctx, refagg_dicts[0]);
jbig2_free(ctx->allocator, refagg_dicts);
return NULL;
}
if (!params->SDHUFF) {
/* Values from Table 17, section 6.5.8.2 (2) */
tparams->IADT = jbig2_arith_int_ctx_new(ctx);
tparams->IAFS = jbig2_arith_int_ctx_new(ctx);
tparams->IADS = jbig2_arith_int_ctx_new(ctx);
tparams->IAIT = jbig2_arith_int_ctx_new(ctx);
/* Table 31 */
for (SBSYMCODELEN = 0; (1 << SBSYMCODELEN) <
(int)(params->SDNUMINSYMS + params->SDNUMNEWSYMS); SBSYMCODELEN++);
tparams->IAID = jbig2_arith_iaid_ctx_new(ctx, SBSYMCODELEN);
tparams->IARI = jbig2_arith_int_ctx_new(ctx);
tparams->IARDW = jbig2_arith_int_ctx_new(ctx);
tparams->IARDH = jbig2_arith_int_ctx_new(ctx);
tparams->IARDX = jbig2_arith_int_ctx_new(ctx);
tparams->IARDY = jbig2_arith_int_ctx_new(ctx);
} else {
tparams->SBHUFFFS = jbig2_build_huffman_table(ctx,
&jbig2_huffman_params_F); /* Table B.6 */
tparams->SBHUFFDS = jbig2_build_huffman_table(ctx,
&jbig2_huffman_params_H); /* Table B.8 */
tparams->SBHUFFDT = jbig2_build_huffman_table(ctx,
&jbig2_huffman_params_K); /* Table B.11 */
tparams->SBHUFFRDW = jbig2_build_huffman_table(ctx,
&jbig2_huffman_params_O); /* Table B.15 */
tparams->SBHUFFRDH = jbig2_build_huffman_table(ctx,
&jbig2_huffman_params_O); /* Table B.15 */
tparams->SBHUFFRDX = jbig2_build_huffman_table(ctx,
&jbig2_huffman_params_O); /* Table B.15 */
tparams->SBHUFFRDY = jbig2_build_huffman_table(ctx,
&jbig2_huffman_params_O); /* Table B.15 */
}
tparams->SBHUFF = params->SDHUFF;
tparams->SBREFINE = 1;
tparams->SBSTRIPS = 1;
tparams->SBDEFPIXEL = 0;
tparams->SBCOMBOP = JBIG2_COMPOSE_OR;
tparams->TRANSPOSED = 0;
tparams->REFCORNER = JBIG2_CORNER_TOPLEFT;
tparams->SBDSOFFSET = 0;
tparams->SBRTEMPLATE = params->SDRTEMPLATE;
}
tparams->SBNUMINSTANCES = REFAGGNINST;
 
image = jbig2_image_new(ctx, SYMWIDTH, HCHEIGHT);
if (image == NULL) {
code = jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"Out of memory creating symbol image");
jbig2_free(ctx->allocator, tparams);
jbig2_sd_release(ctx, refagg_dicts[0]);
jbig2_free(ctx->allocator, refagg_dicts);
return NULL;
}
 
/* multiple symbols are handled as a text region */
jbig2_decode_text_region(ctx, segment, tparams, (const Jbig2SymbolDict * const *)refagg_dicts,
n_refagg_dicts, image, data, size, GR_stats, as, (Jbig2WordStream *)NULL);
 
SDNEWSYMS->glyphs[NSYMSDECODED] = image;
refagg_dicts[0]->glyphs[params->SDNUMINSYMS + NSYMSDECODED] = jbig2_image_clone(ctx, SDNEWSYMS->glyphs[NSYMSDECODED]);
} else {
/* 6.5.8.2.2 */
/* bool SBHUFF = params->SDHUFF; */
Jbig2RefinementRegionParams rparams;
Jbig2Image *image;
uint32_t ID;
int32_t RDX, RDY;
int ninsyms = params->SDINSYMS->n_symbols;
 
if (params->SDHUFF) {
ID = jbig2_huffman_get_bits(hs, SBSYMCODELEN);
RDX = jbig2_huffman_get(hs, SDHUFFRDX, &code);
RDY = jbig2_huffman_get(hs, SDHUFFRDX, &code);
} else {
code = jbig2_arith_iaid_decode(IAID, as, (int32_t*)&ID);
code = jbig2_arith_int_decode(IARDX, as, &RDX);
code = jbig2_arith_int_decode(IARDY, as, &RDY);
}
 
if (ID >= ninsyms+NSYMSDECODED) {
code = jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"refinement references unknown symbol %d", ID);
return NULL;
}
 
jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
"symbol is a refinement of id %d with the refinement applied at (%d,%d)",
ID, RDX, RDY);
 
image = jbig2_image_new(ctx, SYMWIDTH, HCHEIGHT);
 
/* Table 18 */
rparams.GRTEMPLATE = params->SDRTEMPLATE;
rparams.reference = (ID < ninsyms) ?
params->SDINSYMS->glyphs[ID] :
SDNEWSYMS->glyphs[ID-ninsyms];
rparams.DX = RDX;
rparams.DY = RDY;
rparams.TPGRON = 0;
memcpy(rparams.grat, params->sdrat, 4);
jbig2_decode_refinement_region(ctx, segment,
&rparams, as, image, GR_stats);
 
SDNEWSYMS->glyphs[NSYMSDECODED] = image;
 
}
}
 
#ifdef OUTPUT_PBM
{
char name[64];
FILE *out;
snprintf(name, 64, "sd.%04d.%04d.pbm",
segment->number, NSYMSDECODED);
out = fopen(name, "wb");
jbig2_image_write_pbm(SDNEWSYMS->glyphs[NSYMSDECODED], out);
jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
"writing out glyph as '%s' ...", name);
fclose(out);
}
#endif
 
}
 
/* 6.5.5 (4c.iii) */
if (params->SDHUFF && !params->SDREFAGG) {
SDNEWSYMWIDTHS[NSYMSDECODED] = SYMWIDTH;
}
 
jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
"decoded symbol %d of %d (%dx%d)",
NSYMSDECODED, params->SDNUMNEWSYMS,
SYMWIDTH, HCHEIGHT);
 
/* 6.5.5 (4c.iv) */
NSYMSDECODED = NSYMSDECODED + 1;
 
} /* end height class decode loop */
 
/* 6.5.5 (4d) */
if (params->SDHUFF && !params->SDREFAGG) {
/* 6.5.9 */
Jbig2Image *image;
int BMSIZE = jbig2_huffman_get(hs, params->SDHUFFBMSIZE, &code);
int j, x;
 
if (code || (BMSIZE < 0)) {
jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"error decoding size of collective bitmap!");
/* todo: memory cleanup */
return NULL;
}
 
/* skip any bits before the next byte boundary */
jbig2_huffman_skip(hs);
 
image = jbig2_image_new(ctx, TOTWIDTH, HCHEIGHT);
if (image == NULL) {
jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"could not allocate collective bitmap image!");
/* todo: memory cleanup */
return NULL;
}
 
if (BMSIZE == 0) {
/* if BMSIZE == 0 bitmap is uncompressed */
const byte *src = data + jbig2_huffman_offset(hs);
const int stride = (image->width >> 3) +
((image->width & 7) ? 1 : 0);
byte *dst = image->data;
 
BMSIZE = image->height * stride;
jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
"reading %dx%d uncompressed bitmap"
" for %d symbols (%d bytes)",
image->width, image->height, NSYMSDECODED - HCFIRSTSYM, BMSIZE);
 
for (j = 0; j < image->height; j++) {
memcpy(dst, src, stride);
dst += image->stride;
src += stride;
}
} else {
Jbig2GenericRegionParams rparams;
 
jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
"reading %dx%d collective bitmap for %d symbols (%d bytes)",
image->width, image->height, NSYMSDECODED - HCFIRSTSYM, BMSIZE);
 
rparams.MMR = 1;
code = jbig2_decode_generic_mmr(ctx, segment, &rparams,
data + jbig2_huffman_offset(hs), BMSIZE, image);
if (code) {
jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"error decoding MMR bitmap image!");
/* todo: memory cleanup */
return NULL;
}
}
 
/* advance past the data we've just read */
jbig2_huffman_advance(hs, BMSIZE);
 
/* copy the collective bitmap into the symbol dictionary */
x = 0;
for (j = HCFIRSTSYM; j < NSYMSDECODED; j++) {
Jbig2Image *glyph;
glyph = jbig2_image_new(ctx, SDNEWSYMWIDTHS[j], HCHEIGHT);
jbig2_image_compose(ctx, glyph, image,
-x, 0, JBIG2_COMPOSE_REPLACE);
x += SDNEWSYMWIDTHS[j];
SDNEWSYMS->glyphs[j] = glyph;
}
jbig2_image_release(ctx, image);
}
 
} /* end of symbol decode loop */
 
if (tparams != NULL)
{
if (!params->SDHUFF)
{
jbig2_arith_int_ctx_free(ctx, tparams->IADT);
jbig2_arith_int_ctx_free(ctx, tparams->IAFS);
jbig2_arith_int_ctx_free(ctx, tparams->IADS);
jbig2_arith_int_ctx_free(ctx, tparams->IAIT);
jbig2_arith_iaid_ctx_free(ctx, tparams->IAID);
jbig2_arith_int_ctx_free(ctx, tparams->IARI);
jbig2_arith_int_ctx_free(ctx, tparams->IARDW);
jbig2_arith_int_ctx_free(ctx, tparams->IARDH);
jbig2_arith_int_ctx_free(ctx, tparams->IARDX);
jbig2_arith_int_ctx_free(ctx, tparams->IARDY);
}
else
{
jbig2_release_huffman_table(ctx, tparams->SBHUFFFS);
jbig2_release_huffman_table(ctx, tparams->SBHUFFDS);
jbig2_release_huffman_table(ctx, tparams->SBHUFFDT);
jbig2_release_huffman_table(ctx, tparams->SBHUFFRDX);
jbig2_release_huffman_table(ctx, tparams->SBHUFFRDY);
jbig2_release_huffman_table(ctx, tparams->SBHUFFRDW);
jbig2_release_huffman_table(ctx, tparams->SBHUFFRDH);
}
jbig2_free(ctx->allocator, tparams);
tparams = NULL;
jbig2_sd_release(ctx, refagg_dicts[0]);
jbig2_free(ctx->allocator, refagg_dicts);
}
 
jbig2_free(ctx->allocator, GB_stats);
 
/* 6.5.10 */
SDEXSYMS = jbig2_sd_new(ctx, params->SDNUMEXSYMS);
{
int i = 0;
int j = 0;
int k, m, exflag = 0;
int32_t exrunlength;
 
if (params->SDINSYMS != NULL)
m = params->SDINSYMS->n_symbols;
else
m = 0;
while (j < params->SDNUMEXSYMS) {
if (params->SDHUFF)
/* FIXME: implement reading from huff table B.1 */
exrunlength = params->SDNUMEXSYMS;
else
code = jbig2_arith_int_decode(IAEX, as, &exrunlength);
if (exrunlength > params->SDNUMEXSYMS - j) {
jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"runlength too large in export symbol table (%d > %d - %d)\n",
exrunlength, params->SDNUMEXSYMS, j);
jbig2_sd_release(ctx, SDEXSYMS);
/* skip to the cleanup code and return SDEXSYMS = NULL */
SDEXSYMS = NULL;
break;
}
for(k = 0; k < exrunlength; k++)
if (exflag) {
SDEXSYMS->glyphs[j++] = (i < m) ?
jbig2_image_clone(ctx, params->SDINSYMS->glyphs[i]) :
jbig2_image_clone(ctx, SDNEWSYMS->glyphs[i-m]);
i++;
}
exflag = !exflag;
}
}
 
jbig2_sd_release(ctx, SDNEWSYMS);
 
if (!params->SDHUFF) {
jbig2_arith_int_ctx_free(ctx, IADH);
jbig2_arith_int_ctx_free(ctx, IADW);
jbig2_arith_int_ctx_free(ctx, IAEX);
jbig2_arith_int_ctx_free(ctx, IAAI);
if (params->SDREFAGG) {
jbig2_arith_iaid_ctx_free(ctx, IAID);
jbig2_arith_int_ctx_free(ctx, IARDX);
jbig2_arith_int_ctx_free(ctx, IARDY);
}
jbig2_free(ctx->allocator, as);
} else {
if (params->SDREFAGG) {
jbig2_free(ctx->allocator, SDNEWSYMWIDTHS);
}
jbig2_release_huffman_table(ctx, SDHUFFRDX);
jbig2_free(ctx->allocator, hs);
}
 
jbig2_word_stream_buf_free(ctx, ws);
 
return SDEXSYMS;
}
 
/* 7.4.2 */
int
jbig2_symbol_dictionary(Jbig2Ctx *ctx, Jbig2Segment *segment,
const byte *segment_data)
{
Jbig2SymbolDictParams params;
uint16_t flags;
int sdat_bytes;
int offset;
Jbig2ArithCx *GB_stats = NULL;
Jbig2ArithCx *GR_stats = NULL;
 
if (segment->data_length < 10)
goto too_short;
 
/* 7.4.2.1.1 */
flags = jbig2_get_int16(segment_data);
params.SDHUFF = flags & 1;
params.SDREFAGG = (flags >> 1) & 1;
params.SDTEMPLATE = (flags >> 10) & 3;
params.SDRTEMPLATE = (flags >> 12) & 1;
 
params.SDHUFFDH = NULL;
params.SDHUFFDW = NULL;
params.SDHUFFBMSIZE = NULL;
params.SDHUFFAGGINST = NULL;
 
if (params.SDHUFF) {
switch ((flags & 0x000c) >> 2) {
case 0: /* Table B.4 */
params.SDHUFFDH = jbig2_build_huffman_table(ctx,
&jbig2_huffman_params_D);
break;
case 1: /* Table B.5 */
params.SDHUFFDH = jbig2_build_huffman_table(ctx,
&jbig2_huffman_params_E);
break;
case 3: /* Custom table from referred segment */
/* We handle this case later by leaving the table as NULL */
return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"symbol dictionary uses custom DH huffman table (NYI)");
case 2:
default:
return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"symbol dictionary specified invalid huffman table");
break;
}
switch ((flags & 0x0030) >> 4) {
case 0: /* Table B.2 */
params.SDHUFFDW = jbig2_build_huffman_table(ctx,
&jbig2_huffman_params_B);
break;
case 1: /* Table B.3 */
params.SDHUFFDW = jbig2_build_huffman_table(ctx,
&jbig2_huffman_params_C);
break;
case 3: /* Custom table from referred segment */
/* We handle this case later by leaving the table as NULL */
return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"symbol dictionary uses custom DW huffman table (NYI)");
case 2:
default:
return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"symbol dictionary specified invalid huffman table");
break;
}
if (flags & 0x0040) {
/* Custom table from referred segment */
return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"symbol dictionary uses custom BMSIZE huffman table (NYI)");
} else {
/* Table B.1 */
params.SDHUFFBMSIZE = jbig2_build_huffman_table(ctx,
&jbig2_huffman_params_A);
}
if (flags & 0x0080) {
/* Custom table from referred segment */
return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"symbol dictionary uses custom REFAGG huffman table (NYI)");
} else {
/* Table B.1 */
params.SDHUFFAGGINST = jbig2_build_huffman_table(ctx,
&jbig2_huffman_params_A);
}
}
 
/* FIXME: there are quite a few of these conditions to check */
/* maybe #ifdef CONFORMANCE and a separate routine */
if (!params.SDHUFF) {
if (flags & 0x000c) {
jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
"SDHUFF is zero, but contrary to spec SDHUFFDH is not.");
}
if (flags & 0x0030) {
jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
"SDHUFF is zero, but contrary to spec SDHUFFDW is not.");
}
}
 
if (flags & 0x0080) {
jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
"bitmap coding context is used (NYI) symbol data likely to be garbage!");
}
 
/* 7.4.2.1.2 */
sdat_bytes = params.SDHUFF ? 0 : params.SDTEMPLATE == 0 ? 8 : 2;
memcpy(params.sdat, segment_data + 2, sdat_bytes);
offset = 2 + sdat_bytes;
 
/* 7.4.2.1.3 */
if (params.SDREFAGG && !params.SDRTEMPLATE) {
if (offset + 4 > segment->data_length)
goto too_short;
memcpy(params.sdrat, segment_data + offset, 4);
offset += 4;
} else {
/* sdrat is meaningless if SDRTEMPLATE is 1, but set a value
to avoid confusion if anybody looks */
memset(params.sdrat, 0, 4);
}
 
if (offset + 8 > segment->data_length)
goto too_short;
 
/* 7.4.2.1.4 */
params.SDNUMEXSYMS = jbig2_get_int32(segment_data + offset);
/* 7.4.2.1.5 */
params.SDNUMNEWSYMS = jbig2_get_int32(segment_data + offset + 4);
offset += 8;
 
jbig2_error(ctx, JBIG2_SEVERITY_INFO, segment->number,
"symbol dictionary, flags=%04x, %d exported syms, %d new syms",
flags, params.SDNUMEXSYMS, params.SDNUMNEWSYMS);
 
/* 7.4.2.2 (2) */
{
int n_dicts = jbig2_sd_count_referred(ctx, segment);
Jbig2SymbolDict **dicts = NULL;
 
params.SDINSYMS = NULL;
if (n_dicts > 0) {
dicts = jbig2_sd_list_referred(ctx, segment);
params.SDINSYMS = jbig2_sd_cat(ctx, n_dicts, dicts);
}
if (params.SDINSYMS != NULL) {
params.SDNUMINSYMS = params.SDINSYMS->n_symbols;
} else {
params.SDNUMINSYMS = 0;
}
}
 
/* 7.4.2.2 (4) */
if (!params.SDHUFF) {
int stats_size = params.SDTEMPLATE == 0 ? 65536 :
params.SDTEMPLATE == 1 ? 8192 : 1024;
GB_stats = jbig2_alloc(ctx->allocator, stats_size);
memset(GB_stats, 0, stats_size);
if (params.SDREFAGG) {
stats_size = params.SDRTEMPLATE ? 1 << 10 : 1 << 13;
GR_stats = jbig2_alloc(ctx->allocator, stats_size);
memset(GR_stats, 0, stats_size);
}
}
 
if (flags & 0x0100) {
jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
"segment marks bitmap coding context as retained (NYI)");
}
 
segment->result = (void *)jbig2_decode_symbol_dict(ctx, segment,
&params,
segment_data + offset,
segment->data_length - offset,
GB_stats, GR_stats);
#ifdef DUMP_SYMDICT
if (segment->result) jbig2_dump_symbol_dict(ctx, segment);
#endif
 
if (params.SDHUFF) {
jbig2_release_huffman_table(ctx, params.SDHUFFDH);
jbig2_release_huffman_table(ctx, params.SDHUFFDW);
jbig2_release_huffman_table(ctx, params.SDHUFFBMSIZE);
jbig2_release_huffman_table(ctx, params.SDHUFFAGGINST);
}
 
/* todo: retain or free GB_stats, GR_stats */
 
return (segment->result != NULL) ? 0 : -1;
 
too_short:
return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"Segment too short");
}
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libjbig2dec/jbig2_symbol_dict.h
0,0 → 1,56
/*
jbig2dec
 
Copyright (C) 2001-2002 Artifex Software, Inc.
 
This software is distributed under license and may not
be copied, modified or distributed except as expressly
authorized under the terms of the license contained in
the file LICENSE in this distribution.
 
For further licensing information refer to http://artifex.com/ or
contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
San Rafael, CA 94903, U.S.A., +1(415)492-9861.
*/
 
/* symbol dictionary header */
 
/* the results of decoding a symbol dictionary */
typedef struct {
int n_symbols;
Jbig2Image **glyphs;
} Jbig2SymbolDict;
 
/* decode a symbol dictionary segment and store the results */
int
jbig2_symbol_dictionary(Jbig2Ctx *ctx, Jbig2Segment *segment,
const byte *segment_data);
 
/* get a particular glyph by index */
Jbig2Image *
jbig2_sd_glyph(Jbig2SymbolDict *dict, unsigned int id);
 
/* return a new empty symbol dict */
Jbig2SymbolDict *
jbig2_sd_new(Jbig2Ctx *ctx, int n_symbols);
 
/* release the memory associated with a symbol dict */
void
jbig2_sd_release(Jbig2Ctx *ctx, Jbig2SymbolDict *dict);
 
/* generate a new symbol dictionary by concatenating a list of
existing dictionaries */
Jbig2SymbolDict *
jbig2_sd_cat(Jbig2Ctx *ctx, int n_dicts,
Jbig2SymbolDict **dicts);
 
/* count the number of dictionary segments referred
to by the given segment */
int
jbig2_sd_count_referred(Jbig2Ctx *ctx, Jbig2Segment *segment);
 
/* return an array of pointers to symbol dictionaries referred
to by a segment */
Jbig2SymbolDict **
jbig2_sd_list_referred(Jbig2Ctx *ctx, Jbig2Segment *segment);
 
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libjbig2dec/jbig2_text.c
0,0 → 1,787
/*
jbig2dec
 
Copyright (C) 2002-2008 Artifex Software, Inc.
 
This software is distributed under license and may not
be copied, modified or distributed except as expressly
authorized under the terms of the license contained in
the file LICENSE in this distribution.
 
For further licensing information refer to http://artifex.com/ or
contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
San Rafael, CA 94903, U.S.A., +1(415)492-9861.
*/
 
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "os_types.h"
 
#include <stddef.h>
#include <string.h> /* memset() */
 
#include "jbig2.h"
#include "jbig2_priv.h"
#include "jbig2_arith.h"
#include "jbig2_arith_int.h"
#include "jbig2_arith_iaid.h"
#include "jbig2_huffman.h"
#include "jbig2_generic.h"
#include "jbig2_symbol_dict.h"
#include "jbig2_text.h"
 
 
/**
* jbig2_decode_text_region: decode a text region segment
*
* @ctx: jbig2 decoder context
* @segment: jbig2 segment (header) structure
* @params: parameters from the text region header
* @dicts: an array of referenced symbol dictionaries
* @n_dicts: the number of referenced symbol dictionaries
* @image: image structure in which to store the decoded region bitmap
* @data: pointer to text region data to be decoded
* @size: length of text region data
*
* Implements the text region decoding procedure
* described in section 6.4 of the JBIG2 spec.
*
* returns: 0 on success
**/
int
jbig2_decode_text_region(Jbig2Ctx *ctx, Jbig2Segment *segment,
const Jbig2TextRegionParams *params,
const Jbig2SymbolDict * const *dicts, const int n_dicts,
Jbig2Image *image,
const byte *data, const size_t size,
Jbig2ArithCx *GR_stats, Jbig2ArithState *as, Jbig2WordStream *ws)
{
/* relevent bits of 6.4.4 */
uint32_t NINSTANCES;
uint32_t ID;
int32_t STRIPT;
int32_t FIRSTS;
int32_t DT;
int32_t DFS;
int32_t IDS;
int32_t CURS;
int32_t CURT;
int S,T;
int x,y;
bool first_symbol;
uint32_t index, SBNUMSYMS;
Jbig2Image *IB;
Jbig2HuffmanState *hs = NULL;
Jbig2HuffmanTable *SBSYMCODES = NULL;
int code = 0;
int RI;
 
SBNUMSYMS = 0;
for (index = 0; index < n_dicts; index++) {
SBNUMSYMS += dicts[index]->n_symbols;
}
jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
"symbol list contains %d glyphs in %d dictionaries", SBNUMSYMS, n_dicts);
 
if (params->SBHUFF) {
Jbig2HuffmanTable *runcodes;
Jbig2HuffmanParams runcodeparams;
Jbig2HuffmanLine runcodelengths[35];
Jbig2HuffmanLine *symcodelengths;
Jbig2HuffmanParams symcodeparams;
int code, err, len, range, r;
 
jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
"huffman coded text region");
hs = jbig2_huffman_new(ctx, ws);
 
/* 7.4.3.1.7 - decode symbol ID Huffman table */
/* this is actually part of the segment header, but it is more
convenient to handle it here */
 
/* parse and build the runlength code huffman table */
for (index = 0; index < 35; index++) {
runcodelengths[index].PREFLEN = jbig2_huffman_get_bits(hs, 4);
runcodelengths[index].RANGELEN = 0;
runcodelengths[index].RANGELOW = index;
jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
" read runcode%d length %d", index, runcodelengths[index].PREFLEN);
}
runcodeparams.HTOOB = 0;
runcodeparams.lines = runcodelengths;
runcodeparams.n_lines = 35;
runcodes = jbig2_build_huffman_table(ctx, &runcodeparams);
if (runcodes == NULL) {
jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"error constructing symbol id runcode table!");
return -1;
}
 
/* decode the symbol id codelengths using the runlength table */
symcodelengths = jbig2_alloc(ctx->allocator, SBNUMSYMS*sizeof(Jbig2HuffmanLine));
if (symcodelengths == NULL) {
jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"memory allocation failure reading symbol ID huffman table!");
return -1;
}
index = 0;
while (index < SBNUMSYMS) {
code = jbig2_huffman_get(hs, runcodes, &err);
if (err != 0 || code < 0 || code >= 35) {
jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"error reading symbol ID huffman table!");
return err ? err : -1;
}
 
if (code < 32) {
len = code;
range = 1;
} else {
if (code == 32) {
len = symcodelengths[index-1].PREFLEN;
if (index < 1) {
jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"error decoding symbol id table: run length with no antecedent!");
/* todo: memory cleanup */
return -1;
}
} else {
len = 0; /* code == 33 or 34 */
}
if (code == 32) range = jbig2_huffman_get_bits(hs, 2) + 3;
else if (code == 33) range = jbig2_huffman_get_bits(hs, 3) + 3;
else if (code == 34) range = jbig2_huffman_get_bits(hs, 7) + 11;
}
jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
" read runcode%d at index %d (length %d range %d)", code, index, len, range);
if (index+range > SBNUMSYMS) {
jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
"runlength extends %d entries beyond the end of symbol id table!",
index+range - SBNUMSYMS);
range = SBNUMSYMS - index;
}
for (r = 0; r < range; r++) {
symcodelengths[index+r].PREFLEN = len;
symcodelengths[index+r].RANGELEN = 0;
symcodelengths[index+r].RANGELOW = index + r;
}
index += r;
}
 
if (index < SBNUMSYMS) {
jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
"runlength codes do not cover the available symbol set");
}
symcodeparams.HTOOB = 0;
symcodeparams.lines = symcodelengths;
symcodeparams.n_lines = SBNUMSYMS;
 
/* skip to byte boundary */
jbig2_huffman_skip(hs);
 
/* finally, construct the symbol id huffman table itself */
SBSYMCODES = jbig2_build_huffman_table(ctx, &symcodeparams);
 
jbig2_free(ctx->allocator, symcodelengths);
jbig2_release_huffman_table(ctx, runcodes);
 
if (SBSYMCODES == NULL) {
jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"could not construct Symbol ID huffman table!");
return -1;
}
}
 
/* 6.4.5 (1) */
jbig2_image_clear(ctx, image, params->SBDEFPIXEL);
 
/* 6.4.6 */
if (params->SBHUFF) {
STRIPT = jbig2_huffman_get(hs, params->SBHUFFDT, &code);
} else {
code = jbig2_arith_int_decode(params->IADT, as, &STRIPT);
}
 
/* 6.4.5 (2) */
STRIPT *= -(params->SBSTRIPS);
FIRSTS = 0;
NINSTANCES = 0;
 
/* 6.4.5 (3) */
while (NINSTANCES < params->SBNUMINSTANCES) {
/* (3b) */
if (params->SBHUFF) {
DT = jbig2_huffman_get(hs, params->SBHUFFDT, &code);
} else {
code = jbig2_arith_int_decode(params->IADT, as, &DT);
}
DT *= params->SBSTRIPS;
STRIPT += DT;
 
first_symbol = TRUE;
/* 6.4.5 (3c) - decode symbols in strip */
for (;;) {
/* (3c.i) */
if (first_symbol) {
/* 6.4.7 */
if (params->SBHUFF) {
DFS = jbig2_huffman_get(hs, params->SBHUFFFS, &code);
} else {
code = jbig2_arith_int_decode(params->IAFS, as, &DFS);
}
FIRSTS += DFS;
CURS = FIRSTS;
first_symbol = FALSE;
 
} else {
/* (3c.ii) / 6.4.8 */
if (params->SBHUFF) {
IDS = jbig2_huffman_get(hs, params->SBHUFFDS, &code);
} else {
code = jbig2_arith_int_decode(params->IADS, as, &IDS);
}
if (code) {
break;
}
CURS += IDS + params->SBDSOFFSET;
}
 
/* (3c.iii) / 6.4.9 */
if (params->SBSTRIPS == 1) {
CURT = 0;
} else if (params->SBHUFF) {
CURT = jbig2_huffman_get_bits(hs, params->LOGSBSTRIPS);
} else {
code = jbig2_arith_int_decode(params->IAIT, as, &CURT);
}
T = STRIPT + CURT;
 
/* (3b.iv) / 6.4.10 - decode the symbol id */
if (params->SBHUFF) {
ID = jbig2_huffman_get(hs, SBSYMCODES, &code);
} else {
code = jbig2_arith_iaid_decode(params->IAID, as, (int *)&ID);
}
if (ID >= SBNUMSYMS) {
return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"symbol id out of range! (%d/%d)", ID, SBNUMSYMS);
}
 
/* (3c.v) / 6.4.11 - look up the symbol bitmap IB */
{
uint32_t id = ID;
 
index = 0;
while (id >= dicts[index]->n_symbols)
id -= dicts[index++]->n_symbols;
IB = jbig2_image_clone(ctx, dicts[index]->glyphs[id]);
}
if (params->SBREFINE) {
if (params->SBHUFF) {
RI = jbig2_huffman_get_bits(hs, 1);
} else {
code = jbig2_arith_int_decode(params->IARI, as, &RI);
}
} else {
RI = 0;
}
if (RI) {
Jbig2RefinementRegionParams rparams;
Jbig2Image *IBO;
int32_t RDW, RDH, RDX, RDY;
Jbig2Image *refimage;
int BMSIZE = 0;
 
/* 6.4.11 (1, 2, 3, 4) */
if (!params->SBHUFF) {
code = jbig2_arith_int_decode(params->IARDW, as, &RDW);
code = jbig2_arith_int_decode(params->IARDH, as, &RDH);
code = jbig2_arith_int_decode(params->IARDX, as, &RDX);
code = jbig2_arith_int_decode(params->IARDY, as, &RDY);
} else {
RDW = jbig2_huffman_get(hs, params->SBHUFFRDW, &code);
RDH = jbig2_huffman_get(hs, params->SBHUFFRDH, &code);
RDX = jbig2_huffman_get(hs, params->SBHUFFRDX, &code);
RDY = jbig2_huffman_get(hs, params->SBHUFFRDY, &code);
BMSIZE = jbig2_huffman_get(hs, params->SBHUFFRSIZE, &code);
jbig2_huffman_skip(hs);
}
 
/* 6.4.11 (6) */
IBO = IB;
refimage = jbig2_image_new(ctx, IBO->width + RDW,
IBO->height + RDH);
if (refimage == NULL) {
jbig2_image_release(ctx, IBO);
if (params->SBHUFF) {
jbig2_release_huffman_table(ctx, SBSYMCODES);
}
return jbig2_error(ctx, JBIG2_SEVERITY_FATAL,
segment->number,
"couldn't allocate reference image");
}
 
/* Table 12 */
rparams.GRTEMPLATE = params->SBRTEMPLATE;
rparams.reference = IBO;
rparams.DX = (RDW >> 1) + RDX;
rparams.DY = (RDH >> 1) + RDY;
rparams.TPGRON = 0;
memcpy(rparams.grat, params->sbrat, 4);
jbig2_decode_refinement_region(ctx, segment,
&rparams, as, refimage, GR_stats);
IB = refimage;
 
jbig2_image_release(ctx, IBO);
 
/* 6.4.11 (7) */
if (params->SBHUFF) {
jbig2_huffman_advance(hs, BMSIZE);
}
 
}
 
/* (3c.vi) */
if ((!params->TRANSPOSED) && (params->REFCORNER > 1)) {
CURS += IB->width - 1;
} else if ((params->TRANSPOSED) && !(params->REFCORNER & 1)) {
CURS += IB->height - 1;
}
 
/* (3c.vii) */
S = CURS;
 
/* (3c.viii) */
if (!params->TRANSPOSED) {
switch (params->REFCORNER) {
case JBIG2_CORNER_TOPLEFT: x = S; y = T; break;
case JBIG2_CORNER_TOPRIGHT: x = S - IB->width + 1; y = T; break;
case JBIG2_CORNER_BOTTOMLEFT: x = S; y = T - IB->height + 1; break;
case JBIG2_CORNER_BOTTOMRIGHT: x = S - IB->width + 1; y = T - IB->height + 1; break;
}
} else { /* TRANSPOSED */
switch (params->REFCORNER) {
case JBIG2_CORNER_TOPLEFT: x = T; y = S; break;
case JBIG2_CORNER_TOPRIGHT: x = T - IB->width + 1; y = S; break;
case JBIG2_CORNER_BOTTOMLEFT: x = T; y = S - IB->height + 1; break;
case JBIG2_CORNER_BOTTOMRIGHT: x = T - IB->width + 1; y = S - IB->height + 1; break;
}
}
 
/* (3c.ix) */
#ifdef JBIG2_DEBUG
jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
"composing glyph id %d: %dx%d @ (%d,%d) symbol %d/%d",
ID, IB->width, IB->height, x, y, NINSTANCES + 1,
params->SBNUMINSTANCES);
#endif
jbig2_image_compose(ctx, image, IB, x, y, params->SBCOMBOP);
 
/* (3c.x) */
if ((!params->TRANSPOSED) && (params->REFCORNER < 2)) {
CURS += IB->width -1 ;
} else if ((params->TRANSPOSED) && (params->REFCORNER & 1)) {
CURS += IB->height - 1;
}
 
/* (3c.xi) */
NINSTANCES++;
 
jbig2_image_release(ctx, IB);
}
/* end strip */
}
/* 6.4.5 (4) */
 
if (params->SBHUFF) {
jbig2_release_huffman_table(ctx, SBSYMCODES);
}
 
return 0;
}
 
/**
* jbig2_text_region: read a text region segment header
**/
int
jbig2_text_region(Jbig2Ctx *ctx, Jbig2Segment *segment, const byte *segment_data)
{
int offset = 0;
Jbig2RegionSegmentInfo region_info;
Jbig2TextRegionParams params;
Jbig2Image *image;
Jbig2SymbolDict **dicts;
int n_dicts;
uint16_t flags;
uint16_t huffman_flags = 0;
Jbig2ArithCx *GR_stats = NULL;
int code = 0;
Jbig2WordStream *ws = NULL;
Jbig2ArithState *as = NULL;
 
/* 7.4.1 */
if (segment->data_length < 17)
goto too_short;
jbig2_get_region_segment_info(&region_info, segment_data);
offset += 17;
 
/* 7.4.3.1.1 */
flags = jbig2_get_int16(segment_data + offset);
offset += 2;
 
jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
"text region header flags 0x%04x", flags);
 
params.SBHUFF = flags & 0x0001;
params.SBREFINE = flags & 0x0002;
params.LOGSBSTRIPS = (flags & 0x000c) >> 2;
params.SBSTRIPS = 1 << params.LOGSBSTRIPS;
params.REFCORNER = (flags & 0x0030) >> 4;
params.TRANSPOSED = flags & 0x0040;
params.SBCOMBOP = (flags & 0x0180) >> 7;
params.SBDEFPIXEL = flags & 0x0200;
/* SBDSOFFSET is a signed 5 bit integer */
params.SBDSOFFSET = (flags & 0x7C00) >> 10;
if (params.SBDSOFFSET > 0x0f) params.SBDSOFFSET -= 0x20;
params.SBRTEMPLATE = flags & 0x8000;
 
if (params.SBDSOFFSET) {
jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
"text region has SBDSOFFSET %d", params.SBDSOFFSET);
}
 
if (params.SBHUFF) /* Huffman coding */
{
/* 7.4.3.1.2 */
huffman_flags = jbig2_get_int16(segment_data + offset);
offset += 2;
 
if (huffman_flags & 0x8000)
jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
"reserved bit 15 of text region huffman flags is not zero");
}
else /* arithmetic coding */
{
/* 7.4.3.1.3 */
if ((params.SBREFINE) && !(params.SBRTEMPLATE))
{
params.sbrat[0] = segment_data[offset];
params.sbrat[1] = segment_data[offset + 1];
params.sbrat[2] = segment_data[offset + 2];
params.sbrat[3] = segment_data[offset + 3];
offset += 4;
} else {
/* zero these for the sake of later debug messages */
memset(params.sbrat, 0, sizeof(params.sbrat));
}
}
 
/* 7.4.3.1.4 */
params.SBNUMINSTANCES = jbig2_get_int32(segment_data + offset);
offset += 4;
 
if (params.SBHUFF) {
/* 7.4.3.1.5 - Symbol ID Huffman table */
/* ...this is handled in the segment body decoder */
 
/* 7.4.3.1.6 - Other Huffman table selection */
switch (huffman_flags & 0x0003) {
case 0: /* Table B.6 */
params.SBHUFFFS = jbig2_build_huffman_table(ctx,
&jbig2_huffman_params_F);
break;
case 1: /* Table B.7 */
params.SBHUFFFS = jbig2_build_huffman_table(ctx,
&jbig2_huffman_params_G);
break;
case 3: /* Custom table from referred segment */
/* We handle this case later by leaving the table as NULL */
return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"text region uses custom FS huffman table (NYI)");
break;
case 2: /* invalid */
default:
return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"text region specified invalid FS huffman table");
break;
}
switch ((huffman_flags & 0x000c) >> 2) {
case 0: /* Table B.8 */
params.SBHUFFDS = jbig2_build_huffman_table(ctx,
&jbig2_huffman_params_H);
break;
case 1: /* Table B.9 */
params.SBHUFFDS = jbig2_build_huffman_table(ctx,
&jbig2_huffman_params_I);
break;
case 2: /* Table B.10 */
params.SBHUFFDS = jbig2_build_huffman_table(ctx,
&jbig2_huffman_params_J);
break;
case 3: /* Custom table from referred segment */
/* We handle this case later by leaving the table as NULL */
return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"text region uses custom DS huffman table (NYI)");
break;
}
switch ((huffman_flags & 0x0030) >> 4) {
case 0: /* Table B.11 */
params.SBHUFFDT = jbig2_build_huffman_table(ctx,
&jbig2_huffman_params_K);
break;
case 1: /* Table B.12 */
params.SBHUFFDT = jbig2_build_huffman_table(ctx,
&jbig2_huffman_params_L);
break;
case 2: /* Table B.13 */
params.SBHUFFDT = jbig2_build_huffman_table(ctx,
&jbig2_huffman_params_M);
break;
case 3: /* Custom table from referred segment */
/* We handle this case later by leaving the table as NULL */
return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"text region uses custom DT huffman table (NYI)");
break;
}
switch ((huffman_flags & 0x00c0) >> 6) {
case 0: /* Table B.14 */
params.SBHUFFRDW = jbig2_build_huffman_table(ctx,
&jbig2_huffman_params_N);
break;
case 1: /* Table B.15 */
params.SBHUFFRDW = jbig2_build_huffman_table(ctx,
&jbig2_huffman_params_O);
break;
case 3: /* Custom table from referred segment */
/* We handle this case later by leaving the table as NULL */
return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"text region uses custom RDW huffman table (NYI)");
break;
case 2: /* invalid */
default:
return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"text region specified invalid RDW huffman table");
break;
}
switch ((huffman_flags & 0x0300) >> 8) {
case 0: /* Table B.14 */
params.SBHUFFRDH = jbig2_build_huffman_table(ctx,
&jbig2_huffman_params_N);
break;
case 1: /* Table B.15 */
params.SBHUFFRDH = jbig2_build_huffman_table(ctx,
&jbig2_huffman_params_O);
break;
case 3: /* Custom table from referred segment */
/* We handle this case later by leaving the table as NULL */
return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"text region uses custom RDH huffman table (NYI)");
break;
case 2: /* invalid */
default:
return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"text region specified invalid RDH huffman table");
break;
}
switch ((huffman_flags & 0x0c00) >> 10) {
case 0: /* Table B.14 */
params.SBHUFFRDX = jbig2_build_huffman_table(ctx,
&jbig2_huffman_params_N);
break;
case 1: /* Table B.15 */
params.SBHUFFRDX = jbig2_build_huffman_table(ctx,
&jbig2_huffman_params_O);
break;
case 3: /* Custom table from referred segment */
/* We handle this case later by leaving the table as NULL */
return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"text region uses custom RDX huffman table (NYI)");
break;
case 2: /* invalid */
default:
return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"text region specified invalid RDX huffman table");
break;
}
switch ((huffman_flags & 0x3000) >> 12) {
case 0: /* Table B.14 */
params.SBHUFFRDY = jbig2_build_huffman_table(ctx,
&jbig2_huffman_params_N);
break;
case 1: /* Table B.15 */
params.SBHUFFRDY = jbig2_build_huffman_table(ctx,
&jbig2_huffman_params_O);
break;
case 3: /* Custom table from referred segment */
/* We handle this case later by leaving the table as NULL */
return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"text region uses custom RDY huffman table (NYI)");
break;
case 2: /* invalid */
default:
return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"text region specified invalid RDY huffman table");
break;
}
switch ((huffman_flags & 0x4000) >> 14) {
case 0: /* Table B.1 */
params.SBHUFFRSIZE = jbig2_build_huffman_table(ctx,
&jbig2_huffman_params_A);
break;
case 1: /* Custom table from referred segment */
/* We handle this case later by leaving the table as NULL */
return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"text region uses custom RSIZE huffman table (NYI)");
break;
}
 
if (huffman_flags & 0x8000) {
jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
"text region huffman flags bit 15 is set, contrary to spec");
}
 
/* 7.4.3.1.7 */
/* For convenience this is done in the body decoder routine */
}
 
jbig2_error(ctx, JBIG2_SEVERITY_INFO, segment->number,
"text region: %d x %d @ (%d,%d) %d symbols",
region_info.width, region_info.height,
region_info.x, region_info.y, params.SBNUMINSTANCES);
 
/* 7.4.3.2 (2) - compose the list of symbol dictionaries */
n_dicts = jbig2_sd_count_referred(ctx, segment);
if (n_dicts != 0) {
dicts = jbig2_sd_list_referred(ctx, segment);
} else {
return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"text region refers to no symbol dictionaries!");
}
if (dicts == NULL) {
return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"unable to retrive symbol dictionaries!"
" previous parsing error?");
} else {
int index;
if (dicts[0] == NULL) {
return jbig2_error(ctx, JBIG2_SEVERITY_WARNING,
segment->number,
"unable to find first referenced symbol dictionary!");
}
for (index = 1; index < n_dicts; index++)
if (dicts[index] == NULL) {
jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
"unable to find all referenced symbol dictionaries!");
n_dicts = index;
}
}
 
/* 7.4.3.2 (3) */
if (!params.SBHUFF && params.SBREFINE) {
int stats_size = params.SBRTEMPLATE ? 1 << 10 : 1 << 13;
GR_stats = jbig2_alloc(ctx->allocator, stats_size);
memset(GR_stats, 0, stats_size);
}
 
image = jbig2_image_new(ctx, region_info.width, region_info.height);
if (image == NULL) {
if (!params.SBHUFF && params.SBREFINE) {
jbig2_free(ctx->allocator, GR_stats);
} else if (params.SBHUFF) {
jbig2_release_huffman_table(ctx, params.SBHUFFFS);
jbig2_release_huffman_table(ctx, params.SBHUFFDS);
jbig2_release_huffman_table(ctx, params.SBHUFFDT);
jbig2_release_huffman_table(ctx, params.SBHUFFRDX);
jbig2_release_huffman_table(ctx, params.SBHUFFRDY);
jbig2_release_huffman_table(ctx, params.SBHUFFRDW);
jbig2_release_huffman_table(ctx, params.SBHUFFRDH);
jbig2_release_huffman_table(ctx, params.SBHUFFRSIZE);
}
return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"couldn't allocate text region image");
}
 
ws = jbig2_word_stream_buf_new(ctx, segment_data + offset, segment->data_length - offset);
if (!params.SBHUFF) {
int SBSYMCODELEN, index;
int SBNUMSYMS = 0;
for (index = 0; index < n_dicts; index++) {
SBNUMSYMS += dicts[index]->n_symbols;
}
 
as = jbig2_arith_new(ctx, ws);
ws = 0;
 
params.IADT = jbig2_arith_int_ctx_new(ctx);
params.IAFS = jbig2_arith_int_ctx_new(ctx);
params.IADS = jbig2_arith_int_ctx_new(ctx);
params.IAIT = jbig2_arith_int_ctx_new(ctx);
/* Table 31 */
for (SBSYMCODELEN = 0; (1 << SBSYMCODELEN) < SBNUMSYMS; SBSYMCODELEN++);
params.IAID = jbig2_arith_iaid_ctx_new(ctx, SBSYMCODELEN);
params.IARI = jbig2_arith_int_ctx_new(ctx);
params.IARDW = jbig2_arith_int_ctx_new(ctx);
params.IARDH = jbig2_arith_int_ctx_new(ctx);
params.IARDX = jbig2_arith_int_ctx_new(ctx);
params.IARDY = jbig2_arith_int_ctx_new(ctx);
}
 
code = jbig2_decode_text_region(ctx, segment, &params,
(const Jbig2SymbolDict * const *)dicts, n_dicts, image,
segment_data + offset, segment->data_length - offset,
GR_stats, as, ws);
 
if (!params.SBHUFF && params.SBREFINE) {
jbig2_free(ctx->allocator, GR_stats);
}
 
if (params.SBHUFF) {
jbig2_release_huffman_table(ctx, params.SBHUFFFS);
jbig2_release_huffman_table(ctx, params.SBHUFFDS);
jbig2_release_huffman_table(ctx, params.SBHUFFDT);
jbig2_release_huffman_table(ctx, params.SBHUFFRDX);
jbig2_release_huffman_table(ctx, params.SBHUFFRDY);
jbig2_release_huffman_table(ctx, params.SBHUFFRDW);
jbig2_release_huffman_table(ctx, params.SBHUFFRDH);
jbig2_release_huffman_table(ctx, params.SBHUFFRSIZE);
}
else {
jbig2_arith_int_ctx_free(ctx, params.IADT);
jbig2_arith_int_ctx_free(ctx, params.IAFS);
jbig2_arith_int_ctx_free(ctx, params.IADS);
jbig2_arith_int_ctx_free(ctx, params.IAIT);
jbig2_arith_iaid_ctx_free(ctx, params.IAID);
jbig2_arith_int_ctx_free(ctx, params.IARI);
jbig2_arith_int_ctx_free(ctx, params.IARDW);
jbig2_arith_int_ctx_free(ctx, params.IARDH);
jbig2_arith_int_ctx_free(ctx, params.IARDX);
jbig2_arith_int_ctx_free(ctx, params.IARDY);
jbig2_free(ctx->allocator, as);
jbig2_word_stream_buf_free(ctx, ws);
}
 
jbig2_free(ctx->allocator, dicts);
 
/* todo: check errors */
 
if ((segment->flags & 63) == 4) {
/* we have an intermediate region here. save it for later */
segment->result = image;
} else {
/* otherwise composite onto the page */
jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
"composing %dx%d decoded text region onto page at (%d, %d)",
region_info.width, region_info.height, region_info.x, region_info.y);
jbig2_page_add_result(ctx, &ctx->pages[ctx->current_page], image,
region_info.x, region_info.y, region_info.op);
jbig2_image_release(ctx, image);
}
 
/* success */
return 0;
 
too_short:
return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"Segment too short");
}
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libjbig2dec/jbig2_text.h
0,0 → 1,73
/*
jbig2dec
 
Copyright (C) 2002-2004 Artifex Software, Inc.
 
This software is distributed under license and may not
be copied, modified or distributed except as expressly
authorized under the terms of the license contained in
the file LICENSE in this distribution.
 
For further licensing information refer to http://artifex.com/ or
contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
San Rafael, CA 94903, U.S.A., +1(415)492-9861.
*/
 
/**
* Headers for Text region handling
**/
 
typedef enum {
JBIG2_CORNER_BOTTOMLEFT = 0,
JBIG2_CORNER_TOPLEFT = 1,
JBIG2_CORNER_BOTTOMRIGHT = 2,
JBIG2_CORNER_TOPRIGHT = 3
} Jbig2RefCorner;
 
typedef struct {
bool SBHUFF;
bool SBREFINE;
bool SBDEFPIXEL;
Jbig2ComposeOp SBCOMBOP;
bool TRANSPOSED;
Jbig2RefCorner REFCORNER;
int SBDSOFFSET;
/* int SBW; */
/* int SBH; */
uint32_t SBNUMINSTANCES;
int LOGSBSTRIPS;
int SBSTRIPS;
/* int SBNUMSYMS; */
/* SBSYMCODES */
/* SBSYMCODELEN */
/* SBSYMS */
Jbig2HuffmanTable *SBHUFFFS;
Jbig2HuffmanTable *SBHUFFDS;
Jbig2HuffmanTable *SBHUFFDT;
Jbig2HuffmanTable *SBHUFFRDW;
Jbig2HuffmanTable *SBHUFFRDH;
Jbig2HuffmanTable *SBHUFFRDX;
Jbig2HuffmanTable *SBHUFFRDY;
Jbig2HuffmanTable *SBHUFFRSIZE;
Jbig2ArithIntCtx *IADT;
Jbig2ArithIntCtx *IAFS;
Jbig2ArithIntCtx *IADS;
Jbig2ArithIntCtx *IAIT;
Jbig2ArithIaidCtx *IAID;
Jbig2ArithIntCtx *IARI;
Jbig2ArithIntCtx *IARDW;
Jbig2ArithIntCtx *IARDH;
Jbig2ArithIntCtx *IARDX;
Jbig2ArithIntCtx *IARDY;
bool SBRTEMPLATE;
int8_t sbrat[4];
} Jbig2TextRegionParams;
 
int
jbig2_decode_text_region(Jbig2Ctx *ctx, Jbig2Segment *segment,
const Jbig2TextRegionParams *params,
const Jbig2SymbolDict * const *dicts, const int n_dicts,
Jbig2Image *image,
const byte *data, const size_t size,
Jbig2ArithCx *GR_stats,
Jbig2ArithState *as, Jbig2WordStream *ws);
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libjbig2dec/jbig2dec.c
0,0 → 1,513
/*
jbig2dec
 
Copyright (C) 2001-2009 Artifex Software, Inc.
 
This software is distributed under license and may not
be copied, modified or distributed except as expressly
authorized under the terms of the license contained in
the file LICENSE in this distribution.
 
For further licensing information refer to http://artifex.com/ or
contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
San Rafael, CA 94903, U.S.A., +1(415)492-9861.
*/
 
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
 
#ifndef PACKAGE
#define PACKAGE "jbig2dec"
#endif
#ifndef VERSION
#define VERSION "unknown-version"
#endif
 
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
 
#ifdef HAVE_GETOPT_H
# include <getopt.h>
#else
# include "getopt.h"
#endif
 
#include "os_types.h"
#include "sha1.h"
 
#include "jbig2.h"
#include "jbig2_image.h"
 
typedef enum {
usage,dump,render
} jbig2dec_mode;
 
typedef enum {
jbig2dec_format_jbig2,
jbig2dec_format_pbm,
jbig2dec_format_png,
jbig2dec_format_none
} jbig2dec_format;
 
typedef struct {
jbig2dec_mode mode;
int verbose, hash;
SHA1_CTX *hash_ctx;
char *output_file;
jbig2dec_format output_format;
} jbig2dec_params_t;
 
static int print_version(void);
static int print_usage(void);
 
/* page hashing functions */
static void
hash_init(jbig2dec_params_t *params)
{
params->hash_ctx = malloc(sizeof(SHA1_CTX));
if (params->hash_ctx == NULL) {
fprintf(stderr, "unable to allocate hash state\n");
params->hash = 0;
return;
} else {
SHA1_Init(params->hash_ctx);
}
}
 
static void
hash_image(jbig2dec_params_t *params, Jbig2Image *image)
{
unsigned int N = image->stride * image->height;
SHA1_Update(params->hash_ctx, image->data, N);
}
 
static void
hash_print(jbig2dec_params_t *params, FILE *out)
{
unsigned char md[SHA1_DIGEST_SIZE];
char digest[2*SHA1_DIGEST_SIZE + 1];
int i;
 
SHA1_Final(params->hash_ctx, md);
for (i = 0; i < SHA1_DIGEST_SIZE; i++) {
snprintf(&(digest[2*i]), 3, "%02x", md[i]);
}
fprintf(out, "%s", digest);
}
 
static void
hash_free(jbig2dec_params_t *params)
{
free(params->hash_ctx);
params->hash_ctx = NULL;
}
 
static int
set_output_format(jbig2dec_params_t *params, const char *format)
{
#ifdef HAVE_LIBPNG
/* this should really by strncasecmp()
TODO: we need to provide our own for portability */
if (!strncmp(format, "png", 3) || !strncmp(format, "PNG", 3)) {
params->output_format=jbig2dec_format_png;
return 0;
}
#endif
/* default to pbm */
params->output_format=jbig2dec_format_pbm;
 
return 0;
}
 
static int
parse_options(int argc, char *argv[], jbig2dec_params_t *params)
{
static struct option long_options[] = {
{"version", 0, NULL, 'V'},
{"help", 0, NULL, 'h'},
{"quiet", 0, NULL, 'q'},
{"verbose", 2, NULL, 'v'},
{"dump", 0, NULL, 'd'},
{"hash", 0, NULL, 'm'},
{"output", 1, NULL, 'o'},
{"format", 1, NULL, 't'},
{NULL, 0, NULL, 0}
};
int option_idx = 1;
int option;
 
while (1) {
option = getopt_long(argc, argv,
"Vh?qvdo:t:", long_options, &option_idx);
if (option == -1) break;
 
switch (option) {
case 0: /* unknown long option */
if (!params->verbose) fprintf(stdout,
"unrecognized option: --%s\n",
long_options[option_idx].name);
break;
case 'q':
params->verbose = 0;
break;
case 'v':
if (optarg) params->verbose = atoi(optarg);
else params->verbose = 2;
break;
case 'h':
case '?':
params->mode = usage;
break;
case 'V':
/* the GNU Coding Standards suggest --version
should override all other options */
print_version();
exit(0);
break;
case 'd':
params->mode=dump;
break;
case 'm':
params->hash = 1;
break;
case 'o':
params->output_file = strdup(optarg);
break;
case 't':
set_output_format(params, optarg);
break;
default:
if (!params->verbose) fprintf(stdout,
"unrecognized option: -%c\n", option);
break;
}
}
return (optind);
}
 
static int
print_version (void)
{
fprintf(stdout, "%s %s\n", PACKAGE, VERSION);
return 0;
}
 
static int
print_usage (void)
{
fprintf(stderr,
"Usage: jbig2dec [options] <file.jbig2>\n"
" or jbig2dec [options] <global_stream> <page_stream>\n"
"\n"
" When invoked with a single file, it attempts to parse it as\n"
" a normal jbig2 file. Invoked with two files, it treats the\n"
" first as the global segments, and the second as the segment\n"
" stream for a particular page. This is useful for examining\n"
" embedded streams.\n"
"\n"
" available options:\n"
" -h --help this usage summary\n"
" -q --quiet suppress diagnostic output\n"
" -v --verbose set the verbosity level\n"
" -d --dump print the structure of the jbig2 file\n"
" rather than explicitly decoding\n"
" --version program name and version information\n"
" --hash print a hash of the decoded document\n"
" -o <file> send decoded output to <file>\n"
" Defaults to the the input with a different\n"
" extension. Pass '-' for stdout.\n"
" -t <type> force a particular output file format\n"
#ifdef HAVE_LIBPNG
" supported options are 'png' and 'pbm'\n"
#else
" the only supported option is 'pbm'\n"
#endif
"\n"
);
 
return 1;
}
 
static int
error_callback(void *error_callback_data, const char *buf, Jbig2Severity severity,
int32_t seg_idx)
{
const jbig2dec_params_t *params = error_callback_data;
char *type;
char segment[22];
 
switch (severity) {
case JBIG2_SEVERITY_DEBUG:
if (params->verbose < 3) return 0;
type = "DEBUG"; break;;
case JBIG2_SEVERITY_INFO:
if (params->verbose < 2) return 0;
type = "info"; break;;
case JBIG2_SEVERITY_WARNING:
if (params->verbose < 1) return 0;
type = "WARNING"; break;;
case JBIG2_SEVERITY_FATAL: type = "FATAL ERROR"; break;;
default: type = "unknown message"; break;;
}
if (seg_idx == -1) segment[0] = '\0';
else snprintf(segment, sizeof(segment), "(segment 0x%02x)", seg_idx);
 
fprintf(stderr, "jbig2dec %s %s %s\n", type, buf, segment);
 
return 0;
}
 
static char *
make_output_filename(const char *input_filename, const char *extension)
{
char *output_filename;
const char *c, *e;
int len;
 
if (extension == NULL) {
fprintf(stderr, "make_output_filename called with no extension!\n");
exit (1);
}
 
if (input_filename == NULL)
c = "out";
else {
/* strip any leading path */
c = strrchr(input_filename, '/'); /* *nix */
if (c == NULL)
c = strrchr(input_filename, '\\'); /* win32/dos */
if (c != NULL)
c++; /* skip the path separator */
else
c = input_filename; /* no leading path */
}
 
/* make sure we haven't just stripped the last character */
if (*c == '\0')
c = "out";
 
/* strip the extension */
len = strlen(c);
e = strrchr(c, '.');
if (e != NULL)
len -= strlen(e);
 
/* allocate enough space for the base + ext */
output_filename = malloc(len + strlen(extension) + 1);
if (output_filename == NULL) {
fprintf(stderr, "couldn't allocate memory for output_filename\n");
exit (1);
}
 
strncpy(output_filename, c, len);
strncpy(output_filename + len, extension, strlen(extension));
*(output_filename + len + strlen(extension)) = '\0';
 
/* return the new string */
return (output_filename);
}
 
static int
write_page_image(jbig2dec_params_t *params, Jbig2Image *image)
{
if (!strncmp(params->output_file, "-", 2))
{
switch (params->output_format) {
#ifdef HAVE_LIBPNG
case jbig2dec_format_png:
jbig2_image_write_png(image, stdout);
break;
#endif
case jbig2dec_format_pbm:
jbig2_image_write_pbm(image, stdout);
break;
default:
fprintf(stderr, "unsupported output format.\n");
return 1;
}
}
else
{
if (params->verbose > 1)
fprintf(stderr, "saving decoded page as '%s'\n", params->output_file);
switch (params->output_format) {
#ifdef HAVE_LIBPNG
case jbig2dec_format_png:
jbig2_image_write_png_file(image, params->output_file);
break;
#endif
case jbig2dec_format_pbm:
jbig2_image_write_pbm_file(image, params->output_file);
break;
default:
fprintf(stderr, "unsupported output format.\n");
return 1;
}
}
 
return 0;
}
 
static int
write_document_hash(jbig2dec_params_t *params)
{
FILE *out;
 
if (!strncmp(params->output_file, "-", 2)) {
out = stderr;
} else {
out = stdout;
}
 
fprintf(out, "Hash of decoded document: ");
hash_print(params, out);
fprintf(out, "\n");
 
return 0;
}
 
int
main (int argc, char **argv)
{
FILE *f = NULL, *f_page = NULL;
Jbig2Ctx *ctx;
uint8_t buf[4096];
jbig2dec_params_t params;
int filearg;
 
/* set defaults */
params.mode = render;
params.verbose = 1;
params.hash = 0;
params.output_file = NULL;
params.output_format = jbig2dec_format_none;
 
filearg = parse_options(argc, argv, &params);
 
if (params.hash) hash_init(&params);
 
switch (params.mode) {
case usage:
print_usage();
exit (0);
break;
case dump:
fprintf(stderr, "Sorry, segment dump not yet implemented\n");
break;
case render:
 
if ((argc - filearg) == 1)
/* only one argument--open as a jbig2 file */
{
char *fn = argv[filearg];
 
f = fopen(fn, "rb");
if (f == NULL)
{
fprintf(stderr, "error opening %s\n", fn);
return 1;
}
}
else if ((argc - filearg) == 2)
/* two arguments open as separate global and page streams */
{
char *fn = argv[filearg];
char *fn_page = argv[filearg+1];
 
f = fopen(fn, "rb");
if (f == NULL)
{
fprintf(stderr, "error opening %s\n", fn);
return 1;
}
 
f_page = fopen(fn_page, "rb");
if (f_page == NULL)
{
fprintf(stderr, "error opening %s\n", fn_page);
return 1;
}
}
else
/* any other number of arguments */
return print_usage();
 
ctx = jbig2_ctx_new(NULL, f_page != NULL ? JBIG2_OPTIONS_EMBEDDED : 0,
NULL,
error_callback, &params);
 
/* pull the whole file/global stream into memory */
for (;;)
{
int n_bytes = fread(buf, 1, sizeof(buf), f);
if (n_bytes <= 0)
break;
if (jbig2_data_in(ctx, buf, n_bytes))
break;
}
fclose(f);
 
/* if there's a local page stream read that in its entirety */
if (f_page != NULL)
{
Jbig2GlobalCtx *global_ctx = jbig2_make_global_ctx(ctx);
ctx = jbig2_ctx_new(NULL, JBIG2_OPTIONS_EMBEDDED, global_ctx,
error_callback, &params);
for (;;)
{
int n_bytes = fread(buf, 1, sizeof(buf), f_page);
if (n_bytes <= 0)
break;
if (jbig2_data_in(ctx, buf, n_bytes))
break;
}
fclose(f_page);
jbig2_global_ctx_free(global_ctx);
}
 
/* retrieve and output the returned pages */
{
Jbig2Image *image;
 
/* work around broken CVision embedded streams */
if (f_page != NULL)
jbig2_complete_page(ctx);
 
if (params.output_file == NULL)
{
#ifdef HAVE_LIBPNG
params.output_file = make_output_filename(argv[filearg], ".png");
params.output_format = jbig2dec_format_png;
#else
params.output_file = make_output_filename(argv[filearg], ".pbm");
params.output_format = jbig2dec_format_pbm;
#endif
} else {
int len = strlen(params.output_file);
if ((len >= 3) && (params.output_format == jbig2dec_format_none))
/* try to set the output type by the given extension */
set_output_format(&params, params.output_file + len - 3);
}
 
/* retrieve and write out all the completed pages */
while ((image = jbig2_page_out(ctx)) != NULL) {
write_page_image(&params, image);
if (params.hash) hash_image(&params, image);
jbig2_release_page(ctx, image);
}
if (params.hash) write_document_hash(&params);
}
 
jbig2_ctx_free(ctx);
 
} /* end params.mode switch */
 
if (params.output_file) free(params.output_file);
if (params.hash) hash_free(&params);
 
/* fin */
return 0;
}
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libjbig2dec/memcmp.c
0,0 → 1,49
/*
jbig2dec
 
Copyright (C) 2001-2005 Artifex Software, Inc.
 
This software is distributed under license and may not
be copied, modified or distributed except as expressly
authorized under the terms of the license contained in
the file LICENSE in this distribution.
 
For further licensing information refer to http://artifex.com/ or
contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
San Rafael, CA 94903, U.S.A., +1(415)492-9861.
*/
 
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
 
#include <stddef.h>
 
/* replacement for broken memcmp() */
 
/*
* compares two byte strings 'a' and 'b', both assumed to be 'len' bytes long
* returns zero if the two strings are identical, otherwise returns -1 or 1
* depending on the relative magnitude of the first differing elements,
* considered as unsigned chars
*/
 
int memcmp(const void *b1, const void *b2, size_t len)
{
unsigned char *a, *b;
size_t i;
 
a = (unsigned char *)b1;
b = (unsigned char *)b2;
for(i = 0; i < len; i++) {
if (*a != *b) {
/* strings differ */
return (*a < *b) ? -1 : 1;
}
a++;
b++;
}
 
/* strings match */
return 0;
}
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libjbig2dec/os_types.h
0,0 → 1,51
/*
jbig2dec
 
Copyright (C) 2003 Artifex Software, Inc.
 
This software is distributed under license and may not
be copied, modified or distributed except as expressly
authorized under the terms of the license contained in
the file LICENSE in this distribution.
 
For further licensing information refer to http://artifex.com/ or
contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
San Rafael, CA 94903, U.S.A., +1(415)492-9861.
*/
 
/*
indirection layer for build and platform-specific definitions
 
in general, this header should ensure that the stdint types are
available, and that any optional compile flags are defined if
the build system doesn't pass them directly.
*/
 
#ifndef _JBIG2_OS_TYPES_H
#define _JBIG2_OS_TYPES_H
 
#if defined(__CYGWIN__) && !defined(HAVE_STDINT_H)
# include <sys/types.h>
# if defined(OLD_CYGWIN_SYS_TYPES)
/*
* Old versions of Cygwin have no stdint.h but define "MS types". Some of
* them conflict with a standard type emulation provided by config_types.h
* so we do a fixup here.
*/
typedef u_int8_t uint8_t;
typedef u_int16_t uint16_t;
typedef u_int32_t uint32_t;
#endif
#elif defined(HAVE_CONFIG_H)
# include "config_types.h"
#elif defined(_WIN32) || defined(__WIN32__)
# include "config_win32.h"
#endif
 
#if defined(HAVE_STDINT_H) || defined(__MACOS__)
# include <stdint.h>
#elif defined(__VMS)
# include <inttypes.h>
#endif
 
#endif /* _JBIG2_OS_TYPES_H */
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libjbig2dec/sha1.c
0,0 → 1,375
/*
SHA-1 in C
By Steve Reid <sreid@sea-to-sky.net>
100% Public Domain
 
-----------------
Modified 7/98
By James H. Brown <jbrown@burgoyne.com>
Still 100% Public Domain
 
Corrected a problem which generated improper hash values on 16 bit machines
Routine SHA1Update changed from
void SHA1Update(SHA1_CTX* context, unsigned char* data, unsigned int
len)
to
void SHA1Update(SHA1_CTX* context, unsigned char* data, unsigned
long len)
 
The 'len' parameter was declared an int which works fine on 32 bit machines.
However, on 16 bit machines an int is too small for the shifts being done
against
it. This caused the hash function to generate incorrect values if len was
greater than 8191 (8K - 1) due to the 'len << 3' on line 3 of SHA1Update().
 
Since the file IO in main() reads 16K at a time, any file 8K or larger would
be guaranteed to generate the wrong hash (e.g. Test Vector #3, a million
"a"s).
 
I also changed the declaration of variables i & j in SHA1Update to
unsigned long from unsigned int for the same reason.
 
These changes should make no difference to any 32 bit implementations since
an
int and a long are the same size in those environments.
 
--
I also corrected a few compiler warnings generated by Borland C.
1. Added #include <process.h> for exit() prototype
2. Removed unused variable 'j' in SHA1Final
3. Changed exit(0) to return(0) at end of main.
 
ALL changes I made can be located by searching for comments containing 'JHB'
-----------------
Modified 8/98
By Steve Reid <sreid@sea-to-sky.net>
Still 100% public domain
 
1- Removed #include <process.h> and used return() instead of exit()
2- Fixed overwriting of finalcount in SHA1Final() (discovered by Chris Hall)
3- Changed email address from steve@edmweb.com to sreid@sea-to-sky.net
 
-----------------
Modified 4/01
By Saul Kravitz <Saul.Kravitz@celera.com>
Still 100% PD
Modified to run on Compaq Alpha hardware.
 
-----------------
Modified 07/2002
By Ralph Giles <giles@ghostscript.com>
Still 100% public domain
modified for use with stdint types, autoconf
code cleanup, removed attribution comments
switched SHA1Final() argument order for consistency
use SHA1_ prefix for public api
move public api to sha1.h
*/
 
/*
Test Vectors (from FIPS PUB 180-1)
"abc"
A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1
A million repetitions of "a"
34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F
*/
 
/* #define SHA1HANDSOFF */
 
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
 
#include <stdio.h>
#include <string.h>
 
#include "os_types.h"
#include "sha1.h"
 
void SHA1_Transform(uint32_t state[5], const uint8_t buffer[64]);
 
#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))
 
/* blk0() and blk() perform the initial expand. */
/* I got the idea of expanding during the round function from SSLeay */
/* FIXME: can we do this in an endian-proof way? */
#ifdef WORDS_BIGENDIAN
#define blk0(i) block->l[i]
#else
#define blk0(i) (block->l[i] = (rol(block->l[i],24)&0xFF00FF00) \
|(rol(block->l[i],8)&0x00FF00FF))
#endif
#define blk(i) (block->l[i&15] = rol(block->l[(i+13)&15]^block->l[(i+8)&15] \
^block->l[(i+2)&15]^block->l[i&15],1))
 
/* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */
#define R0(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk0(i)+0x5A827999+rol(v,5);w=rol(w,30);
#define R1(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk(i)+0x5A827999+rol(v,5);w=rol(w,30);
#define R2(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0x6ED9EBA1+rol(v,5);w=rol(w,30);
#define R3(v,w,x,y,z,i) z+=(((w|x)&y)|(w&x))+blk(i)+0x8F1BBCDC+rol(v,5);w=rol(w,30);
#define R4(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=rol(w,30);
 
 
#ifdef VERBOSE /* SAK */
void SHAPrintContext(SHA1_CTX *context, char *msg){
printf("%s (%d,%d) %x %x %x %x %x\n",
msg,
context->count[0], context->count[1],
context->state[0],
context->state[1],
context->state[2],
context->state[3],
context->state[4]);
}
#endif /* VERBOSE */
 
/* Hash a single 512-bit block. This is the core of the algorithm. */
void SHA1_Transform(uint32_t state[5], const uint8_t buffer[64])
{
uint32_t a, b, c, d, e;
typedef union {
uint8_t c[64];
uint32_t l[16];
} CHAR64LONG16;
CHAR64LONG16* block;
 
#ifdef SHA1HANDSOFF
static uint8_t workspace[64];
block = (CHAR64LONG16*)workspace;
memcpy(block, buffer, 64);
#else
block = (CHAR64LONG16*)buffer;
#endif
 
/* Copy context->state[] to working vars */
a = state[0];
b = state[1];
c = state[2];
d = state[3];
e = state[4];
 
/* 4 rounds of 20 operations each. Loop unrolled. */
R0(a,b,c,d,e, 0); R0(e,a,b,c,d, 1); R0(d,e,a,b,c, 2); R0(c,d,e,a,b, 3);
R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5); R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7);
R0(c,d,e,a,b, 8); R0(b,c,d,e,a, 9); R0(a,b,c,d,e,10); R0(e,a,b,c,d,11);
R0(d,e,a,b,c,12); R0(c,d,e,a,b,13); R0(b,c,d,e,a,14); R0(a,b,c,d,e,15);
R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19);
R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23);
R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27);
R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31);
R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35);
R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39);
R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43);
R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47);
R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51);
R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55);
R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59);
R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63);
R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67);
R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71);
R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75);
R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79);
 
/* Add the working vars back into context.state[] */
state[0] += a;
state[1] += b;
state[2] += c;
state[3] += d;
state[4] += e;
 
/* Wipe variables */
a = b = c = d = e = 0;
}
 
 
/* SHA1Init - Initialize new context */
void SHA1_Init(SHA1_CTX* context)
{
/* SHA1 initialization constants */
context->state[0] = 0x67452301;
context->state[1] = 0xEFCDAB89;
context->state[2] = 0x98BADCFE;
context->state[3] = 0x10325476;
context->state[4] = 0xC3D2E1F0;
context->count[0] = context->count[1] = 0;
}
 
 
/* Run your data through this. */
void SHA1_Update(SHA1_CTX* context, const uint8_t* data, const size_t len)
{
size_t i, j;
 
#ifdef VERBOSE
SHAPrintContext(context, "before");
#endif
 
j = (context->count[0] >> 3) & 63;
if ((context->count[0] += len << 3) < (len << 3)) context->count[1]++;
context->count[1] += (len >> 29);
if ((j + len) > 63) {
memcpy(&context->buffer[j], data, (i = 64-j));
SHA1_Transform(context->state, context->buffer);
for ( ; i + 63 < len; i += 64) {
SHA1_Transform(context->state, data + i);
}
j = 0;
}
else i = 0;
memcpy(&context->buffer[j], &data[i], len - i);
 
#ifdef VERBOSE
SHAPrintContext(context, "after ");
#endif
}
 
 
/* Add padding and return the message digest. */
void SHA1_Final(SHA1_CTX* context, uint8_t digest[SHA1_DIGEST_SIZE])
{
uint32_t i;
uint8_t finalcount[8];
 
for (i = 0; i < 8; i++) {
finalcount[i] = (unsigned char)((context->count[(i >= 4 ? 0 : 1)]
>> ((3-(i & 3)) * 8) ) & 255); /* Endian independent */
}
SHA1_Update(context, (uint8_t *)"\200", 1);
while ((context->count[0] & 504) != 448) {
SHA1_Update(context, (uint8_t *)"\0", 1);
}
SHA1_Update(context, finalcount, 8); /* Should cause a SHA1_Transform() */
for (i = 0; i < SHA1_DIGEST_SIZE; i++) {
digest[i] = (uint8_t)
((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255);
}
 
/* Wipe variables */
i = 0;
memset(context->buffer, 0, 64);
memset(context->state, 0, 20);
memset(context->count, 0, 8);
memset(finalcount, 0, 8); /* SWR */
 
#ifdef SHA1HANDSOFF /* make SHA1Transform overwrite its own static vars */
SHA1_Transform(context->state, context->buffer);
#endif
}
 
/*************************************************************/
 
#if 0
int main(int argc, char** argv)
{
int i, j;
SHA1_CTX context;
unsigned char digest[SHA1_DIGEST_SIZE], buffer[16384];
FILE* file;
 
if (argc > 2) {
puts("Public domain SHA-1 implementation - by Steve Reid <sreid@sea-to-sky.net>");
puts("Modified for 16 bit environments 7/98 - by James H. Brown <jbrown@burgoyne.com>"); /* JHB */
puts("Produces the SHA-1 hash of a file, or stdin if no file is specified.");
return(0);
}
if (argc < 2) {
file = stdin;
}
else {
if (!(file = fopen(argv[1], "rb"))) {
fputs("Unable to open file.", stderr);
return(-1);
}
}
SHA1_Init(&context);
while (!feof(file)) { /* note: what if ferror(file) */
i = fread(buffer, 1, 16384, file);
SHA1_Update(&context, buffer, i);
}
SHA1_Final(&context, digest);
fclose(file);
for (i = 0; i < SHA1_DIGEST_SIZE/4; i++) {
for (j = 0; j < 4; j++) {
printf("%02X", digest[i*4+j]);
}
putchar(' ');
}
putchar('\n');
return(0); /* JHB */
}
#endif
 
/* self test */
 
#ifdef TEST
 
static char *test_data[] = {
"abc",
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
"A million repetitions of 'a'"};
static char *test_results[] = {
"A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D",
"84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1",
"34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F"};
 
 
void digest_to_hex(const uint8_t digest[SHA1_DIGEST_SIZE], char *output)
{
int i,j;
char *c = output;
 
for (i = 0; i < SHA1_DIGEST_SIZE/4; i++) {
for (j = 0; j < 4; j++) {
sprintf(c,"%02X", digest[i*4+j]);
c += 2;
}
sprintf(c, " ");
c += 1;
}
*(c - 1) = '\0';
}
 
int main(int argc, char** argv)
{
int k;
SHA1_CTX context;
uint8_t digest[20];
char output[80];
 
fprintf(stdout, "verifying SHA-1 implementation... ");
 
for (k = 0; k < 2; k++){
SHA1_Init(&context);
SHA1_Update(&context, (uint8_t*)test_data[k], strlen(test_data[k]));
SHA1_Final(&context, digest);
digest_to_hex(digest, output);
 
if (strcmp(output, test_results[k])) {
fprintf(stdout, "FAIL\n");
fprintf(stderr,"* hash of \"%s\" incorrect:\n", test_data[k]);
fprintf(stderr,"\t%s returned\n", output);
fprintf(stderr,"\t%s is correct\n", test_results[k]);
return (1);
}
}
/* million 'a' vector we feed separately */
SHA1_Init(&context);
for (k = 0; k < 1000000; k++)
SHA1_Update(&context, (uint8_t*)"a", 1);
SHA1_Final(&context, digest);
digest_to_hex(digest, output);
if (strcmp(output, test_results[2])) {
fprintf(stdout, "FAIL\n");
fprintf(stderr,"* hash of \"%s\" incorrect:\n", test_data[2]);
fprintf(stderr,"\t%s returned\n", output);
fprintf(stderr,"\t%s is correct\n", test_results[2]);
return (1);
}
 
/* success */
fprintf(stdout, "ok\n");
return(0);
}
#endif /* TEST */
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libjbig2dec/sha1.h
0,0 → 1,27
/* public api for steve reid's public domain SHA-1 implementation */
/* this file is in the public domain */
 
#ifndef __SHA1_H
#define __SHA1_H
 
#ifdef __cplusplus
extern "C" {
#endif
 
typedef struct {
uint32_t state[5];
uint32_t count[2];
uint8_t buffer[64];
} SHA1_CTX;
 
#define SHA1_DIGEST_SIZE 20
 
void SHA1_Init(SHA1_CTX* context);
void SHA1_Update(SHA1_CTX* context, const uint8_t* data, const size_t len);
void SHA1_Final(SHA1_CTX* context, uint8_t digest[SHA1_DIGEST_SIZE]);
 
#ifdef __cplusplus
}
#endif
 
#endif /* __SHA1_H */
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libopenjpeg/Makefile
0,0 → 1,18
CC = kos32-gcc
LD = kos32-ld
 
SDK_DIR = ../../../sdk
CFLAGS = -c -fno-ident -O2 -fomit-frame-pointer -fno-ident -U__WIN32__ -U_Win32 -U_WIN32 -U__MINGW32__ -UWIN32
 
INCLUDES = -I $(SDK_DIR)/sources/newlib/libc/include -I $(SDK_DIR)/sources/freetype/include -I $(SDK_DIR)/sources/zlib -I .
 
SRC := $(notdir $(wildcard *.c))
OBJECTS = $(patsubst %.c, %.o, $(SRC))
 
default: $(patsubst %.c,%.o,$(SRC))
ar rcs libopenjpeg.a *.o
rm *.o
mv libopenjpeg.a ../lib
 
%.o : %.c Makefile $(SRC)
$(CC) $(CFLAGS) $(INCLUDES) -o $@ $<
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libopenjpeg/bio.c
0,0 → 1,187
/*
* Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2007, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
 
#include "opj_includes.h"
 
/** @defgroup BIO BIO - Individual bit input-output stream */
/*@{*/
 
/** @name Local static functions */
/*@{*/
 
/**
Write a bit
@param bio BIO handle
@param b Bit to write (0 or 1)
*/
static void bio_putbit(opj_bio_t *bio, int b);
/**
Read a bit
@param bio BIO handle
@return Returns the read bit
*/
static int bio_getbit(opj_bio_t *bio);
/**
Write a byte
@param bio BIO handle
@return Returns 0 if successful, returns 1 otherwise
*/
static int bio_byteout(opj_bio_t *bio);
/**
Read a byte
@param bio BIO handle
@return Returns 0 if successful, returns 1 otherwise
*/
static int bio_bytein(opj_bio_t *bio);
 
/*@}*/
 
/*@}*/
 
/*
==========================================================
local functions
==========================================================
*/
 
static int bio_byteout(opj_bio_t *bio) {
bio->buf = (bio->buf << 8) & 0xffff;
bio->ct = bio->buf == 0xff00 ? 7 : 8;
if (bio->bp >= bio->end) {
return 1;
}
*bio->bp++ = bio->buf >> 8;
return 0;
}
 
static int bio_bytein(opj_bio_t *bio) {
bio->buf = (bio->buf << 8) & 0xffff;
bio->ct = bio->buf == 0xff00 ? 7 : 8;
if (bio->bp >= bio->end) {
return 1;
}
bio->buf |= *bio->bp++;
return 0;
}
 
static void bio_putbit(opj_bio_t *bio, int b) {
if (bio->ct == 0) {
bio_byteout(bio);
}
bio->ct--;
bio->buf |= b << bio->ct;
}
 
static int bio_getbit(opj_bio_t *bio) {
if (bio->ct == 0) {
bio_bytein(bio);
}
bio->ct--;
return (bio->buf >> bio->ct) & 1;
}
 
/*
==========================================================
Bit Input/Output interface
==========================================================
*/
 
opj_bio_t* bio_create(void) {
opj_bio_t *bio = (opj_bio_t*)opj_malloc(sizeof(opj_bio_t));
return bio;
}
 
void bio_destroy(opj_bio_t *bio) {
if(bio) {
opj_free(bio);
}
}
 
int bio_numbytes(opj_bio_t *bio) {
return (bio->bp - bio->start);
}
 
void bio_init_enc(opj_bio_t *bio, unsigned char *bp, int len) {
bio->start = bp;
bio->end = bp + len;
bio->bp = bp;
bio->buf = 0;
bio->ct = 8;
}
 
void bio_init_dec(opj_bio_t *bio, unsigned char *bp, int len) {
bio->start = bp;
bio->end = bp + len;
bio->bp = bp;
bio->buf = 0;
bio->ct = 0;
}
 
void bio_write(opj_bio_t *bio, int v, int n) {
int i;
for (i = n - 1; i >= 0; i--) {
bio_putbit(bio, (v >> i) & 1);
}
}
 
int bio_read(opj_bio_t *bio, int n) {
int i, v;
v = 0;
for (i = n - 1; i >= 0; i--) {
v += bio_getbit(bio) << i;
}
return v;
}
 
int bio_flush(opj_bio_t *bio) {
bio->ct = 0;
if (bio_byteout(bio)) {
return 1;
}
if (bio->ct == 7) {
bio->ct = 0;
if (bio_byteout(bio)) {
return 1;
}
}
return 0;
}
 
int bio_inalign(opj_bio_t *bio) {
bio->ct = 0;
if ((bio->buf & 0xff) == 0xff) {
if (bio_bytein(bio)) {
return 1;
}
bio->ct = 0;
}
return 0;
}
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libopenjpeg/bio.h
0,0 → 1,125
/*
* Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2007, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
 
#ifndef __BIO_H
#define __BIO_H
/**
@file bio.h
@brief Implementation of an individual bit input-output (BIO)
 
The functions in BIO.C have for goal to realize an individual bit input - output.
*/
 
/** @defgroup BIO BIO - Individual bit input-output stream */
/*@{*/
 
/**
Individual bit input-output stream (BIO)
*/
typedef struct opj_bio {
/** pointer to the start of the buffer */
unsigned char *start;
/** pointer to the end of the buffer */
unsigned char *end;
/** pointer to the present position in the buffer */
unsigned char *bp;
/** temporary place where each byte is read or written */
unsigned int buf;
/** coder : number of bits free to write. decoder : number of bits read */
int ct;
} opj_bio_t;
 
/** @name Exported functions */
/*@{*/
/* ----------------------------------------------------------------------- */
/**
Create a new BIO handle
@return Returns a new BIO handle if successful, returns NULL otherwise
*/
opj_bio_t* bio_create(void);
/**
Destroy a previously created BIO handle
@param bio BIO handle to destroy
*/
void bio_destroy(opj_bio_t *bio);
/**
Number of bytes written.
@param bio BIO handle
@return Returns the number of bytes written
*/
int bio_numbytes(opj_bio_t *bio);
/**
Init encoder
@param bio BIO handle
@param bp Output buffer
@param len Output buffer length
*/
void bio_init_enc(opj_bio_t *bio, unsigned char *bp, int len);
/**
Init decoder
@param bio BIO handle
@param bp Input buffer
@param len Input buffer length
*/
void bio_init_dec(opj_bio_t *bio, unsigned char *bp, int len);
/**
Write bits
@param bio BIO handle
@param v Value of bits
@param n Number of bits to write
*/
void bio_write(opj_bio_t *bio, int v, int n);
/**
Read bits
@param bio BIO handle
@param n Number of bits to read
@return Returns the corresponding read number
*/
int bio_read(opj_bio_t *bio, int n);
/**
Flush bits
@param bio BIO handle
@return Returns 1 if successful, returns 0 otherwise
*/
int bio_flush(opj_bio_t *bio);
/**
Passes the ending bits (coming from flushing)
@param bio BIO handle
@return Returns 1 if successful, returns 0 otherwise
*/
int bio_inalign(opj_bio_t *bio);
/* ----------------------------------------------------------------------- */
/*@}*/
 
/*@}*/
 
#endif /* __BIO_H */
 
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libopenjpeg/cio.c
0,0 → 1,191
/*
* Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2007, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
 
#include "opj_includes.h"
 
/* ----------------------------------------------------------------------- */
 
opj_cio_t* OPJ_CALLCONV opj_cio_open(opj_common_ptr cinfo, unsigned char *buffer, int length) {
opj_cp_t *cp = NULL;
opj_cio_t *cio = (opj_cio_t*)opj_malloc(sizeof(opj_cio_t));
if(!cio) return NULL;
cio->cinfo = cinfo;
if(buffer && length) {
/* wrap a user buffer containing the encoded image */
cio->openmode = OPJ_STREAM_READ;
cio->buffer = buffer;
cio->length = length;
}
else if(!buffer && !length && cinfo) {
/* allocate a buffer for the encoded image */
cio->openmode = OPJ_STREAM_WRITE;
switch(cinfo->codec_format) {
case CODEC_J2K:
cp = ((opj_j2k_t*)cinfo->j2k_handle)->cp;
break;
case CODEC_JP2:
cp = ((opj_jp2_t*)cinfo->jp2_handle)->j2k->cp;
break;
default:
opj_free(cio);
return NULL;
}
cio->length = (unsigned int) (0.1625 * cp->img_size + 2000); /* 0.1625 = 1.3/8 and 2000 bytes as a minimum for headers */
cio->buffer = (unsigned char *)opj_malloc(cio->length);
if(!cio->buffer) {
opj_event_msg(cio->cinfo, EVT_ERROR, "Error allocating memory for compressed bitstream\n");
opj_free(cio);
return NULL;
}
}
else {
opj_free(cio);
return NULL;
}
 
/* Initialize byte IO */
cio->start = cio->buffer;
cio->end = cio->buffer + cio->length;
cio->bp = cio->buffer;
 
return cio;
}
 
void OPJ_CALLCONV opj_cio_close(opj_cio_t *cio) {
if(cio) {
if(cio->openmode == OPJ_STREAM_WRITE) {
/* destroy the allocated buffer */
opj_free(cio->buffer);
}
/* destroy the cio */
opj_free(cio);
}
}
 
 
/* ----------------------------------------------------------------------- */
 
/*
* Get position in byte stream.
*/
int OPJ_CALLCONV cio_tell(opj_cio_t *cio) {
return cio->bp - cio->start;
}
 
/*
* Set position in byte stream.
*
* pos : position, in number of bytes, from the beginning of the stream
*/
void OPJ_CALLCONV cio_seek(opj_cio_t *cio, int pos) {
cio->bp = cio->start + pos;
}
 
/*
* Number of bytes left before the end of the stream.
*/
int cio_numbytesleft(opj_cio_t *cio) {
return cio->end - cio->bp;
}
 
/*
* Get pointer to the current position in the stream.
*/
unsigned char *cio_getbp(opj_cio_t *cio) {
return cio->bp;
}
 
/*
* Write a byte.
*/
bool cio_byteout(opj_cio_t *cio, unsigned char v) {
if (cio->bp >= cio->end) {
opj_event_msg(cio->cinfo, EVT_ERROR, "write error\n");
return false;
}
*cio->bp++ = v;
return true;
}
 
/*
* Read a byte.
*/
unsigned char cio_bytein(opj_cio_t *cio) {
if (cio->bp >= cio->end) {
opj_event_msg(cio->cinfo, EVT_ERROR, "read error: passed the end of the codestream (start = %d, current = %d, end = %d\n", cio->start, cio->bp, cio->end);
return 0;
}
return *cio->bp++;
}
 
/*
* Write some bytes.
*
* v : value to write
* n : number of bytes to write
*/
unsigned int cio_write(opj_cio_t *cio, unsigned int v, int n) {
int i;
for (i = n - 1; i >= 0; i--) {
if( !cio_byteout(cio, (unsigned char) ((v >> (i << 3)) & 0xff)) )
return 0;
}
return n;
}
 
/*
* Read some bytes.
*
* n : number of bytes to read
*
* return : value of the n bytes read
*/
unsigned int cio_read(opj_cio_t *cio, int n) {
int i;
unsigned int v;
v = 0;
for (i = n - 1; i >= 0; i--) {
v += cio_bytein(cio) << (i << 3);
}
return v;
}
 
/*
* Skip some bytes.
*
* n : number of bytes to skip
*/
void cio_skip(opj_cio_t *cio, int n) {
cio->bp += n;
}
 
 
 
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libopenjpeg/cio.h
0,0 → 1,86
/*
* Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2007, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
 
#ifndef __CIO_H
#define __CIO_H
/**
@file cio.h
@brief Implementation of a byte input-output process (CIO)
 
The functions in CIO.C have for goal to realize a byte input / output process.
*/
 
/** @defgroup CIO CIO - byte input-output stream */
/*@{*/
 
/** @name Exported functions (see also openjpeg.h) */
/*@{*/
/* ----------------------------------------------------------------------- */
/**
Number of bytes left before the end of the stream
@param cio CIO handle
@return Returns the number of bytes before the end of the stream
*/
int cio_numbytesleft(opj_cio_t *cio);
/**
Get pointer to the current position in the stream
@param cio CIO handle
@return Returns a pointer to the current position
*/
unsigned char *cio_getbp(opj_cio_t *cio);
/**
Write some bytes
@param cio CIO handle
@param v Value to write
@param n Number of bytes to write
@return Returns the number of bytes written or 0 if an error occured
*/
unsigned int cio_write(opj_cio_t *cio, unsigned int v, int n);
/**
Read some bytes
@param cio CIO handle
@param n Number of bytes to read
@return Returns the value of the n bytes read
*/
unsigned int cio_read(opj_cio_t *cio, int n);
/**
Skip some bytes
@param cio CIO handle
@param n Number of bytes to skip
*/
void cio_skip(opj_cio_t *cio, int n);
/* ----------------------------------------------------------------------- */
/*@}*/
 
/*@}*/
 
#endif /* __CIO_H */
 
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libopenjpeg/dwt.c
0,0 → 1,858
/*
* Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2007, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2007, Jonathan Ballard <dzonatas@dzonux.net>
* Copyright (c) 2007, Callum Lerwick <seg@haxxed.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
 
#ifdef __SSE__
#include <xmmintrin.h>
#endif
 
#include "opj_includes.h"
 
/** @defgroup DWT DWT - Implementation of a discrete wavelet transform */
/*@{*/
 
#define WS(i) v->mem[(i)*2]
#define WD(i) v->mem[(1+(i)*2)]
 
/** @name Local data structures */
/*@{*/
 
typedef struct dwt_local {
int* mem;
int dn;
int sn;
int cas;
} dwt_t;
 
typedef union {
float f[4];
} v4;
 
typedef struct v4dwt_local {
v4* wavelet ;
int dn ;
int sn ;
int cas ;
} v4dwt_t ;
 
static const float dwt_alpha = 1.586134342f; // 12994
static const float dwt_beta = 0.052980118f; // 434
static const float dwt_gamma = -0.882911075f; // -7233
static const float dwt_delta = -0.443506852f; // -3633
 
static const float K = 1.230174105f; // 10078
/* FIXME: What is this constant? */
static const float c13318 = 1.625732422f;
 
/*@}*/
 
/**
Virtual function type for wavelet transform in 1-D
*/
typedef void (*DWT1DFN)(dwt_t* v);
 
/** @name Local static functions */
/*@{*/
 
/**
Forward lazy transform (horizontal)
*/
static void dwt_deinterleave_h(int *a, int *b, int dn, int sn, int cas);
/**
Forward lazy transform (vertical)
*/
static void dwt_deinterleave_v(int *a, int *b, int dn, int sn, int x, int cas);
/**
Inverse lazy transform (horizontal)
*/
static void dwt_interleave_h(dwt_t* h, int *a);
/**
Inverse lazy transform (vertical)
*/
static void dwt_interleave_v(dwt_t* v, int *a, int x);
/**
Forward 5-3 wavelet transform in 1-D
*/
static void dwt_encode_1(int *a, int dn, int sn, int cas);
/**
Inverse 5-3 wavelet transform in 1-D
*/
static void dwt_decode_1(dwt_t *v);
/**
Forward 9-7 wavelet transform in 1-D
*/
static void dwt_encode_1_real(int *a, int dn, int sn, int cas);
/**
Explicit calculation of the Quantization Stepsizes
*/
static void dwt_encode_stepsize(int stepsize, int numbps, opj_stepsize_t *bandno_stepsize);
/**
Inverse wavelet transform in 2-D.
*/
static void dwt_decode_tile(opj_tcd_tilecomp_t* tilec, int i, DWT1DFN fn);
 
/*@}*/
 
/*@}*/
 
#define S(i) a[(i)*2]
#define D(i) a[(1+(i)*2)]
#define S_(i) ((i)<0?S(0):((i)>=sn?S(sn-1):S(i)))
#define D_(i) ((i)<0?D(0):((i)>=dn?D(dn-1):D(i)))
/* new */
#define SS_(i) ((i)<0?S(0):((i)>=dn?S(dn-1):S(i)))
#define DD_(i) ((i)<0?D(0):((i)>=sn?D(sn-1):D(i)))
 
/* <summary> */
/* This table contains the norms of the 5-3 wavelets for different bands. */
/* </summary> */
static const double dwt_norms[4][10] = {
{1.000, 1.500, 2.750, 5.375, 10.68, 21.34, 42.67, 85.33, 170.7, 341.3},
{1.038, 1.592, 2.919, 5.703, 11.33, 22.64, 45.25, 90.48, 180.9},
{1.038, 1.592, 2.919, 5.703, 11.33, 22.64, 45.25, 90.48, 180.9},
{.7186, .9218, 1.586, 3.043, 6.019, 12.01, 24.00, 47.97, 95.93}
};
 
/* <summary> */
/* This table contains the norms of the 9-7 wavelets for different bands. */
/* </summary> */
static const double dwt_norms_real[4][10] = {
{1.000, 1.965, 4.177, 8.403, 16.90, 33.84, 67.69, 135.3, 270.6, 540.9},
{2.022, 3.989, 8.355, 17.04, 34.27, 68.63, 137.3, 274.6, 549.0},
{2.022, 3.989, 8.355, 17.04, 34.27, 68.63, 137.3, 274.6, 549.0},
{2.080, 3.865, 8.307, 17.18, 34.71, 69.59, 139.3, 278.6, 557.2}
};
 
/*
==========================================================
local functions
==========================================================
*/
 
/* <summary> */
/* Forward lazy transform (horizontal). */
/* </summary> */
static void dwt_deinterleave_h(int *a, int *b, int dn, int sn, int cas) {
int i;
for (i=0; i<sn; i++) b[i]=a[2*i+cas];
for (i=0; i<dn; i++) b[sn+i]=a[(2*i+1-cas)];
}
 
/* <summary> */
/* Forward lazy transform (vertical). */
/* </summary> */
static void dwt_deinterleave_v(int *a, int *b, int dn, int sn, int x, int cas) {
int i;
for (i=0; i<sn; i++) b[i*x]=a[2*i+cas];
for (i=0; i<dn; i++) b[(sn+i)*x]=a[(2*i+1-cas)];
}
 
/* <summary> */
/* Inverse lazy transform (horizontal). */
/* </summary> */
static void dwt_interleave_h(dwt_t* h, int *a) {
int *ai = a;
int *bi = h->mem + h->cas;
int i = h->sn;
while( i-- ) {
*bi = *(ai++);
bi += 2;
}
ai = a + h->sn;
bi = h->mem + 1 - h->cas;
i = h->dn ;
while( i-- ) {
*bi = *(ai++);
bi += 2;
}
}
 
/* <summary> */
/* Inverse lazy transform (vertical). */
/* </summary> */
static void dwt_interleave_v(dwt_t* v, int *a, int x) {
int *ai = a;
int *bi = v->mem + v->cas;
int i = v->sn;
while( i-- ) {
*bi = *ai;
bi += 2;
ai += x;
}
ai = a + (v->sn * x);
bi = v->mem + 1 - v->cas;
i = v->dn ;
while( i-- ) {
*bi = *ai;
bi += 2;
ai += x;
}
}
 
 
/* <summary> */
/* Forward 5-3 wavelet transform in 1-D. */
/* </summary> */
static void dwt_encode_1(int *a, int dn, int sn, int cas) {
int i;
if (!cas) {
if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */
for (i = 0; i < dn; i++) D(i) -= (S_(i) + S_(i + 1)) >> 1;
for (i = 0; i < sn; i++) S(i) += (D_(i - 1) + D_(i) + 2) >> 2;
}
} else {
if (!sn && dn == 1) /* NEW : CASE ONE ELEMENT */
S(0) *= 2;
else {
for (i = 0; i < dn; i++) S(i) -= (DD_(i) + DD_(i - 1)) >> 1;
for (i = 0; i < sn; i++) D(i) += (SS_(i) + SS_(i + 1) + 2) >> 2;
}
}
}
 
/* <summary> */
/* Inverse 5-3 wavelet transform in 1-D. */
/* </summary> */
static void dwt_decode_1_(int *a, int dn, int sn, int cas) {
int i;
if (!cas) {
if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */
for (i = 0; i < sn; i++) S(i) -= (D_(i - 1) + D_(i) + 2) >> 2;
for (i = 0; i < dn; i++) D(i) += (S_(i) + S_(i + 1)) >> 1;
}
} else {
if (!sn && dn == 1) /* NEW : CASE ONE ELEMENT */
S(0) /= 2;
else {
for (i = 0; i < sn; i++) D(i) -= (SS_(i) + SS_(i + 1) + 2) >> 2;
for (i = 0; i < dn; i++) S(i) += (DD_(i) + DD_(i - 1)) >> 1;
}
}
}
 
/* <summary> */
/* Inverse 5-3 wavelet transform in 1-D. */
/* </summary> */
static void dwt_decode_1(dwt_t *v) {
dwt_decode_1_(v->mem, v->dn, v->sn, v->cas);
}
 
/* <summary> */
/* Forward 9-7 wavelet transform in 1-D. */
/* </summary> */
static void dwt_encode_1_real(int *a, int dn, int sn, int cas) {
int i;
if (!cas) {
if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */
for (i = 0; i < dn; i++)
D(i) -= fix_mul(S_(i) + S_(i + 1), 12993);
for (i = 0; i < sn; i++)
S(i) -= fix_mul(D_(i - 1) + D_(i), 434);
for (i = 0; i < dn; i++)
D(i) += fix_mul(S_(i) + S_(i + 1), 7233);
for (i = 0; i < sn; i++)
S(i) += fix_mul(D_(i - 1) + D_(i), 3633);
for (i = 0; i < dn; i++)
D(i) = fix_mul(D(i), 5038); /*5038 */
for (i = 0; i < sn; i++)
S(i) = fix_mul(S(i), 6659); /*6660 */
}
} else {
if ((sn > 0) || (dn > 1)) { /* NEW : CASE ONE ELEMENT */
for (i = 0; i < dn; i++)
S(i) -= fix_mul(DD_(i) + DD_(i - 1), 12993);
for (i = 0; i < sn; i++)
D(i) -= fix_mul(SS_(i) + SS_(i + 1), 434);
for (i = 0; i < dn; i++)
S(i) += fix_mul(DD_(i) + DD_(i - 1), 7233);
for (i = 0; i < sn; i++)
D(i) += fix_mul(SS_(i) + SS_(i + 1), 3633);
for (i = 0; i < dn; i++)
S(i) = fix_mul(S(i), 5038); /*5038 */
for (i = 0; i < sn; i++)
D(i) = fix_mul(D(i), 6659); /*6660 */
}
}
}
 
static void dwt_encode_stepsize(int stepsize, int numbps, opj_stepsize_t *bandno_stepsize) {
int p, n;
p = int_floorlog2(stepsize) - 13;
n = 11 - int_floorlog2(stepsize);
bandno_stepsize->mant = (n < 0 ? stepsize >> -n : stepsize << n) & 0x7ff;
bandno_stepsize->expn = numbps - p;
}
 
/*
==========================================================
DWT interface
==========================================================
*/
 
/* <summary> */
/* Forward 5-3 wavelet transform in 2-D. */
/* </summary> */
void dwt_encode(opj_tcd_tilecomp_t * tilec) {
int i, j, k;
int *a = NULL;
int *aj = NULL;
int *bj = NULL;
int w, l;
w = tilec->x1-tilec->x0;
l = tilec->numresolutions-1;
a = tilec->data;
for (i = 0; i < l; i++) {
int rw; /* width of the resolution level computed */
int rh; /* height of the resolution level computed */
int rw1; /* width of the resolution level once lower than computed one */
int rh1; /* height of the resolution level once lower than computed one */
int cas_col; /* 0 = non inversion on horizontal filtering 1 = inversion between low-pass and high-pass filtering */
int cas_row; /* 0 = non inversion on vertical filtering 1 = inversion between low-pass and high-pass filtering */
int dn, sn;
rw = tilec->resolutions[l - i].x1 - tilec->resolutions[l - i].x0;
rh = tilec->resolutions[l - i].y1 - tilec->resolutions[l - i].y0;
rw1= tilec->resolutions[l - i - 1].x1 - tilec->resolutions[l - i - 1].x0;
rh1= tilec->resolutions[l - i - 1].y1 - tilec->resolutions[l - i - 1].y0;
cas_row = tilec->resolutions[l - i].x0 % 2;
cas_col = tilec->resolutions[l - i].y0 % 2;
sn = rh1;
dn = rh - rh1;
bj = (int*)opj_malloc(rh * sizeof(int));
for (j = 0; j < rw; j++) {
aj = a + j;
for (k = 0; k < rh; k++) bj[k] = aj[k*w];
dwt_encode_1(bj, dn, sn, cas_col);
dwt_deinterleave_v(bj, aj, dn, sn, w, cas_col);
}
opj_free(bj);
sn = rw1;
dn = rw - rw1;
bj = (int*)opj_malloc(rw * sizeof(int));
for (j = 0; j < rh; j++) {
aj = a + j * w;
for (k = 0; k < rw; k++) bj[k] = aj[k];
dwt_encode_1(bj, dn, sn, cas_row);
dwt_deinterleave_h(bj, aj, dn, sn, cas_row);
}
opj_free(bj);
}
}
 
 
/* <summary> */
/* Inverse 5-3 wavelet transform in 2-D. */
/* </summary> */
void dwt_decode(opj_tcd_tilecomp_t* tilec, int numres) {
dwt_decode_tile(tilec, numres, &dwt_decode_1);
}
 
 
/* <summary> */
/* Get gain of 5-3 wavelet transform. */
/* </summary> */
int dwt_getgain(int orient) {
if (orient == 0)
return 0;
if (orient == 1 || orient == 2)
return 1;
return 2;
}
 
/* <summary> */
/* Get norm of 5-3 wavelet. */
/* </summary> */
double dwt_getnorm(int level, int orient) {
return dwt_norms[orient][level];
}
 
/* <summary> */
/* Forward 9-7 wavelet transform in 2-D. */
/* </summary> */
 
void dwt_encode_real(opj_tcd_tilecomp_t * tilec) {
int i, j, k;
int *a = NULL;
int *aj = NULL;
int *bj = NULL;
int w, l;
w = tilec->x1-tilec->x0;
l = tilec->numresolutions-1;
a = tilec->data;
for (i = 0; i < l; i++) {
int rw; /* width of the resolution level computed */
int rh; /* height of the resolution level computed */
int rw1; /* width of the resolution level once lower than computed one */
int rh1; /* height of the resolution level once lower than computed one */
int cas_col; /* 0 = non inversion on horizontal filtering 1 = inversion between low-pass and high-pass filtering */
int cas_row; /* 0 = non inversion on vertical filtering 1 = inversion between low-pass and high-pass filtering */
int dn, sn;
rw = tilec->resolutions[l - i].x1 - tilec->resolutions[l - i].x0;
rh = tilec->resolutions[l - i].y1 - tilec->resolutions[l - i].y0;
rw1= tilec->resolutions[l - i - 1].x1 - tilec->resolutions[l - i - 1].x0;
rh1= tilec->resolutions[l - i - 1].y1 - tilec->resolutions[l - i - 1].y0;
cas_row = tilec->resolutions[l - i].x0 % 2;
cas_col = tilec->resolutions[l - i].y0 % 2;
sn = rh1;
dn = rh - rh1;
bj = (int*)opj_malloc(rh * sizeof(int));
for (j = 0; j < rw; j++) {
aj = a + j;
for (k = 0; k < rh; k++) bj[k] = aj[k*w];
dwt_encode_1_real(bj, dn, sn, cas_col);
dwt_deinterleave_v(bj, aj, dn, sn, w, cas_col);
}
opj_free(bj);
sn = rw1;
dn = rw - rw1;
bj = (int*)opj_malloc(rw * sizeof(int));
for (j = 0; j < rh; j++) {
aj = a + j * w;
for (k = 0; k < rw; k++) bj[k] = aj[k];
dwt_encode_1_real(bj, dn, sn, cas_row);
dwt_deinterleave_h(bj, aj, dn, sn, cas_row);
}
opj_free(bj);
}
}
 
 
/* <summary> */
/* Get gain of 9-7 wavelet transform. */
/* </summary> */
int dwt_getgain_real(int orient) {
(void)orient;
return 0;
}
 
/* <summary> */
/* Get norm of 9-7 wavelet. */
/* </summary> */
double dwt_getnorm_real(int level, int orient) {
return dwt_norms_real[orient][level];
}
 
void dwt_calc_explicit_stepsizes(opj_tccp_t * tccp, int prec) {
int numbands, bandno;
numbands = 3 * tccp->numresolutions - 2;
for (bandno = 0; bandno < numbands; bandno++) {
double stepsize;
int resno, level, orient, gain;
 
resno = (bandno == 0) ? 0 : ((bandno - 1) / 3 + 1);
orient = (bandno == 0) ? 0 : ((bandno - 1) % 3 + 1);
level = tccp->numresolutions - 1 - resno;
gain = (tccp->qmfbid == 0) ? 0 : ((orient == 0) ? 0 : (((orient == 1) || (orient == 2)) ? 1 : 2));
if (tccp->qntsty == J2K_CCP_QNTSTY_NOQNT) {
stepsize = 1.0;
} else {
double norm = dwt_norms_real[orient][level];
stepsize = (1 << (gain)) / norm;
}
dwt_encode_stepsize((int) floor(stepsize * 8192.0), prec + gain, &tccp->stepsizes[bandno]);
}
}
 
 
/* <summary> */
/* Determine maximum computed resolution level for inverse wavelet transform */
/* </summary> */
static int dwt_decode_max_resolution(opj_tcd_resolution_t* restrict r, int i) {
int mr = 1;
int w;
while( --i ) {
r++;
if( mr < ( w = r->x1 - r->x0 ) )
mr = w ;
if( mr < ( w = r->y1 - r->y0 ) )
mr = w ;
}
return mr ;
}
 
 
/* <summary> */
/* Inverse wavelet transform in 2-D. */
/* </summary> */
static void dwt_decode_tile(opj_tcd_tilecomp_t* tilec, int numres, DWT1DFN dwt_1D) {
dwt_t h;
dwt_t v;
 
opj_tcd_resolution_t* tr = tilec->resolutions;
 
int rw = tr->x1 - tr->x0; /* width of the resolution level computed */
int rh = tr->y1 - tr->y0; /* height of the resolution level computed */
 
int w = tilec->x1 - tilec->x0;
 
h.mem = opj_aligned_malloc(dwt_decode_max_resolution(tr, numres) * sizeof(int));
v.mem = h.mem;
 
while( --numres) {
int * restrict tiledp = tilec->data;
int j;
 
++tr;
h.sn = rw;
v.sn = rh;
 
rw = tr->x1 - tr->x0;
rh = tr->y1 - tr->y0;
 
h.dn = rw - h.sn;
h.cas = tr->x0 % 2;
 
for(j = 0; j < rh; ++j) {
dwt_interleave_h(&h, &tiledp[j*w]);
(dwt_1D)(&h);
memcpy(&tiledp[j*w], h.mem, rw * sizeof(int));
}
 
v.dn = rh - v.sn;
v.cas = tr->y0 % 2;
 
for(j = 0; j < rw; ++j){
int k;
dwt_interleave_v(&v, &tiledp[j], w);
(dwt_1D)(&v);
for(k = 0; k < rh; ++k) {
tiledp[k * w + j] = v.mem[k];
}
}
}
opj_aligned_free(h.mem);
}
 
static void v4dwt_interleave_h(v4dwt_t* restrict w, float* restrict a, int x, int size){
float* restrict bi = (float*) (w->wavelet + w->cas);
int count = w->sn;
int i, k;
for(k = 0; k < 2; ++k){
if (count + 3 * x < size && ((int) a & 0x0f) == 0 && ((int) bi & 0x0f) == 0 && (x & 0x0f) == 0) {
/* Fast code path */
for(i = 0; i < count; ++i){
int j = i;
bi[i*8 ] = a[j];
j += x;
bi[i*8 + 1] = a[j];
j += x;
bi[i*8 + 2] = a[j];
j += x;
bi[i*8 + 3] = a[j];
}
} else {
/* Slow code path */
for(i = 0; i < count; ++i){
int j = i;
bi[i*8 ] = a[j];
j += x;
if(j > size) continue;
bi[i*8 + 1] = a[j];
j += x;
if(j > size) continue;
bi[i*8 + 2] = a[j];
j += x;
if(j > size) continue;
bi[i*8 + 3] = a[j];
}
}
bi = (float*) (w->wavelet + 1 - w->cas);
a += w->sn;
size -= w->sn;
count = w->dn;
}
}
 
static void v4dwt_interleave_v(v4dwt_t* restrict v , float* restrict a , int x){
v4* restrict bi = v->wavelet + v->cas;
int i;
for(i = 0; i < v->sn; ++i){
memcpy(&bi[i*2], &a[i*x], 4 * sizeof(float));
}
a += v->sn * x;
bi = v->wavelet + 1 - v->cas;
for(i = 0; i < v->dn; ++i){
memcpy(&bi[i*2], &a[i*x], 4 * sizeof(float));
}
}
 
#ifdef __SSE__
 
static void v4dwt_decode_step1_sse(v4* w, int count, const __m128 c){
__m128* restrict vw = (__m128*) w;
int i;
/* 4x unrolled loop */
for(i = 0; i < count >> 2; ++i){
*vw = _mm_mul_ps(*vw, c);
vw += 2;
*vw = _mm_mul_ps(*vw, c);
vw += 2;
*vw = _mm_mul_ps(*vw, c);
vw += 2;
*vw = _mm_mul_ps(*vw, c);
vw += 2;
}
count &= 3;
for(i = 0; i < count; ++i){
*vw = _mm_mul_ps(*vw, c);
vw += 2;
}
}
 
static void v4dwt_decode_step2_sse(v4* l, v4* w, int k, int m, __m128 c){
__m128* restrict vl = (__m128*) l;
__m128* restrict vw = (__m128*) w;
int i;
__m128 tmp1, tmp2, tmp3;
tmp1 = vl[0];
for(i = 0; i < m; ++i){
tmp2 = vw[-1];
tmp3 = vw[ 0];
vw[-1] = _mm_add_ps(tmp2, _mm_mul_ps(_mm_add_ps(tmp1, tmp3), c));
tmp1 = tmp3;
vw += 2;
}
vl = vw - 2;
if(m >= k){
return;
}
c = _mm_add_ps(c, c);
c = _mm_mul_ps(c, vl[0]);
for(; m < k; ++m){
__m128 tmp = vw[-1];
vw[-1] = _mm_add_ps(tmp, c);
vw += 2;
}
}
 
#else
 
static void v4dwt_decode_step1(v4* w, int count, const float c){
float* restrict fw = (float*) w;
int i;
for(i = 0; i < count; ++i){
float tmp1 = fw[i*8 ];
float tmp2 = fw[i*8 + 1];
float tmp3 = fw[i*8 + 2];
float tmp4 = fw[i*8 + 3];
fw[i*8 ] = tmp1 * c;
fw[i*8 + 1] = tmp2 * c;
fw[i*8 + 2] = tmp3 * c;
fw[i*8 + 3] = tmp4 * c;
}
}
 
static void v4dwt_decode_step2(v4* l, v4* w, int k, int m, float c){
float* restrict fl = (float*) l;
float* restrict fw = (float*) w;
int i;
for(i = 0; i < m; ++i){
float tmp1_1 = fl[0];
float tmp1_2 = fl[1];
float tmp1_3 = fl[2];
float tmp1_4 = fl[3];
float tmp2_1 = fw[-4];
float tmp2_2 = fw[-3];
float tmp2_3 = fw[-2];
float tmp2_4 = fw[-1];
float tmp3_1 = fw[0];
float tmp3_2 = fw[1];
float tmp3_3 = fw[2];
float tmp3_4 = fw[3];
fw[-4] = tmp2_1 + ((tmp1_1 + tmp3_1) * c);
fw[-3] = tmp2_2 + ((tmp1_2 + tmp3_2) * c);
fw[-2] = tmp2_3 + ((tmp1_3 + tmp3_3) * c);
fw[-1] = tmp2_4 + ((tmp1_4 + tmp3_4) * c);
fl = fw;
fw += 8;
}
if(m < k){
float c1;
float c2;
float c3;
float c4;
c += c;
c1 = fl[0] * c;
c2 = fl[1] * c;
c3 = fl[2] * c;
c4 = fl[3] * c;
for(; m < k; ++m){
float tmp1 = fw[-4];
float tmp2 = fw[-3];
float tmp3 = fw[-2];
float tmp4 = fw[-1];
fw[-4] = tmp1 + c1;
fw[-3] = tmp2 + c2;
fw[-2] = tmp3 + c3;
fw[-1] = tmp4 + c4;
fw += 8;
}
}
}
 
#endif
 
/* <summary> */
/* Inverse 9-7 wavelet transform in 1-D. */
/* </summary> */
static void v4dwt_decode(v4dwt_t* restrict dwt){
int a, b;
if(dwt->cas == 0) {
if(!((dwt->dn > 0) || (dwt->sn > 1))){
return;
}
a = 0;
b = 1;
}else{
if(!((dwt->sn > 0) || (dwt->dn > 1))) {
return;
}
a = 1;
b = 0;
}
#ifdef __SSE__
v4dwt_decode_step1_sse(dwt->wavelet+a, dwt->sn, _mm_set1_ps(K));
v4dwt_decode_step1_sse(dwt->wavelet+b, dwt->dn, _mm_set1_ps(c13318));
v4dwt_decode_step2_sse(dwt->wavelet+b, dwt->wavelet+a+1, dwt->sn, int_min(dwt->sn, dwt->dn-a), _mm_set1_ps(dwt_delta));
v4dwt_decode_step2_sse(dwt->wavelet+a, dwt->wavelet+b+1, dwt->dn, int_min(dwt->dn, dwt->sn-b), _mm_set1_ps(dwt_gamma));
v4dwt_decode_step2_sse(dwt->wavelet+b, dwt->wavelet+a+1, dwt->sn, int_min(dwt->sn, dwt->dn-a), _mm_set1_ps(dwt_beta));
v4dwt_decode_step2_sse(dwt->wavelet+a, dwt->wavelet+b+1, dwt->dn, int_min(dwt->dn, dwt->sn-b), _mm_set1_ps(dwt_alpha));
#else
v4dwt_decode_step1(dwt->wavelet+a, dwt->sn, K);
v4dwt_decode_step1(dwt->wavelet+b, dwt->dn, c13318);
v4dwt_decode_step2(dwt->wavelet+b, dwt->wavelet+a+1, dwt->sn, int_min(dwt->sn, dwt->dn-a), dwt_delta);
v4dwt_decode_step2(dwt->wavelet+a, dwt->wavelet+b+1, dwt->dn, int_min(dwt->dn, dwt->sn-b), dwt_gamma);
v4dwt_decode_step2(dwt->wavelet+b, dwt->wavelet+a+1, dwt->sn, int_min(dwt->sn, dwt->dn-a), dwt_beta);
v4dwt_decode_step2(dwt->wavelet+a, dwt->wavelet+b+1, dwt->dn, int_min(dwt->dn, dwt->sn-b), dwt_alpha);
#endif
}
 
/* <summary> */
/* Inverse 9-7 wavelet transform in 2-D. */
/* </summary> */
void dwt_decode_real(opj_tcd_tilecomp_t* restrict tilec, int numres){
v4dwt_t h;
v4dwt_t v;
 
opj_tcd_resolution_t* res = tilec->resolutions;
 
int rw = res->x1 - res->x0; /* width of the resolution level computed */
int rh = res->y1 - res->y0; /* height of the resolution level computed */
 
int w = tilec->x1 - tilec->x0;
 
h.wavelet = (v4*) opj_aligned_malloc((dwt_decode_max_resolution(res, numres)+5) * sizeof(v4));
v.wavelet = h.wavelet;
 
while( --numres) {
float * restrict aj = (float*) tilec->data;
int bufsize = (tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0);
int j;
 
h.sn = rw;
v.sn = rh;
 
++res;
 
rw = res->x1 - res->x0; /* width of the resolution level computed */
rh = res->y1 - res->y0; /* height of the resolution level computed */
 
h.dn = rw - h.sn;
h.cas = res->x0 % 2;
 
for(j = rh; j > 3; j -= 4){
int k;
v4dwt_interleave_h(&h, aj, w, bufsize);
v4dwt_decode(&h);
for(k = rw; --k >= 0;){
aj[k ] = h.wavelet[k].f[0];
aj[k+w ] = h.wavelet[k].f[1];
aj[k+w*2] = h.wavelet[k].f[2];
aj[k+w*3] = h.wavelet[k].f[3];
}
aj += w*4;
bufsize -= w*4;
}
if (rh & 0x03) {
int k;
j = rh & 0x03;
v4dwt_interleave_h(&h, aj, w, bufsize);
v4dwt_decode(&h);
for(k = rw; --k >= 0;){
switch(j) {
case 3: aj[k+w*2] = h.wavelet[k].f[2];
case 2: aj[k+w ] = h.wavelet[k].f[1];
case 1: aj[k ] = h.wavelet[k].f[0];
}
}
}
 
v.dn = rh - v.sn;
v.cas = res->y0 % 2;
 
aj = (float*) tilec->data;
for(j = rw; j > 3; j -= 4){
int k;
v4dwt_interleave_v(&v, aj, w);
v4dwt_decode(&v);
for(k = 0; k < rh; ++k){
memcpy(&aj[k*w], &v.wavelet[k], 4 * sizeof(float));
}
aj += 4;
}
if (rw & 0x03){
int k;
j = rw & 0x03;
v4dwt_interleave_v(&v, aj, w);
v4dwt_decode(&v);
for(k = 0; k < rh; ++k){
memcpy(&aj[k*w], &v.wavelet[k], j * sizeof(float));
}
}
}
 
opj_aligned_free(h.wavelet);
}
 
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libopenjpeg/dwt.h
0,0 → 1,113
/*
* Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2007, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
 
#ifndef __DWT_H
#define __DWT_H
/**
@file dwt.h
@brief Implementation of a discrete wavelet transform (DWT)
 
The functions in DWT.C have for goal to realize forward and inverse discret wavelet
transform with filter 5-3 (reversible) and filter 9-7 (irreversible). The functions in
DWT.C are used by some function in TCD.C.
*/
 
/** @defgroup DWT DWT - Implementation of a discrete wavelet transform */
/*@{*/
 
 
/** @name Exported functions */
/*@{*/
/* ----------------------------------------------------------------------- */
/**
Forward 5-3 wavelet tranform in 2-D.
Apply a reversible DWT transform to a component of an image.
@param tilec Tile component information (current tile)
*/
void dwt_encode(opj_tcd_tilecomp_t * tilec);
/**
Inverse 5-3 wavelet tranform in 2-D.
Apply a reversible inverse DWT transform to a component of an image.
@param tilec Tile component information (current tile)
@param numres Number of resolution levels to decode
*/
void dwt_decode(opj_tcd_tilecomp_t* tilec, int numres);
/**
Get the gain of a subband for the reversible 5-3 DWT.
@param orient Number that identifies the subband (0->LL, 1->HL, 2->LH, 3->HH)
@return Returns 0 if orient = 0, returns 1 if orient = 1 or 2, returns 2 otherwise
*/
int dwt_getgain(int orient);
/**
Get the norm of a wavelet function of a subband at a specified level for the reversible 5-3 DWT.
@param level Level of the wavelet function
@param orient Band of the wavelet function
@return Returns the norm of the wavelet function
*/
double dwt_getnorm(int level, int orient);
/**
Forward 9-7 wavelet transform in 2-D.
Apply an irreversible DWT transform to a component of an image.
@param tilec Tile component information (current tile)
*/
void dwt_encode_real(opj_tcd_tilecomp_t * tilec);
/**
Inverse 9-7 wavelet transform in 2-D.
Apply an irreversible inverse DWT transform to a component of an image.
@param tilec Tile component information (current tile)
@param numres Number of resolution levels to decode
*/
void dwt_decode_real(opj_tcd_tilecomp_t* tilec, int numres);
/**
Get the gain of a subband for the irreversible 9-7 DWT.
@param orient Number that identifies the subband (0->LL, 1->HL, 2->LH, 3->HH)
@return Returns the gain of the 9-7 wavelet transform
*/
int dwt_getgain_real(int orient);
/**
Get the norm of a wavelet function of a subband at a specified level for the irreversible 9-7 DWT
@param level Level of the wavelet function
@param orient Band of the wavelet function
@return Returns the norm of the 9-7 wavelet
*/
double dwt_getnorm_real(int level, int orient);
/**
Explicit calculation of the Quantization Stepsizes
@param tccp Tile-component coding parameters
@param prec Precint analyzed
*/
void dwt_calc_explicit_stepsizes(opj_tccp_t * tccp, int prec);
/* ----------------------------------------------------------------------- */
/*@}*/
 
/*@}*/
 
#endif /* __DWT_H */
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libopenjpeg/event.c
0,0 → 1,121
/*
* Copyright (c) 2005, Hervé Drolon, FreeImage Team
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
 
#include "opj_includes.h"
 
/* ==========================================================
Utility functions
==========================================================*/
 
#ifndef _WIN32
static char*
i2a(unsigned i, char *a, unsigned r) {
if (i/r > 0) a = i2a(i/r,a,r);
*a = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[i%r];
return a+1;
}
 
/**
Transforms integer i into an ascii string and stores the result in a;
string is encoded in the base indicated by r.
@param i Number to be converted
@param a String result
@param r Base of value; must be in the range 2 - 36
@return Returns a
*/
static char *
_itoa(int i, char *a, int r) {
r = ((r < 2) || (r > 36)) ? 10 : r;
if(i < 0) {
*a = '-';
*i2a(-i, a+1, r) = 0;
}
else *i2a(i, a, r) = 0;
return a;
}
 
#endif /* !_WIN32 */
 
/* ----------------------------------------------------------------------- */
 
opj_event_mgr_t* OPJ_CALLCONV opj_set_event_mgr(opj_common_ptr cinfo, opj_event_mgr_t *event_mgr, void *context) {
if(cinfo) {
opj_event_mgr_t *previous = cinfo->event_mgr;
cinfo->event_mgr = event_mgr;
cinfo->client_data = context;
return previous;
}
 
return NULL;
}
 
bool opj_event_msg(opj_common_ptr cinfo, int event_type, const char *fmt, ...) {
#define MSG_SIZE 512 /* 512 bytes should be more than enough for a short message */
opj_msg_callback msg_handler = NULL;
 
opj_event_mgr_t *event_mgr = cinfo->event_mgr;
if(event_mgr != NULL) {
switch(event_type) {
case EVT_ERROR:
msg_handler = event_mgr->error_handler;
break;
case EVT_WARNING:
msg_handler = event_mgr->warning_handler;
break;
case EVT_INFO:
msg_handler = event_mgr->info_handler;
break;
default:
break;
}
if(msg_handler == NULL) {
return false;
}
} else {
return false;
}
 
if ((fmt != NULL) && (event_mgr != NULL)) {
va_list arg;
int str_length/*, i, j*/; /* UniPG */
char message[MSG_SIZE];
memset(message, 0, MSG_SIZE);
/* initialize the optional parameter list */
va_start(arg, fmt);
/* check the length of the format string */
str_length = (strlen(fmt) > MSG_SIZE) ? MSG_SIZE : strlen(fmt);
/* parse the format string and put the result in 'message' */
vsprintf(message, fmt, arg); /* UniPG */
/* deinitialize the optional parameter list */
va_end(arg);
 
/* output the message to the user program */
msg_handler(message, cinfo->client_data);
}
 
return true;
}
 
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libopenjpeg/event.h
0,0 → 1,58
/*
* Copyright (c) 2005, Hervé Drolon, FreeImage Team
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __EVENT_H
#define __EVENT_H
/**
@file event.h
@brief Implementation of a event callback system
 
The functions in EVENT.C have for goal to send output messages (errors, warnings, debug) to the user.
*/
 
#define EVT_ERROR 1 /**< Error event type */
#define EVT_WARNING 2 /**< Warning event type */
#define EVT_INFO 4 /**< Debug event type */
 
/** @defgroup EVENT EVENT - Implementation of a event callback system */
/*@{*/
 
/** @name Exported functions (see also openjpeg.h) */
/*@{*/
/* ----------------------------------------------------------------------- */
/**
Write formatted data to a string and send the string to a user callback.
@param cinfo Codec context info
@param event_type Event type or callback to use to send the message
@param fmt Format-control string (plus optionnal arguments)
@return Returns true if successful, returns false otherwise
*/
bool opj_event_msg(opj_common_ptr cinfo, int event_type, const char *fmt, ...);
/* ----------------------------------------------------------------------- */
/*@}*/
 
/*@}*/
 
#endif /* __EVENT_H */
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libopenjpeg/fix.h
0,0 → 1,64
/*
* Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2007, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __FIX_H
#define __FIX_H
 
#if defined(_MSC_VER) || defined(__BORLANDC__)
#define int64 __int64
#else
#define int64 long long
#endif
 
/**
@file fix.h
@brief Implementation of operations of specific multiplication (FIX)
 
The functions in FIX.H have for goal to realize specific multiplication.
*/
 
/** @defgroup FIX FIX - Implementation of operations of specific multiplication */
/*@{*/
 
/**
Multiply two fixed-precision rational numbers.
@param a
@param b
@return Returns a * b
*/
static INLINE int fix_mul(int a, int b) {
int64 temp = (int64) a * (int64) b ;
temp += temp & 4096;
return (int) (temp >> 13) ;
}
 
/*@}*/
 
#endif /* __FIX_H */
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libopenjpeg/image.c
0,0 → 1,89
/*
* Copyright (c) 2005, Hervé Drolon, FreeImage Team
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
 
#include "opj_includes.h"
 
opj_image_t* opj_image_create0(void) {
opj_image_t *image = (opj_image_t*)opj_calloc(1, sizeof(opj_image_t));
return image;
}
 
opj_image_t* OPJ_CALLCONV opj_image_create(int numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc) {
int compno;
opj_image_t *image = NULL;
 
image = (opj_image_t*) opj_calloc(1, sizeof(opj_image_t));
if(image) {
image->color_space = clrspc;
image->numcomps = numcmpts;
/* allocate memory for the per-component information */
image->comps = (opj_image_comp_t*)opj_malloc(image->numcomps * sizeof(opj_image_comp_t));
if(!image->comps) {
fprintf(stderr,"Unable to allocate memory for image.\n");
opj_image_destroy(image);
return NULL;
}
/* create the individual image components */
for(compno = 0; compno < numcmpts; compno++) {
opj_image_comp_t *comp = &image->comps[compno];
comp->dx = cmptparms[compno].dx;
comp->dy = cmptparms[compno].dy;
comp->w = cmptparms[compno].w;
comp->h = cmptparms[compno].h;
comp->x0 = cmptparms[compno].x0;
comp->y0 = cmptparms[compno].y0;
comp->prec = cmptparms[compno].prec;
comp->bpp = cmptparms[compno].bpp;
comp->sgnd = cmptparms[compno].sgnd;
comp->data = (int*) opj_calloc(comp->w * comp->h, sizeof(int));
if(!comp->data) {
fprintf(stderr,"Unable to allocate memory for image.\n");
opj_image_destroy(image);
return NULL;
}
}
}
 
return image;
}
 
void OPJ_CALLCONV opj_image_destroy(opj_image_t *image) {
int i;
if(image) {
if(image->comps) {
/* image components */
for(i = 0; i < image->numcomps; i++) {
opj_image_comp_t *image_comp = &image->comps[i];
if(image_comp->data) {
opj_free(image_comp->data);
}
}
opj_free(image->comps);
}
opj_free(image);
}
}
 
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libopenjpeg/image.h
0,0 → 1,48
/*
* Copyright (c) 2005, Hervé Drolon, FreeImage Team
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __IMAGE_H
#define __IMAGE_H
/**
@file image.h
@brief Implementation of operations on images (IMAGE)
 
The functions in IMAGE.C have for goal to realize operations on images.
*/
 
/** @defgroup IMAGE IMAGE - Implementation of operations on images */
/*@{*/
 
/**
Create an empty image
@todo this function should be removed
@return returns an empty image if successful, returns NULL otherwise
*/
opj_image_t* opj_image_create0(void);
 
/*@}*/
 
#endif /* __IMAGE_H */
 
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libopenjpeg/int.h
0,0 → 1,119
/*
* Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2007, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __INT_H
#define __INT_H
/**
@file int.h
@brief Implementation of operations on integers (INT)
 
The functions in INT.H have for goal to realize operations on integers.
*/
 
/** @defgroup INT INT - Implementation of operations on integers */
/*@{*/
 
/** @name Exported functions (see also openjpeg.h) */
/*@{*/
/* ----------------------------------------------------------------------- */
/**
Get the minimum of two integers
@return Returns a if a < b else b
*/
static INLINE int int_min(int a, int b) {
return a < b ? a : b;
}
/**
Get the maximum of two integers
@return Returns a if a > b else b
*/
static INLINE int int_max(int a, int b) {
return (a > b) ? a : b;
}
/**
Clamp an integer inside an interval
@return
<ul>
<li>Returns a if (min < a < max)
<li>Returns max if (a > max)
<li>Returns min if (a < min)
</ul>
*/
static INLINE int int_clamp(int a, int min, int max) {
if (a < min)
return min;
if (a > max)
return max;
return a;
}
/**
@return Get absolute value of integer
*/
static INLINE int int_abs(int a) {
return a < 0 ? -a : a;
}
/**
Divide an integer and round upwards
@return Returns a divided by b
*/
static INLINE int int_ceildiv(int a, int b) {
return (a + b - 1) / b;
}
/**
Divide an integer by a power of 2 and round upwards
@return Returns a divided by 2^b
*/
static INLINE int int_ceildivpow2(int a, int b) {
return (a + (1 << b) - 1) >> b;
}
/**
Divide an integer by a power of 2 and round downwards
@return Returns a divided by 2^b
*/
static INLINE int int_floordivpow2(int a, int b) {
return a >> b;
}
/**
Get logarithm of an integer and round downwards
@return Returns log2(a)
*/
static INLINE int int_floorlog2(int a) {
int l;
for (l = 0; a > 1; l++) {
a >>= 1;
}
return l;
}
/* ----------------------------------------------------------------------- */
/*@}*/
 
/*@}*/
 
#endif
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libopenjpeg/j2k.c
0,0 → 1,2434
/*
* Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2007, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2006-2007, Parvatha Elangovan
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
 
#include "opj_includes.h"
 
/** @defgroup J2K J2K - JPEG-2000 codestream reader/writer */
/*@{*/
 
/** @name Local static functions */
/*@{*/
 
/**
Write the SOC marker (Start Of Codestream)
@param j2k J2K handle
*/
static void j2k_write_soc(opj_j2k_t *j2k);
/**
Read the SOC marker (Start of Codestream)
@param j2k J2K handle
*/
static void j2k_read_soc(opj_j2k_t *j2k);
/**
Write the SIZ marker (image and tile size)
@param j2k J2K handle
*/
static void j2k_write_siz(opj_j2k_t *j2k);
/**
Read the SIZ marker (image and tile size)
@param j2k J2K handle
*/
static void j2k_read_siz(opj_j2k_t *j2k);
/**
Write the COM marker (comment)
@param j2k J2K handle
*/
static void j2k_write_com(opj_j2k_t *j2k);
/**
Read the COM marker (comment)
@param j2k J2K handle
*/
static void j2k_read_com(opj_j2k_t *j2k);
/**
Write the value concerning the specified component in the marker COD and COC
@param j2k J2K handle
@param compno Number of the component concerned by the information written
*/
static void j2k_write_cox(opj_j2k_t *j2k, int compno);
/**
Read the value concerning the specified component in the marker COD and COC
@param j2k J2K handle
@param compno Number of the component concerned by the information read
*/
static void j2k_read_cox(opj_j2k_t *j2k, int compno);
/**
Write the COD marker (coding style default)
@param j2k J2K handle
*/
static void j2k_write_cod(opj_j2k_t *j2k);
/**
Read the COD marker (coding style default)
@param j2k J2K handle
*/
static void j2k_read_cod(opj_j2k_t *j2k);
/**
Write the COC marker (coding style component)
@param j2k J2K handle
@param compno Number of the component concerned by the information written
*/
static void j2k_write_coc(opj_j2k_t *j2k, int compno);
/**
Read the COC marker (coding style component)
@param j2k J2K handle
*/
static void j2k_read_coc(opj_j2k_t *j2k);
/**
Write the value concerning the specified component in the marker QCD and QCC
@param j2k J2K handle
@param compno Number of the component concerned by the information written
*/
static void j2k_write_qcx(opj_j2k_t *j2k, int compno);
/**
Read the value concerning the specified component in the marker QCD and QCC
@param j2k J2K handle
@param compno Number of the component concern by the information read
@param len Length of the information in the QCX part of the marker QCD/QCC
*/
static void j2k_read_qcx(opj_j2k_t *j2k, int compno, int len);
/**
Write the QCD marker (quantization default)
@param j2k J2K handle
*/
static void j2k_write_qcd(opj_j2k_t *j2k);
/**
Read the QCD marker (quantization default)
@param j2k J2K handle
*/
static void j2k_read_qcd(opj_j2k_t *j2k);
/**
Write the QCC marker (quantization component)
@param j2k J2K handle
@param compno Number of the component concerned by the information written
*/
static void j2k_write_qcc(opj_j2k_t *j2k, int compno);
/**
Read the QCC marker (quantization component)
@param j2k J2K handle
*/
static void j2k_read_qcc(opj_j2k_t *j2k);
/**
Write the POC marker (progression order change)
@param j2k J2K handle
*/
static void j2k_write_poc(opj_j2k_t *j2k);
/**
Read the POC marker (progression order change)
@param j2k J2K handle
*/
static void j2k_read_poc(opj_j2k_t *j2k);
/**
Read the CRG marker (component registration)
@param j2k J2K handle
*/
static void j2k_read_crg(opj_j2k_t *j2k);
/**
Read the TLM marker (tile-part lengths)
@param j2k J2K handle
*/
static void j2k_read_tlm(opj_j2k_t *j2k);
/**
Read the PLM marker (packet length, main header)
@param j2k J2K handle
*/
static void j2k_read_plm(opj_j2k_t *j2k);
/**
Read the PLT marker (packet length, tile-part header)
@param j2k J2K handle
*/
static void j2k_read_plt(opj_j2k_t *j2k);
/**
Read the PPM marker (packet packet headers, main header)
@param j2k J2K handle
*/
static void j2k_read_ppm(opj_j2k_t *j2k);
/**
Read the PPT marker (packet packet headers, tile-part header)
@param j2k J2K handle
*/
static void j2k_read_ppt(opj_j2k_t *j2k);
/**
Write the TLM marker (Mainheader)
@param j2k J2K handle
*/
static void j2k_write_tlm(opj_j2k_t *j2k);
/**
Write the SOT marker (start of tile-part)
@param j2k J2K handle
*/
static void j2k_write_sot(opj_j2k_t *j2k);
/**
Read the SOT marker (start of tile-part)
@param j2k J2K handle
*/
static void j2k_read_sot(opj_j2k_t *j2k);
/**
Write the SOD marker (start of data)
@param j2k J2K handle
@param tile_coder Pointer to a TCD handle
*/
static void j2k_write_sod(opj_j2k_t *j2k, void *tile_coder);
/**
Read the SOD marker (start of data)
@param j2k J2K handle
*/
static void j2k_read_sod(opj_j2k_t *j2k);
/**
Write the RGN marker (region-of-interest)
@param j2k J2K handle
@param compno Number of the component concerned by the information written
@param tileno Number of the tile concerned by the information written
*/
static void j2k_write_rgn(opj_j2k_t *j2k, int compno, int tileno);
/**
Read the RGN marker (region-of-interest)
@param j2k J2K handle
*/
static void j2k_read_rgn(opj_j2k_t *j2k);
/**
Write the EOC marker (end of codestream)
@param j2k J2K handle
*/
static void j2k_write_eoc(opj_j2k_t *j2k);
/**
Read the EOC marker (end of codestream)
@param j2k J2K handle
*/
static void j2k_read_eoc(opj_j2k_t *j2k);
/**
Read an unknown marker
@param j2k J2K handle
*/
static void j2k_read_unk(opj_j2k_t *j2k);
 
/*@}*/
 
/*@}*/
 
/* ----------------------------------------------------------------------- */
typedef struct j2k_prog_order{
OPJ_PROG_ORDER enum_prog;
char str_prog[4];
}j2k_prog_order_t;
 
j2k_prog_order_t j2k_prog_order_list[] = {
{CPRL, "CPRL"},
{LRCP, "LRCP"},
{PCRL, "PCRL"},
{RLCP, "RLCP"},
{RPCL, "RPCL"},
{(OPJ_PROG_ORDER)-1, ""}
};
 
char *j2k_convert_progression_order(OPJ_PROG_ORDER prg_order){
j2k_prog_order_t *po;
for(po = j2k_prog_order_list; po->enum_prog != -1; po++ ){
if(po->enum_prog == prg_order){
break;
}
}
return po->str_prog;
}
 
/* ----------------------------------------------------------------------- */
static int j2k_get_num_tp(opj_cp_t *cp,int pino,int tileno){
char *prog;
int i;
int tpnum=1,tpend=0;
opj_tcp_t *tcp = &cp->tcps[tileno];
prog = j2k_convert_progression_order(tcp->prg);
if(cp->tp_on == 1){
for(i=0;i<4;i++){
if(tpend!=1){
if( cp->tp_flag == prog[i] ){
tpend=1;cp->tp_pos=i;
}
switch(prog[i]){
case 'C':
tpnum= tpnum * tcp->pocs[pino].compE;
break;
case 'R':
tpnum= tpnum * tcp->pocs[pino].resE;
break;
case 'P':
tpnum= tpnum * tcp->pocs[pino].prcE;
break;
case 'L':
tpnum= tpnum * tcp->pocs[pino].layE;
break;
}
}
}
}else{
tpnum=1;
}
return tpnum;
}
 
/** mem allocation for TLM marker*/
int j2k_calculate_tp(opj_cp_t *cp,int img_numcomp,opj_image_t *image,opj_j2k_t *j2k ){
int pino,tileno,totnum_tp=0;
j2k->cur_totnum_tp = (int *) opj_malloc(cp->tw * cp->th * sizeof(int));
for (tileno = 0; tileno < cp->tw * cp->th; tileno++) {
int cur_totnum_tp = 0;
opj_tcp_t *tcp = &cp->tcps[tileno];
for(pino = 0; pino <= tcp->numpocs; pino++) {
int tp_num=0;
opj_pi_iterator_t *pi = pi_initialise_encode(image, cp, tileno,FINAL_PASS);
if(!pi) { return -1;}
tp_num = j2k_get_num_tp(cp,pino,tileno);
totnum_tp = totnum_tp + tp_num;
cur_totnum_tp = cur_totnum_tp + tp_num;
pi_destroy(pi, cp, tileno);
}
j2k->cur_totnum_tp[tileno] = cur_totnum_tp;
/* INDEX >> */
if (j2k->cstr_info) {
j2k->cstr_info->tile[tileno].num_tps = cur_totnum_tp;
j2k->cstr_info->tile[tileno].tp = (opj_tp_info_t *) opj_malloc(cur_totnum_tp * sizeof(opj_tp_info_t));
}
/* << INDEX */
}
return totnum_tp;
}
 
static void j2k_write_soc(opj_j2k_t *j2k) {
opj_cio_t *cio = j2k->cio;
cio_write(cio, J2K_MS_SOC, 2);
 
/* UniPG>> */
#ifdef USE_JPWL
 
/* update markers struct */
j2k_add_marker(j2k->cstr_info, J2K_MS_SOC, cio_tell(cio) - 2, 2);
 
#endif /* USE_JPWL */
/* <<UniPG */
}
 
static void j2k_read_soc(opj_j2k_t *j2k) {
j2k->state = J2K_STATE_MHSIZ;
/* Index */
if (j2k->cstr_info) {
j2k->cstr_info->main_head_start = cio_tell(j2k->cio) - 2;
j2k->cstr_info->codestream_size = cio_numbytesleft(j2k->cio) + 2 - j2k->cstr_info->main_head_start;
}
}
 
static void j2k_write_siz(opj_j2k_t *j2k) {
int i;
int lenp, len;
 
opj_cio_t *cio = j2k->cio;
opj_image_t *image = j2k->image;
opj_cp_t *cp = j2k->cp;
cio_write(cio, J2K_MS_SIZ, 2); /* SIZ */
lenp = cio_tell(cio);
cio_skip(cio, 2);
cio_write(cio, cp->rsiz, 2); /* Rsiz (capabilities) */
cio_write(cio, image->x1, 4); /* Xsiz */
cio_write(cio, image->y1, 4); /* Ysiz */
cio_write(cio, image->x0, 4); /* X0siz */
cio_write(cio, image->y0, 4); /* Y0siz */
cio_write(cio, cp->tdx, 4); /* XTsiz */
cio_write(cio, cp->tdy, 4); /* YTsiz */
cio_write(cio, cp->tx0, 4); /* XT0siz */
cio_write(cio, cp->ty0, 4); /* YT0siz */
cio_write(cio, image->numcomps, 2); /* Csiz */
for (i = 0; i < image->numcomps; i++) {
cio_write(cio, image->comps[i].prec - 1 + (image->comps[i].sgnd << 7), 1); /* Ssiz_i */
cio_write(cio, image->comps[i].dx, 1); /* XRsiz_i */
cio_write(cio, image->comps[i].dy, 1); /* YRsiz_i */
}
len = cio_tell(cio) - lenp;
cio_seek(cio, lenp);
cio_write(cio, len, 2); /* Lsiz */
cio_seek(cio, lenp + len);
}
 
static void j2k_read_siz(opj_j2k_t *j2k) {
int len, i;
opj_cio_t *cio = j2k->cio;
opj_image_t *image = j2k->image;
opj_cp_t *cp = j2k->cp;
len = cio_read(cio, 2); /* Lsiz */
cio_read(cio, 2); /* Rsiz (capabilities) */
image->x1 = cio_read(cio, 4); /* Xsiz */
image->y1 = cio_read(cio, 4); /* Ysiz */
image->x0 = cio_read(cio, 4); /* X0siz */
image->y0 = cio_read(cio, 4); /* Y0siz */
cp->tdx = cio_read(cio, 4); /* XTsiz */
cp->tdy = cio_read(cio, 4); /* YTsiz */
cp->tx0 = cio_read(cio, 4); /* XT0siz */
cp->ty0 = cio_read(cio, 4); /* YT0siz */
if ((image->x0<0)||(image->x1<0)||(image->y0<0)||(image->y1<0)) {
opj_event_msg(j2k->cinfo, EVT_ERROR,
"%s: invalid image size (x0:%d, x1:%d, y0:%d, y1:%d)\n",
image->x0,image->x1,image->y0,image->y1);
return;
}
image->numcomps = cio_read(cio, 2); /* Csiz */
 
#ifdef USE_JPWL
if (j2k->cp->correct) {
/* if JPWL is on, we check whether TX errors have damaged
too much the SIZ parameters */
if (!(image->x1 * image->y1)) {
opj_event_msg(j2k->cinfo, EVT_ERROR,
"JPWL: bad image size (%d x %d)\n",
image->x1, image->y1);
if (!JPWL_ASSUME || JPWL_ASSUME) {
opj_event_msg(j2k->cinfo, EVT_ERROR, "JPWL: giving up\n");
return;
}
}
if (image->numcomps != ((len - 38) / 3)) {
opj_event_msg(j2k->cinfo, JPWL_ASSUME ? EVT_WARNING : EVT_ERROR,
"JPWL: Csiz is %d => space in SIZ only for %d comps.!!!\n",
image->numcomps, ((len - 38) / 3));
if (!JPWL_ASSUME) {
opj_event_msg(j2k->cinfo, EVT_ERROR, "JPWL: giving up\n");
return;
}
/* we try to correct */
opj_event_msg(j2k->cinfo, EVT_WARNING, "- trying to adjust this\n");
if (image->numcomps < ((len - 38) / 3)) {
len = 38 + 3 * image->numcomps;
opj_event_msg(j2k->cinfo, EVT_WARNING, "- setting Lsiz to %d => HYPOTHESIS!!!\n",
len);
} else {
image->numcomps = ((len - 38) / 3);
opj_event_msg(j2k->cinfo, EVT_WARNING, "- setting Csiz to %d => HYPOTHESIS!!!\n",
image->numcomps);
}
}
 
/* update components number in the jpwl_exp_comps filed */
cp->exp_comps = image->numcomps;
}
#endif /* USE_JPWL */
 
image->comps = (opj_image_comp_t*) opj_calloc(image->numcomps, sizeof(opj_image_comp_t));
for (i = 0; i < image->numcomps; i++) {
int tmp, w, h;
tmp = cio_read(cio, 1); /* Ssiz_i */
image->comps[i].prec = (tmp & 0x7f) + 1;
image->comps[i].sgnd = tmp >> 7;
image->comps[i].dx = cio_read(cio, 1); /* XRsiz_i */
image->comps[i].dy = cio_read(cio, 1); /* YRsiz_i */
#ifdef USE_JPWL
if (j2k->cp->correct) {
/* if JPWL is on, we check whether TX errors have damaged
too much the SIZ parameters, again */
if (!(image->comps[i].dx * image->comps[i].dy)) {
opj_event_msg(j2k->cinfo, JPWL_ASSUME ? EVT_WARNING : EVT_ERROR,
"JPWL: bad XRsiz_%d/YRsiz_%d (%d x %d)\n",
i, i, image->comps[i].dx, image->comps[i].dy);
if (!JPWL_ASSUME) {
opj_event_msg(j2k->cinfo, EVT_ERROR, "JPWL: giving up\n");
return;
}
/* we try to correct */
opj_event_msg(j2k->cinfo, EVT_WARNING, "- trying to adjust them\n");
if (!image->comps[i].dx) {
image->comps[i].dx = 1;
opj_event_msg(j2k->cinfo, EVT_WARNING, "- setting XRsiz_%d to %d => HYPOTHESIS!!!\n",
i, image->comps[i].dx);
}
if (!image->comps[i].dy) {
image->comps[i].dy = 1;
opj_event_msg(j2k->cinfo, EVT_WARNING, "- setting YRsiz_%d to %d => HYPOTHESIS!!!\n",
i, image->comps[i].dy);
}
}
}
#endif /* USE_JPWL */
 
/* TODO: unused ? */
w = int_ceildiv(image->x1 - image->x0, image->comps[i].dx);
h = int_ceildiv(image->y1 - image->y0, image->comps[i].dy);
 
image->comps[i].resno_decoded = 0; /* number of resolution decoded */
image->comps[i].factor = cp->reduce; /* reducing factor per component */
}
cp->tw = int_ceildiv(image->x1 - cp->tx0, cp->tdx);
cp->th = int_ceildiv(image->y1 - cp->ty0, cp->tdy);
 
#ifdef USE_JPWL
if (j2k->cp->correct) {
/* if JPWL is on, we check whether TX errors have damaged
too much the SIZ parameters */
if ((cp->tw < 1) || (cp->th < 1) || (cp->tw > cp->max_tiles) || (cp->th > cp->max_tiles)) {
opj_event_msg(j2k->cinfo, JPWL_ASSUME ? EVT_WARNING : EVT_ERROR,
"JPWL: bad number of tiles (%d x %d)\n",
cp->tw, cp->th);
if (!JPWL_ASSUME) {
opj_event_msg(j2k->cinfo, EVT_ERROR, "JPWL: giving up\n");
return;
}
/* we try to correct */
opj_event_msg(j2k->cinfo, EVT_WARNING, "- trying to adjust them\n");
if (cp->tw < 1) {
cp->tw= 1;
opj_event_msg(j2k->cinfo, EVT_WARNING, "- setting %d tiles in x => HYPOTHESIS!!!\n",
cp->tw);
}
if (cp->tw > cp->max_tiles) {
cp->tw= 1;
opj_event_msg(j2k->cinfo, EVT_WARNING, "- too large x, increase expectance of %d\n"
"- setting %d tiles in x => HYPOTHESIS!!!\n",
cp->max_tiles, cp->tw);
}
if (cp->th < 1) {
cp->th= 1;
opj_event_msg(j2k->cinfo, EVT_WARNING, "- setting %d tiles in y => HYPOTHESIS!!!\n",
cp->th);
}
if (cp->th > cp->max_tiles) {
cp->th= 1;
opj_event_msg(j2k->cinfo, EVT_WARNING, "- too large y, increase expectance of %d to continue\n",
"- setting %d tiles in y => HYPOTHESIS!!!\n",
cp->max_tiles, cp->th);
}
}
}
#endif /* USE_JPWL */
 
cp->tcps = (opj_tcp_t*) opj_calloc(cp->tw * cp->th, sizeof(opj_tcp_t));
cp->tileno = (int*) opj_malloc(cp->tw * cp->th * sizeof(int));
cp->tileno_size = 0;
#ifdef USE_JPWL
if (j2k->cp->correct) {
if (!cp->tcps) {
opj_event_msg(j2k->cinfo, JPWL_ASSUME ? EVT_WARNING : EVT_ERROR,
"JPWL: could not alloc tcps field of cp\n");
if (!JPWL_ASSUME || JPWL_ASSUME) {
opj_event_msg(j2k->cinfo, EVT_ERROR, "JPWL: giving up\n");
return;
}
}
}
#endif /* USE_JPWL */
 
for (i = 0; i < cp->tw * cp->th; i++) {
cp->tcps[i].POC = 0;
cp->tcps[i].numpocs = 0;
cp->tcps[i].first = 1;
}
/* Initialization for PPM marker */
cp->ppm = 0;
cp->ppm_data = NULL;
cp->ppm_data_first = NULL;
cp->ppm_previous = 0;
cp->ppm_store = 0;
 
j2k->default_tcp->tccps = (opj_tccp_t*) opj_calloc(image->numcomps, sizeof(opj_tccp_t));
for (i = 0; i < cp->tw * cp->th; i++) {
cp->tcps[i].tccps = (opj_tccp_t*) opj_malloc(image->numcomps * sizeof(opj_tccp_t));
}
j2k->tile_data = (unsigned char**) opj_calloc(cp->tw * cp->th, sizeof(unsigned char*));
j2k->tile_len = (int*) opj_calloc(cp->tw * cp->th, sizeof(int));
j2k->state = J2K_STATE_MH;
 
/* Index */
if (j2k->cstr_info) {
opj_codestream_info_t *cstr_info = j2k->cstr_info;
cstr_info->image_w = image->x1 - image->x0;
cstr_info->image_h = image->y1 - image->y0;
cstr_info->numcomps = image->numcomps;
cstr_info->tw = cp->tw;
cstr_info->th = cp->th;
cstr_info->tile_x = cp->tdx;
cstr_info->tile_y = cp->tdy;
cstr_info->tile_Ox = cp->tx0;
cstr_info->tile_Oy = cp->ty0;
cstr_info->tile = (opj_tile_info_t*) opj_calloc(cp->tw * cp->th, sizeof(opj_tile_info_t));
}
}
 
static void j2k_write_com(opj_j2k_t *j2k) {
unsigned int i;
int lenp, len;
 
if(j2k->cp->comment) {
opj_cio_t *cio = j2k->cio;
char *comment = j2k->cp->comment;
 
cio_write(cio, J2K_MS_COM, 2);
lenp = cio_tell(cio);
cio_skip(cio, 2);
cio_write(cio, 1, 2); /* General use (IS 8859-15:1999 (Latin) values) */
for (i = 0; i < strlen(comment); i++) {
cio_write(cio, comment[i], 1);
}
len = cio_tell(cio) - lenp;
cio_seek(cio, lenp);
cio_write(cio, len, 2);
cio_seek(cio, lenp + len);
}
}
 
static void j2k_read_com(opj_j2k_t *j2k) {
int len;
opj_cio_t *cio = j2k->cio;
 
len = cio_read(cio, 2);
cio_skip(cio, len - 2);
}
 
static void j2k_write_cox(opj_j2k_t *j2k, int compno) {
int i;
 
opj_cp_t *cp = j2k->cp;
opj_tcp_t *tcp = &cp->tcps[j2k->curtileno];
opj_tccp_t *tccp = &tcp->tccps[compno];
opj_cio_t *cio = j2k->cio;
cio_write(cio, tccp->numresolutions - 1, 1); /* SPcox (D) */
cio_write(cio, tccp->cblkw - 2, 1); /* SPcox (E) */
cio_write(cio, tccp->cblkh - 2, 1); /* SPcox (F) */
cio_write(cio, tccp->cblksty, 1); /* SPcox (G) */
cio_write(cio, tccp->qmfbid, 1); /* SPcox (H) */
if (tccp->csty & J2K_CCP_CSTY_PRT) {
for (i = 0; i < tccp->numresolutions; i++) {
cio_write(cio, tccp->prcw[i] + (tccp->prch[i] << 4), 1); /* SPcox (I_i) */
}
}
}
 
static void j2k_read_cox(opj_j2k_t *j2k, int compno) {
int i;
 
opj_cp_t *cp = j2k->cp;
opj_tcp_t *tcp = j2k->state == J2K_STATE_TPH ? &cp->tcps[j2k->curtileno] : j2k->default_tcp;
opj_tccp_t *tccp = &tcp->tccps[compno];
opj_cio_t *cio = j2k->cio;
 
tccp->numresolutions = cio_read(cio, 1) + 1; /* SPcox (D) */
 
// If user wants to remove more resolutions than the codestream contains, return error
if (cp->reduce >= tccp->numresolutions) {
opj_event_msg(j2k->cinfo, EVT_ERROR, "Error decoding component %d.\nThe number of resolutions to remove is higher than the number "
"of resolutions of this component\nModify the cp_reduce parameter.\n\n", compno);
j2k->state |= J2K_STATE_ERR;
}
 
tccp->cblkw = cio_read(cio, 1) + 2; /* SPcox (E) */
tccp->cblkh = cio_read(cio, 1) + 2; /* SPcox (F) */
tccp->cblksty = cio_read(cio, 1); /* SPcox (G) */
tccp->qmfbid = cio_read(cio, 1); /* SPcox (H) */
if (tccp->csty & J2K_CP_CSTY_PRT) {
for (i = 0; i < tccp->numresolutions; i++) {
int tmp = cio_read(cio, 1); /* SPcox (I_i) */
tccp->prcw[i] = tmp & 0xf;
tccp->prch[i] = tmp >> 4;
}
}
 
/* INDEX >> */
if(j2k->cstr_info && compno == 0) {
for (i = 0; i < tccp->numresolutions; i++) {
if (tccp->csty & J2K_CP_CSTY_PRT) {
j2k->cstr_info->tile[j2k->curtileno].pdx[i] = tccp->prcw[i];
j2k->cstr_info->tile[j2k->curtileno].pdy[i] = tccp->prch[i];
}
else {
j2k->cstr_info->tile[j2k->curtileno].pdx[i] = 15;
j2k->cstr_info->tile[j2k->curtileno].pdx[i] = 15;
}
}
}
/* << INDEX */
}
 
static void j2k_write_cod(opj_j2k_t *j2k) {
opj_cp_t *cp = NULL;
opj_tcp_t *tcp = NULL;
int lenp, len;
 
opj_cio_t *cio = j2k->cio;
cio_write(cio, J2K_MS_COD, 2); /* COD */
lenp = cio_tell(cio);
cio_skip(cio, 2);
cp = j2k->cp;
tcp = &cp->tcps[j2k->curtileno];
 
cio_write(cio, tcp->csty, 1); /* Scod */
cio_write(cio, tcp->prg, 1); /* SGcod (A) */
cio_write(cio, tcp->numlayers, 2); /* SGcod (B) */
cio_write(cio, tcp->mct, 1); /* SGcod (C) */
j2k_write_cox(j2k, 0);
len = cio_tell(cio) - lenp;
cio_seek(cio, lenp);
cio_write(cio, len, 2); /* Lcod */
cio_seek(cio, lenp + len);
}
 
static void j2k_read_cod(opj_j2k_t *j2k) {
int len, i, pos;
opj_cio_t *cio = j2k->cio;
opj_cp_t *cp = j2k->cp;
opj_tcp_t *tcp = j2k->state == J2K_STATE_TPH ? &cp->tcps[j2k->curtileno] : j2k->default_tcp;
opj_image_t *image = j2k->image;
len = cio_read(cio, 2); /* Lcod */
tcp->csty = cio_read(cio, 1); /* Scod */
tcp->prg = (OPJ_PROG_ORDER)cio_read(cio, 1); /* SGcod (A) */
tcp->numlayers = cio_read(cio, 2); /* SGcod (B) */
tcp->mct = cio_read(cio, 1); /* SGcod (C) */
pos = cio_tell(cio);
for (i = 0; i < image->numcomps; i++) {
tcp->tccps[i].csty = tcp->csty & J2K_CP_CSTY_PRT;
cio_seek(cio, pos);
j2k_read_cox(j2k, i);
}
 
/* Index */
if (j2k->cstr_info) {
opj_codestream_info_t *cstr_info = j2k->cstr_info;
cstr_info->prog = tcp->prg;
cstr_info->numlayers = tcp->numlayers;
cstr_info->numdecompos = (int*) opj_malloc(image->numcomps * sizeof(int));
for (i = 0; i < image->numcomps; i++) {
cstr_info->numdecompos[i] = tcp->tccps[i].numresolutions - 1;
}
}
}
 
static void j2k_write_coc(opj_j2k_t *j2k, int compno) {
int lenp, len;
 
opj_cp_t *cp = j2k->cp;
opj_tcp_t *tcp = &cp->tcps[j2k->curtileno];
opj_image_t *image = j2k->image;
opj_cio_t *cio = j2k->cio;
cio_write(cio, J2K_MS_COC, 2); /* COC */
lenp = cio_tell(cio);
cio_skip(cio, 2);
cio_write(cio, compno, image->numcomps <= 256 ? 1 : 2); /* Ccoc */
cio_write(cio, tcp->tccps[compno].csty, 1); /* Scoc */
j2k_write_cox(j2k, compno);
len = cio_tell(cio) - lenp;
cio_seek(cio, lenp);
cio_write(cio, len, 2); /* Lcoc */
cio_seek(cio, lenp + len);
}
 
static void j2k_read_coc(opj_j2k_t *j2k) {
int len, compno;
 
opj_cp_t *cp = j2k->cp;
opj_tcp_t *tcp = j2k->state == J2K_STATE_TPH ? &cp->tcps[j2k->curtileno] : j2k->default_tcp;
opj_image_t *image = j2k->image;
opj_cio_t *cio = j2k->cio;
len = cio_read(cio, 2); /* Lcoc */
compno = cio_read(cio, image->numcomps <= 256 ? 1 : 2); /* Ccoc */
tcp->tccps[compno].csty = cio_read(cio, 1); /* Scoc */
j2k_read_cox(j2k, compno);
}
 
static void j2k_write_qcx(opj_j2k_t *j2k, int compno) {
int bandno, numbands;
int expn, mant;
opj_cp_t *cp = j2k->cp;
opj_tcp_t *tcp = &cp->tcps[j2k->curtileno];
opj_tccp_t *tccp = &tcp->tccps[compno];
opj_cio_t *cio = j2k->cio;
cio_write(cio, tccp->qntsty + (tccp->numgbits << 5), 1); /* Sqcx */
numbands = tccp->qntsty == J2K_CCP_QNTSTY_SIQNT ? 1 : tccp->numresolutions * 3 - 2;
for (bandno = 0; bandno < numbands; bandno++) {
expn = tccp->stepsizes[bandno].expn;
mant = tccp->stepsizes[bandno].mant;
if (tccp->qntsty == J2K_CCP_QNTSTY_NOQNT) {
cio_write(cio, expn << 3, 1); /* SPqcx_i */
} else {
cio_write(cio, (expn << 11) + mant, 2); /* SPqcx_i */
}
}
}
 
static void j2k_read_qcx(opj_j2k_t *j2k, int compno, int len) {
int tmp;
int bandno, numbands;
 
opj_cp_t *cp = j2k->cp;
opj_tcp_t *tcp = j2k->state == J2K_STATE_TPH ? &cp->tcps[j2k->curtileno] : j2k->default_tcp;
opj_tccp_t *tccp = &tcp->tccps[compno];
opj_cio_t *cio = j2k->cio;
 
tmp = cio_read(cio, 1); /* Sqcx */
tccp->qntsty = tmp & 0x1f;
tccp->numgbits = tmp >> 5;
numbands = (tccp->qntsty == J2K_CCP_QNTSTY_SIQNT) ?
1 : ((tccp->qntsty == J2K_CCP_QNTSTY_NOQNT) ? len - 1 : (len - 1) / 2);
 
#ifdef USE_JPWL
if (j2k->cp->correct) {
 
/* if JPWL is on, we check whether there are too many subbands */
if ((numbands < 0) || (numbands >= J2K_MAXBANDS)) {
opj_event_msg(j2k->cinfo, JPWL_ASSUME ? EVT_WARNING : EVT_ERROR,
"JPWL: bad number of subbands in Sqcx (%d)\n",
numbands);
if (!JPWL_ASSUME) {
opj_event_msg(j2k->cinfo, EVT_ERROR, "JPWL: giving up\n");
return;
}
/* we try to correct */
numbands = 1;
opj_event_msg(j2k->cinfo, EVT_WARNING, "- trying to adjust them\n"
"- setting number of bands to %d => HYPOTHESIS!!!\n",
numbands);
};
 
};
#endif /* USE_JPWL */
 
for (bandno = 0; bandno < numbands; bandno++) {
int expn, mant;
if (tccp->qntsty == J2K_CCP_QNTSTY_NOQNT) {
expn = cio_read(cio, 1) >> 3; /* SPqcx_i */
mant = 0;
} else {
tmp = cio_read(cio, 2); /* SPqcx_i */
expn = tmp >> 11;
mant = tmp & 0x7ff;
}
tccp->stepsizes[bandno].expn = expn;
tccp->stepsizes[bandno].mant = mant;
}
/* Add Antonin : if scalar_derived -> compute other stepsizes */
if (tccp->qntsty == J2K_CCP_QNTSTY_SIQNT) {
for (bandno = 1; bandno < J2K_MAXBANDS; bandno++) {
tccp->stepsizes[bandno].expn =
((tccp->stepsizes[0].expn) - ((bandno - 1) / 3) > 0) ?
(tccp->stepsizes[0].expn) - ((bandno - 1) / 3) : 0;
tccp->stepsizes[bandno].mant = tccp->stepsizes[0].mant;
}
}
/* ddA */
}
 
static void j2k_write_qcd(opj_j2k_t *j2k) {
int lenp, len;
 
opj_cio_t *cio = j2k->cio;
cio_write(cio, J2K_MS_QCD, 2); /* QCD */
lenp = cio_tell(cio);
cio_skip(cio, 2);
j2k_write_qcx(j2k, 0);
len = cio_tell(cio) - lenp;
cio_seek(cio, lenp);
cio_write(cio, len, 2); /* Lqcd */
cio_seek(cio, lenp + len);
}
 
static void j2k_read_qcd(opj_j2k_t *j2k) {
int len, i, pos;
 
opj_cio_t *cio = j2k->cio;
opj_image_t *image = j2k->image;
len = cio_read(cio, 2); /* Lqcd */
pos = cio_tell(cio);
for (i = 0; i < image->numcomps; i++) {
cio_seek(cio, pos);
j2k_read_qcx(j2k, i, len - 2);
}
}
 
static void j2k_write_qcc(opj_j2k_t *j2k, int compno) {
int lenp, len;
 
opj_cio_t *cio = j2k->cio;
cio_write(cio, J2K_MS_QCC, 2); /* QCC */
lenp = cio_tell(cio);
cio_skip(cio, 2);
cio_write(cio, compno, j2k->image->numcomps <= 256 ? 1 : 2); /* Cqcc */
j2k_write_qcx(j2k, compno);
len = cio_tell(cio) - lenp;
cio_seek(cio, lenp);
cio_write(cio, len, 2); /* Lqcc */
cio_seek(cio, lenp + len);
}
 
static void j2k_read_qcc(opj_j2k_t *j2k) {
int len, compno;
int numcomp = j2k->image->numcomps;
opj_cio_t *cio = j2k->cio;
len = cio_read(cio, 2); /* Lqcc */
compno = cio_read(cio, numcomp <= 256 ? 1 : 2); /* Cqcc */
 
#ifdef USE_JPWL
if (j2k->cp->correct) {
 
static int backup_compno = 0;
 
/* compno is negative or larger than the number of components!!! */
if ((compno < 0) || (compno >= numcomp)) {
opj_event_msg(j2k->cinfo, EVT_ERROR,
"JPWL: bad component number in QCC (%d out of a maximum of %d)\n",
compno, numcomp);
if (!JPWL_ASSUME) {
opj_event_msg(j2k->cinfo, EVT_ERROR, "JPWL: giving up\n");
return;
}
/* we try to correct */
compno = backup_compno % numcomp;
opj_event_msg(j2k->cinfo, EVT_WARNING, "- trying to adjust this\n"
"- setting component number to %d\n",
compno);
}
 
/* keep your private count of tiles */
backup_compno++;
};
#endif /* USE_JPWL */
 
j2k_read_qcx(j2k, compno, len - 2 - (numcomp <= 256 ? 1 : 2));
}
 
static void j2k_write_poc(opj_j2k_t *j2k) {
int len, numpchgs, i;
 
int numcomps = j2k->image->numcomps;
opj_cp_t *cp = j2k->cp;
opj_tcp_t *tcp = &cp->tcps[j2k->curtileno];
opj_tccp_t *tccp = &tcp->tccps[0];
opj_cio_t *cio = j2k->cio;
 
numpchgs = 1 + tcp->numpocs;
cio_write(cio, J2K_MS_POC, 2); /* POC */
len = 2 + (5 + 2 * (numcomps <= 256 ? 1 : 2)) * numpchgs;
cio_write(cio, len, 2); /* Lpoc */
for (i = 0; i < numpchgs; i++) {
opj_poc_t *poc = &tcp->pocs[i];
cio_write(cio, poc->resno0, 1); /* RSpoc_i */
cio_write(cio, poc->compno0, (numcomps <= 256 ? 1 : 2)); /* CSpoc_i */
cio_write(cio, poc->layno1, 2); /* LYEpoc_i */
poc->layno1 = int_min(poc->layno1, tcp->numlayers);
cio_write(cio, poc->resno1, 1); /* REpoc_i */
poc->resno1 = int_min(poc->resno1, tccp->numresolutions);
cio_write(cio, poc->compno1, (numcomps <= 256 ? 1 : 2)); /* CEpoc_i */
poc->compno1 = int_min(poc->compno1, numcomps);
cio_write(cio, poc->prg, 1); /* Ppoc_i */
}
}
 
static void j2k_read_poc(opj_j2k_t *j2k) {
int len, numpchgs, i, old_poc;
 
int numcomps = j2k->image->numcomps;
opj_cp_t *cp = j2k->cp;
opj_tcp_t *tcp = j2k->state == J2K_STATE_TPH ? &cp->tcps[j2k->curtileno] : j2k->default_tcp;
opj_cio_t *cio = j2k->cio;
old_poc = tcp->POC ? tcp->numpocs + 1 : 0;
tcp->POC = 1;
len = cio_read(cio, 2); /* Lpoc */
numpchgs = (len - 2) / (5 + 2 * (numcomps <= 256 ? 1 : 2));
for (i = old_poc; i < numpchgs + old_poc; i++) {
opj_poc_t *poc;
poc = &tcp->pocs[i];
poc->resno0 = cio_read(cio, 1); /* RSpoc_i */
poc->compno0 = cio_read(cio, numcomps <= 256 ? 1 : 2); /* CSpoc_i */
poc->layno1 = cio_read(cio, 2); /* LYEpoc_i */
poc->resno1 = cio_read(cio, 1); /* REpoc_i */
poc->compno1 = int_min(
cio_read(cio, numcomps <= 256 ? 1 : 2), (unsigned int) numcomps); /* CEpoc_i */
poc->prg = (OPJ_PROG_ORDER)cio_read(cio, 1); /* Ppoc_i */
}
tcp->numpocs = numpchgs + old_poc - 1;
}
 
static void j2k_read_crg(opj_j2k_t *j2k) {
int len, i, Xcrg_i, Ycrg_i;
opj_cio_t *cio = j2k->cio;
int numcomps = j2k->image->numcomps;
len = cio_read(cio, 2); /* Lcrg */
for (i = 0; i < numcomps; i++) {
Xcrg_i = cio_read(cio, 2); /* Xcrg_i */
Ycrg_i = cio_read(cio, 2); /* Ycrg_i */
}
}
 
static void j2k_read_tlm(opj_j2k_t *j2k) {
int len, Ztlm, Stlm, ST, SP, tile_tlm, i;
long int Ttlm_i, Ptlm_i;
 
opj_cio_t *cio = j2k->cio;
len = cio_read(cio, 2); /* Ltlm */
Ztlm = cio_read(cio, 1); /* Ztlm */
Stlm = cio_read(cio, 1); /* Stlm */
ST = ((Stlm >> 4) & 0x01) + ((Stlm >> 4) & 0x02);
SP = (Stlm >> 6) & 0x01;
tile_tlm = (len - 4) / ((SP + 1) * 2 + ST);
for (i = 0; i < tile_tlm; i++) {
Ttlm_i = cio_read(cio, ST); /* Ttlm_i */
Ptlm_i = cio_read(cio, SP ? 4 : 2); /* Ptlm_i */
}
}
 
static void j2k_read_plm(opj_j2k_t *j2k) {
int len, i, Zplm, Nplm, add, packet_len = 0;
opj_cio_t *cio = j2k->cio;
 
len = cio_read(cio, 2); /* Lplm */
Zplm = cio_read(cio, 1); /* Zplm */
len -= 3;
while (len > 0) {
Nplm = cio_read(cio, 4); /* Nplm */
len -= 4;
for (i = Nplm; i > 0; i--) {
add = cio_read(cio, 1);
len--;
packet_len = (packet_len << 7) + add; /* Iplm_ij */
if ((add & 0x80) == 0) {
/* New packet */
packet_len = 0;
}
if (len <= 0)
break;
}
}
}
 
static void j2k_read_plt(opj_j2k_t *j2k) {
int len, i, Zplt, packet_len = 0, add;
opj_cio_t *cio = j2k->cio;
len = cio_read(cio, 2); /* Lplt */
Zplt = cio_read(cio, 1); /* Zplt */
for (i = len - 3; i > 0; i--) {
add = cio_read(cio, 1);
packet_len = (packet_len << 7) + add; /* Iplt_i */
if ((add & 0x80) == 0) {
/* New packet */
packet_len = 0;
}
}
}
 
static void j2k_read_ppm(opj_j2k_t *j2k) {
int len, Z_ppm, i, j;
int N_ppm;
 
opj_cp_t *cp = j2k->cp;
opj_cio_t *cio = j2k->cio;
len = cio_read(cio, 2);
cp->ppm = 1;
Z_ppm = cio_read(cio, 1); /* Z_ppm */
len -= 3;
while (len > 0) {
if (cp->ppm_previous == 0) {
N_ppm = cio_read(cio, 4); /* N_ppm */
len -= 4;
} else {
N_ppm = cp->ppm_previous;
}
j = cp->ppm_store;
if (Z_ppm == 0) { /* First PPM marker */
cp->ppm_data = (unsigned char *) opj_malloc(N_ppm * sizeof(unsigned char));
cp->ppm_data_first = cp->ppm_data;
cp->ppm_len = N_ppm;
} else { /* NON-first PPM marker */
cp->ppm_data = (unsigned char *) opj_realloc(cp->ppm_data, (N_ppm + cp->ppm_store) * sizeof(unsigned char));
 
#ifdef USE_JPWL
/* this memory allocation check could be done even in non-JPWL cases */
if (cp->correct) {
if (!cp->ppm_data) {
opj_event_msg(j2k->cinfo, EVT_ERROR,
"JPWL: failed memory allocation during PPM marker parsing (pos. %x)\n",
cio_tell(cio));
if (!JPWL_ASSUME || JPWL_ASSUME) {
opj_free(cp->ppm_data);
opj_event_msg(j2k->cinfo, EVT_ERROR, "JPWL: giving up\n");
return;
}
}
}
#endif
 
cp->ppm_data_first = cp->ppm_data;
cp->ppm_len = N_ppm + cp->ppm_store;
}
for (i = N_ppm; i > 0; i--) { /* Read packet header */
cp->ppm_data[j] = cio_read(cio, 1);
j++;
len--;
if (len == 0)
break; /* Case of non-finished packet header in present marker but finished in next one */
}
cp->ppm_previous = i - 1;
cp->ppm_store = j;
}
}
 
static void j2k_read_ppt(opj_j2k_t *j2k) {
int len, Z_ppt, i, j = 0;
 
opj_cp_t *cp = j2k->cp;
opj_tcp_t *tcp = cp->tcps + j2k->curtileno;
opj_cio_t *cio = j2k->cio;
 
len = cio_read(cio, 2);
Z_ppt = cio_read(cio, 1);
tcp->ppt = 1;
if (Z_ppt == 0) { /* First PPT marker */
tcp->ppt_data = (unsigned char *) opj_malloc((len - 3) * sizeof(unsigned char));
tcp->ppt_data_first = tcp->ppt_data;
tcp->ppt_store = 0;
tcp->ppt_len = len - 3;
} else { /* NON-first PPT marker */
tcp->ppt_data = (unsigned char *) opj_realloc(tcp->ppt_data, (len - 3 + tcp->ppt_store) * sizeof(unsigned char));
tcp->ppt_data_first = tcp->ppt_data;
tcp->ppt_len = len - 3 + tcp->ppt_store;
}
j = tcp->ppt_store;
for (i = len - 3; i > 0; i--) {
tcp->ppt_data[j] = cio_read(cio, 1);
j++;
}
tcp->ppt_store = j;
}
 
static void j2k_write_tlm(opj_j2k_t *j2k){
int lenp;
opj_cio_t *cio = j2k->cio;
j2k->tlm_start = cio_tell(cio);
cio_write(cio, J2K_MS_TLM, 2);/* TLM */
lenp = 4 + (5*j2k->totnum_tp);
cio_write(cio,lenp,2); /* Ltlm */
cio_write(cio, 0,1); /* Ztlm=0*/
cio_write(cio,80,1); /* Stlm ST=1(8bits-255 tiles max),SP=1(Ptlm=32bits) */
cio_skip(cio,5*j2k->totnum_tp);
}
 
static void j2k_write_sot(opj_j2k_t *j2k) {
int lenp, len;
 
opj_cio_t *cio = j2k->cio;
 
j2k->sot_start = cio_tell(cio);
cio_write(cio, J2K_MS_SOT, 2); /* SOT */
lenp = cio_tell(cio);
cio_skip(cio, 2); /* Lsot (further) */
cio_write(cio, j2k->curtileno, 2); /* Isot */
cio_skip(cio, 4); /* Psot (further in j2k_write_sod) */
cio_write(cio, j2k->cur_tp_num , 1); /* TPsot */
cio_write(cio, j2k->cur_totnum_tp[j2k->curtileno], 1); /* TNsot */
len = cio_tell(cio) - lenp;
cio_seek(cio, lenp);
cio_write(cio, len, 2); /* Lsot */
cio_seek(cio, lenp + len);
 
/* UniPG>> */
#ifdef USE_JPWL
/* update markers struct */
j2k_add_marker(j2k->cstr_info, J2K_MS_SOT, j2k->sot_start, len + 2);
#endif /* USE_JPWL */
/* <<UniPG */
}
 
static void j2k_read_sot(opj_j2k_t *j2k) {
int len, tileno, totlen, partno, numparts, i;
opj_tcp_t *tcp = NULL;
char status = 0;
 
opj_cp_t *cp = j2k->cp;
opj_cio_t *cio = j2k->cio;
 
len = cio_read(cio, 2);
tileno = cio_read(cio, 2);
 
#ifdef USE_JPWL
if (j2k->cp->correct) {
 
static int backup_tileno = 0;
 
/* tileno is negative or larger than the number of tiles!!! */
if ((tileno < 0) || (tileno > (cp->tw * cp->th))) {
opj_event_msg(j2k->cinfo, EVT_ERROR,
"JPWL: bad tile number (%d out of a maximum of %d)\n",
tileno, (cp->tw * cp->th));
if (!JPWL_ASSUME) {
opj_event_msg(j2k->cinfo, EVT_ERROR, "JPWL: giving up\n");
return;
}
/* we try to correct */
tileno = backup_tileno;
opj_event_msg(j2k->cinfo, EVT_WARNING, "- trying to adjust this\n"
"- setting tile number to %d\n",
tileno);
}
 
/* keep your private count of tiles */
backup_tileno++;
};
#endif /* USE_JPWL */
if (cp->tileno_size == 0) {
cp->tileno[cp->tileno_size] = tileno;
cp->tileno_size++;
} else {
i = 0;
while (i < cp->tileno_size && status == 0) {
status = cp->tileno[i] == tileno ? 1 : 0;
i++;
}
if (status == 0) {
cp->tileno[cp->tileno_size] = tileno;
cp->tileno_size++;
}
}
totlen = cio_read(cio, 4);
 
#ifdef USE_JPWL
if (j2k->cp->correct) {
 
/* totlen is negative or larger than the bytes left!!! */
if ((totlen < 0) || (totlen > (cio_numbytesleft(cio) + 8))) {
opj_event_msg(j2k->cinfo, EVT_ERROR,
"JPWL: bad tile byte size (%d bytes against %d bytes left)\n",
totlen, cio_numbytesleft(cio) + 8);
if (!JPWL_ASSUME) {
opj_event_msg(j2k->cinfo, EVT_ERROR, "JPWL: giving up\n");
return;
}
/* we try to correct */
totlen = 0;
opj_event_msg(j2k->cinfo, EVT_WARNING, "- trying to adjust this\n"
"- setting Psot to %d => assuming it is the last tile\n",
totlen);
}
 
};
#endif /* USE_JPWL */
 
if (!totlen)
totlen = cio_numbytesleft(cio) + 8;
partno = cio_read(cio, 1);
numparts = cio_read(cio, 1);
j2k->curtileno = tileno;
j2k->cur_tp_num = partno;
j2k->eot = cio_getbp(cio) - 12 + totlen;
j2k->state = J2K_STATE_TPH;
tcp = &cp->tcps[j2k->curtileno];
 
/* Index */
if (j2k->cstr_info) {
if (tcp->first) {
if (tileno == 0)
j2k->cstr_info->main_head_end = cio_tell(cio) - 13;
j2k->cstr_info->tile[tileno].tileno = tileno;
j2k->cstr_info->tile[tileno].start_pos = cio_tell(cio) - 12;
j2k->cstr_info->tile[tileno].end_pos = j2k->cstr_info->tile[tileno].start_pos + totlen - 1;
j2k->cstr_info->tile[tileno].num_tps = numparts;
if (numparts)
j2k->cstr_info->tile[tileno].tp = (opj_tp_info_t *) opj_malloc(numparts * sizeof(opj_tp_info_t));
else
j2k->cstr_info->tile[tileno].tp = (opj_tp_info_t *) opj_malloc(10 * sizeof(opj_tp_info_t)); // Fixme (10)
}
else {
j2k->cstr_info->tile[tileno].end_pos += totlen;
}
j2k->cstr_info->tile[tileno].tp[partno].tp_start_pos = cio_tell(cio) - 12;
j2k->cstr_info->tile[tileno].tp[partno].tp_end_pos =
j2k->cstr_info->tile[tileno].tp[partno].tp_start_pos + totlen - 1;
}
if (tcp->first == 1) {
/* Initialization PPT */
opj_tccp_t *tmp = tcp->tccps;
memcpy(tcp, j2k->default_tcp, sizeof(opj_tcp_t));
tcp->ppt = 0;
tcp->ppt_data = NULL;
tcp->ppt_data_first = NULL;
tcp->tccps = tmp;
 
for (i = 0; i < j2k->image->numcomps; i++) {
tcp->tccps[i] = j2k->default_tcp->tccps[i];
}
cp->tcps[j2k->curtileno].first = 0;
}
}
 
static void j2k_write_sod(opj_j2k_t *j2k, void *tile_coder) {
int l, layno;
int totlen;
opj_tcp_t *tcp = NULL;
opj_codestream_info_t *cstr_info = NULL;
opj_tcd_t *tcd = (opj_tcd_t*)tile_coder; /* cast is needed because of conflicts in header inclusions */
opj_cp_t *cp = j2k->cp;
opj_cio_t *cio = j2k->cio;
 
tcd->tp_num = j2k->tp_num ;
tcd->cur_tp_num = j2k->cur_tp_num;
cio_write(cio, J2K_MS_SOD, 2);
if (j2k->curtileno == 0) {
j2k->sod_start = cio_tell(cio) + j2k->pos_correction;
}
 
/* INDEX >> */
cstr_info = j2k->cstr_info;
if (cstr_info) {
if (!j2k->cur_tp_num ) {
cstr_info->tile[j2k->curtileno].end_header = cio_tell(cio) + j2k->pos_correction - 1;
j2k->cstr_info->tile[j2k->curtileno].tileno = j2k->curtileno;
}
else{
if(cstr_info->tile[j2k->curtileno].packet[cstr_info->packno - 1].end_pos < cio_tell(cio))
cstr_info->tile[j2k->curtileno].packet[cstr_info->packno].start_pos = cio_tell(cio);
}
/* UniPG>> */
#ifdef USE_JPWL
/* update markers struct */
j2k_add_marker(j2k->cstr_info, J2K_MS_SOD, j2k->sod_start, 2);
#endif /* USE_JPWL */
/* <<UniPG */
}
/* << INDEX */
tcp = &cp->tcps[j2k->curtileno];
for (layno = 0; layno < tcp->numlayers; layno++) {
if (tcp->rates[layno]>(j2k->sod_start / (cp->th * cp->tw))) {
tcp->rates[layno]-=(j2k->sod_start / (cp->th * cp->tw));
} else if (tcp->rates[layno]) {
tcp->rates[layno]=1;
}
}
if(j2k->cur_tp_num == 0){
tcd->tcd_image->tiles->packno = 0;
if(cstr_info)
cstr_info->packno = 0;
}
l = tcd_encode_tile(tcd, j2k->curtileno, cio_getbp(cio), cio_numbytesleft(cio) - 2, cstr_info);
/* Writing Psot in SOT marker */
totlen = cio_tell(cio) + l - j2k->sot_start;
cio_seek(cio, j2k->sot_start + 6);
cio_write(cio, totlen, 4);
cio_seek(cio, j2k->sot_start + totlen);
/* Writing Ttlm and Ptlm in TLM marker */
if(cp->cinema){
cio_seek(cio, j2k->tlm_start + 6 + (5*j2k->cur_tp_num));
cio_write(cio, j2k->curtileno, 1);
cio_write(cio, totlen, 4);
}
cio_seek(cio, j2k->sot_start + totlen);
}
 
static void j2k_read_sod(opj_j2k_t *j2k) {
int len, truncate = 0, i;
unsigned char *data = NULL, *data_ptr = NULL;
 
opj_cio_t *cio = j2k->cio;
int curtileno = j2k->curtileno;
 
/* Index */
if (j2k->cstr_info) {
j2k->cstr_info->tile[j2k->curtileno].tp[j2k->cur_tp_num].tp_end_header =
cio_tell(cio) + j2k->pos_correction - 1;
if (j2k->cur_tp_num == 0)
j2k->cstr_info->tile[j2k->curtileno].end_header = cio_tell(cio) + j2k->pos_correction - 1;
j2k->cstr_info->packno = 0;
}
len = int_min(j2k->eot - cio_getbp(cio), cio_numbytesleft(cio) + 1);
 
if (len == cio_numbytesleft(cio) + 1) {
truncate = 1; /* Case of a truncate codestream */
}
 
data = j2k->tile_data[curtileno];
data = (unsigned char*) opj_realloc(data, (j2k->tile_len[curtileno] + len) * sizeof(unsigned char));
 
data_ptr = data + j2k->tile_len[curtileno];
for (i = 0; i < len; i++) {
data_ptr[i] = cio_read(cio, 1);
}
 
j2k->tile_len[curtileno] += len;
j2k->tile_data[curtileno] = data;
if (!truncate) {
j2k->state = J2K_STATE_TPHSOT;
} else {
j2k->state = J2K_STATE_NEOC; /* RAJOUTE !! */
}
j2k->cur_tp_num++;
}
 
static void j2k_write_rgn(opj_j2k_t *j2k, int compno, int tileno) {
opj_cp_t *cp = j2k->cp;
opj_tcp_t *tcp = &cp->tcps[tileno];
opj_cio_t *cio = j2k->cio;
int numcomps = j2k->image->numcomps;
cio_write(cio, J2K_MS_RGN, 2); /* RGN */
cio_write(cio, numcomps <= 256 ? 5 : 6, 2); /* Lrgn */
cio_write(cio, compno, numcomps <= 256 ? 1 : 2); /* Crgn */
cio_write(cio, 0, 1); /* Srgn */
cio_write(cio, tcp->tccps[compno].roishift, 1); /* SPrgn */
}
 
static void j2k_read_rgn(opj_j2k_t *j2k) {
int len, compno, roisty;
 
opj_cp_t *cp = j2k->cp;
opj_tcp_t *tcp = j2k->state == J2K_STATE_TPH ? &cp->tcps[j2k->curtileno] : j2k->default_tcp;
opj_cio_t *cio = j2k->cio;
int numcomps = j2k->image->numcomps;
 
len = cio_read(cio, 2); /* Lrgn */
compno = cio_read(cio, numcomps <= 256 ? 1 : 2); /* Crgn */
roisty = cio_read(cio, 1); /* Srgn */
 
#ifdef USE_JPWL
if (j2k->cp->correct) {
/* totlen is negative or larger than the bytes left!!! */
if (compno >= numcomps) {
opj_event_msg(j2k->cinfo, EVT_ERROR,
"JPWL: bad component number in RGN (%d when there are only %d)\n",
compno, numcomps);
if (!JPWL_ASSUME || JPWL_ASSUME) {
opj_event_msg(j2k->cinfo, EVT_ERROR, "JPWL: giving up\n");
return;
}
}
};
#endif /* USE_JPWL */
 
tcp->tccps[compno].roishift = cio_read(cio, 1); /* SPrgn */
}
 
static void j2k_write_eoc(opj_j2k_t *j2k) {
opj_cio_t *cio = j2k->cio;
/* opj_event_msg(j2k->cinfo, "%.8x: EOC\n", cio_tell(cio) + j2k->pos_correction); */
cio_write(cio, J2K_MS_EOC, 2);
 
/* UniPG>> */
#ifdef USE_JPWL
/* update markers struct */
j2k_add_marker(j2k->cstr_info, J2K_MS_EOC, cio_tell(cio) - 2, 2);
#endif /* USE_JPWL */
/* <<UniPG */
}
 
static void j2k_read_eoc(opj_j2k_t *j2k) {
int i, tileno;
bool success;
 
/* if packets should be decoded */
if (j2k->cp->limit_decoding != DECODE_ALL_BUT_PACKETS) {
opj_tcd_t *tcd = tcd_create(j2k->cinfo);
tcd_malloc_decode(tcd, j2k->image, j2k->cp);
for (i = 0; i < j2k->cp->tileno_size; i++) {
tcd_malloc_decode_tile(tcd, j2k->image, j2k->cp, i, j2k->cstr_info);
tileno = j2k->cp->tileno[i];
success = tcd_decode_tile(tcd, j2k->tile_data[tileno], j2k->tile_len[tileno], tileno, j2k->cstr_info);
opj_free(j2k->tile_data[tileno]);
j2k->tile_data[tileno] = NULL;
tcd_free_decode_tile(tcd, i);
if (success == false) {
j2k->state |= J2K_STATE_ERR;
break;
}
}
tcd_free_decode(tcd);
tcd_destroy(tcd);
}
/* if packets should not be decoded */
else {
for (i = 0; i < j2k->cp->tileno_size; i++) {
tileno = j2k->cp->tileno[i];
opj_free(j2k->tile_data[tileno]);
j2k->tile_data[tileno] = NULL;
}
}
if (j2k->state & J2K_STATE_ERR)
j2k->state = J2K_STATE_MT + J2K_STATE_ERR;
else
j2k->state = J2K_STATE_MT;
}
 
typedef struct opj_dec_mstabent {
/** marker value */
int id;
/** value of the state when the marker can appear */
int states;
/** action linked to the marker */
void (*handler) (opj_j2k_t *j2k);
} opj_dec_mstabent_t;
 
opj_dec_mstabent_t j2k_dec_mstab[] = {
{J2K_MS_SOC, J2K_STATE_MHSOC, j2k_read_soc},
{J2K_MS_SOT, J2K_STATE_MH | J2K_STATE_TPHSOT, j2k_read_sot},
{J2K_MS_SOD, J2K_STATE_TPH, j2k_read_sod},
{J2K_MS_EOC, J2K_STATE_TPHSOT, j2k_read_eoc},
{J2K_MS_SIZ, J2K_STATE_MHSIZ, j2k_read_siz},
{J2K_MS_COD, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_cod},
{J2K_MS_COC, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_coc},
{J2K_MS_RGN, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_rgn},
{J2K_MS_QCD, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_qcd},
{J2K_MS_QCC, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_qcc},
{J2K_MS_POC, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_poc},
{J2K_MS_TLM, J2K_STATE_MH, j2k_read_tlm},
{J2K_MS_PLM, J2K_STATE_MH, j2k_read_plm},
{J2K_MS_PLT, J2K_STATE_TPH, j2k_read_plt},
{J2K_MS_PPM, J2K_STATE_MH, j2k_read_ppm},
{J2K_MS_PPT, J2K_STATE_TPH, j2k_read_ppt},
{J2K_MS_SOP, 0, 0},
{J2K_MS_CRG, J2K_STATE_MH, j2k_read_crg},
{J2K_MS_COM, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_com},
 
#ifdef USE_JPWL
{J2K_MS_EPC, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_epc},
{J2K_MS_EPB, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_epb},
{J2K_MS_ESD, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_esd},
{J2K_MS_RED, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_red},
#endif /* USE_JPWL */
#ifdef USE_JPSEC
{J2K_MS_SEC, J2K_STATE_MH, j2k_read_sec},
{J2K_MS_INSEC, 0, j2k_read_insec},
#endif /* USE_JPSEC */
 
{0, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_unk}
};
 
static void j2k_read_unk(opj_j2k_t *j2k) {
opj_event_msg(j2k->cinfo, EVT_WARNING, "Unknown marker\n");
 
#ifdef USE_JPWL
if (j2k->cp->correct) {
int m = 0, id, i;
int min_id = 0, min_dist = 17, cur_dist = 0, tmp_id;
cio_seek(j2k->cio, cio_tell(j2k->cio) - 2);
id = cio_read(j2k->cio, 2);
opj_event_msg(j2k->cinfo, EVT_ERROR,
"JPWL: really don't know this marker %x\n",
id);
if (!JPWL_ASSUME) {
opj_event_msg(j2k->cinfo, EVT_ERROR,
"- possible synch loss due to uncorrectable codestream errors => giving up\n");
return;
}
/* OK, activate this at your own risk!!! */
/* we look for the marker at the minimum hamming distance from this */
while (j2k_dec_mstab[m].id) {
/* 1's where they differ */
tmp_id = j2k_dec_mstab[m].id ^ id;
 
/* compute the hamming distance between our id and the current */
cur_dist = 0;
for (i = 0; i < 16; i++) {
if ((tmp_id >> i) & 0x0001) {
cur_dist++;
}
}
 
/* if current distance is smaller, set the minimum */
if (cur_dist < min_dist) {
min_dist = cur_dist;
min_id = j2k_dec_mstab[m].id;
}
/* jump to the next marker */
m++;
}
 
/* do we substitute the marker? */
if (min_dist < JPWL_MAXIMUM_HAMMING) {
opj_event_msg(j2k->cinfo, EVT_ERROR,
"- marker %x is at distance %d from the read %x\n",
min_id, min_dist, id);
opj_event_msg(j2k->cinfo, EVT_ERROR,
"- trying to substitute in place and crossing fingers!\n");
cio_seek(j2k->cio, cio_tell(j2k->cio) - 2);
cio_write(j2k->cio, min_id, 2);
 
/* rewind */
cio_seek(j2k->cio, cio_tell(j2k->cio) - 2);
 
}
 
};
#endif /* USE_JPWL */
 
}
 
/**
Read the lookup table containing all the marker, status and action
@param id Marker value
*/
static opj_dec_mstabent_t *j2k_dec_mstab_lookup(int id) {
opj_dec_mstabent_t *e;
for (e = j2k_dec_mstab; e->id != 0; e++) {
if (e->id == id) {
break;
}
}
return e;
}
 
/* ----------------------------------------------------------------------- */
/* J2K / JPT decoder interface */
/* ----------------------------------------------------------------------- */
 
opj_j2k_t* j2k_create_decompress(opj_common_ptr cinfo) {
opj_j2k_t *j2k = (opj_j2k_t*) opj_calloc(1, sizeof(opj_j2k_t));
if(!j2k)
return NULL;
 
j2k->default_tcp = (opj_tcp_t*) opj_calloc(1, sizeof(opj_tcp_t));
if(!j2k->default_tcp) {
opj_free(j2k);
return NULL;
}
 
j2k->cinfo = cinfo;
j2k->tile_data = NULL;
 
return j2k;
}
 
void j2k_destroy_decompress(opj_j2k_t *j2k) {
int i = 0;
 
if(j2k->tile_len != NULL) {
opj_free(j2k->tile_len);
}
if(j2k->tile_data != NULL) {
opj_free(j2k->tile_data);
}
if(j2k->default_tcp != NULL) {
opj_tcp_t *default_tcp = j2k->default_tcp;
if(default_tcp->ppt_data_first != NULL) {
opj_free(default_tcp->ppt_data_first);
}
if(j2k->default_tcp->tccps != NULL) {
opj_free(j2k->default_tcp->tccps);
}
opj_free(j2k->default_tcp);
}
if(j2k->cp != NULL) {
opj_cp_t *cp = j2k->cp;
if(cp->tcps != NULL) {
for(i = 0; i < cp->tw * cp->th; i++) {
if(cp->tcps[i].ppt_data_first != NULL) {
opj_free(cp->tcps[i].ppt_data_first);
}
if(cp->tcps[i].tccps != NULL) {
opj_free(cp->tcps[i].tccps);
}
}
opj_free(cp->tcps);
}
if(cp->ppm_data_first != NULL) {
opj_free(cp->ppm_data_first);
}
if(cp->tileno != NULL) {
opj_free(cp->tileno);
}
if(cp->comment != NULL) {
opj_free(cp->comment);
}
 
opj_free(cp);
}
opj_free(j2k);
}
 
void j2k_setup_decoder(opj_j2k_t *j2k, opj_dparameters_t *parameters) {
if(j2k && parameters) {
/* create and initialize the coding parameters structure */
opj_cp_t *cp = (opj_cp_t*) opj_calloc(1, sizeof(opj_cp_t));
cp->reduce = parameters->cp_reduce;
cp->layer = parameters->cp_layer;
cp->limit_decoding = parameters->cp_limit_decoding;
 
#ifdef USE_JPWL
cp->correct = parameters->jpwl_correct;
cp->exp_comps = parameters->jpwl_exp_comps;
cp->max_tiles = parameters->jpwl_max_tiles;
#endif /* USE_JPWL */
 
 
/* keep a link to cp so that we can destroy it later in j2k_destroy_decompress */
j2k->cp = cp;
}
}
 
opj_image_t* j2k_decode(opj_j2k_t *j2k, opj_cio_t *cio, opj_codestream_info_t *cstr_info) {
opj_image_t *image = NULL;
 
opj_common_ptr cinfo = j2k->cinfo;
 
j2k->cio = cio;
j2k->cstr_info = cstr_info;
if (cstr_info)
memset(cstr_info, 0, sizeof(opj_codestream_info_t));
 
/* create an empty image */
image = opj_image_create0();
j2k->image = image;
 
j2k->state = J2K_STATE_MHSOC;
 
for (;;) {
opj_dec_mstabent_t *e;
int id = cio_read(cio, 2);
 
#ifdef USE_JPWL
/* we try to honor JPWL correction power */
if (j2k->cp->correct) {
 
int orig_pos = cio_tell(cio);
bool status;
 
/* call the corrector */
status = jpwl_correct(j2k);
 
/* go back to where you were */
cio_seek(cio, orig_pos - 2);
 
/* re-read the marker */
id = cio_read(cio, 2);
 
/* check whether it begins with ff */
if (id >> 8 != 0xff) {
opj_event_msg(cinfo, EVT_ERROR,
"JPWL: possible bad marker %x at %d\n",
id, cio_tell(cio) - 2);
if (!JPWL_ASSUME) {
opj_image_destroy(image);
opj_event_msg(cinfo, EVT_ERROR, "JPWL: giving up\n");
return 0;
}
/* we try to correct */
id = id | 0xff00;
cio_seek(cio, cio_tell(cio) - 2);
cio_write(cio, id, 2);
opj_event_msg(cinfo, EVT_WARNING, "- trying to adjust this\n"
"- setting marker to %x\n",
id);
}
 
}
#endif /* USE_JPWL */
 
if (id >> 8 != 0xff) {
opj_image_destroy(image);
opj_event_msg(cinfo, EVT_ERROR, "%.8x: expected a marker instead of %x\n", cio_tell(cio) - 2, id);
return 0;
}
e = j2k_dec_mstab_lookup(id);
// Check if the marker is known
if (!(j2k->state & e->states)) {
opj_image_destroy(image);
opj_event_msg(cinfo, EVT_ERROR, "%.8x: unexpected marker %x\n", cio_tell(cio) - 2, id);
return 0;
}
// Check if the decoding is limited to the main header
if (e->id == J2K_MS_SOT && j2k->cp->limit_decoding == LIMIT_TO_MAIN_HEADER) {
opj_event_msg(cinfo, EVT_INFO, "Main Header decoded.\n");
return image;
}
 
if (e->handler) {
(*e->handler)(j2k);
}
if (j2k->state & J2K_STATE_ERR)
return NULL;
 
if (j2k->state == J2K_STATE_MT) {
break;
}
if (j2k->state == J2K_STATE_NEOC) {
break;
}
}
if (j2k->state == J2K_STATE_NEOC) {
j2k_read_eoc(j2k);
}
 
if (j2k->state != J2K_STATE_MT) {
opj_event_msg(cinfo, EVT_WARNING, "Incomplete bitstream\n");
}
 
return image;
}
 
/*
* Read a JPT-stream and decode file
*
*/
opj_image_t* j2k_decode_jpt_stream(opj_j2k_t *j2k, opj_cio_t *cio, opj_codestream_info_t *cstr_info) {
opj_image_t *image = NULL;
opj_jpt_msg_header_t header;
int position;
 
opj_common_ptr cinfo = j2k->cinfo;
j2k->cio = cio;
 
/* create an empty image */
image = opj_image_create0();
j2k->image = image;
 
j2k->state = J2K_STATE_MHSOC;
/* Initialize the header */
jpt_init_msg_header(&header);
/* Read the first header of the message */
jpt_read_msg_header(cinfo, cio, &header);
position = cio_tell(cio);
if (header.Class_Id != 6) { /* 6 : Main header data-bin message */
opj_image_destroy(image);
opj_event_msg(cinfo, EVT_ERROR, "[JPT-stream] : Expecting Main header first [class_Id %d] !\n", header.Class_Id);
return 0;
}
for (;;) {
opj_dec_mstabent_t *e = NULL;
int id;
if (!cio_numbytesleft(cio)) {
j2k_read_eoc(j2k);
return image;
}
/* data-bin read -> need to read a new header */
if ((unsigned int) (cio_tell(cio) - position) == header.Msg_length) {
jpt_read_msg_header(cinfo, cio, &header);
position = cio_tell(cio);
if (header.Class_Id != 4) { /* 4 : Tile data-bin message */
opj_image_destroy(image);
opj_event_msg(cinfo, EVT_ERROR, "[JPT-stream] : Expecting Tile info !\n");
return 0;
}
}
id = cio_read(cio, 2);
if (id >> 8 != 0xff) {
opj_image_destroy(image);
opj_event_msg(cinfo, EVT_ERROR, "%.8x: expected a marker instead of %x\n", cio_tell(cio) - 2, id);
return 0;
}
e = j2k_dec_mstab_lookup(id);
if (!(j2k->state & e->states)) {
opj_image_destroy(image);
opj_event_msg(cinfo, EVT_ERROR, "%.8x: unexpected marker %x\n", cio_tell(cio) - 2, id);
return 0;
}
if (e->handler) {
(*e->handler)(j2k);
}
if (j2k->state == J2K_STATE_MT) {
break;
}
if (j2k->state == J2K_STATE_NEOC) {
break;
}
}
if (j2k->state == J2K_STATE_NEOC) {
j2k_read_eoc(j2k);
}
if (j2k->state != J2K_STATE_MT) {
opj_event_msg(cinfo, EVT_WARNING, "Incomplete bitstream\n");
}
 
return image;
}
 
/* ----------------------------------------------------------------------- */
/* J2K encoder interface */
/* ----------------------------------------------------------------------- */
 
opj_j2k_t* j2k_create_compress(opj_common_ptr cinfo) {
opj_j2k_t *j2k = (opj_j2k_t*) opj_calloc(1, sizeof(opj_j2k_t));
if(j2k) {
j2k->cinfo = cinfo;
}
return j2k;
}
 
void j2k_destroy_compress(opj_j2k_t *j2k) {
int tileno;
 
if(!j2k) return;
if(j2k->cp != NULL) {
opj_cp_t *cp = j2k->cp;
 
if(cp->comment) {
opj_free(cp->comment);
}
if(cp->matrice) {
opj_free(cp->matrice);
}
for (tileno = 0; tileno < cp->tw * cp->th; tileno++) {
opj_free(cp->tcps[tileno].tccps);
}
opj_free(cp->tcps);
opj_free(cp);
}
 
opj_free(j2k);
}
 
void j2k_setup_encoder(opj_j2k_t *j2k, opj_cparameters_t *parameters, opj_image_t *image) {
int i, j, tileno, numpocs_tile;
opj_cp_t *cp = NULL;
 
if(!j2k || !parameters || ! image) {
return;
}
 
/* create and initialize the coding parameters structure */
cp = (opj_cp_t*) opj_calloc(1, sizeof(opj_cp_t));
 
/* keep a link to cp so that we can destroy it later in j2k_destroy_compress */
j2k->cp = cp;
 
/* set default values for cp */
cp->tw = 1;
cp->th = 1;
 
/*
copy user encoding parameters
*/
cp->cinema = parameters->cp_cinema;
cp->max_comp_size = parameters->max_comp_size;
cp->rsiz = parameters->cp_rsiz;
cp->disto_alloc = parameters->cp_disto_alloc;
cp->fixed_alloc = parameters->cp_fixed_alloc;
cp->fixed_quality = parameters->cp_fixed_quality;
 
/* mod fixed_quality */
if(parameters->cp_matrice) {
size_t array_size = parameters->tcp_numlayers * parameters->numresolution * 3 * sizeof(int);
cp->matrice = (int *) opj_malloc(array_size);
memcpy(cp->matrice, parameters->cp_matrice, array_size);
}
 
/* tiles */
cp->tdx = parameters->cp_tdx;
cp->tdy = parameters->cp_tdy;
 
/* tile offset */
cp->tx0 = parameters->cp_tx0;
cp->ty0 = parameters->cp_ty0;
 
/* comment string */
if(parameters->cp_comment) {
cp->comment = (char*)opj_malloc(strlen(parameters->cp_comment) + 1);
if(cp->comment) {
strcpy(cp->comment, parameters->cp_comment);
}
}
 
/*
calculate other encoding parameters
*/
 
if (parameters->tile_size_on) {
cp->tw = int_ceildiv(image->x1 - cp->tx0, cp->tdx);
cp->th = int_ceildiv(image->y1 - cp->ty0, cp->tdy);
} else {
cp->tdx = image->x1 - cp->tx0;
cp->tdy = image->y1 - cp->ty0;
}
 
if(parameters->tp_on){
cp->tp_flag = parameters->tp_flag;
cp->tp_on = 1;
}
cp->img_size = 0;
for(i=0;i<image->numcomps ;i++){
cp->img_size += (image->comps[i].w *image->comps[i].h * image->comps[i].prec);
}
 
 
#ifdef USE_JPWL
/*
calculate JPWL encoding parameters
*/
 
if (parameters->jpwl_epc_on) {
int i;
 
/* set JPWL on */
cp->epc_on = true;
cp->info_on = false; /* no informative technique */
 
/* set EPB on */
if ((parameters->jpwl_hprot_MH > 0) || (parameters->jpwl_hprot_TPH[0] > 0)) {
cp->epb_on = true;
cp->hprot_MH = parameters->jpwl_hprot_MH;
for (i = 0; i < JPWL_MAX_NO_TILESPECS; i++) {
cp->hprot_TPH_tileno[i] = parameters->jpwl_hprot_TPH_tileno[i];
cp->hprot_TPH[i] = parameters->jpwl_hprot_TPH[i];
}
/* if tile specs are not specified, copy MH specs */
if (cp->hprot_TPH[0] == -1) {
cp->hprot_TPH_tileno[0] = 0;
cp->hprot_TPH[0] = parameters->jpwl_hprot_MH;
}
for (i = 0; i < JPWL_MAX_NO_PACKSPECS; i++) {
cp->pprot_tileno[i] = parameters->jpwl_pprot_tileno[i];
cp->pprot_packno[i] = parameters->jpwl_pprot_packno[i];
cp->pprot[i] = parameters->jpwl_pprot[i];
}
}
 
/* set ESD writing */
if ((parameters->jpwl_sens_size == 1) || (parameters->jpwl_sens_size == 2)) {
cp->esd_on = true;
 
cp->sens_size = parameters->jpwl_sens_size;
cp->sens_addr = parameters->jpwl_sens_addr;
cp->sens_range = parameters->jpwl_sens_range;
 
cp->sens_MH = parameters->jpwl_sens_MH;
for (i = 0; i < JPWL_MAX_NO_TILESPECS; i++) {
cp->sens_TPH_tileno[i] = parameters->jpwl_sens_TPH_tileno[i];
cp->sens_TPH[i] = parameters->jpwl_sens_TPH[i];
}
}
 
/* always set RED writing to false: we are at the encoder */
cp->red_on = false;
 
} else {
cp->epc_on = false;
}
#endif /* USE_JPWL */
 
 
/* initialize the mutiple tiles */
/* ---------------------------- */
cp->tcps = (opj_tcp_t*) opj_calloc(cp->tw * cp->th, sizeof(opj_tcp_t));
 
for (tileno = 0; tileno < cp->tw * cp->th; tileno++) {
opj_tcp_t *tcp = &cp->tcps[tileno];
tcp->numlayers = parameters->tcp_numlayers;
for (j = 0; j < tcp->numlayers; j++) {
if(cp->cinema){
if (cp->fixed_quality) {
tcp->distoratio[j] = parameters->tcp_distoratio[j];
}
tcp->rates[j] = parameters->tcp_rates[j];
}else{
if (cp->fixed_quality) { /* add fixed_quality */
tcp->distoratio[j] = parameters->tcp_distoratio[j];
} else {
tcp->rates[j] = parameters->tcp_rates[j];
}
}
}
tcp->csty = parameters->csty;
tcp->prg = parameters->prog_order;
tcp->mct = parameters->tcp_mct;
 
numpocs_tile = 0;
tcp->POC = 0;
if (parameters->numpocs) {
/* initialisation of POC */
tcp->POC = 1;
for (i = 0; i < parameters->numpocs; i++) {
if((tileno == parameters->POC[i].tile - 1) || (parameters->POC[i].tile == -1)) {
opj_poc_t *tcp_poc = &tcp->pocs[numpocs_tile];
tcp_poc->resno0 = parameters->POC[numpocs_tile].resno0;
tcp_poc->compno0 = parameters->POC[numpocs_tile].compno0;
tcp_poc->layno1 = parameters->POC[numpocs_tile].layno1;
tcp_poc->resno1 = parameters->POC[numpocs_tile].resno1;
tcp_poc->compno1 = parameters->POC[numpocs_tile].compno1;
tcp_poc->prg1 = parameters->POC[numpocs_tile].prg1;
tcp_poc->tile = parameters->POC[numpocs_tile].tile;
numpocs_tile++;
}
}
tcp->numpocs = numpocs_tile -1 ;
}else{
tcp->numpocs = 0;
}
 
tcp->tccps = (opj_tccp_t*) opj_calloc(image->numcomps, sizeof(opj_tccp_t));
 
for (i = 0; i < image->numcomps; i++) {
opj_tccp_t *tccp = &tcp->tccps[i];
tccp->csty = parameters->csty & 0x01; /* 0 => one precinct || 1 => custom precinct */
tccp->numresolutions = parameters->numresolution;
tccp->cblkw = int_floorlog2(parameters->cblockw_init);
tccp->cblkh = int_floorlog2(parameters->cblockh_init);
tccp->cblksty = parameters->mode;
tccp->qmfbid = parameters->irreversible ? 0 : 1;
tccp->qntsty = parameters->irreversible ? J2K_CCP_QNTSTY_SEQNT : J2K_CCP_QNTSTY_NOQNT;
tccp->numgbits = 2;
if (i == parameters->roi_compno) {
tccp->roishift = parameters->roi_shift;
} else {
tccp->roishift = 0;
}
 
if(parameters->cp_cinema)
{
//Precinct size for lowest frequency subband=128
tccp->prcw[0] = 7;
tccp->prch[0] = 7;
//Precinct size at all other resolutions = 256
for (j = 1; j < tccp->numresolutions; j++) {
tccp->prcw[j] = 8;
tccp->prch[j] = 8;
}
}else{
if (parameters->csty & J2K_CCP_CSTY_PRT) {
int p = 0;
for (j = tccp->numresolutions - 1; j >= 0; j--) {
if (p < parameters->res_spec) {
if (parameters->prcw_init[p] < 1) {
tccp->prcw[j] = 1;
} else {
tccp->prcw[j] = int_floorlog2(parameters->prcw_init[p]);
}
if (parameters->prch_init[p] < 1) {
tccp->prch[j] = 1;
}else {
tccp->prch[j] = int_floorlog2(parameters->prch_init[p]);
}
 
} else {
int res_spec = parameters->res_spec;
int size_prcw = parameters->prcw_init[res_spec - 1] >> (p - (res_spec - 1));
int size_prch = parameters->prch_init[res_spec - 1] >> (p - (res_spec - 1));
if (size_prcw < 1) {
tccp->prcw[j] = 1;
} else {
tccp->prcw[j] = int_floorlog2(size_prcw);
}
if (size_prch < 1) {
tccp->prch[j] = 1;
} else {
tccp->prch[j] = int_floorlog2(size_prch);
}
}
p++;
/*printf("\nsize precinct for level %d : %d,%d\n", j,tccp->prcw[j], tccp->prch[j]); */
} //end for
} else {
for (j = 0; j < tccp->numresolutions; j++) {
tccp->prcw[j] = 15;
tccp->prch[j] = 15;
}
}
}
 
dwt_calc_explicit_stepsizes(tccp, image->comps[i].prec);
}
}
}
 
bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info) {
int tileno, compno;
opj_cp_t *cp = NULL;
 
opj_tcd_t *tcd = NULL; /* TCD component */
 
j2k->cio = cio;
j2k->image = image;
 
cp = j2k->cp;
 
/* INDEX >> */
j2k->cstr_info = cstr_info;
if (cstr_info) {
int compno;
cstr_info->tile = (opj_tile_info_t *) opj_malloc(cp->tw * cp->th * sizeof(opj_tile_info_t));
cstr_info->image_w = image->x1 - image->x0;
cstr_info->image_h = image->y1 - image->y0;
cstr_info->prog = (&cp->tcps[0])->prg;
cstr_info->tw = cp->tw;
cstr_info->th = cp->th;
cstr_info->tile_x = cp->tdx; /* new version parser */
cstr_info->tile_y = cp->tdy; /* new version parser */
cstr_info->tile_Ox = cp->tx0; /* new version parser */
cstr_info->tile_Oy = cp->ty0; /* new version parser */
cstr_info->numcomps = image->numcomps;
cstr_info->numlayers = (&cp->tcps[0])->numlayers;
cstr_info->numdecompos = (int*) opj_malloc(image->numcomps * sizeof(int));
for (compno=0; compno < image->numcomps; compno++) {
cstr_info->numdecompos[compno] = (&cp->tcps[0])->tccps->numresolutions - 1;
}
cstr_info->D_max = 0.0; /* ADD Marcela */
cstr_info->main_head_start = cio_tell(cio); /* position of SOC */
cstr_info->maxmarknum = 100;
cstr_info->marker = (opj_marker_info_t *) opj_malloc(cstr_info->maxmarknum * sizeof(opj_marker_info_t));
cstr_info->marknum = 0;
}
/* << INDEX */
 
j2k_write_soc(j2k);
j2k_write_siz(j2k);
j2k_write_cod(j2k);
j2k_write_qcd(j2k);
 
if(cp->cinema){
for (compno = 1; compno < image->numcomps; compno++) {
j2k_write_coc(j2k, compno);
j2k_write_qcc(j2k, compno);
}
}
 
for (compno = 0; compno < image->numcomps; compno++) {
opj_tcp_t *tcp = &cp->tcps[0];
if (tcp->tccps[compno].roishift)
j2k_write_rgn(j2k, compno, 0);
}
if (cp->comment != NULL) {
j2k_write_com(j2k);
}
 
j2k->totnum_tp = j2k_calculate_tp(cp,image->numcomps,image,j2k);
/* TLM Marker*/
if(cp->cinema){
j2k_write_tlm(j2k);
if (cp->cinema == CINEMA4K_24) {
j2k_write_poc(j2k);
}
}
 
/* uncomment only for testing JPSEC marker writing */
/* j2k_write_sec(j2k); */
 
/* INDEX >> */
if(cstr_info) {
cstr_info->main_head_end = cio_tell(cio) - 1;
}
/* << INDEX */
/**** Main Header ENDS here ***/
 
/* create the tile encoder */
tcd = tcd_create(j2k->cinfo);
 
/* encode each tile */
for (tileno = 0; tileno < cp->tw * cp->th; tileno++) {
int pino;
int tilepartno=0;
/* UniPG>> */
int acc_pack_num = 0;
/* <<UniPG */
 
 
opj_tcp_t *tcp = &cp->tcps[tileno];
opj_event_msg(j2k->cinfo, EVT_INFO, "tile number %d / %d\n", tileno + 1, cp->tw * cp->th);
 
j2k->curtileno = tileno;
j2k->cur_tp_num = 0;
tcd->cur_totnum_tp = j2k->cur_totnum_tp[j2k->curtileno];
/* initialisation before tile encoding */
if (tileno == 0) {
tcd_malloc_encode(tcd, image, cp, j2k->curtileno);
} else {
tcd_init_encode(tcd, image, cp, j2k->curtileno);
}
 
/* INDEX >> */
if(cstr_info) {
cstr_info->tile[j2k->curtileno].start_pos = cio_tell(cio) + j2k->pos_correction;
}
/* << INDEX */
 
for(pino = 0; pino <= tcp->numpocs; pino++) {
int tot_num_tp;
tcd->cur_pino=pino;
 
/*Get number of tile parts*/
tot_num_tp = j2k_get_num_tp(cp,pino,tileno);
tcd->tp_pos = cp->tp_pos;
 
for(tilepartno = 0; tilepartno < tot_num_tp ; tilepartno++){
j2k->tp_num = tilepartno;
/* INDEX >> */
if(cstr_info)
cstr_info->tile[j2k->curtileno].tp[j2k->cur_tp_num].tp_start_pos =
cio_tell(cio) + j2k->pos_correction;
/* << INDEX */
j2k_write_sot(j2k);
 
if(j2k->cur_tp_num == 0 && cp->cinema == 0){
for (compno = 1; compno < image->numcomps; compno++) {
j2k_write_coc(j2k, compno);
j2k_write_qcc(j2k, compno);
}
if (cp->tcps[tileno].numpocs) {
j2k_write_poc(j2k);
}
}
 
/* INDEX >> */
if(cstr_info)
cstr_info->tile[j2k->curtileno].tp[j2k->cur_tp_num].tp_end_header =
cio_tell(cio) + j2k->pos_correction + 1;
/* << INDEX */
 
j2k_write_sod(j2k, tcd);
 
/* INDEX >> */
if(cstr_info) {
cstr_info->tile[j2k->curtileno].tp[j2k->cur_tp_num].tp_end_pos =
cio_tell(cio) + j2k->pos_correction - 1;
cstr_info->tile[j2k->curtileno].tp[j2k->cur_tp_num].tp_start_pack =
acc_pack_num;
cstr_info->tile[j2k->curtileno].tp[j2k->cur_tp_num].tp_numpacks =
cstr_info->packno - acc_pack_num;
acc_pack_num = cstr_info->packno;
}
/* << INDEX */
 
j2k->cur_tp_num++;
}
}
if(cstr_info) {
cstr_info->tile[j2k->curtileno].end_pos = cio_tell(cio) + j2k->pos_correction - 1;
}
 
 
/*
if (tile->PPT) { // BAD PPT !!!
FILE *PPT_file;
int i;
PPT_file=fopen("PPT","rb");
fprintf(stderr,"%c%c%c%c",255,97,tile->len_ppt/256,tile->len_ppt%256);
for (i=0;i<tile->len_ppt;i++) {
unsigned char elmt;
fread(&elmt, 1, 1, PPT_file);
fwrite(&elmt,1,1,f);
}
fclose(PPT_file);
unlink("PPT");
}
*/
 
}
 
/* destroy the tile encoder */
tcd_free_encode(tcd);
tcd_destroy(tcd);
 
opj_free(j2k->cur_totnum_tp);
 
j2k_write_eoc(j2k);
 
if(cstr_info) {
cstr_info->codestream_size = cio_tell(cio) + j2k->pos_correction;
/* UniPG>> */
/* The following adjustment is done to adjust the codestream size */
/* if SOD is not at 0 in the buffer. Useful in case of JP2, where */
/* the first bunch of bytes is not in the codestream */
cstr_info->codestream_size -= cstr_info->main_head_start;
/* <<UniPG */
}
 
#ifdef USE_JPWL
/*
preparation of JPWL marker segments
*/
if(cp->epc_on) {
 
/* encode according to JPWL */
jpwl_encode(j2k, cio, image);
 
}
#endif /* USE_JPWL */
 
return true;
}
 
 
 
 
 
 
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libopenjpeg/j2k.h
0,0 → 1,446
/*
* Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2007, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2006-2007, Parvatha Elangovan
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __J2K_H
#define __J2K_H
/**
@file j2k.h
@brief The JPEG-2000 Codestream Reader/Writer (J2K)
 
The functions in J2K.C have for goal to read/write the several parts of the codestream: markers and data.
*/
 
/** @defgroup J2K J2K - JPEG-2000 codestream reader/writer */
/*@{*/
 
#define J2K_CP_CSTY_PRT 0x01
#define J2K_CP_CSTY_SOP 0x02
#define J2K_CP_CSTY_EPH 0x04
#define J2K_CCP_CSTY_PRT 0x01
#define J2K_CCP_CBLKSTY_LAZY 0x01 /**< Selective arithmetic coding bypass */
#define J2K_CCP_CBLKSTY_RESET 0x02 /**< Reset context probabilities on coding pass boundaries */
#define J2K_CCP_CBLKSTY_TERMALL 0x04 /**< Termination on each coding pass */
#define J2K_CCP_CBLKSTY_VSC 0x08 /**< Vertically stripe causal context */
#define J2K_CCP_CBLKSTY_PTERM 0x10 /**< Predictable termination */
#define J2K_CCP_CBLKSTY_SEGSYM 0x20 /**< Segmentation symbols are used */
#define J2K_CCP_QNTSTY_NOQNT 0
#define J2K_CCP_QNTSTY_SIQNT 1
#define J2K_CCP_QNTSTY_SEQNT 2
 
/* ----------------------------------------------------------------------- */
 
#define J2K_MS_SOC 0xff4f /**< SOC marker value */
#define J2K_MS_SOT 0xff90 /**< SOT marker value */
#define J2K_MS_SOD 0xff93 /**< SOD marker value */
#define J2K_MS_EOC 0xffd9 /**< EOC marker value */
#define J2K_MS_SIZ 0xff51 /**< SIZ marker value */
#define J2K_MS_COD 0xff52 /**< COD marker value */
#define J2K_MS_COC 0xff53 /**< COC marker value */
#define J2K_MS_RGN 0xff5e /**< RGN marker value */
#define J2K_MS_QCD 0xff5c /**< QCD marker value */
#define J2K_MS_QCC 0xff5d /**< QCC marker value */
#define J2K_MS_POC 0xff5f /**< POC marker value */
#define J2K_MS_TLM 0xff55 /**< TLM marker value */
#define J2K_MS_PLM 0xff57 /**< PLM marker value */
#define J2K_MS_PLT 0xff58 /**< PLT marker value */
#define J2K_MS_PPM 0xff60 /**< PPM marker value */
#define J2K_MS_PPT 0xff61 /**< PPT marker value */
#define J2K_MS_SOP 0xff91 /**< SOP marker value */
#define J2K_MS_EPH 0xff92 /**< EPH marker value */
#define J2K_MS_CRG 0xff63 /**< CRG marker value */
#define J2K_MS_COM 0xff64 /**< COM marker value */
/* UniPG>> */
#ifdef USE_JPWL
#define J2K_MS_EPC 0xff68 /**< EPC marker value (Part 11: JPEG 2000 for Wireless) */
#define J2K_MS_EPB 0xff66 /**< EPB marker value (Part 11: JPEG 2000 for Wireless) */
#define J2K_MS_ESD 0xff67 /**< ESD marker value (Part 11: JPEG 2000 for Wireless) */
#define J2K_MS_RED 0xff69 /**< RED marker value (Part 11: JPEG 2000 for Wireless) */
#endif /* USE_JPWL */
#ifdef USE_JPSEC
#define J2K_MS_SEC 0xff65 /**< SEC marker value (Part 8: Secure JPEG 2000) */
#define J2K_MS_INSEC 0xff94 /**< INSEC marker value (Part 8: Secure JPEG 2000) */
#endif /* USE_JPSEC */
/* <<UniPG */
 
 
/* ----------------------------------------------------------------------- */
 
/**
Values that specify the status of the decoding process when decoding the main header.
These values may be combined with a | operator.
*/
typedef enum J2K_STATUS {
J2K_STATE_MHSOC = 0x0001, /**< a SOC marker is expected */
J2K_STATE_MHSIZ = 0x0002, /**< a SIZ marker is expected */
J2K_STATE_MH = 0x0004, /**< the decoding process is in the main header */
J2K_STATE_TPHSOT = 0x0008, /**< the decoding process is in a tile part header and expects a SOT marker */
J2K_STATE_TPH = 0x0010, /**< the decoding process is in a tile part header */
J2K_STATE_MT = 0x0020, /**< the EOC marker has just been read */
J2K_STATE_NEOC = 0x0040, /**< the decoding process must not expect a EOC marker because the codestream is truncated */
J2K_STATE_ERR = 0x0080 /**< the decoding process has encountered an error */
} J2K_STATUS;
 
/* ----------------------------------------------------------------------- */
 
/**
T2 encoding mode
*/
typedef enum T2_MODE {
THRESH_CALC = 0, /** Function called in Rate allocation process*/
FINAL_PASS = 1 /** Function called in Tier 2 process*/
}J2K_T2_MODE;
 
/**
Quantization stepsize
*/
typedef struct opj_stepsize {
/** exponent */
int expn;
/** mantissa */
int mant;
} opj_stepsize_t;
 
/**
Tile-component coding parameters
*/
typedef struct opj_tccp {
/** coding style */
int csty;
/** number of resolutions */
int numresolutions;
/** code-blocks width */
int cblkw;
/** code-blocks height */
int cblkh;
/** code-block coding style */
int cblksty;
/** discrete wavelet transform identifier */
int qmfbid;
/** quantisation style */
int qntsty;
/** stepsizes used for quantization */
opj_stepsize_t stepsizes[J2K_MAXBANDS];
/** number of guard bits */
int numgbits;
/** Region Of Interest shift */
int roishift;
/** precinct width */
int prcw[J2K_MAXRLVLS];
/** precinct height */
int prch[J2K_MAXRLVLS];
} opj_tccp_t;
 
/**
Tile coding parameters :
this structure is used to store coding/decoding parameters common to all
tiles (information like COD, COC in main header)
*/
typedef struct opj_tcp {
/** 1 : first part-tile of a tile */
int first;
/** coding style */
int csty;
/** progression order */
OPJ_PROG_ORDER prg;
/** number of layers */
int numlayers;
/** multi-component transform identifier */
int mct;
/** rates of layers */
float rates[100];
/** number of progression order changes */
int numpocs;
/** indicates if a POC marker has been used O:NO, 1:YES */
int POC;
/** progression order changes */
opj_poc_t pocs[32];
/** packet header store there for futur use in t2_decode_packet */
unsigned char *ppt_data;
/** pointer remaining on the first byte of the first header if ppt is used */
unsigned char *ppt_data_first;
/** If ppt == 1 --> there was a PPT marker for the present tile */
int ppt;
/** used in case of multiple marker PPT (number of info already stored) */
int ppt_store;
/** ppmbug1 */
int ppt_len;
/** add fixed_quality */
float distoratio[100];
/** tile-component coding parameters */
opj_tccp_t *tccps;
} opj_tcp_t;
 
/**
Coding parameters
*/
typedef struct opj_cp {
/** Digital cinema profile*/
OPJ_CINEMA_MODE cinema;
/** Maximum rate for each component. If == 0, component size limitation is not considered */
int max_comp_size;
/** Size of the image in bits*/
int img_size;
/** Rsiz*/
OPJ_RSIZ_CAPABILITIES rsiz;
/** Enabling Tile part generation*/
char tp_on;
/** Flag determining tile part generation*/
char tp_flag;
/** Position of tile part flag in progression order*/
int tp_pos;
/** allocation by rate/distortion */
int disto_alloc;
/** allocation by fixed layer */
int fixed_alloc;
/** add fixed_quality */
int fixed_quality;
/** if != 0, then original dimension divided by 2^(reduce); if == 0 or not used, image is decoded to the full resolution */
int reduce;
/** if != 0, then only the first "layer" layers are decoded; if == 0 or not used, all the quality layers are decoded */
int layer;
/** if == NO_LIMITATION, decode entire codestream; if == LIMIT_TO_MAIN_HEADER then only decode the main header */
OPJ_LIMIT_DECODING limit_decoding;
/** XTOsiz */
int tx0;
/** YTOsiz */
int ty0;
/** XTsiz */
int tdx;
/** YTsiz */
int tdy;
/** comment for coding */
char *comment;
/** number of tiles in width */
int tw;
/** number of tiles in heigth */
int th;
/** ID number of the tiles present in the codestream */
int *tileno;
/** size of the vector tileno */
int tileno_size;
/** packet header store there for futur use in t2_decode_packet */
unsigned char *ppm_data;
/** pointer remaining on the first byte of the first header if ppm is used */
unsigned char *ppm_data_first;
/** if ppm == 1 --> there was a PPM marker for the present tile */
int ppm;
/** use in case of multiple marker PPM (number of info already store) */
int ppm_store;
/** use in case of multiple marker PPM (case on non-finished previous info) */
int ppm_previous;
/** ppmbug1 */
int ppm_len;
/** tile coding parameters */
opj_tcp_t *tcps;
/** fixed layer */
int *matrice;
/* UniPG>> */
#ifdef USE_JPWL
/** enables writing of EPC in MH, thus activating JPWL */
bool epc_on;
/** enables writing of EPB, in case of activated JPWL */
bool epb_on;
/** enables writing of ESD, in case of activated JPWL */
bool esd_on;
/** enables writing of informative techniques of ESD, in case of activated JPWL */
bool info_on;
/** enables writing of RED, in case of activated JPWL */
bool red_on;
/** error protection method for MH (0,1,16,32,37-128) */
int hprot_MH;
/** tile number of header protection specification (>=0) */
int hprot_TPH_tileno[JPWL_MAX_NO_TILESPECS];
/** error protection methods for TPHs (0,1,16,32,37-128) */
int hprot_TPH[JPWL_MAX_NO_TILESPECS];
/** tile number of packet protection specification (>=0) */
int pprot_tileno[JPWL_MAX_NO_PACKSPECS];
/** packet number of packet protection specification (>=0) */
int pprot_packno[JPWL_MAX_NO_PACKSPECS];
/** error protection methods for packets (0,1,16,32,37-128) */
int pprot[JPWL_MAX_NO_PACKSPECS];
/** enables writing of ESD, (0/2/4 bytes) */
int sens_size;
/** sensitivity addressing size (0=auto/2/4 bytes) */
int sens_addr;
/** sensitivity range (0-3) */
int sens_range;
/** sensitivity method for MH (-1,0-7) */
int sens_MH;
/** tile number of sensitivity specification (>=0) */
int sens_TPH_tileno[JPWL_MAX_NO_TILESPECS];
/** sensitivity methods for TPHs (-1,0-7) */
int sens_TPH[JPWL_MAX_NO_TILESPECS];
/** enables JPWL correction at the decoder */
bool correct;
/** expected number of components at the decoder */
int exp_comps;
/** maximum number of tiles at the decoder */
int max_tiles;
#endif /* USE_JPWL */
/* <<UniPG */
} opj_cp_t;
 
/**
JPEG-2000 codestream reader/writer
*/
typedef struct opj_j2k {
/** codec context */
opj_common_ptr cinfo;
 
/** locate in which part of the codestream the decoder is (main header, tile header, end) */
int state;
/** number of the tile curently concern by coding/decoding */
int curtileno;
/** Tile part number*/
int tp_num;
/** Tilepart number currently coding*/
int cur_tp_num;
/** Total number of tileparts of the current tile*/
int *cur_totnum_tp;
/**
locate the start position of the TLM marker
after encoding the tilepart, a jump (in j2k_write_sod) is done to the TLM marker to store the value of its length.
*/
int tlm_start;
/** Total num of tile parts in whole image = num tiles* num tileparts in each tile*/
/** used in TLMmarker*/
int totnum_tp;
/**
locate the position of the end of the tile in the codestream,
used to detect a truncated codestream (in j2k_read_sod)
*/
unsigned char *eot;
/**
locate the start position of the SOT marker of the current coded tile:
after encoding the tile, a jump (in j2k_write_sod) is done to the SOT marker to store the value of its length.
*/
int sot_start;
int sod_start;
/**
as the J2K-file is written in several parts during encoding,
it enables to make the right correction in position return by cio_tell
*/
int pos_correction;
/** array used to store the data of each tile */
unsigned char **tile_data;
/** array used to store the length of each tile */
int *tile_len;
/**
decompression only :
store decoding parameters common to all tiles (information like COD, COC in main header)
*/
opj_tcp_t *default_tcp;
/** pointer to the encoded / decoded image */
opj_image_t *image;
/** pointer to the coding parameters */
opj_cp_t *cp;
/** helper used to write the index file */
opj_codestream_info_t *cstr_info;
/** pointer to the byte i/o stream */
opj_cio_t *cio;
} opj_j2k_t;
 
/** @name Exported functions */
/*@{*/
/* ----------------------------------------------------------------------- */
/**
Creates a J2K decompression structure
@param cinfo Codec context info
@return Returns a handle to a J2K decompressor if successful, returns NULL otherwise
*/
opj_j2k_t* j2k_create_decompress(opj_common_ptr cinfo);
/**
Destroy a J2K decompressor handle
@param j2k J2K decompressor handle to destroy
*/
void j2k_destroy_decompress(opj_j2k_t *j2k);
/**
Setup the decoder decoding parameters using user parameters.
Decoding parameters are returned in j2k->cp.
@param j2k J2K decompressor handle
@param parameters decompression parameters
*/
void j2k_setup_decoder(opj_j2k_t *j2k, opj_dparameters_t *parameters);
/**
Decode an image from a JPEG-2000 codestream
@param j2k J2K decompressor handle
@param cio Input buffer stream
@param cstr_info Codestream information structure if required, NULL otherwise
@return Returns a decoded image if successful, returns NULL otherwise
*/
opj_image_t* j2k_decode(opj_j2k_t *j2k, opj_cio_t *cio, opj_codestream_info_t *cstr_info);
/**
Decode an image form a JPT-stream (JPEG 2000, JPIP)
@param j2k J2K decompressor handle
@param cio Input buffer stream
@param cstr_info Codestream information structure if required, NULL otherwise
@return Returns a decoded image if successful, returns NULL otherwise
*/
opj_image_t* j2k_decode_jpt_stream(opj_j2k_t *j2k, opj_cio_t *cio, opj_codestream_info_t *cstr_info);
/**
Creates a J2K compression structure
@param cinfo Codec context info
@return Returns a handle to a J2K compressor if successful, returns NULL otherwise
*/
opj_j2k_t* j2k_create_compress(opj_common_ptr cinfo);
/**
Destroy a J2K compressor handle
@param j2k J2K compressor handle to destroy
*/
void j2k_destroy_compress(opj_j2k_t *j2k);
/**
Setup the encoder parameters using the current image and using user parameters.
Coding parameters are returned in j2k->cp.
@param j2k J2K compressor handle
@param parameters compression parameters
@param image input filled image
*/
void j2k_setup_encoder(opj_j2k_t *j2k, opj_cparameters_t *parameters, opj_image_t *image);
/**
Converts an enum type progression order to string type
*/
char *j2k_convert_progression_order(OPJ_PROG_ORDER prg_order);
/**
Encode an image into a JPEG-2000 codestream
@param j2k J2K compressor handle
@param cio Output buffer stream
@param image Image to encode
@param cstr_info Codestream information structure if required, NULL otherwise
@return Returns true if successful, returns false otherwise
*/
bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info);
 
/* ----------------------------------------------------------------------- */
/*@}*/
 
/*@}*/
 
#endif /* __J2K_H */
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libopenjpeg/j2k_lib.c
0,0 → 1,59
/*
* Copyright (c) 2005, Hervé Drolon, FreeImage Team
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
 
#ifdef _WIN32
#include <windows.h>
#else
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/times.h>
#endif /* _WIN32 */
#include "opj_includes.h"
 
double opj_clock(void) {
#ifdef _WIN32
/* _WIN32: use QueryPerformance (very accurate) */
LARGE_INTEGER freq , t ;
/* freq is the clock speed of the CPU */
QueryPerformanceFrequency(&freq) ;
/* cout << "freq = " << ((double) freq.QuadPart) << endl; */
/* t is the high resolution performance counter (see MSDN) */
QueryPerformanceCounter ( & t ) ;
return ( t.QuadPart /(double) freq.QuadPart ) ;
#else
/* Unix or Linux: use resource usage */
struct rusage t;
double procTime;
/* (1) Get the rusage data structure at this moment (man getrusage) */
getrusage(0,&t);
/* (2) What is the elapsed time ? - CPU time = User time + System time */
/* (2a) Get the seconds */
procTime = t.ru_utime.tv_sec + t.ru_stime.tv_sec;
/* (2b) More precisely! Get the microseconds part ! */
return ( procTime + (t.ru_utime.tv_usec + t.ru_stime.tv_usec) * 1e-6 ) ;
#endif
}
 
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libopenjpeg/j2k_lib.h
0,0 → 1,54
/*
* Copyright (c) 2005, Hervé Drolon, FreeImage Team
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __J2K_LIB_H
#define __J2K_LIB_H
/**
@file j2k_lib.h
@brief Internal functions
 
The functions in J2K_LIB.C are internal utilities mainly used for timing.
*/
 
/** @defgroup MISC MISC - Miscellaneous internal functions */
/*@{*/
 
/** @name Exported functions */
/*@{*/
/* ----------------------------------------------------------------------- */
 
/**
Difference in successive opj_clock() calls tells you the elapsed time
@return Returns time in seconds
*/
double opj_clock(void);
 
/* ----------------------------------------------------------------------- */
/*@}*/
 
/*@}*/
 
#endif /* __J2K_LIB_H */
 
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libopenjpeg/jp2.c
0,0 → 1,1089
/*
* Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2007, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "opj_includes.h"
 
/** @defgroup JP2 JP2 - JPEG-2000 file format reader/writer */
/*@{*/
 
/** @name Local static functions */
/*@{*/
 
/**
Read box headers
@param cinfo Codec context info
@param cio Input stream
@param box
@return Returns true if successful, returns false otherwise
*/
static bool jp2_read_boxhdr(opj_common_ptr cinfo, opj_cio_t *cio, opj_jp2_box_t *box);
/*static void jp2_write_url(opj_cio_t *cio, char *Idx_file);*/
/**
Read the IHDR box - Image Header box
@param jp2 JP2 handle
@param cio Input buffer stream
@return Returns true if successful, returns false otherwise
*/
static bool jp2_read_ihdr(opj_jp2_t *jp2, opj_cio_t *cio);
static void jp2_write_ihdr(opj_jp2_t *jp2, opj_cio_t *cio);
static void jp2_write_bpcc(opj_jp2_t *jp2, opj_cio_t *cio);
static bool jp2_read_bpcc(opj_jp2_t *jp2, opj_cio_t *cio);
static void jp2_write_colr(opj_jp2_t *jp2, opj_cio_t *cio);
/**
Write the FTYP box - File type box
@param jp2 JP2 handle
@param cio Output buffer stream
*/
static void jp2_write_ftyp(opj_jp2_t *jp2, opj_cio_t *cio);
/**
Read the FTYP box - File type box
@param jp2 JP2 handle
@param cio Input buffer stream
@return Returns true if successful, returns false otherwise
*/
static bool jp2_read_ftyp(opj_jp2_t *jp2, opj_cio_t *cio);
static int jp2_write_jp2c(opj_jp2_t *jp2, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info);
static bool jp2_read_jp2c(opj_jp2_t *jp2, opj_cio_t *cio, unsigned int *j2k_codestream_length, unsigned int *j2k_codestream_offset);
static void jp2_write_jp(opj_cio_t *cio);
/**
Read the JP box - JPEG 2000 signature
@param jp2 JP2 handle
@param cio Input buffer stream
@return Returns true if successful, returns false otherwise
*/
static bool jp2_read_jp(opj_jp2_t *jp2, opj_cio_t *cio);
/**
Decode the structure of a JP2 file
@param jp2 JP2 handle
@param cio Input buffer stream
@param color Collector for profile, cdef and pclr data
@return Returns true if successful, returns false otherwise
*/
static bool jp2_read_struct(opj_jp2_t *jp2, opj_cio_t *cio,
opj_jp2_color_t *color);
/**
Apply collected palette data
@param color Collector for profile, cdef and pclr data
@param image
*/
static void jp2_apply_pclr(opj_jp2_color_t *color, opj_image_t *image);
/**
Collect palette data
@param jp2 JP2 handle
@param cio Input buffer stream
@param box
@param color Collector for profile, cdef and pclr data
@return Returns true if successful, returns false otherwise
*/
static bool jp2_read_pclr(opj_jp2_t *jp2, opj_cio_t *cio,
opj_jp2_box_t *box, opj_jp2_color_t *color);
/**
Collect component mapping data
@param jp2 JP2 handle
@param cio Input buffer stream
@param box
@param color Collector for profile, cdef and pclr data
@return Returns true if successful, returns false otherwise
*/
static bool jp2_read_cmap(opj_jp2_t *jp2, opj_cio_t *cio,
opj_jp2_box_t *box, opj_jp2_color_t *color);
/**
Collect colour specification data
@param jp2 JP2 handle
@param cio Input buffer stream
@param box
@param color Collector for profile, cdef and pclr data
@return Returns true if successful, returns false otherwise
*/
static bool jp2_read_colr(opj_jp2_t *jp2, opj_cio_t *cio,
opj_jp2_box_t *box, opj_jp2_color_t *color);
/*@}*/
 
/*@}*/
 
/* ----------------------------------------------------------------------- */
 
static bool jp2_read_boxhdr(opj_common_ptr cinfo, opj_cio_t *cio, opj_jp2_box_t *box) {
box->init_pos = cio_tell(cio);
box->length = cio_read(cio, 4);
box->type = cio_read(cio, 4);
if (box->length == 1) {
if (cio_read(cio, 4) != 0) {
opj_event_msg(cinfo, EVT_ERROR, "Cannot handle box sizes higher than 2^32\n");
return false;
}
box->length = cio_read(cio, 4);
if (box->length == 0)
box->length = cio_numbytesleft(cio) + 12;
}
else if (box->length == 0) {
box->length = cio_numbytesleft(cio) + 8;
}
return true;
}
 
#if 0
static void jp2_write_url(opj_cio_t *cio, char *Idx_file) {
unsigned int i;
opj_jp2_box_t box;
 
box.init_pos = cio_tell(cio);
cio_skip(cio, 4);
cio_write(cio, JP2_URL, 4); /* DBTL */
cio_write(cio, 0, 1); /* VERS */
cio_write(cio, 0, 3); /* FLAG */
 
if(Idx_file) {
for (i = 0; i < strlen(Idx_file); i++) {
cio_write(cio, Idx_file[i], 1);
}
}
 
box.length = cio_tell(cio) - box.init_pos;
cio_seek(cio, box.init_pos);
cio_write(cio, box.length, 4); /* L */
cio_seek(cio, box.init_pos + box.length);
}
#endif
 
static bool jp2_read_ihdr(opj_jp2_t *jp2, opj_cio_t *cio) {
opj_jp2_box_t box;
 
opj_common_ptr cinfo = jp2->cinfo;
 
jp2_read_boxhdr(cinfo, cio, &box);
if (JP2_IHDR != box.type) {
opj_event_msg(cinfo, EVT_ERROR, "Expected IHDR Marker\n");
return false;
}
 
jp2->h = cio_read(cio, 4); /* HEIGHT */
jp2->w = cio_read(cio, 4); /* WIDTH */
jp2->numcomps = cio_read(cio, 2); /* NC */
jp2->comps = (opj_jp2_comps_t*) opj_malloc(jp2->numcomps * sizeof(opj_jp2_comps_t));
 
jp2->bpc = cio_read(cio, 1); /* BPC */
 
jp2->C = cio_read(cio, 1); /* C */
jp2->UnkC = cio_read(cio, 1); /* UnkC */
jp2->IPR = cio_read(cio, 1); /* IPR */
 
if (cio_tell(cio) - box.init_pos != box.length) {
opj_event_msg(cinfo, EVT_ERROR, "Error with IHDR Box\n");
return false;
}
 
return true;
}
 
static void jp2_write_ihdr(opj_jp2_t *jp2, opj_cio_t *cio) {
opj_jp2_box_t box;
 
box.init_pos = cio_tell(cio);
cio_skip(cio, 4);
cio_write(cio, JP2_IHDR, 4); /* IHDR */
 
cio_write(cio, jp2->h, 4); /* HEIGHT */
cio_write(cio, jp2->w, 4); /* WIDTH */
cio_write(cio, jp2->numcomps, 2); /* NC */
 
cio_write(cio, jp2->bpc, 1); /* BPC */
 
cio_write(cio, jp2->C, 1); /* C : Always 7 */
cio_write(cio, jp2->UnkC, 1); /* UnkC, colorspace unknown */
cio_write(cio, jp2->IPR, 1); /* IPR, no intellectual property */
 
box.length = cio_tell(cio) - box.init_pos;
cio_seek(cio, box.init_pos);
cio_write(cio, box.length, 4); /* L */
cio_seek(cio, box.init_pos + box.length);
}
 
static void jp2_write_bpcc(opj_jp2_t *jp2, opj_cio_t *cio) {
unsigned int i;
opj_jp2_box_t box;
 
box.init_pos = cio_tell(cio);
cio_skip(cio, 4);
cio_write(cio, JP2_BPCC, 4); /* BPCC */
 
for (i = 0; i < jp2->numcomps; i++) {
cio_write(cio, jp2->comps[i].bpcc, 1);
}
 
box.length = cio_tell(cio) - box.init_pos;
cio_seek(cio, box.init_pos);
cio_write(cio, box.length, 4); /* L */
cio_seek(cio, box.init_pos + box.length);
}
 
 
static bool jp2_read_bpcc(opj_jp2_t *jp2, opj_cio_t *cio) {
unsigned int i;
opj_jp2_box_t box;
 
opj_common_ptr cinfo = jp2->cinfo;
 
jp2_read_boxhdr(cinfo, cio, &box);
if (JP2_BPCC != box.type) {
opj_event_msg(cinfo, EVT_ERROR, "Expected BPCC Marker\n");
return false;
}
 
for (i = 0; i < jp2->numcomps; i++) {
jp2->comps[i].bpcc = cio_read(cio, 1);
}
 
if (cio_tell(cio) - box.init_pos != box.length) {
opj_event_msg(cinfo, EVT_ERROR, "Error with BPCC Box\n");
return false;
}
 
return true;
}
 
static void jp2_write_colr(opj_jp2_t *jp2, opj_cio_t *cio) {
opj_jp2_box_t box;
 
box.init_pos = cio_tell(cio);
cio_skip(cio, 4);
cio_write(cio, JP2_COLR, 4); /* COLR */
 
cio_write(cio, jp2->meth, 1); /* METH */
cio_write(cio, jp2->precedence, 1); /* PRECEDENCE */
cio_write(cio, jp2->approx, 1); /* APPROX */
 
if (jp2->meth == 1) {
cio_write(cio, jp2->enumcs, 4); /* EnumCS */
} else {
cio_write(cio, 0, 1); /* PROFILE (??) */
}
 
box.length = cio_tell(cio) - box.init_pos;
cio_seek(cio, box.init_pos);
cio_write(cio, box.length, 4); /* L */
cio_seek(cio, box.init_pos + box.length);
}
 
static void jp2_free_pclr(opj_jp2_color_t *color)
{
opj_free(color->jp2_pclr->channel_sign);
opj_free(color->jp2_pclr->channel_size);
opj_free(color->jp2_pclr->entries);
 
if(color->jp2_pclr->cmap) opj_free(color->jp2_pclr->cmap);
 
opj_free(color->jp2_pclr); color->jp2_pclr = NULL;
}
 
static void free_color_data(opj_jp2_color_t *color)
{
if(color->jp2_pclr)
{
jp2_free_pclr(color);
}
if(color->jp2_cdef)
{
if(color->jp2_cdef->info) opj_free(color->jp2_cdef->info);
opj_free(color->jp2_cdef);
}
if(color->icc_profile_buf) opj_free(color->icc_profile_buf);
}
 
static void jp2_apply_pclr(opj_jp2_color_t *color, opj_image_t *image)
{
opj_image_comp_t *old_comps, *new_comps;
unsigned char *channel_size, *channel_sign;
unsigned int *entries;
opj_jp2_cmap_comp_t *cmap;
int *src, *dst;
unsigned int j, max;
unsigned short i, nr_channels, cmp, pcol;
int k, top_k;
 
channel_size = color->jp2_pclr->channel_size;
channel_sign = color->jp2_pclr->channel_sign;
entries = color->jp2_pclr->entries;
cmap = color->jp2_pclr->cmap;
nr_channels = color->jp2_pclr->nr_channels;
 
old_comps = image->comps;
new_comps = (opj_image_comp_t*)
opj_malloc(nr_channels * sizeof(opj_image_comp_t));
 
for(i = 0; i < nr_channels; ++i)
{
pcol = cmap[i].pcol; cmp = cmap[i].cmp;
 
new_comps[pcol] = old_comps[cmp];
 
if(cmap[i].mtyp == 0) /* Direct use */
{
old_comps[cmp].data = NULL; continue;
}
/* Palette mapping: */
new_comps[pcol].data = (int*)
opj_malloc(old_comps[cmp].w * old_comps[cmp].h * sizeof(int));
new_comps[pcol].prec = channel_size[i];
new_comps[pcol].sgnd = channel_sign[i];
}
top_k = color->jp2_pclr->nr_entries - 1;
 
for(i = 0; i < nr_channels; ++i)
{
/* Direct use: */
if(cmap[i].mtyp == 0) continue;
 
/* Palette mapping: */
cmp = cmap[i].cmp; pcol = cmap[i].pcol;
src = old_comps[cmp].data;
dst = new_comps[pcol].data;
max = new_comps[pcol].w * new_comps[pcol].h;
 
for(j = 0; j < max; ++j)
{
/* The index */
if((k = src[j]) < 0) k = 0; else if(k > top_k) k = top_k;
/* The colour */
dst[j] = entries[k * nr_channels + pcol];
}
}
max = image->numcomps;
for(i = 0; i < max; ++i)
{
if(old_comps[i].data) opj_free(old_comps[i].data);
}
opj_free(old_comps);
image->comps = new_comps;
image->numcomps = nr_channels;
 
jp2_free_pclr(color);
 
}/* apply_pclr() */
 
static bool jp2_read_pclr(opj_jp2_t *jp2, opj_cio_t *cio,
opj_jp2_box_t *box, opj_jp2_color_t *color)
{
opj_jp2_pclr_t *jp2_pclr;
unsigned char *channel_size, *channel_sign;
unsigned int *entries;
unsigned short nr_entries, nr_channels;
unsigned short i, j;
unsigned char uc;
 
/* Part 1, I.5.3.4: 'There shall be at most one Palette box inside
* a JP2 Header box' :
*/
if(color->jp2_pclr) return false;
 
nr_entries = cio_read(cio, 2); /* NE */
nr_channels = cio_read(cio, 1);/* NPC */
 
entries = (unsigned int*)
opj_malloc(nr_channels * nr_entries * sizeof(unsigned int));
channel_size = (unsigned char*)opj_malloc(nr_channels);
channel_sign = (unsigned char*)opj_malloc(nr_channels);
 
jp2_pclr = (opj_jp2_pclr_t*)opj_malloc(sizeof(opj_jp2_pclr_t));
jp2_pclr->channel_sign = channel_sign;
jp2_pclr->channel_size = channel_size;
jp2_pclr->entries = entries;
jp2_pclr->nr_entries = nr_entries;
jp2_pclr->nr_channels = nr_channels;
jp2_pclr->cmap = NULL;
 
color->jp2_pclr = jp2_pclr;
 
for(i = 0; i < nr_channels; ++i)
{
uc = cio_read(cio, 1); /* Bi */
channel_size[i] = (uc & 0x7f) + 1;
channel_sign[i] = (uc & 0x80)?1:0;
}
 
for(j = 0; j < nr_entries; ++j)
{
for(i = 0; i < nr_channels; ++i)
{
/* Cji */
*entries++ = cio_read(cio, channel_size[i]>>3);
}
}
 
return true;
}/* jp2_read_pclr() */
 
static bool jp2_read_cmap(opj_jp2_t *jp2, opj_cio_t *cio,
opj_jp2_box_t *box, opj_jp2_color_t *color)
{
opj_jp2_cmap_comp_t *cmap;
unsigned short i, nr_channels;
 
/* Need nr_channels: */
if(color->jp2_pclr == NULL) return false;
 
/* Part 1, I.5.3.5: 'There shall be at most one Component Mapping box
* inside a JP2 Header box' :
*/
if(color->jp2_pclr->cmap) return false;
 
nr_channels = color->jp2_pclr->nr_channels;
cmap = (opj_jp2_cmap_comp_t*)
opj_malloc(nr_channels * sizeof(opj_jp2_cmap_comp_t));
 
for(i = 0; i < nr_channels; ++i)
{
cmap[i].cmp = cio_read(cio, 2);
cmap[i].mtyp = cio_read(cio, 1);
cmap[i].pcol = cio_read(cio, 1);
 
}
color->jp2_pclr->cmap = cmap;
 
return true;
}/* jp2_read_cmap() */
 
static void jp2_apply_cdef(opj_image_t *image, opj_jp2_color_t *color)
{
opj_jp2_cdef_info_t *info;
int color_space;
unsigned short i, n, cn, typ, asoc, acn;
 
color_space = image->color_space;
info = color->jp2_cdef->info;
n = color->jp2_cdef->n;
 
for(i = 0; i < n; ++i)
{
/* WATCH: acn = asoc - 1 ! */
if((asoc = info[i].asoc) == 0) continue;
 
cn = info[i].cn; typ = info[i].typ; acn = asoc - 1;
 
if(cn != acn)
{
opj_image_comp_t saved;
 
memcpy(&saved, &image->comps[cn], sizeof(opj_image_comp_t));
memcpy(&image->comps[cn], &image->comps[acn], sizeof(opj_image_comp_t));
memcpy(&image->comps[acn], &saved, sizeof(opj_image_comp_t));
 
info[i].asoc = cn + 1;
info[acn].asoc = info[acn].cn + 1;
}
}
if(color->jp2_cdef->info) opj_free(color->jp2_cdef->info);
 
opj_free(color->jp2_cdef); color->jp2_cdef = NULL;
 
}/* jp2_apply_cdef() */
 
static bool jp2_read_cdef(opj_jp2_t *jp2, opj_cio_t *cio,
opj_jp2_box_t *box, opj_jp2_color_t *color)
{
opj_jp2_cdef_info_t *info;
unsigned short i, n;
 
/* Part 1, I.5.3.6: 'The shall be at most one Channel Definition box
* inside a JP2 Header box.'
*/
if(color->jp2_cdef) return false;
 
if((n = cio_read(cio, 2)) == 0) return false; /* szukw000: FIXME */
 
info = (opj_jp2_cdef_info_t*)
opj_malloc(n * sizeof(opj_jp2_cdef_info_t));
 
color->jp2_cdef = (opj_jp2_cdef_t*)opj_malloc(sizeof(opj_jp2_cdef_t));
color->jp2_cdef->info = info;
color->jp2_cdef->n = n;
 
for(i = 0; i < n; ++i)
{
info[i].cn = cio_read(cio, 2);
info[i].typ = cio_read(cio, 2);
info[i].asoc = cio_read(cio, 2);
 
}
return true;
}/* jp2_read_cdef() */
 
static bool jp2_read_colr(opj_jp2_t *jp2, opj_cio_t *cio,
opj_jp2_box_t *box, opj_jp2_color_t *color)
{
int skip_len;
opj_common_ptr cinfo;
 
/* Part 1, I.5.3.3 : 'A conforming JP2 reader shall ignore all Colour
* Specification boxes after the first.'
*/
if(color->jp2_has_colr) return false;
 
cinfo = jp2->cinfo;
 
jp2->meth = cio_read(cio, 1); /* METH */
jp2->precedence = cio_read(cio, 1); /* PRECEDENCE */
jp2->approx = cio_read(cio, 1); /* APPROX */
 
if (jp2->meth == 1)
{
jp2->enumcs = cio_read(cio, 4); /* EnumCS */
}
else
{
/* skip PROFILE */
skip_len = box->init_pos + box->length - cio_tell(cio);
if (skip_len < 0)
{
opj_event_msg(cinfo, EVT_ERROR, "Error with COLR box size\n");
return false;
}
if(skip_len > 0)
{
unsigned char *start;
 
start = cio_getbp(cio);
color->icc_profile_buf = (unsigned char*)opj_malloc(skip_len);
color->icc_profile_len = skip_len;
 
cio_skip(cio, box->init_pos + box->length - cio_tell(cio));
 
memcpy(color->icc_profile_buf, start, skip_len);
}
}
 
if (cio_tell(cio) - box->init_pos != box->length)
{
opj_event_msg(cinfo, EVT_ERROR, "Error with COLR Box\n");
return false;
}
color->jp2_has_colr = 1;
 
return true;
}/* jp2_read_colr() */
 
bool jp2_read_jp2h(opj_jp2_t *jp2, opj_cio_t *cio, opj_jp2_color_t *color)
{
opj_jp2_box_t box;
unsigned int jp2h_end;
 
opj_common_ptr cinfo = jp2->cinfo;
 
jp2_read_boxhdr(cinfo, cio, &box);
do
{
if (JP2_JP2H != box.type)
{
if (box.type == JP2_JP2C)
{
opj_event_msg(cinfo, EVT_ERROR, "Expected JP2H Marker\n");
return false;
}
cio_skip(cio, box.length - 8);
 
if(cio->bp >= cio->end) return false;
 
jp2_read_boxhdr(cinfo, cio, &box);
}
} while(JP2_JP2H != box.type);
 
if (!jp2_read_ihdr(jp2, cio))
return false;
jp2h_end = box.init_pos + box.length;
 
if (jp2->bpc == 255)
{
if (!jp2_read_bpcc(jp2, cio))
return false;
}
jp2_read_boxhdr(cinfo, cio, &box);
 
while(cio_tell(cio) < jp2h_end)
{
if(box.type == JP2_COLR)
{
if( !jp2_read_colr(jp2, cio, &box, color))
{
cio_seek(cio, box.init_pos + 8);
cio_skip(cio, box.length - 8);
}
jp2_read_boxhdr(cinfo, cio, &box);
continue;
}
if(box.type == JP2_CDEF)
{
if( !jp2_read_cdef(jp2, cio, &box, color))
{
cio_seek(cio, box.init_pos + 8);
cio_skip(cio, box.length - 8);
}
jp2_read_boxhdr(cinfo, cio, &box);
continue;
}
if(box.type == JP2_PCLR)
{
if( !jp2_read_pclr(jp2, cio, &box, color))
{
cio_seek(cio, box.init_pos + 8);
cio_skip(cio, box.length - 8);
}
jp2_read_boxhdr(cinfo, cio, &box);
continue;
}
if(box.type == JP2_CMAP)
{
if( !jp2_read_cmap(jp2, cio, &box, color))
{
cio_seek(cio, box.init_pos + 8);
cio_skip(cio, box.length - 8);
}
jp2_read_boxhdr(cinfo, cio, &box);
continue;
}
cio_seek(cio, box.init_pos + 8);
cio_skip(cio, box.length - 8);
jp2_read_boxhdr(cinfo, cio, &box);
 
}/* while(cio_tell(cio) < box_end) */
 
cio_seek(cio, jp2h_end);
 
/* Part 1, I.5.3.3 : 'must contain at least one' */
return (color->jp2_has_colr == 1);
 
}/* jp2_read_jp2h() */
 
opj_image_t* jp2_decode(opj_jp2_t *jp2, opj_cio_t *cio,
opj_codestream_info_t *cstr_info)
{
opj_common_ptr cinfo;
opj_image_t *image = NULL;
opj_jp2_color_t color;
 
if(!jp2 || !cio)
{
return NULL;
}
memset(&color, 0, sizeof(opj_jp2_color_t));
cinfo = jp2->cinfo;
 
/* JP2 decoding */
if(!jp2_read_struct(jp2, cio, &color))
{
free_color_data(&color);
opj_event_msg(cinfo, EVT_ERROR, "Failed to decode jp2 structure\n");
return NULL;
}
 
/* J2K decoding */
image = j2k_decode(jp2->j2k, cio, cstr_info);
 
if(!image)
{
free_color_data(&color);
opj_event_msg(cinfo, EVT_ERROR, "Failed to decode J2K image\n");
return NULL;
}
 
/* Set Image Color Space */
if (jp2->enumcs == 16)
image->color_space = CLRSPC_SRGB;
else if (jp2->enumcs == 17)
image->color_space = CLRSPC_GRAY;
else if (jp2->enumcs == 18)
image->color_space = CLRSPC_SYCC;
else
image->color_space = CLRSPC_UNKNOWN;
 
if(color.jp2_cdef)
{
jp2_apply_cdef(image, &color);
}
if(color.jp2_pclr)
{
/* Part 1, I.5.3.4: Either both or none : */
if( !color.jp2_pclr->cmap)
jp2_free_pclr(&color);
else
jp2_apply_pclr(&color, image);
}
if(color.icc_profile_buf)
{
image->icc_profile_buf = color.icc_profile_buf;
color.icc_profile_buf = NULL;
image->icc_profile_len = color.icc_profile_len;
}
return image;
 
}/* jp2_decode() */
 
 
void jp2_write_jp2h(opj_jp2_t *jp2, opj_cio_t *cio) {
opj_jp2_box_t box;
 
box.init_pos = cio_tell(cio);
cio_skip(cio, 4);
cio_write(cio, JP2_JP2H, 4); /* JP2H */
 
jp2_write_ihdr(jp2, cio);
 
if (jp2->bpc == 255) {
jp2_write_bpcc(jp2, cio);
}
jp2_write_colr(jp2, cio);
 
box.length = cio_tell(cio) - box.init_pos;
cio_seek(cio, box.init_pos);
cio_write(cio, box.length, 4); /* L */
cio_seek(cio, box.init_pos + box.length);
}
 
static void jp2_write_ftyp(opj_jp2_t *jp2, opj_cio_t *cio) {
unsigned int i;
opj_jp2_box_t box;
 
box.init_pos = cio_tell(cio);
cio_skip(cio, 4);
cio_write(cio, JP2_FTYP, 4); /* FTYP */
 
cio_write(cio, jp2->brand, 4); /* BR */
cio_write(cio, jp2->minversion, 4); /* MinV */
 
for (i = 0; i < jp2->numcl; i++) {
cio_write(cio, jp2->cl[i], 4); /* CL */
}
 
box.length = cio_tell(cio) - box.init_pos;
cio_seek(cio, box.init_pos);
cio_write(cio, box.length, 4); /* L */
cio_seek(cio, box.init_pos + box.length);
}
 
static bool jp2_read_ftyp(opj_jp2_t *jp2, opj_cio_t *cio) {
int i;
opj_jp2_box_t box;
 
opj_common_ptr cinfo = jp2->cinfo;
 
jp2_read_boxhdr(cinfo, cio, &box);
 
if (JP2_FTYP != box.type) {
opj_event_msg(cinfo, EVT_ERROR, "Expected FTYP Marker\n");
return false;
}
 
jp2->brand = cio_read(cio, 4); /* BR */
jp2->minversion = cio_read(cio, 4); /* MinV */
jp2->numcl = (box.length - 16) / 4;
jp2->cl = (unsigned int *) opj_malloc(jp2->numcl * sizeof(unsigned int));
 
for (i = 0; i < (int)jp2->numcl; i++) {
jp2->cl[i] = cio_read(cio, 4); /* CLi */
}
 
if (cio_tell(cio) - box.init_pos != box.length) {
opj_event_msg(cinfo, EVT_ERROR, "Error with FTYP Box\n");
return false;
}
 
return true;
}
 
static int jp2_write_jp2c(opj_jp2_t *jp2, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info) {
unsigned int j2k_codestream_offset, j2k_codestream_length;
opj_jp2_box_t box;
 
opj_j2k_t *j2k = jp2->j2k;
 
box.init_pos = cio_tell(cio);
cio_skip(cio, 4);
cio_write(cio, JP2_JP2C, 4); /* JP2C */
 
/* J2K encoding */
j2k_codestream_offset = cio_tell(cio);
if(!j2k_encode(j2k, cio, image, cstr_info)) {
opj_event_msg(j2k->cinfo, EVT_ERROR, "Failed to encode image\n");
return 0;
}
j2k_codestream_length = cio_tell(cio) - j2k_codestream_offset;
 
jp2->j2k_codestream_offset = j2k_codestream_offset;
jp2->j2k_codestream_length = j2k_codestream_length;
 
box.length = 8 + jp2->j2k_codestream_length;
cio_seek(cio, box.init_pos);
cio_write(cio, box.length, 4); /* L */
cio_seek(cio, box.init_pos + box.length);
 
return box.length;
}
 
static bool jp2_read_jp2c(opj_jp2_t *jp2, opj_cio_t *cio, unsigned int *j2k_codestream_length, unsigned int *j2k_codestream_offset) {
opj_jp2_box_t box;
 
opj_common_ptr cinfo = jp2->cinfo;
 
jp2_read_boxhdr(cinfo, cio, &box);
do {
if(JP2_JP2C != box.type) {
cio_skip(cio, box.length - 8);
jp2_read_boxhdr(cinfo, cio, &box);
}
} while(JP2_JP2C != box.type);
 
*j2k_codestream_offset = cio_tell(cio);
*j2k_codestream_length = box.length - 8;
 
return true;
}
 
static void jp2_write_jp(opj_cio_t *cio) {
opj_jp2_box_t box;
 
box.init_pos = cio_tell(cio);
cio_skip(cio, 4);
cio_write(cio, JP2_JP, 4); /* JP2 signature */
cio_write(cio, 0x0d0a870a, 4);
 
box.length = cio_tell(cio) - box.init_pos;
cio_seek(cio, box.init_pos);
cio_write(cio, box.length, 4); /* L */
cio_seek(cio, box.init_pos + box.length);
}
 
static bool jp2_read_jp(opj_jp2_t *jp2, opj_cio_t *cio) {
opj_jp2_box_t box;
 
opj_common_ptr cinfo = jp2->cinfo;
 
jp2_read_boxhdr(cinfo, cio, &box);
if (JP2_JP != box.type) {
opj_event_msg(cinfo, EVT_ERROR, "Expected JP Marker\n");
return false;
}
if (0x0d0a870a != cio_read(cio, 4)) {
opj_event_msg(cinfo, EVT_ERROR, "Error with JP Marker\n");
return false;
}
if (cio_tell(cio) - box.init_pos != box.length) {
opj_event_msg(cinfo, EVT_ERROR, "Error with JP Box size\n");
return false;
}
 
return true;
}
 
 
static bool jp2_read_struct(opj_jp2_t *jp2, opj_cio_t *cio,
opj_jp2_color_t *color) {
if (!jp2_read_jp(jp2, cio))
return false;
if (!jp2_read_ftyp(jp2, cio))
return false;
if (!jp2_read_jp2h(jp2, cio, color))
return false;
if (!jp2_read_jp2c(jp2, cio, &jp2->j2k_codestream_length, &jp2->j2k_codestream_offset))
return false;
return true;
}
 
/* ----------------------------------------------------------------------- */
/* JP2 decoder interface */
/* ----------------------------------------------------------------------- */
 
opj_jp2_t* jp2_create_decompress(opj_common_ptr cinfo) {
opj_jp2_t *jp2 = (opj_jp2_t*) opj_calloc(1, sizeof(opj_jp2_t));
if(jp2) {
jp2->cinfo = cinfo;
/* create the J2K codec */
jp2->j2k = j2k_create_decompress(cinfo);
if(jp2->j2k == NULL) {
jp2_destroy_decompress(jp2);
return NULL;
}
}
return jp2;
}
 
void jp2_destroy_decompress(opj_jp2_t *jp2) {
if(jp2) {
/* destroy the J2K codec */
j2k_destroy_decompress(jp2->j2k);
 
if(jp2->comps) {
opj_free(jp2->comps);
}
if(jp2->cl) {
opj_free(jp2->cl);
}
opj_free(jp2);
}
}
 
void jp2_setup_decoder(opj_jp2_t *jp2, opj_dparameters_t *parameters) {
/* setup the J2K codec */
j2k_setup_decoder(jp2->j2k, parameters);
/* further JP2 initializations go here */
}
 
/* ----------------------------------------------------------------------- */
/* JP2 encoder interface */
/* ----------------------------------------------------------------------- */
 
opj_jp2_t* jp2_create_compress(opj_common_ptr cinfo) {
opj_jp2_t *jp2 = (opj_jp2_t*)opj_malloc(sizeof(opj_jp2_t));
if(jp2) {
jp2->cinfo = cinfo;
/* create the J2K codec */
jp2->j2k = j2k_create_compress(cinfo);
if(jp2->j2k == NULL) {
jp2_destroy_compress(jp2);
return NULL;
}
}
return jp2;
}
 
void jp2_destroy_compress(opj_jp2_t *jp2) {
if(jp2) {
/* destroy the J2K codec */
j2k_destroy_compress(jp2->j2k);
 
if(jp2->comps) {
opj_free(jp2->comps);
}
if(jp2->cl) {
opj_free(jp2->cl);
}
opj_free(jp2);
}
}
 
void jp2_setup_encoder(opj_jp2_t *jp2, opj_cparameters_t *parameters, opj_image_t *image) {
int i;
int depth_0, sign;
 
if(!jp2 || !parameters || !image)
return;
 
/* setup the J2K codec */
/* ------------------- */
 
/* Check if number of components respects standard */
if (image->numcomps < 1 || image->numcomps > 16384) {
opj_event_msg(jp2->cinfo, EVT_ERROR, "Invalid number of components specified while setting up JP2 encoder\n");
return;
}
 
j2k_setup_encoder(jp2->j2k, parameters, image);
 
/* setup the JP2 codec */
/* ------------------- */
/* Profile box */
 
jp2->brand = JP2_JP2; /* BR */
jp2->minversion = 0; /* MinV */
jp2->numcl = 1;
jp2->cl = (unsigned int*) opj_malloc(jp2->numcl * sizeof(unsigned int));
jp2->cl[0] = JP2_JP2; /* CL0 : JP2 */
 
/* Image Header box */
 
jp2->numcomps = image->numcomps; /* NC */
jp2->comps = (opj_jp2_comps_t*) opj_malloc(jp2->numcomps * sizeof(opj_jp2_comps_t));
jp2->h = image->y1 - image->y0; /* HEIGHT */
jp2->w = image->x1 - image->x0; /* WIDTH */
/* BPC */
depth_0 = image->comps[0].prec - 1;
sign = image->comps[0].sgnd;
jp2->bpc = depth_0 + (sign << 7);
for (i = 1; i < image->numcomps; i++) {
int depth = image->comps[i].prec - 1;
sign = image->comps[i].sgnd;
if (depth_0 != depth)
jp2->bpc = 255;
}
jp2->C = 7; /* C : Always 7 */
jp2->UnkC = 0; /* UnkC, colorspace specified in colr box */
jp2->IPR = 0; /* IPR, no intellectual property */
/* BitsPerComponent box */
 
for (i = 0; i < image->numcomps; i++) {
jp2->comps[i].bpcc = image->comps[i].prec - 1 + (image->comps[i].sgnd << 7);
}
 
/* Colour Specification box */
 
if ((image->numcomps == 1 || image->numcomps == 3) && (jp2->bpc != 255)) {
jp2->meth = 1; /* METH: Enumerated colourspace */
} else {
jp2->meth = 2; /* METH: Restricted ICC profile */
}
if (jp2->meth == 1) {
if (image->color_space == 1)
jp2->enumcs = 16; /* sRGB as defined by IEC 61966–2–1 */
else if (image->color_space == 2)
jp2->enumcs = 17; /* greyscale */
else if (image->color_space == 3)
jp2->enumcs = 18; /* YUV */
} else {
jp2->enumcs = 0; /* PROFILE (??) */
}
jp2->precedence = 0; /* PRECEDENCE */
jp2->approx = 0; /* APPROX */
 
}
 
bool jp2_encode(opj_jp2_t *jp2, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info) {
 
/* JP2 encoding */
 
/* JPEG 2000 Signature box */
jp2_write_jp(cio);
/* File Type box */
jp2_write_ftyp(jp2, cio);
/* JP2 Header box */
jp2_write_jp2h(jp2, cio);
 
/* J2K encoding */
 
if(!jp2_write_jp2c(jp2, cio, image, cstr_info)) {
opj_event_msg(jp2->cinfo, EVT_ERROR, "Failed to encode image\n");
return false;
}
 
return true;
}
 
 
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libopenjpeg/jp2.h
0,0 → 1,231
/*
* Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2007, Professor Benoit Macq
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __JP2_H
#define __JP2_H
/**
@file jp2.h
@brief The JPEG-2000 file format Reader/Writer (JP2)
 
*/
 
/** @defgroup JP2 JP2 - JPEG-2000 file format reader/writer */
/*@{*/
 
#define JPIP_JPIP 0x6a706970
 
#define JP2_JP 0x6a502020 /**< JPEG 2000 signature box */
#define JP2_FTYP 0x66747970 /**< File type box */
#define JP2_JP2H 0x6a703268 /**< JP2 header box */
#define JP2_IHDR 0x69686472 /**< Image header box */
#define JP2_COLR 0x636f6c72 /**< Colour specification box */
#define JP2_JP2C 0x6a703263 /**< Contiguous codestream box */
#define JP2_URL 0x75726c20 /**< URL box */
#define JP2_DTBL 0x6474626c /**< Data Reference box */
#define JP2_BPCC 0x62706363 /**< Bits per component box */
#define JP2_JP2 0x6a703220 /**< File type fields */
#define JP2_PCLR 0x70636c72 /**< Palette box */
#define JP2_CMAP 0x636d6170 /**< Component Mapping box */
#define JP2_CDEF 0x63646566 /**< Channel Definition box */
 
/* ----------------------------------------------------------------------- */
/**
Channel description: channel index, type, assocation
*/
typedef struct opj_jp2_cdef_info
{
unsigned short cn, typ, asoc;
} opj_jp2_cdef_info_t;
 
/**
Channel descriptions and number of descriptions
*/
typedef struct opj_jp2_cdef
{
opj_jp2_cdef_info_t *info;
unsigned short n;
} opj_jp2_cdef_t;
 
/**
Component mappings: channel index, mapping type, palette index
*/
typedef struct opj_jp2_cmap_comp
{
unsigned short cmp;
unsigned char mtyp, pcol;
} opj_jp2_cmap_comp_t;
 
/**
Palette data: table entries, palette columns
*/
typedef struct opj_jp2_pclr
{
unsigned int *entries;
unsigned char *channel_sign;
unsigned char *channel_size;
opj_jp2_cmap_comp_t *cmap;
unsigned short nr_entries, nr_channels;
} opj_jp2_pclr_t;
 
/**
Collector for ICC profile, palette, component mapping, channel description
*/
typedef struct opj_jp2_color
{
unsigned char *icc_profile_buf;
int icc_profile_len;
 
opj_jp2_cdef_t *jp2_cdef;
opj_jp2_pclr_t *jp2_pclr;
unsigned char jp2_has_colr;
} opj_jp2_color_t;
 
/**
JP2 component
*/
typedef struct opj_jp2_comps {
int depth;
int sgnd;
int bpcc;
} opj_jp2_comps_t;
 
/**
JPEG-2000 file format reader/writer
*/
typedef struct opj_jp2 {
/** codec context */
opj_common_ptr cinfo;
/** handle to the J2K codec */
opj_j2k_t *j2k;
unsigned int w;
unsigned int h;
unsigned int numcomps;
unsigned int bpc;
unsigned int C;
unsigned int UnkC;
unsigned int IPR;
unsigned int meth;
unsigned int approx;
unsigned int enumcs;
unsigned int precedence;
unsigned int brand;
unsigned int minversion;
unsigned int numcl;
unsigned int *cl;
opj_jp2_comps_t *comps;
unsigned int j2k_codestream_offset;
unsigned int j2k_codestream_length;
} opj_jp2_t;
 
/**
JP2 Box
*/
typedef struct opj_jp2_box {
int length;
int type;
int init_pos;
} opj_jp2_box_t;
 
/** @name Exported functions */
/*@{*/
/* ----------------------------------------------------------------------- */
/**
Write the JP2H box - JP2 Header box (used in MJ2)
@param jp2 JP2 handle
@param cio Output buffer stream
*/
void jp2_write_jp2h(opj_jp2_t *jp2, opj_cio_t *cio);
/**
Read the JP2H box - JP2 Header box (used in MJ2)
@param jp2 JP2 handle
@param cio Input buffer stream
@param ext Collector for profile, cdef and pclr data
@return Returns true if successful, returns false otherwise
*/
bool jp2_read_jp2h(opj_jp2_t *jp2, opj_cio_t *cio, opj_jp2_color_t *color);
/**
Creates a JP2 decompression structure
@param cinfo Codec context info
@return Returns a handle to a JP2 decompressor if successful, returns NULL otherwise
*/
opj_jp2_t* jp2_create_decompress(opj_common_ptr cinfo);
/**
Destroy a JP2 decompressor handle
@param jp2 JP2 decompressor handle to destroy
*/
void jp2_destroy_decompress(opj_jp2_t *jp2);
/**
Setup the decoder decoding parameters using user parameters.
Decoding parameters are returned in jp2->j2k->cp.
@param jp2 JP2 decompressor handle
@param parameters decompression parameters
*/
void jp2_setup_decoder(opj_jp2_t *jp2, opj_dparameters_t *parameters);
/**
Decode an image from a JPEG-2000 file stream
@param jp2 JP2 decompressor handle
@param cio Input buffer stream
@param cstr_info Codestream information structure if required, NULL otherwise
@return Returns a decoded image if successful, returns NULL otherwise
*/
opj_image_t* jp2_decode(opj_jp2_t *jp2, opj_cio_t *cio, opj_codestream_info_t *cstr_info);
/**
Creates a JP2 compression structure
@param cinfo Codec context info
@return Returns a handle to a JP2 compressor if successful, returns NULL otherwise
*/
opj_jp2_t* jp2_create_compress(opj_common_ptr cinfo);
/**
Destroy a JP2 compressor handle
@param jp2 JP2 compressor handle to destroy
*/
void jp2_destroy_compress(opj_jp2_t *jp2);
/**
Setup the encoder parameters using the current image and using user parameters.
Coding parameters are returned in jp2->j2k->cp.
@param jp2 JP2 compressor handle
@param parameters compression parameters
@param image input filled image
*/
void jp2_setup_encoder(opj_jp2_t *jp2, opj_cparameters_t *parameters, opj_image_t *image);
/**
Encode an image into a JPEG-2000 file stream
@param jp2 JP2 compressor handle
@param cio Output buffer stream
@param image Image to encode
@param cstr_info Codestream information structure if required, NULL otherwise
@return Returns true if successful, returns false otherwise
*/
bool jp2_encode(opj_jp2_t *jp2, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info);
/* ----------------------------------------------------------------------- */
/*@}*/
 
/*@}*/
 
#endif /* __JP2_H */
 
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libopenjpeg/jpt.c
0,0 → 1,155
/*
* Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2007, Professor Benoit Macq
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
 
#include "opj_includes.h"
 
/*
* Read the information contains in VBAS [JPP/JPT stream message header]
* Store information (7 bits) in value
*
*/
unsigned int jpt_read_VBAS_info(opj_cio_t *cio, unsigned int value) {
unsigned char elmt;
 
elmt = cio_read(cio, 1);
while ((elmt >> 7) == 1) {
value = (value << 7);
value |= (elmt & 0x7f);
elmt = cio_read(cio, 1);
}
value = (value << 7);
value |= (elmt & 0x7f);
 
return value;
}
 
/*
* Initialize the value of the message header structure
*
*/
void jpt_init_msg_header(opj_jpt_msg_header_t * header) {
header->Id = 0; /* In-class Identifier */
header->last_byte = 0; /* Last byte information */
header->Class_Id = 0; /* Class Identifier */
header->CSn_Id = 0; /* CSn : index identifier */
header->Msg_offset = 0; /* Message offset */
header->Msg_length = 0; /* Message length */
header->Layer_nb = 0; /* Auxiliary for JPP case */
}
 
/*
* Re-initialize the value of the message header structure
*
* Only parameters always present in message header
*
*/
void jpt_reinit_msg_header(opj_jpt_msg_header_t * header) {
header->Id = 0; /* In-class Identifier */
header->last_byte = 0; /* Last byte information */
header->Msg_offset = 0; /* Message offset */
header->Msg_length = 0; /* Message length */
}
 
/*
* Read the message header for a JPP/JPT - stream
*
*/
void jpt_read_msg_header(opj_common_ptr cinfo, opj_cio_t *cio, opj_jpt_msg_header_t *header) {
unsigned char elmt, Class = 0, CSn = 0;
jpt_reinit_msg_header(header);
 
/* ------------- */
/* VBAS : Bin-ID */
/* ------------- */
elmt = cio_read(cio, 1);
 
/* See for Class and CSn */
switch ((elmt >> 5) & 0x03) {
case 0:
opj_event_msg(cinfo, EVT_ERROR, "Forbidden value encounter in message header !!\n");
break;
case 1:
Class = 0;
CSn = 0;
break;
case 2:
Class = 1;
CSn = 0;
break;
case 3:
Class = 1;
CSn = 1;
break;
default:
break;
}
 
/* see information on bits 'c' [p 10 : A.2.1 general, ISO/IEC FCD 15444-9] */
if (((elmt >> 4) & 0x01) == 1)
header->last_byte = 1;
 
/* In-class identifier */
header->Id |= (elmt & 0x0f);
if ((elmt >> 7) == 1)
header->Id = jpt_read_VBAS_info(cio, header->Id);
 
/* ------------ */
/* VBAS : Class */
/* ------------ */
if (Class == 1) {
header->Class_Id = 0;
header->Class_Id = jpt_read_VBAS_info(cio, header->Class_Id);
}
 
/* ---------- */
/* VBAS : CSn */
/* ---------- */
if (CSn == 1) {
header->CSn_Id = 0;
header->CSn_Id = jpt_read_VBAS_info(cio, header->CSn_Id);
}
 
/* ----------------- */
/* VBAS : Msg_offset */
/* ----------------- */
header->Msg_offset = jpt_read_VBAS_info(cio, header->Msg_offset);
 
/* ----------------- */
/* VBAS : Msg_length */
/* ----------------- */
header->Msg_length = jpt_read_VBAS_info(cio, header->Msg_length);
 
/* ---------- */
/* VBAS : Aux */
/* ---------- */
if ((header->Class_Id & 0x01) == 1) {
header->Layer_nb = 0;
header->Layer_nb = jpt_read_VBAS_info(cio, header->Layer_nb);
}
}
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libopenjpeg/jpt.h
0,0 → 1,75
/*
* Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2007, Professor Benoit Macq
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
 
#ifndef __JPT_H
#define __JPT_H
/**
@file jpt.h
@brief JPT-stream reader (JPEG 2000, JPIP)
 
JPT-stream functions are implemented in J2K.C.
*/
 
/**
Message Header JPT stream structure
*/
typedef struct opj_jpt_msg_header {
/** In-class Identifier */
unsigned int Id;
/** Last byte information */
unsigned int last_byte;
/** Class Identifier */
unsigned int Class_Id;
/** CSn : index identifier */
unsigned int CSn_Id;
/** Message offset */
unsigned int Msg_offset;
/** Message length */
unsigned int Msg_length;
/** Auxiliary for JPP case */
unsigned int Layer_nb;
} opj_jpt_msg_header_t;
 
/* ----------------------------------------------------------------------- */
 
/**
Initialize the value of the message header structure
@param header Message header structure
*/
void jpt_init_msg_header(opj_jpt_msg_header_t * header);
 
/**
Read the message header for a JPP/JPT - stream
@param cinfo Codec context info
@param cio CIO handle
@param header Message header structure
*/
void jpt_read_msg_header(opj_common_ptr cinfo, opj_cio_t *cio, opj_jpt_msg_header_t *header);
 
#endif
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libopenjpeg/lrintf.c
0,0 → 1,6
#include <math.h>
/*
long long int lrintf(float x) {
return floor(x);
}
*/
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libopenjpeg/mct.c
0,0 → 1,190
/*
* Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2007, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
 
#ifdef __SSE__
#include <xmmintrin.h>
#endif
 
#include "opj_includes.h"
 
/* <summary> */
/* This table contains the norms of the basis function of the reversible MCT. */
/* </summary> */
static const double mct_norms[3] = { 1.732, .8292, .8292 };
 
/* <summary> */
/* This table contains the norms of the basis function of the irreversible MCT. */
/* </summary> */
static const double mct_norms_real[3] = { 1.732, 1.805, 1.573 };
 
/* <summary> */
/* Foward reversible MCT. */
/* </summary> */
void mct_encode(
int* restrict c0,
int* restrict c1,
int* restrict c2,
int n)
{
int i;
for(i = 0; i < n; ++i) {
int r = c0[i];
int g = c1[i];
int b = c2[i];
int y = (r + (g * 2) + b) >> 2;
int u = b - g;
int v = r - g;
c0[i] = y;
c1[i] = u;
c2[i] = v;
}
}
 
/* <summary> */
/* Inverse reversible MCT. */
/* </summary> */
void mct_decode(
int* restrict c0,
int* restrict c1,
int* restrict c2,
int n)
{
int i;
for (i = 0; i < n; ++i) {
int y = c0[i];
int u = c1[i];
int v = c2[i];
int g = y - ((u + v) >> 2);
int r = v + g;
int b = u + g;
c0[i] = r;
c1[i] = g;
c2[i] = b;
}
}
 
/* <summary> */
/* Get norm of basis function of reversible MCT. */
/* </summary> */
double mct_getnorm(int compno) {
return mct_norms[compno];
}
 
/* <summary> */
/* Foward irreversible MCT. */
/* </summary> */
void mct_encode_real(
int* restrict c0,
int* restrict c1,
int* restrict c2,
int n)
{
int i;
for(i = 0; i < n; ++i) {
int r = c0[i];
int g = c1[i];
int b = c2[i];
int y = fix_mul(r, 2449) + fix_mul(g, 4809) + fix_mul(b, 934);
int u = -fix_mul(r, 1382) - fix_mul(g, 2714) + fix_mul(b, 4096);
int v = fix_mul(r, 4096) - fix_mul(g, 3430) - fix_mul(b, 666);
c0[i] = y;
c1[i] = u;
c2[i] = v;
}
}
 
/* <summary> */
/* Inverse irreversible MCT. */
/* </summary> */
void mct_decode_real(
float* restrict c0,
float* restrict c1,
float* restrict c2,
int n)
{
int i;
#ifdef __SSE__
__m128 vrv, vgu, vgv, vbu;
vrv = _mm_set1_ps(1.402f);
vgu = _mm_set1_ps(0.34413f);
vgv = _mm_set1_ps(0.71414f);
vbu = _mm_set1_ps(1.772f);
for (i = 0; i < (n >> 3); ++i) {
__m128 vy, vu, vv;
__m128 vr, vg, vb;
 
vy = _mm_load_ps(c0);
vu = _mm_load_ps(c1);
vv = _mm_load_ps(c2);
vr = _mm_add_ps(vy, _mm_mul_ps(vv, vrv));
vg = _mm_sub_ps(_mm_sub_ps(vy, _mm_mul_ps(vu, vgu)), _mm_mul_ps(vv, vgv));
vb = _mm_add_ps(vy, _mm_mul_ps(vu, vbu));
_mm_store_ps(c0, vr);
_mm_store_ps(c1, vg);
_mm_store_ps(c2, vb);
c0 += 4;
c1 += 4;
c2 += 4;
 
vy = _mm_load_ps(c0);
vu = _mm_load_ps(c1);
vv = _mm_load_ps(c2);
vr = _mm_add_ps(vy, _mm_mul_ps(vv, vrv));
vg = _mm_sub_ps(_mm_sub_ps(vy, _mm_mul_ps(vu, vgu)), _mm_mul_ps(vv, vgv));
vb = _mm_add_ps(vy, _mm_mul_ps(vu, vbu));
_mm_store_ps(c0, vr);
_mm_store_ps(c1, vg);
_mm_store_ps(c2, vb);
c0 += 4;
c1 += 4;
c2 += 4;
}
n &= 7;
#endif
for(i = 0; i < n; ++i) {
float y = c0[i];
float u = c1[i];
float v = c2[i];
float r = y + (v * 1.402f);
float g = y - (u * 0.34413f) - (v * (0.71414f));
float b = y + (u * 1.772f);
c0[i] = r;
c1[i] = g;
c2[i] = b;
}
}
 
/* <summary> */
/* Get norm of basis function of irreversible MCT. */
/* </summary> */
double mct_getnorm_real(int compno) {
return mct_norms_real[compno];
}
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libopenjpeg/mct.h
0,0 → 1,98
/*
* Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2007, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
 
#ifndef __MCT_H
#define __MCT_H
/**
@file mct.h
@brief Implementation of a multi-component transforms (MCT)
 
The functions in MCT.C have for goal to realize reversible and irreversible multicomponent
transform. The functions in MCT.C are used by some function in TCD.C.
*/
 
/** @defgroup MCT MCT - Implementation of a multi-component transform */
/*@{*/
 
/** @name Exported functions */
/*@{*/
/* ----------------------------------------------------------------------- */
/**
Apply a reversible multi-component transform to an image
@param c0 Samples for red component
@param c1 Samples for green component
@param c2 Samples blue component
@param n Number of samples for each component
*/
void mct_encode(int *c0, int *c1, int *c2, int n);
/**
Apply a reversible multi-component inverse transform to an image
@param c0 Samples for luminance component
@param c1 Samples for red chrominance component
@param c2 Samples for blue chrominance component
@param n Number of samples for each component
*/
void mct_decode(int *c0, int *c1, int *c2, int n);
/**
Get norm of the basis function used for the reversible multi-component transform
@param compno Number of the component (0->Y, 1->U, 2->V)
@return
*/
double mct_getnorm(int compno);
 
/**
Apply an irreversible multi-component transform to an image
@param c0 Samples for red component
@param c1 Samples for green component
@param c2 Samples blue component
@param n Number of samples for each component
*/
void mct_encode_real(int *c0, int *c1, int *c2, int n);
/**
Apply an irreversible multi-component inverse transform to an image
@param c0 Samples for luminance component
@param c1 Samples for red chrominance component
@param c2 Samples for blue chrominance component
@param n Number of samples for each component
*/
void mct_decode_real(float* c0, float* c1, float* c2, int n);
/**
Get norm of the basis function used for the irreversible multi-component transform
@param compno Number of the component (0->Y, 1->U, 2->V)
@return
*/
double mct_getnorm_real(int compno);
/* ----------------------------------------------------------------------- */
/*@}*/
 
/*@}*/
 
#endif /* __MCT_H */
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libopenjpeg/mqc.c
0,0 → 1,593
/*
* Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2007, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
 
#include "opj_includes.h"
 
/** @defgroup MQC MQC - Implementation of an MQ-Coder */
/*@{*/
 
/** @name Local static functions */
/*@{*/
 
/**
Output a byte, doing bit-stuffing if necessary.
After a 0xff byte, the next byte must be smaller than 0x90.
@param mqc MQC handle
*/
static void mqc_byteout(opj_mqc_t *mqc);
/**
Renormalize mqc->a and mqc->c while encoding, so that mqc->a stays between 0x8000 and 0x10000
@param mqc MQC handle
*/
static void mqc_renorme(opj_mqc_t *mqc);
/**
Encode the most probable symbol
@param mqc MQC handle
*/
static void mqc_codemps(opj_mqc_t *mqc);
/**
Encode the most least symbol
@param mqc MQC handle
*/
static void mqc_codelps(opj_mqc_t *mqc);
/**
Fill mqc->c with 1's for flushing
@param mqc MQC handle
*/
static void mqc_setbits(opj_mqc_t *mqc);
/**
FIXME: documentation ???
@param mqc MQC handle
@return
*/
static INLINE int mqc_mpsexchange(opj_mqc_t *const mqc);
/**
FIXME: documentation ???
@param mqc MQC handle
@return
*/
static INLINE int mqc_lpsexchange(opj_mqc_t *const mqc);
/**
Input a byte
@param mqc MQC handle
*/
static INLINE void mqc_bytein(opj_mqc_t *const mqc);
/**
Renormalize mqc->a and mqc->c while decoding
@param mqc MQC handle
*/
static INLINE void mqc_renormd(opj_mqc_t *const mqc);
/*@}*/
 
/*@}*/
 
/* <summary> */
/* This array defines all the possible states for a context. */
/* </summary> */
static opj_mqc_state_t mqc_states[47 * 2] = {
{0x5601, 0, &mqc_states[2], &mqc_states[3]},
{0x5601, 1, &mqc_states[3], &mqc_states[2]},
{0x3401, 0, &mqc_states[4], &mqc_states[12]},
{0x3401, 1, &mqc_states[5], &mqc_states[13]},
{0x1801, 0, &mqc_states[6], &mqc_states[18]},
{0x1801, 1, &mqc_states[7], &mqc_states[19]},
{0x0ac1, 0, &mqc_states[8], &mqc_states[24]},
{0x0ac1, 1, &mqc_states[9], &mqc_states[25]},
{0x0521, 0, &mqc_states[10], &mqc_states[58]},
{0x0521, 1, &mqc_states[11], &mqc_states[59]},
{0x0221, 0, &mqc_states[76], &mqc_states[66]},
{0x0221, 1, &mqc_states[77], &mqc_states[67]},
{0x5601, 0, &mqc_states[14], &mqc_states[13]},
{0x5601, 1, &mqc_states[15], &mqc_states[12]},
{0x5401, 0, &mqc_states[16], &mqc_states[28]},
{0x5401, 1, &mqc_states[17], &mqc_states[29]},
{0x4801, 0, &mqc_states[18], &mqc_states[28]},
{0x4801, 1, &mqc_states[19], &mqc_states[29]},
{0x3801, 0, &mqc_states[20], &mqc_states[28]},
{0x3801, 1, &mqc_states[21], &mqc_states[29]},
{0x3001, 0, &mqc_states[22], &mqc_states[34]},
{0x3001, 1, &mqc_states[23], &mqc_states[35]},
{0x2401, 0, &mqc_states[24], &mqc_states[36]},
{0x2401, 1, &mqc_states[25], &mqc_states[37]},
{0x1c01, 0, &mqc_states[26], &mqc_states[40]},
{0x1c01, 1, &mqc_states[27], &mqc_states[41]},
{0x1601, 0, &mqc_states[58], &mqc_states[42]},
{0x1601, 1, &mqc_states[59], &mqc_states[43]},
{0x5601, 0, &mqc_states[30], &mqc_states[29]},
{0x5601, 1, &mqc_states[31], &mqc_states[28]},
{0x5401, 0, &mqc_states[32], &mqc_states[28]},
{0x5401, 1, &mqc_states[33], &mqc_states[29]},
{0x5101, 0, &mqc_states[34], &mqc_states[30]},
{0x5101, 1, &mqc_states[35], &mqc_states[31]},
{0x4801, 0, &mqc_states[36], &mqc_states[32]},
{0x4801, 1, &mqc_states[37], &mqc_states[33]},
{0x3801, 0, &mqc_states[38], &mqc_states[34]},
{0x3801, 1, &mqc_states[39], &mqc_states[35]},
{0x3401, 0, &mqc_states[40], &mqc_states[36]},
{0x3401, 1, &mqc_states[41], &mqc_states[37]},
{0x3001, 0, &mqc_states[42], &mqc_states[38]},
{0x3001, 1, &mqc_states[43], &mqc_states[39]},
{0x2801, 0, &mqc_states[44], &mqc_states[38]},
{0x2801, 1, &mqc_states[45], &mqc_states[39]},
{0x2401, 0, &mqc_states[46], &mqc_states[40]},
{0x2401, 1, &mqc_states[47], &mqc_states[41]},
{0x2201, 0, &mqc_states[48], &mqc_states[42]},
{0x2201, 1, &mqc_states[49], &mqc_states[43]},
{0x1c01, 0, &mqc_states[50], &mqc_states[44]},
{0x1c01, 1, &mqc_states[51], &mqc_states[45]},
{0x1801, 0, &mqc_states[52], &mqc_states[46]},
{0x1801, 1, &mqc_states[53], &mqc_states[47]},
{0x1601, 0, &mqc_states[54], &mqc_states[48]},
{0x1601, 1, &mqc_states[55], &mqc_states[49]},
{0x1401, 0, &mqc_states[56], &mqc_states[50]},
{0x1401, 1, &mqc_states[57], &mqc_states[51]},
{0x1201, 0, &mqc_states[58], &mqc_states[52]},
{0x1201, 1, &mqc_states[59], &mqc_states[53]},
{0x1101, 0, &mqc_states[60], &mqc_states[54]},
{0x1101, 1, &mqc_states[61], &mqc_states[55]},
{0x0ac1, 0, &mqc_states[62], &mqc_states[56]},
{0x0ac1, 1, &mqc_states[63], &mqc_states[57]},
{0x09c1, 0, &mqc_states[64], &mqc_states[58]},
{0x09c1, 1, &mqc_states[65], &mqc_states[59]},
{0x08a1, 0, &mqc_states[66], &mqc_states[60]},
{0x08a1, 1, &mqc_states[67], &mqc_states[61]},
{0x0521, 0, &mqc_states[68], &mqc_states[62]},
{0x0521, 1, &mqc_states[69], &mqc_states[63]},
{0x0441, 0, &mqc_states[70], &mqc_states[64]},
{0x0441, 1, &mqc_states[71], &mqc_states[65]},
{0x02a1, 0, &mqc_states[72], &mqc_states[66]},
{0x02a1, 1, &mqc_states[73], &mqc_states[67]},
{0x0221, 0, &mqc_states[74], &mqc_states[68]},
{0x0221, 1, &mqc_states[75], &mqc_states[69]},
{0x0141, 0, &mqc_states[76], &mqc_states[70]},
{0x0141, 1, &mqc_states[77], &mqc_states[71]},
{0x0111, 0, &mqc_states[78], &mqc_states[72]},
{0x0111, 1, &mqc_states[79], &mqc_states[73]},
{0x0085, 0, &mqc_states[80], &mqc_states[74]},
{0x0085, 1, &mqc_states[81], &mqc_states[75]},
{0x0049, 0, &mqc_states[82], &mqc_states[76]},
{0x0049, 1, &mqc_states[83], &mqc_states[77]},
{0x0025, 0, &mqc_states[84], &mqc_states[78]},
{0x0025, 1, &mqc_states[85], &mqc_states[79]},
{0x0015, 0, &mqc_states[86], &mqc_states[80]},
{0x0015, 1, &mqc_states[87], &mqc_states[81]},
{0x0009, 0, &mqc_states[88], &mqc_states[82]},
{0x0009, 1, &mqc_states[89], &mqc_states[83]},
{0x0005, 0, &mqc_states[90], &mqc_states[84]},
{0x0005, 1, &mqc_states[91], &mqc_states[85]},
{0x0001, 0, &mqc_states[90], &mqc_states[86]},
{0x0001, 1, &mqc_states[91], &mqc_states[87]},
{0x5601, 0, &mqc_states[92], &mqc_states[92]},
{0x5601, 1, &mqc_states[93], &mqc_states[93]},
};
 
/*
==========================================================
local functions
==========================================================
*/
 
static void mqc_byteout(opj_mqc_t *mqc) {
if (*mqc->bp == 0xff) {
mqc->bp++;
*mqc->bp = mqc->c >> 20;
mqc->c &= 0xfffff;
mqc->ct = 7;
} else {
if ((mqc->c & 0x8000000) == 0) { /* ((mqc->c&0x8000000)==0) CHANGE */
mqc->bp++;
*mqc->bp = mqc->c >> 19;
mqc->c &= 0x7ffff;
mqc->ct = 8;
} else {
(*mqc->bp)++;
if (*mqc->bp == 0xff) {
mqc->c &= 0x7ffffff;
mqc->bp++;
*mqc->bp = mqc->c >> 20;
mqc->c &= 0xfffff;
mqc->ct = 7;
} else {
mqc->bp++;
*mqc->bp = mqc->c >> 19;
mqc->c &= 0x7ffff;
mqc->ct = 8;
}
}
}
}
 
static void mqc_renorme(opj_mqc_t *mqc) {
do {
mqc->a <<= 1;
mqc->c <<= 1;
mqc->ct--;
if (mqc->ct == 0) {
mqc_byteout(mqc);
}
} while ((mqc->a & 0x8000) == 0);
}
 
static void mqc_codemps(opj_mqc_t *mqc) {
mqc->a -= (*mqc->curctx)->qeval;
if ((mqc->a & 0x8000) == 0) {
if (mqc->a < (*mqc->curctx)->qeval) {
mqc->a = (*mqc->curctx)->qeval;
} else {
mqc->c += (*mqc->curctx)->qeval;
}
*mqc->curctx = (*mqc->curctx)->nmps;
mqc_renorme(mqc);
} else {
mqc->c += (*mqc->curctx)->qeval;
}
}
 
static void mqc_codelps(opj_mqc_t *mqc) {
mqc->a -= (*mqc->curctx)->qeval;
if (mqc->a < (*mqc->curctx)->qeval) {
mqc->c += (*mqc->curctx)->qeval;
} else {
mqc->a = (*mqc->curctx)->qeval;
}
*mqc->curctx = (*mqc->curctx)->nlps;
mqc_renorme(mqc);
}
 
static void mqc_setbits(opj_mqc_t *mqc) {
unsigned int tempc = mqc->c + mqc->a;
mqc->c |= 0xffff;
if (mqc->c >= tempc) {
mqc->c -= 0x8000;
}
}
 
static INLINE int mqc_mpsexchange(opj_mqc_t *const mqc) {
int d;
if (mqc->a < (*mqc->curctx)->qeval) {
d = 1 - (*mqc->curctx)->mps;
*mqc->curctx = (*mqc->curctx)->nlps;
} else {
d = (*mqc->curctx)->mps;
*mqc->curctx = (*mqc->curctx)->nmps;
}
return d;
}
 
static INLINE int mqc_lpsexchange(opj_mqc_t *const mqc) {
int d;
if (mqc->a < (*mqc->curctx)->qeval) {
mqc->a = (*mqc->curctx)->qeval;
d = (*mqc->curctx)->mps;
*mqc->curctx = (*mqc->curctx)->nmps;
} else {
mqc->a = (*mqc->curctx)->qeval;
d = 1 - (*mqc->curctx)->mps;
*mqc->curctx = (*mqc->curctx)->nlps;
}
return d;
}
 
#ifdef MQC_PERF_OPT
static INLINE void mqc_bytein(opj_mqc_t *const mqc) {
unsigned int i = *((unsigned int *) mqc->bp);
mqc->c += i & 0xffff00;
mqc->ct = i & 0x0f;
mqc->bp += (i >> 2) & 0x04;
}
#else
static void mqc_bytein(opj_mqc_t *const mqc) {
if (mqc->bp != mqc->end) {
unsigned int c;
if (mqc->bp + 1 != mqc->end) {
c = *(mqc->bp + 1);
} else {
c = 0xff;
}
if (*mqc->bp == 0xff) {
if (c > 0x8f) {
mqc->c += 0xff00;
mqc->ct = 8;
} else {
mqc->bp++;
mqc->c += c << 9;
mqc->ct = 7;
}
} else {
mqc->bp++;
mqc->c += c << 8;
mqc->ct = 8;
}
} else {
mqc->c += 0xff00;
mqc->ct = 8;
}
}
#endif
 
static INLINE void mqc_renormd(opj_mqc_t *const mqc) {
do {
if (mqc->ct == 0) {
mqc_bytein(mqc);
}
mqc->a <<= 1;
mqc->c <<= 1;
mqc->ct--;
} while (mqc->a < 0x8000);
}
 
/*
==========================================================
MQ-Coder interface
==========================================================
*/
 
opj_mqc_t* mqc_create(void) {
opj_mqc_t *mqc = (opj_mqc_t*)opj_malloc(sizeof(opj_mqc_t));
#ifdef MQC_PERF_OPT
mqc->buffer = NULL;
#endif
return mqc;
}
 
void mqc_destroy(opj_mqc_t *mqc) {
if(mqc) {
#ifdef MQC_PERF_OPT
if (mqc->buffer) {
opj_free(mqc->buffer);
}
#endif
opj_free(mqc);
}
}
 
int mqc_numbytes(opj_mqc_t *mqc) {
return mqc->bp - mqc->start;
}
 
void mqc_init_enc(opj_mqc_t *mqc, unsigned char *bp) {
mqc_setcurctx(mqc, 0);
mqc->a = 0x8000;
mqc->c = 0;
mqc->bp = bp - 1;
mqc->ct = 12;
if (*mqc->bp == 0xff) {
mqc->ct = 13;
}
mqc->start = bp;
}
 
void mqc_encode(opj_mqc_t *mqc, int d) {
if ((*mqc->curctx)->mps == d) {
mqc_codemps(mqc);
} else {
mqc_codelps(mqc);
}
}
 
void mqc_flush(opj_mqc_t *mqc) {
mqc_setbits(mqc);
mqc->c <<= mqc->ct;
mqc_byteout(mqc);
mqc->c <<= mqc->ct;
mqc_byteout(mqc);
if (*mqc->bp != 0xff) {
mqc->bp++;
}
}
 
void mqc_bypass_init_enc(opj_mqc_t *mqc) {
mqc->c = 0;
mqc->ct = 8;
/*if (*mqc->bp == 0xff) {
mqc->ct = 7;
} */
}
 
void mqc_bypass_enc(opj_mqc_t *mqc, int d) {
mqc->ct--;
mqc->c = mqc->c + (d << mqc->ct);
if (mqc->ct == 0) {
mqc->bp++;
*mqc->bp = mqc->c;
mqc->ct = 8;
if (*mqc->bp == 0xff) {
mqc->ct = 7;
}
mqc->c = 0;
}
}
 
int mqc_bypass_flush_enc(opj_mqc_t *mqc) {
unsigned char bit_padding;
bit_padding = 0;
if (mqc->ct != 0) {
while (mqc->ct > 0) {
mqc->ct--;
mqc->c += bit_padding << mqc->ct;
bit_padding = (bit_padding + 1) & 0x01;
}
mqc->bp++;
*mqc->bp = mqc->c;
mqc->ct = 8;
mqc->c = 0;
}
return 1;
}
 
void mqc_reset_enc(opj_mqc_t *mqc) {
mqc_resetstates(mqc);
mqc_setstate(mqc, T1_CTXNO_UNI, 0, 46);
mqc_setstate(mqc, T1_CTXNO_AGG, 0, 3);
mqc_setstate(mqc, T1_CTXNO_ZC, 0, 4);
}
 
int mqc_restart_enc(opj_mqc_t *mqc) {
int correction = 1;
/* <flush part> */
int n = 27 - 15 - mqc->ct;
mqc->c <<= mqc->ct;
while (n > 0) {
mqc_byteout(mqc);
n -= mqc->ct;
mqc->c <<= mqc->ct;
}
mqc_byteout(mqc);
return correction;
}
 
void mqc_restart_init_enc(opj_mqc_t *mqc) {
/* <Re-init part> */
mqc_setcurctx(mqc, 0);
mqc->a = 0x8000;
mqc->c = 0;
mqc->ct = 12;
mqc->bp--;
if (*mqc->bp == 0xff) {
mqc->ct = 13;
}
}
 
void mqc_erterm_enc(opj_mqc_t *mqc) {
int k = 11 - mqc->ct + 1;
while (k > 0) {
mqc->c <<= mqc->ct;
mqc->ct = 0;
mqc_byteout(mqc);
k -= mqc->ct;
}
if (*mqc->bp != 0xff) {
mqc_byteout(mqc);
}
}
 
void mqc_segmark_enc(opj_mqc_t *mqc) {
int i;
mqc_setcurctx(mqc, 18);
for (i = 1; i < 5; i++) {
mqc_encode(mqc, i % 2);
}
}
 
void mqc_init_dec(opj_mqc_t *mqc, unsigned char *bp, int len) {
mqc_setcurctx(mqc, 0);
mqc->start = bp;
mqc->end = bp + len;
mqc->bp = bp;
if (len==0) mqc->c = 0xff << 16;
else mqc->c = *mqc->bp << 16;
 
#ifdef MQC_PERF_OPT
{
unsigned int c;
unsigned int *ip;
unsigned char *end = mqc->end - 1;
mqc->buffer = opj_realloc(mqc->buffer, (2 * len + 1) * sizeof(unsigned int));
ip = (unsigned int *) mqc->buffer;
 
while (bp != end) {
c = *(bp + 1);
if (*bp == 0xff) {
if (c > 0x8f) {
*ip = 0x0000ff18;
} else {
bp++;
*ip = 0x00000017 | (c << 9);
}
} else {
bp++;
*ip = 0x00000018 | (c << 8);
}
ip++;
}
 
/* Handle last byte of data */
c = 0xff;
if (*bp == 0xff) {
*ip = 0x0000ff18;
} else {
bp++;
*ip = 0x00000018 | (c << 8);
}
ip++;
 
*ip = 0x0000ff08;
mqc->bp = mqc->buffer;
}
#endif
mqc_bytein(mqc);
mqc->c <<= 7;
mqc->ct -= 7;
mqc->a = 0x8000;
}
 
int mqc_decode(opj_mqc_t *const mqc) {
int d;
mqc->a -= (*mqc->curctx)->qeval;
if ((mqc->c >> 16) < (*mqc->curctx)->qeval) {
d = mqc_lpsexchange(mqc);
mqc_renormd(mqc);
} else {
mqc->c -= (*mqc->curctx)->qeval << 16;
if ((mqc->a & 0x8000) == 0) {
d = mqc_mpsexchange(mqc);
mqc_renormd(mqc);
} else {
d = (*mqc->curctx)->mps;
}
}
 
return d;
}
 
void mqc_resetstates(opj_mqc_t *mqc) {
int i;
for (i = 0; i < MQC_NUMCTXS; i++) {
mqc->ctxs[i] = mqc_states;
}
}
 
void mqc_setstate(opj_mqc_t *mqc, int ctxno, int msb, int prob) {
mqc->ctxs[ctxno] = &mqc_states[msb + (prob << 1)];
}
 
 
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libopenjpeg/mqc.h
0,0 → 1,200
/*
* Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2007, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
 
#ifndef __MQC_H
#define __MQC_H
/**
@file mqc.h
@brief Implementation of an MQ-Coder (MQC)
 
The functions in MQC.C have for goal to realize the MQ-coder operations. The functions
in MQC.C are used by some function in T1.C.
*/
 
/** @defgroup MQC MQC - Implementation of an MQ-Coder */
/*@{*/
 
/**
This struct defines the state of a context.
*/
typedef struct opj_mqc_state {
/** the probability of the Least Probable Symbol (0.75->0x8000, 1.5->0xffff) */
unsigned int qeval;
/** the Most Probable Symbol (0 or 1) */
int mps;
/** next state if the next encoded symbol is the MPS */
struct opj_mqc_state *nmps;
/** next state if the next encoded symbol is the LPS */
struct opj_mqc_state *nlps;
} opj_mqc_state_t;
 
#define MQC_NUMCTXS 19
 
/**
MQ coder
*/
typedef struct opj_mqc {
unsigned int c;
unsigned int a;
unsigned int ct;
unsigned char *bp;
unsigned char *start;
unsigned char *end;
opj_mqc_state_t *ctxs[MQC_NUMCTXS];
opj_mqc_state_t **curctx;
#ifdef MQC_PERF_OPT
unsigned char *buffer;
#endif
} opj_mqc_t;
 
/** @name Exported functions */
/*@{*/
/* ----------------------------------------------------------------------- */
/**
Create a new MQC handle
@return Returns a new MQC handle if successful, returns NULL otherwise
*/
opj_mqc_t* mqc_create(void);
/**
Destroy a previously created MQC handle
@param mqc MQC handle to destroy
*/
void mqc_destroy(opj_mqc_t *mqc);
/**
Return the number of bytes written/read since initialisation
@param mqc MQC handle
@return Returns the number of bytes already encoded
*/
int mqc_numbytes(opj_mqc_t *mqc);
/**
Reset the states of all the context of the coder/decoder
(each context is set to a state where 0 and 1 are more or less equiprobable)
@param mqc MQC handle
*/
void mqc_resetstates(opj_mqc_t *mqc);
/**
Set the state of a particular context
@param mqc MQC handle
@param ctxno Number that identifies the context
@param msb The MSB of the new state of the context
@param prob Number that identifies the probability of the symbols for the new state of the context
*/
void mqc_setstate(opj_mqc_t *mqc, int ctxno, int msb, int prob);
/**
Initialize the encoder
@param mqc MQC handle
@param bp Pointer to the start of the buffer where the bytes will be written
*/
void mqc_init_enc(opj_mqc_t *mqc, unsigned char *bp);
/**
Set the current context used for coding/decoding
@param mqc MQC handle
@param ctxno Number that identifies the context
*/
#define mqc_setcurctx(mqc, ctxno) (mqc)->curctx = &(mqc)->ctxs[(int)(ctxno)]
/**
Encode a symbol using the MQ-coder
@param mqc MQC handle
@param d The symbol to be encoded (0 or 1)
*/
void mqc_encode(opj_mqc_t *mqc, int d);
/**
Flush the encoder, so that all remaining data is written
@param mqc MQC handle
*/
void mqc_flush(opj_mqc_t *mqc);
/**
BYPASS mode switch, initialization operation.
JPEG 2000 p 505.
<h2>Not fully implemented and tested !!</h2>
@param mqc MQC handle
*/
void mqc_bypass_init_enc(opj_mqc_t *mqc);
/**
BYPASS mode switch, coding operation.
JPEG 2000 p 505.
<h2>Not fully implemented and tested !!</h2>
@param mqc MQC handle
@param d The symbol to be encoded (0 or 1)
*/
void mqc_bypass_enc(opj_mqc_t *mqc, int d);
/**
BYPASS mode switch, flush operation
<h2>Not fully implemented and tested !!</h2>
@param mqc MQC handle
@return Returns 1 (always)
*/
int mqc_bypass_flush_enc(opj_mqc_t *mqc);
/**
RESET mode switch
@param mqc MQC handle
*/
void mqc_reset_enc(opj_mqc_t *mqc);
/**
RESTART mode switch (TERMALL)
@param mqc MQC handle
@return Returns 1 (always)
*/
int mqc_restart_enc(opj_mqc_t *mqc);
/**
RESTART mode switch (TERMALL) reinitialisation
@param mqc MQC handle
*/
void mqc_restart_init_enc(opj_mqc_t *mqc);
/**
ERTERM mode switch (PTERM)
@param mqc MQC handle
*/
void mqc_erterm_enc(opj_mqc_t *mqc);
/**
SEGMARK mode switch (SEGSYM)
@param mqc MQC handle
*/
void mqc_segmark_enc(opj_mqc_t *mqc);
/**
Initialize the decoder
@param mqc MQC handle
@param bp Pointer to the start of the buffer from which the bytes will be read
@param len Length of the input buffer
*/
void mqc_init_dec(opj_mqc_t *mqc, unsigned char *bp, int len);
/**
Decode a symbol
@param mqc MQC handle
@return Returns the decoded symbol (0 or 1)
*/
int mqc_decode(opj_mqc_t *const mqc);
/* ----------------------------------------------------------------------- */
/*@}*/
 
/*@}*/
 
#endif /* __MQC_H */
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libopenjpeg/openjpeg.c
0,0 → 1,337
/*
* Copyright (c) 2005, Hervé Drolon, FreeImage Team
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
 
#ifdef _WIN32
#include <windows.h>
#endif /* _WIN32 */
 
#include "opj_config.h"
#include "opj_includes.h"
 
/* ---------------------------------------------------------------------- */
#ifdef _WIN32
#ifndef OPJ_STATIC
BOOL APIENTRY
DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
switch (ul_reason_for_call) {
case DLL_PROCESS_ATTACH :
break;
case DLL_PROCESS_DETACH :
break;
case DLL_THREAD_ATTACH :
case DLL_THREAD_DETACH :
break;
}
 
return TRUE;
}
#endif /* OPJ_STATIC */
#endif /* _WIN32 */
 
/* ---------------------------------------------------------------------- */
 
 
const char* OPJ_CALLCONV opj_version(void) {
return PACKAGE_VERSION;
}
 
opj_dinfo_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT format) {
opj_dinfo_t *dinfo = (opj_dinfo_t*)opj_calloc(1, sizeof(opj_dinfo_t));
if(!dinfo) return NULL;
dinfo->is_decompressor = true;
switch(format) {
case CODEC_J2K:
case CODEC_JPT:
/* get a J2K decoder handle */
dinfo->j2k_handle = (void*)j2k_create_decompress((opj_common_ptr)dinfo);
if(!dinfo->j2k_handle) {
opj_free(dinfo);
return NULL;
}
break;
case CODEC_JP2:
/* get a JP2 decoder handle */
dinfo->jp2_handle = (void*)jp2_create_decompress((opj_common_ptr)dinfo);
if(!dinfo->jp2_handle) {
opj_free(dinfo);
return NULL;
}
break;
case CODEC_UNKNOWN:
default:
opj_free(dinfo);
return NULL;
}
 
dinfo->codec_format = format;
 
return dinfo;
}
 
void OPJ_CALLCONV opj_destroy_decompress(opj_dinfo_t *dinfo) {
if(dinfo) {
/* destroy the codec */
switch(dinfo->codec_format) {
case CODEC_J2K:
case CODEC_JPT:
j2k_destroy_decompress((opj_j2k_t*)dinfo->j2k_handle);
break;
case CODEC_JP2:
jp2_destroy_decompress((opj_jp2_t*)dinfo->jp2_handle);
break;
case CODEC_UNKNOWN:
default:
break;
}
/* destroy the decompressor */
opj_free(dinfo);
}
}
 
void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t *parameters) {
if(parameters) {
memset(parameters, 0, sizeof(opj_dparameters_t));
/* default decoding parameters */
parameters->cp_layer = 0;
parameters->cp_reduce = 0;
parameters->cp_limit_decoding = NO_LIMITATION;
 
parameters->decod_format = -1;
parameters->cod_format = -1;
/* UniPG>> */
#ifdef USE_JPWL
parameters->jpwl_correct = false;
parameters->jpwl_exp_comps = JPWL_EXPECTED_COMPONENTS;
parameters->jpwl_max_tiles = JPWL_MAXIMUM_TILES;
#endif /* USE_JPWL */
/* <<UniPG */
}
}
 
void OPJ_CALLCONV opj_setup_decoder(opj_dinfo_t *dinfo, opj_dparameters_t *parameters) {
if(dinfo && parameters) {
switch(dinfo->codec_format) {
case CODEC_J2K:
case CODEC_JPT:
j2k_setup_decoder((opj_j2k_t*)dinfo->j2k_handle, parameters);
break;
case CODEC_JP2:
jp2_setup_decoder((opj_jp2_t*)dinfo->jp2_handle, parameters);
break;
case CODEC_UNKNOWN:
default:
break;
}
}
}
 
opj_image_t* OPJ_CALLCONV opj_decode(opj_dinfo_t *dinfo, opj_cio_t *cio) {
return opj_decode_with_info(dinfo, cio, NULL);
}
 
opj_image_t* OPJ_CALLCONV opj_decode_with_info(opj_dinfo_t *dinfo, opj_cio_t *cio, opj_codestream_info_t *cstr_info) {
if(dinfo && cio) {
switch(dinfo->codec_format) {
case CODEC_J2K:
return j2k_decode((opj_j2k_t*)dinfo->j2k_handle, cio, cstr_info);
case CODEC_JPT:
return j2k_decode_jpt_stream((opj_j2k_t*)dinfo->j2k_handle, cio, cstr_info);
case CODEC_JP2:
return jp2_decode((opj_jp2_t*)dinfo->jp2_handle, cio, cstr_info);
case CODEC_UNKNOWN:
default:
break;
}
}
return NULL;
}
 
opj_cinfo_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT format) {
opj_cinfo_t *cinfo = (opj_cinfo_t*)opj_calloc(1, sizeof(opj_cinfo_t));
if(!cinfo) return NULL;
cinfo->is_decompressor = false;
switch(format) {
case CODEC_J2K:
/* get a J2K coder handle */
cinfo->j2k_handle = (void*)j2k_create_compress((opj_common_ptr)cinfo);
if(!cinfo->j2k_handle) {
opj_free(cinfo);
return NULL;
}
break;
case CODEC_JP2:
/* get a JP2 coder handle */
cinfo->jp2_handle = (void*)jp2_create_compress((opj_common_ptr)cinfo);
if(!cinfo->jp2_handle) {
opj_free(cinfo);
return NULL;
}
break;
case CODEC_JPT:
case CODEC_UNKNOWN:
default:
opj_free(cinfo);
return NULL;
}
 
cinfo->codec_format = format;
 
return cinfo;
}
 
void OPJ_CALLCONV opj_destroy_compress(opj_cinfo_t *cinfo) {
if(cinfo) {
/* destroy the codec */
switch(cinfo->codec_format) {
case CODEC_J2K:
j2k_destroy_compress((opj_j2k_t*)cinfo->j2k_handle);
break;
case CODEC_JP2:
jp2_destroy_compress((opj_jp2_t*)cinfo->jp2_handle);
break;
case CODEC_JPT:
case CODEC_UNKNOWN:
default:
break;
}
/* destroy the decompressor */
opj_free(cinfo);
}
}
 
void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *parameters) {
if(parameters) {
memset(parameters, 0, sizeof(opj_cparameters_t));
/* default coding parameters */
parameters->cp_cinema = OFF;
parameters->max_comp_size = 0;
parameters->numresolution = 6;
parameters->cp_rsiz = STD_RSIZ;
parameters->cblockw_init = 64;
parameters->cblockh_init = 64;
parameters->prog_order = LRCP;
parameters->roi_compno = -1; /* no ROI */
parameters->subsampling_dx = 1;
parameters->subsampling_dy = 1;
parameters->tp_on = 0;
parameters->decod_format = -1;
parameters->cod_format = -1;
parameters->tcp_rates[0] = 0;
parameters->tcp_numlayers = 0;
parameters->cp_disto_alloc = 0;
parameters->cp_fixed_alloc = 0;
parameters->cp_fixed_quality = 0;
 
/* UniPG>> */
#ifdef USE_JPWL
parameters->jpwl_epc_on = false;
parameters->jpwl_hprot_MH = -1; /* -1 means unassigned */
{
int i;
for (i = 0; i < JPWL_MAX_NO_TILESPECS; i++) {
parameters->jpwl_hprot_TPH_tileno[i] = -1; /* unassigned */
parameters->jpwl_hprot_TPH[i] = 0; /* absent */
}
};
{
int i;
for (i = 0; i < JPWL_MAX_NO_PACKSPECS; i++) {
parameters->jpwl_pprot_tileno[i] = -1; /* unassigned */
parameters->jpwl_pprot_packno[i] = -1; /* unassigned */
parameters->jpwl_pprot[i] = 0; /* absent */
}
};
parameters->jpwl_sens_size = 0; /* 0 means no ESD */
parameters->jpwl_sens_addr = 0; /* 0 means auto */
parameters->jpwl_sens_range = 0; /* 0 means packet */
parameters->jpwl_sens_MH = -1; /* -1 means unassigned */
{
int i;
for (i = 0; i < JPWL_MAX_NO_TILESPECS; i++) {
parameters->jpwl_sens_TPH_tileno[i] = -1; /* unassigned */
parameters->jpwl_sens_TPH[i] = -1; /* absent */
}
};
#endif /* USE_JPWL */
/* <<UniPG */
}
}
 
void OPJ_CALLCONV opj_setup_encoder(opj_cinfo_t *cinfo, opj_cparameters_t *parameters, opj_image_t *image) {
if(cinfo && parameters && image) {
switch(cinfo->codec_format) {
case CODEC_J2K:
j2k_setup_encoder((opj_j2k_t*)cinfo->j2k_handle, parameters, image);
break;
case CODEC_JP2:
jp2_setup_encoder((opj_jp2_t*)cinfo->jp2_handle, parameters, image);
break;
case CODEC_JPT:
case CODEC_UNKNOWN:
default:
break;
}
}
}
 
bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, char *index) {
if (index != NULL)
opj_event_msg((opj_common_ptr)cinfo, EVT_WARNING, "Set index to NULL when calling the opj_encode function.\n"
"To extract the index, use the opj_encode_with_info() function.\n"
"No index will be generated during this encoding\n");
return opj_encode_with_info(cinfo, cio, image, NULL);
}
 
bool OPJ_CALLCONV opj_encode_with_info(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info) {
if(cinfo && cio && image) {
switch(cinfo->codec_format) {
case CODEC_J2K:
return j2k_encode((opj_j2k_t*)cinfo->j2k_handle, cio, image, cstr_info);
case CODEC_JP2:
return jp2_encode((opj_jp2_t*)cinfo->jp2_handle, cio, image, cstr_info);
case CODEC_JPT:
case CODEC_UNKNOWN:
default:
break;
}
}
return false;
}
 
void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_t *cstr_info) {
if (cstr_info) {
int tileno;
for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) {
opj_tile_info_t *tile_info = &cstr_info->tile[tileno];
opj_free(tile_info->thresh);
opj_free(tile_info->packet);
opj_free(tile_info->tp);
}
opj_free(cstr_info->tile);
opj_free(cstr_info->marker);
opj_free(cstr_info->numdecompos);
}
}
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libopenjpeg/openjpeg.h
0,0 → 1,915
/*
* Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2007, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2006-2007, Parvatha Elangovan
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef OPENJPEG_H
#define OPENJPEG_H
 
 
/*
==========================================================
Compiler directives
==========================================================
*/
 
#if defined(OPJ_STATIC) || !defined(_WIN32)
#define OPJ_API
#define OPJ_CALLCONV
#else
#define OPJ_CALLCONV __stdcall
/*
The following ifdef block is the standard way of creating macros which make exporting
from a DLL simpler. All files within this DLL are compiled with the OPJ_EXPORTS
symbol defined on the command line. this symbol should not be defined on any project
that uses this DLL. This way any other project whose source files include this file see
OPJ_API functions as being imported from a DLL, wheras this DLL sees symbols
defined with this macro as being exported.
*/
#if defined(OPJ_EXPORTS) || defined(DLL_EXPORT)
#define OPJ_API __declspec(dllexport)
#else
#define OPJ_API __declspec(dllimport)
#endif /* OPJ_EXPORTS */
#endif /* !OPJ_STATIC || !_WIN32 */
 
#ifndef __cplusplus
#if defined(HAVE_STDBOOL_H)
/*
The C language implementation does correctly provide the standard header
file "stdbool.h".
*/
#include <stdbool.h>
#else
/*
The C language implementation does not provide the standard header file
"stdbool.h" as required by ISO/IEC 9899:1999. Try to compensate for this
braindamage below.
*/
#if !defined(bool)
#define bool int
#endif
#if !defined(true)
#define true 1
#endif
#if !defined(false)
#define false 0
#endif
#endif
#endif /* __cplusplus */
 
/*
==========================================================
Useful constant definitions
==========================================================
*/
 
#define OPJ_PATH_LEN 4096 /**< Maximum allowed size for filenames */
 
#define J2K_MAXRLVLS 33 /**< Number of maximum resolution level authorized */
#define J2K_MAXBANDS (3*J2K_MAXRLVLS-2) /**< Number of maximum sub-band linked to number of resolution level */
 
/* UniPG>> */
#define JPWL_MAX_NO_TILESPECS 16 /**< Maximum number of tile parts expected by JPWL: increase at your will */
#define JPWL_MAX_NO_PACKSPECS 16 /**< Maximum number of packet parts expected by JPWL: increase at your will */
#define JPWL_MAX_NO_MARKERS 512 /**< Maximum number of JPWL markers: increase at your will */
#define JPWL_PRIVATEINDEX_NAME "jpwl_index_privatefilename" /**< index file name used when JPWL is on */
#define JPWL_EXPECTED_COMPONENTS 3 /**< Expect this number of components, so you'll find better the first EPB */
#define JPWL_MAXIMUM_TILES 8192 /**< Expect this maximum number of tiles, to avoid some crashes */
#define JPWL_MAXIMUM_HAMMING 2 /**< Expect this maximum number of bit errors in marker id's */
#define JPWL_MAXIMUM_EPB_ROOM 65450 /**< Expect this maximum number of bytes for composition of EPBs */
/* <<UniPG */
 
/*
==========================================================
enum definitions
==========================================================
*/
/**
Rsiz Capabilities
*/
typedef enum RSIZ_CAPABILITIES {
STD_RSIZ = 0, /** Standard JPEG2000 profile*/
CINEMA2K = 3, /** Profile name for a 2K image*/
CINEMA4K = 4 /** Profile name for a 4K image*/
} OPJ_RSIZ_CAPABILITIES;
 
/**
Digital cinema operation mode
*/
typedef enum CINEMA_MODE {
OFF = 0, /** Not Digital Cinema*/
CINEMA2K_24 = 1, /** 2K Digital Cinema at 24 fps*/
CINEMA2K_48 = 2, /** 2K Digital Cinema at 48 fps*/
CINEMA4K_24 = 3 /** 4K Digital Cinema at 24 fps*/
}OPJ_CINEMA_MODE;
 
/**
Progression order
*/
typedef enum PROG_ORDER {
PROG_UNKNOWN = -1, /**< place-holder */
LRCP = 0, /**< layer-resolution-component-precinct order */
RLCP = 1, /**< resolution-layer-component-precinct order */
RPCL = 2, /**< resolution-precinct-component-layer order */
PCRL = 3, /**< precinct-component-resolution-layer order */
CPRL = 4 /**< component-precinct-resolution-layer order */
} OPJ_PROG_ORDER;
 
/**
Supported image color spaces
*/
typedef enum COLOR_SPACE {
CLRSPC_UNKNOWN = -1, /**< not supported by the library */
CLRSPC_UNSPECIFIED = 0, /**< not specified in the codestream */
CLRSPC_SRGB = 1, /**< sRGB */
CLRSPC_GRAY = 2, /**< grayscale */
CLRSPC_SYCC = 3 /**< YUV */
} OPJ_COLOR_SPACE;
 
/**
Supported codec
*/
typedef enum CODEC_FORMAT {
CODEC_UNKNOWN = -1, /**< place-holder */
CODEC_J2K = 0, /**< JPEG-2000 codestream : read/write */
CODEC_JPT = 1, /**< JPT-stream (JPEG 2000, JPIP) : read only */
CODEC_JP2 = 2 /**< JPEG-2000 file format : read/write */
} OPJ_CODEC_FORMAT;
 
/**
Limit decoding to certain portions of the codestream.
*/
typedef enum LIMIT_DECODING {
NO_LIMITATION = 0, /**< No limitation for the decoding. The entire codestream will de decoded */
LIMIT_TO_MAIN_HEADER = 1, /**< The decoding is limited to the Main Header */
DECODE_ALL_BUT_PACKETS = 2 /**< Decode everything except the JPEG 2000 packets */
} OPJ_LIMIT_DECODING;
 
/*
==========================================================
event manager typedef definitions
==========================================================
*/
 
/**
Callback function prototype for events
@param msg Event message
@param client_data
*/
typedef void (*opj_msg_callback) (const char *msg, void *client_data);
 
/**
Message handler object
used for
<ul>
<li>Error messages
<li>Warning messages
<li>Debugging messages
</ul>
*/
typedef struct opj_event_mgr {
/** Error message callback if available, NULL otherwise */
opj_msg_callback error_handler;
/** Warning message callback if available, NULL otherwise */
opj_msg_callback warning_handler;
/** Debug message callback if available, NULL otherwise */
opj_msg_callback info_handler;
} opj_event_mgr_t;
 
 
/*
==========================================================
codec typedef definitions
==========================================================
*/
 
/**
Progression order changes
*/
typedef struct opj_poc {
/** Resolution num start, Component num start, given by POC */
int resno0, compno0;
/** Layer num end,Resolution num end, Component num end, given by POC */
int layno1, resno1, compno1;
/** Layer num start,Precinct num start, Precinct num end */
int layno0, precno0, precno1;
/** Progression order enum*/
OPJ_PROG_ORDER prg1,prg;
/** Progression order string*/
char progorder[5];
/** Tile number */
int tile;
/** Start and end values for Tile width and height*/
int tx0,tx1,ty0,ty1;
/** Start value, initialised in pi_initialise_encode*/
int layS, resS, compS, prcS;
/** End value, initialised in pi_initialise_encode */
int layE, resE, compE, prcE;
/** Start and end values of Tile width and height, initialised in pi_initialise_encode*/
int txS,txE,tyS,tyE,dx,dy;
/** Temporary values for Tile parts, initialised in pi_create_encode */
int lay_t, res_t, comp_t, prc_t,tx0_t,ty0_t;
} opj_poc_t;
 
/**
Compression parameters
*/
typedef struct opj_cparameters {
/** size of tile: tile_size_on = false (not in argument) or = true (in argument) */
bool tile_size_on;
/** XTOsiz */
int cp_tx0;
/** YTOsiz */
int cp_ty0;
/** XTsiz */
int cp_tdx;
/** YTsiz */
int cp_tdy;
/** allocation by rate/distortion */
int cp_disto_alloc;
/** allocation by fixed layer */
int cp_fixed_alloc;
/** add fixed_quality */
int cp_fixed_quality;
/** fixed layer */
int *cp_matrice;
/** comment for coding */
char *cp_comment;
/** csty : coding style */
int csty;
/** progression order (default LRCP) */
OPJ_PROG_ORDER prog_order;
/** progression order changes */
opj_poc_t POC[32];
/** number of progression order changes (POC), default to 0 */
int numpocs;
/** number of layers */
int tcp_numlayers;
/** rates of layers */
float tcp_rates[100];
/** different psnr for successive layers */
float tcp_distoratio[100];
/** number of resolutions */
int numresolution;
/** initial code block width, default to 64 */
int cblockw_init;
/** initial code block height, default to 64 */
int cblockh_init;
/** mode switch (cblk_style) */
int mode;
/** 1 : use the irreversible DWT 9-7, 0 : use lossless compression (default) */
int irreversible;
/** region of interest: affected component in [0..3], -1 means no ROI */
int roi_compno;
/** region of interest: upshift value */
int roi_shift;
/* number of precinct size specifications */
int res_spec;
/** initial precinct width */
int prcw_init[J2K_MAXRLVLS];
/** initial precinct height */
int prch_init[J2K_MAXRLVLS];
 
/**@name command line encoder parameters (not used inside the library) */
/*@{*/
/** input file name */
char infile[OPJ_PATH_LEN];
/** output file name */
char outfile[OPJ_PATH_LEN];
/** DEPRECATED. Index generation is now handeld with the opj_encode_with_info() function. Set to NULL */
int index_on;
/** DEPRECATED. Index generation is now handeld with the opj_encode_with_info() function. Set to NULL */
char index[OPJ_PATH_LEN];
/** subimage encoding: origin image offset in x direction */
int image_offset_x0;
/** subimage encoding: origin image offset in y direction */
int image_offset_y0;
/** subsampling value for dx */
int subsampling_dx;
/** subsampling value for dy */
int subsampling_dy;
/** input file format 0: PGX, 1: PxM, 2: BMP 3:TIF*/
int decod_format;
/** output file format 0: J2K, 1: JP2, 2: JPT */
int cod_format;
/*@}*/
 
/* UniPG>> */
/**@name JPWL encoding parameters */
/*@{*/
/** enables writing of EPC in MH, thus activating JPWL */
bool jpwl_epc_on;
/** error protection method for MH (0,1,16,32,37-128) */
int jpwl_hprot_MH;
/** tile number of header protection specification (>=0) */
int jpwl_hprot_TPH_tileno[JPWL_MAX_NO_TILESPECS];
/** error protection methods for TPHs (0,1,16,32,37-128) */
int jpwl_hprot_TPH[JPWL_MAX_NO_TILESPECS];
/** tile number of packet protection specification (>=0) */
int jpwl_pprot_tileno[JPWL_MAX_NO_PACKSPECS];
/** packet number of packet protection specification (>=0) */
int jpwl_pprot_packno[JPWL_MAX_NO_PACKSPECS];
/** error protection methods for packets (0,1,16,32,37-128) */
int jpwl_pprot[JPWL_MAX_NO_PACKSPECS];
/** enables writing of ESD, (0=no/1/2 bytes) */
int jpwl_sens_size;
/** sensitivity addressing size (0=auto/2/4 bytes) */
int jpwl_sens_addr;
/** sensitivity range (0-3) */
int jpwl_sens_range;
/** sensitivity method for MH (-1=no,0-7) */
int jpwl_sens_MH;
/** tile number of sensitivity specification (>=0) */
int jpwl_sens_TPH_tileno[JPWL_MAX_NO_TILESPECS];
/** sensitivity methods for TPHs (-1=no,0-7) */
int jpwl_sens_TPH[JPWL_MAX_NO_TILESPECS];
/*@}*/
/* <<UniPG */
 
/** Digital Cinema compliance 0-not compliant, 1-compliant*/
OPJ_CINEMA_MODE cp_cinema;
/** Maximum rate for each component. If == 0, component size limitation is not considered */
int max_comp_size;
/** Profile name*/
OPJ_RSIZ_CAPABILITIES cp_rsiz;
/** Tile part generation*/
char tp_on;
/** Flag for Tile part generation*/
char tp_flag;
/** MCT (multiple component transform) */
char tcp_mct;
} opj_cparameters_t;
 
/**
Decompression parameters
*/
typedef struct opj_dparameters {
/**
Set the number of highest resolution levels to be discarded.
The image resolution is effectively divided by 2 to the power of the number of discarded levels.
The reduce factor is limited by the smallest total number of decomposition levels among tiles.
if != 0, then original dimension divided by 2^(reduce);
if == 0 or not used, image is decoded to the full resolution
*/
int cp_reduce;
/**
Set the maximum number of quality layers to decode.
If there are less quality layers than the specified number, all the quality layers are decoded.
if != 0, then only the first "layer" layers are decoded;
if == 0 or not used, all the quality layers are decoded
*/
int cp_layer;
 
/**@name command line encoder parameters (not used inside the library) */
/*@{*/
/** input file name */
char infile[OPJ_PATH_LEN];
/** output file name */
char outfile[OPJ_PATH_LEN];
/** input file format 0: J2K, 1: JP2, 2: JPT */
int decod_format;
/** output file format 0: PGX, 1: PxM, 2: BMP */
int cod_format;
/*@}*/
 
/* UniPG>> */
/**@name JPWL decoding parameters */
/*@{*/
/** activates the JPWL correction capabilities */
bool jpwl_correct;
/** expected number of components */
int jpwl_exp_comps;
/** maximum number of tiles */
int jpwl_max_tiles;
/*@}*/
/* <<UniPG */
 
/**
Specify whether the decoding should be done on the entire codestream, or be limited to the main header
Limiting the decoding to the main header makes it possible to extract the characteristics of the codestream
if == NO_LIMITATION, the entire codestream is decoded;
if == LIMIT_TO_MAIN_HEADER, only the main header is decoded;
*/
OPJ_LIMIT_DECODING cp_limit_decoding;
 
} opj_dparameters_t;
 
/** Common fields between JPEG-2000 compression and decompression master structs. */
 
#define opj_common_fields \
opj_event_mgr_t *event_mgr; /**< pointer to the event manager */\
void * client_data; /**< Available for use by application */\
bool is_decompressor; /**< So common code can tell which is which */\
OPJ_CODEC_FORMAT codec_format; /**< selected codec */\
void *j2k_handle; /**< pointer to the J2K codec */\
void *jp2_handle; /**< pointer to the JP2 codec */\
void *mj2_handle /**< pointer to the MJ2 codec */
/* Routines that are to be used by both halves of the library are declared
* to receive a pointer to this structure. There are no actual instances of
* opj_common_struct_t, only of opj_cinfo_t and opj_dinfo_t.
*/
typedef struct opj_common_struct {
opj_common_fields; /* Fields common to both master struct types */
/* Additional fields follow in an actual opj_cinfo_t or
* opj_dinfo_t. All three structs must agree on these
* initial fields! (This would be a lot cleaner in C++.)
*/
} opj_common_struct_t;
 
typedef opj_common_struct_t * opj_common_ptr;
 
/**
Compression context info
*/
typedef struct opj_cinfo {
/** Fields shared with opj_dinfo_t */
opj_common_fields;
/* other specific fields go here */
} opj_cinfo_t;
 
/**
Decompression context info
*/
typedef struct opj_dinfo {
/** Fields shared with opj_cinfo_t */
opj_common_fields;
/* other specific fields go here */
} opj_dinfo_t;
 
/*
==========================================================
I/O stream typedef definitions
==========================================================
*/
 
/*
* Stream open flags.
*/
/** The stream was opened for reading. */
#define OPJ_STREAM_READ 0x0001
/** The stream was opened for writing. */
#define OPJ_STREAM_WRITE 0x0002
 
/**
Byte input-output stream (CIO)
*/
typedef struct opj_cio {
/** codec context */
opj_common_ptr cinfo;
 
/** open mode (read/write) either OPJ_STREAM_READ or OPJ_STREAM_WRITE */
int openmode;
/** pointer to the start of the buffer */
unsigned char *buffer;
/** buffer size in bytes */
int length;
 
/** pointer to the start of the stream */
unsigned char *start;
/** pointer to the end of the stream */
unsigned char *end;
/** pointer to the current position */
unsigned char *bp;
} opj_cio_t;
 
/*
==========================================================
image typedef definitions
==========================================================
*/
 
/**
Defines a single image component
*/
typedef struct opj_image_comp {
/** XRsiz: horizontal separation of a sample of ith component with respect to the reference grid */
int dx;
/** YRsiz: vertical separation of a sample of ith component with respect to the reference grid */
int dy;
/** data width */
int w;
/** data height */
int h;
/** x component offset compared to the whole image */
int x0;
/** y component offset compared to the whole image */
int y0;
/** precision */
int prec;
/** image depth in bits */
int bpp;
/** signed (1) / unsigned (0) */
int sgnd;
/** number of decoded resolution */
int resno_decoded;
/** number of division by 2 of the out image compared to the original size of image */
int factor;
/** image component data */
int *data;
} opj_image_comp_t;
 
/**
Defines image data and characteristics
*/
typedef struct opj_image {
/** XOsiz: horizontal offset from the origin of the reference grid to the left side of the image area */
int x0;
/** YOsiz: vertical offset from the origin of the reference grid to the top side of the image area */
int y0;
/** Xsiz: width of the reference grid */
int x1;
/** Ysiz: height of the reference grid */
int y1;
/** number of components in the image */
int numcomps;
/** color space: sRGB, Greyscale or YUV */
OPJ_COLOR_SPACE color_space;
/** image components */
opj_image_comp_t *comps;
/** 'restricted' ICC profile */
unsigned char *icc_profile_buf;
/** size of ICC profile */
int icc_profile_len;
} opj_image_t;
 
/**
Component parameters structure used by the opj_image_create function
*/
typedef struct opj_image_comptparm {
/** XRsiz: horizontal separation of a sample of ith component with respect to the reference grid */
int dx;
/** YRsiz: vertical separation of a sample of ith component with respect to the reference grid */
int dy;
/** data width */
int w;
/** data height */
int h;
/** x component offset compared to the whole image */
int x0;
/** y component offset compared to the whole image */
int y0;
/** precision */
int prec;
/** image depth in bits */
int bpp;
/** signed (1) / unsigned (0) */
int sgnd;
} opj_image_cmptparm_t;
 
/*
==========================================================
Information on the JPEG 2000 codestream
==========================================================
*/
 
/**
Index structure : Information concerning a packet inside tile
*/
typedef struct opj_packet_info {
/** packet start position (including SOP marker if it exists) */
int start_pos;
/** end of packet header position (including EPH marker if it exists)*/
int end_ph_pos;
/** packet end position */
int end_pos;
/** packet distorsion */
double disto;
} opj_packet_info_t;
 
/**
Index structure : Information concerning tile-parts
*/
typedef struct opj_tp_info {
/** start position of tile part */
int tp_start_pos;
/** end position of tile part header */
int tp_end_header;
/** end position of tile part */
int tp_end_pos;
/** start packet of tile part */
int tp_start_pack;
/** number of packets of tile part */
int tp_numpacks;
} opj_tp_info_t;
 
/**
Index structure : information regarding tiles
*/
typedef struct opj_tile_info {
/** value of thresh for each layer by tile cfr. Marcela */
double *thresh;
/** number of tile */
int tileno;
/** start position */
int start_pos;
/** end position of the header */
int end_header;
/** end position */
int end_pos;
/** precinct number for each resolution level (width) */
int pw[33];
/** precinct number for each resolution level (height) */
int ph[33];
/** precinct size (in power of 2), in X for each resolution level */
int pdx[33];
/** precinct size (in power of 2), in Y for each resolution level */
int pdy[33];
/** information concerning packets inside tile */
opj_packet_info_t *packet;
/** add fixed_quality */
int numpix;
/** add fixed_quality */
double distotile;
/** number of tile parts */
int num_tps;
/** information concerning tile parts */
opj_tp_info_t *tp;
} opj_tile_info_t;
 
/* UniPG>> */
/**
Marker structure
*/
typedef struct opj_marker_info_t {
/** marker type */
unsigned short int type;
/** position in codestream */
int pos;
/** length, marker val included */
int len;
} opj_marker_info_t;
/* <<UniPG */
 
/**
Index structure of the codestream
*/
typedef struct opj_codestream_info {
/** maximum distortion reduction on the whole image (add for Marcela) */
double D_max;
/** packet number */
int packno;
/** writing the packet in the index with t2_encode_packets */
int index_write;
/** image width */
int image_w;
/** image height */
int image_h;
/** progression order */
OPJ_PROG_ORDER prog;
/** tile size in x */
int tile_x;
/** tile size in y */
int tile_y;
/** */
int tile_Ox;
/** */
int tile_Oy;
/** number of tiles in X */
int tw;
/** number of tiles in Y */
int th;
/** component numbers */
int numcomps;
/** number of layer */
int numlayers;
/** number of decomposition for each component */
int *numdecompos;
/* UniPG>> */
/** number of markers */
int marknum;
/** list of markers */
opj_marker_info_t *marker;
/** actual size of markers array */
int maxmarknum;
/* <<UniPG */
/** main header position */
int main_head_start;
/** main header position */
int main_head_end;
/** codestream's size */
int codestream_size;
/** information regarding tiles inside image */
opj_tile_info_t *tile;
} opj_codestream_info_t;
 
#ifdef __cplusplus
extern "C" {
#endif
 
 
/*
==========================================================
openjpeg version
==========================================================
*/
 
OPJ_API const char * OPJ_CALLCONV opj_version(void);
 
/*
==========================================================
image functions definitions
==========================================================
*/
 
/**
Create an image
@param numcmpts number of components
@param cmptparms components parameters
@param clrspc image color space
@return returns a new image structure if successful, returns NULL otherwise
*/
OPJ_API opj_image_t* OPJ_CALLCONV opj_image_create(int numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc);
 
/**
Deallocate any resources associated with an image
@param image image to be destroyed
*/
OPJ_API void OPJ_CALLCONV opj_image_destroy(opj_image_t *image);
 
/*
==========================================================
stream functions definitions
==========================================================
*/
 
/**
Open and allocate a memory stream for read / write.
On reading, the user must provide a buffer containing encoded data. The buffer will be
wrapped by the returned CIO handle.
On writing, buffer parameters must be set to 0: a buffer will be allocated by the library
to contain encoded data.
@param cinfo Codec context info
@param buffer Reading: buffer address. Writing: NULL
@param length Reading: buffer length. Writing: 0
@return Returns a CIO handle if successful, returns NULL otherwise
*/
OPJ_API opj_cio_t* OPJ_CALLCONV opj_cio_open(opj_common_ptr cinfo, unsigned char *buffer, int length);
 
/**
Close and free a CIO handle
@param cio CIO handle to free
*/
OPJ_API void OPJ_CALLCONV opj_cio_close(opj_cio_t *cio);
 
/**
Get position in byte stream
@param cio CIO handle
@return Returns the position in bytes
*/
OPJ_API int OPJ_CALLCONV cio_tell(opj_cio_t *cio);
/**
Set position in byte stream
@param cio CIO handle
@param pos Position, in number of bytes, from the beginning of the stream
*/
OPJ_API void OPJ_CALLCONV cio_seek(opj_cio_t *cio, int pos);
 
/*
==========================================================
event manager functions definitions
==========================================================
*/
 
OPJ_API opj_event_mgr_t* OPJ_CALLCONV opj_set_event_mgr(opj_common_ptr cinfo, opj_event_mgr_t *event_mgr, void *context);
 
/*
==========================================================
codec functions definitions
==========================================================
*/
/**
Creates a J2K/JPT/JP2 decompression structure
@param format Decoder to select
@return Returns a handle to a decompressor if successful, returns NULL otherwise
*/
OPJ_API opj_dinfo_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT format);
/**
Destroy a decompressor handle
@param dinfo decompressor handle to destroy
*/
OPJ_API void OPJ_CALLCONV opj_destroy_decompress(opj_dinfo_t *dinfo);
/**
Set decoding parameters to default values
@param parameters Decompression parameters
*/
OPJ_API void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t *parameters);
/**
Setup the decoder decoding parameters using user parameters.
Decoding parameters are returned in j2k->cp.
@param dinfo decompressor handle
@param parameters decompression parameters
*/
OPJ_API void OPJ_CALLCONV opj_setup_decoder(opj_dinfo_t *dinfo, opj_dparameters_t *parameters);
/**
Decode an image from a JPEG-2000 codestream
@param dinfo decompressor handle
@param cio Input buffer stream
@return Returns a decoded image if successful, returns NULL otherwise
*/
OPJ_API opj_image_t* OPJ_CALLCONV opj_decode(opj_dinfo_t *dinfo, opj_cio_t *cio);
 
/**
Decode an image from a JPEG-2000 codestream and extract the codestream information
@param dinfo decompressor handle
@param cio Input buffer stream
@param cstr_info Codestream information structure if needed afterwards, NULL otherwise
@return Returns a decoded image if successful, returns NULL otherwise
*/
OPJ_API opj_image_t* OPJ_CALLCONV opj_decode_with_info(opj_dinfo_t *dinfo, opj_cio_t *cio, opj_codestream_info_t *cstr_info);
/**
Creates a J2K/JP2 compression structure
@param format Coder to select
@return Returns a handle to a compressor if successful, returns NULL otherwise
*/
OPJ_API opj_cinfo_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT format);
/**
Destroy a compressor handle
@param cinfo compressor handle to destroy
*/
OPJ_API void OPJ_CALLCONV opj_destroy_compress(opj_cinfo_t *cinfo);
/**
Set encoding parameters to default values, that means :
<ul>
<li>Lossless
<li>1 tile
<li>Size of precinct : 2^15 x 2^15 (means 1 precinct)
<li>Size of code-block : 64 x 64
<li>Number of resolutions: 6
<li>No SOP marker in the codestream
<li>No EPH marker in the codestream
<li>No sub-sampling in x or y direction
<li>No mode switch activated
<li>Progression order: LRCP
<li>No index file
<li>No ROI upshifted
<li>No offset of the origin of the image
<li>No offset of the origin of the tiles
<li>Reversible DWT 5-3
</ul>
@param parameters Compression parameters
*/
OPJ_API void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *parameters);
/**
Setup the encoder parameters using the current image and using user parameters.
@param cinfo Compressor handle
@param parameters Compression parameters
@param image Input filled image
*/
OPJ_API void OPJ_CALLCONV opj_setup_encoder(opj_cinfo_t *cinfo, opj_cparameters_t *parameters, opj_image_t *image);
/**
Encode an image into a JPEG-2000 codestream
@param cinfo compressor handle
@param cio Output buffer stream
@param image Image to encode
@param index Depreacted -> Set to NULL. To extract index, used opj_encode_wci()
@return Returns true if successful, returns false otherwise
*/
OPJ_API bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, char *index);
/**
Encode an image into a JPEG-2000 codestream and extract the codestream information
@param cinfo compressor handle
@param cio Output buffer stream
@param image Image to encode
@param cstr_info Codestream information structure if needed afterwards, NULL otherwise
@return Returns true if successful, returns false otherwise
*/
OPJ_API bool OPJ_CALLCONV opj_encode_with_info(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info);
/**
Destroy Codestream information after compression or decompression
@param cstr_info Codestream information structure
*/
OPJ_API void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_t *cstr_info);
 
#ifdef __cplusplus
}
#endif
 
#endif /* OPENJPEG_H */
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libopenjpeg/opj_config.h
0,0 → 1,105
/* opj_config.h. Generated from opj_config.h.in by configure. */
/* opj_config.h.in. Generated from configure.ac by autoheader. */
 
/* Define if building universal (internal helper macro) */
/* #undef AC_APPLE_UNIVERSAL_BUILD */
 
/* Define to 1 if you have the <dlfcn.h> header file. */
#define HAVE_DLFCN_H 0
 
/* Define to 1 if fseeko (and presumably ftello) exists and is declared. */
#define HAVE_FSEEKO 1
 
/* Define to 1 if you have the <inttypes.h> header file. */
#define HAVE_INTTYPES_H 0
 
/* Define to 1 if you have the `lcms' library (-llcms). */
#define HAVE_LIBLCMS 0
 
/* define to 1 if you have lcms version 1.x */
#define HAVE_LIBLCMS1 0
 
/* define to 1 if you have lcms version 2.x */
/* #undef HAVE_LIBLCMS2 */
 
/* define to 1 if you have libpng */
#define HAVE_LIBPNG 1
 
/* define to 1 if you have libtiff */
#define HAVE_LIBTIFF 0
 
/* Define to 1 if you have the <memory.h> header file. */
#define HAVE_MEMORY_H 1
 
/* Define to 1 if you have the <stdint.h> header file. */
#define HAVE_STDINT_H 1
 
/* Define to 1 if you have the <stdlib.h> header file. */
#define HAVE_STDLIB_H 1
 
/* Define to 1 if you have the <strings.h> header file. */
#define HAVE_STRINGS_H 0
 
/* Define to 1 if you have the <string.h> header file. */
#define HAVE_STRING_H 1
 
/* Define to 1 if you have the <sys/stat.h> header file. */
#define HAVE_SYS_STAT_H 1
 
/* Define to 1 if you have the <sys/types.h> header file. */
#define HAVE_SYS_TYPES_H 1
 
/* Define to 1 if you have the <unistd.h> header file. */
#define HAVE_UNISTD_H 1
 
/* Define to the sub-directory in which libtool stores uninstalled libraries.
*/
#define LT_OBJDIR ".libs/"
 
/* Name of package */
#define PACKAGE "openjpeg-1.4.0"
 
/* Define to the address where bug reports for this package should be sent. */
#define PACKAGE_BUGREPORT "http://code.google.com/p/openjpeg/"
 
/* Define to the full name of this package. */
#define PACKAGE_NAME "OpenJPEG"
 
/* Define to the full name and version of this package. */
#define PACKAGE_STRING "OpenJPEG 1.4.0"
 
/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "openjpeg-1.4.0"
 
/* Define to the home page for this package. */
#define PACKAGE_URL "http://www.openjpeg.org/"
 
/* Define to the version of this package. */
#define PACKAGE_VERSION "1.4.0"
 
/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1
 
/* Version number of package */
#define VERSION "1.4.0"
 
/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
significant byte first (like Motorola and SPARC, unlike Intel). */
#if defined AC_APPLE_UNIVERSAL_BUILD
# if defined __BIG_ENDIAN__
# define WORDS_BIGENDIAN 1
# endif
#else
# ifndef WORDS_BIGENDIAN
/* # undef WORDS_BIGENDIAN */
# endif
#endif
 
/* Number of bits in a file offset, on hosts where this is settable. */
#define _FILE_OFFSET_BITS 64
 
/* Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2). */
/* #undef _LARGEFILE_SOURCE */
 
/* Define for large files, on AIX-style hosts. */
/* #undef _LARGE_FILES */
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libopenjpeg/opj_includes.h
0,0 → 1,136
/*
* Copyright (c) 2005, Hervé Drolon, FreeImage Team
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef OPJ_INCLUDES_H
#define OPJ_INCLUDES_H
 
/*
==========================================================
Standard includes used by the library
==========================================================
*/
// #include <memory.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <float.h>
#include <time.h>
#include <stdio.h>
#include <stdarg.h>
#include <ctype.h>
 
/*
==========================================================
OpenJPEG interface
==========================================================
*/
#include "openjpeg.h"
 
/*
==========================================================
OpenJPEG modules
==========================================================
*/
 
/* Ignore GCC attributes if this is not GCC */
#ifndef __GNUC__
#define __attribute__(x) /* __attribute__(x) */
#endif
 
/*
The inline keyword is supported by C99 but not by C90.
Most compilers implement their own version of this keyword ...
*/
#ifndef INLINE
#if defined(_MSC_VER)
#define INLINE __forceinline
#elif defined(__GNUC__)
#define INLINE __inline__
#elif defined(__MWERKS__)
#define INLINE inline
#else
/* add other compilers here ... */
#define INLINE
#endif /* defined(<Compiler>) */
#endif /* INLINE */
 
/* Are restricted pointers available? (C99) */
#if (__STDC_VERSION__ != 199901L)
/* Not a C99 compiler */
#ifdef __GNUC__
#define restrict __restrict__
#else
#define restrict /* restrict */
#endif
#endif
 
/* MSVC and Borland C do not have lrintf */
#if defined(_MSC_VER) || defined(__BORLANDC__)
static INLINE long lrintf(float f){
#ifdef _M_X64
return (long)((f>0.0f) ? (f + 0.5f):(f -0.5f));
#else
int i;
_asm{
fld f
fistp i
};
return i;
#endif
}
#endif
 
#include "j2k_lib.h"
#include "opj_malloc.h"
#include "event.h"
#include "cio.h"
 
#include "image.h"
#include "j2k.h"
#include "jp2.h"
#include "jpt.h"
 
#include "mqc.h"
#include "raw.h"
#include "bio.h"
#include "tgt.h"
#include "pi.h"
#include "tcd.h"
#include "t1.h"
#include "dwt.h"
#include "t2.h"
#include "mct.h"
#include "int.h"
#include "fix.h"
 
/* JPWL>> */
#ifdef USE_JPWL
#include "../jpwl/jpwl.h"
#endif /* USE_JPWL */
/* <<JPWL */
 
#endif /* OPJ_INCLUDES_H */
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libopenjpeg/opj_malloc.h
0,0 → 1,166
/*
* Copyright (c) 2005, Hervé Drolon, FreeImage Team
* Copyright (c) 2007, Callum Lerwick <seg@haxxed.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __OPJ_MALLOC_H
#define __OPJ_MALLOC_H
/**
@file opj_malloc.h
@brief Internal functions
 
The functions in opj_malloc.h are internal utilities used for memory management.
*/
 
/** @defgroup MISC MISC - Miscellaneous internal functions */
/*@{*/
 
/** @name Exported functions */
/*@{*/
/* ----------------------------------------------------------------------- */
 
/**
Allocate an uninitialized memory block
@param size Bytes to allocate
@return Returns a void pointer to the allocated space, or NULL if there is insufficient memory available
*/
#ifdef ALLOC_PERF_OPT
void * OPJ_CALLCONV opj_malloc(size_t size);
#else
#define opj_malloc(size) malloc(size)
#endif
 
/**
Allocate a memory block with elements initialized to 0
@param num Blocks to allocate
@param size Bytes per block to allocate
@return Returns a void pointer to the allocated space, or NULL if there is insufficient memory available
*/
#ifdef ALLOC_PERF_OPT
void * OPJ_CALLCONV opj_calloc(size_t _NumOfElements, size_t _SizeOfElements);
#else
#define opj_calloc(num, size) calloc(num, size)
#endif
 
/**
Allocate memory aligned to a 16 byte boundry
@param size Bytes to allocate
@return Returns a void pointer to the allocated space, or NULL if there is insufficient memory available
*/
/* FIXME: These should be set with cmake tests, but we're currently not requiring use of cmake */
#ifdef _WIN32
/* Someone should tell the mingw people that their malloc.h ought to provide _mm_malloc() */
#ifdef __GNUC__
#include <mm_malloc.h>
#define HAVE_MM_MALLOC
#else /* MSVC, Intel C++ */
#include <malloc.h>
#ifdef _mm_malloc
#define HAVE_MM_MALLOC
#endif
#endif
#else /* Not _WIN32 */
 
#if defined(__sun)
#define HAVE_MEMALIGN
/* Linux x86_64 and OSX always align allocations to 16 bytes */
#elif !defined(__amd64__) && !defined(__APPLE__)
// #define HAVE_MEMALIGN
#include <malloc.h>
#endif
#endif
 
#define opj_aligned_malloc(size) malloc(size)
#define opj_aligned_free(m) free(m)
 
#ifdef HAVE_MM_MALLOC
#undef opj_aligned_malloc
#define opj_aligned_malloc(size) _mm_malloc(size, 16)
#undef opj_aligned_free
#define opj_aligned_free(m) _mm_free(m)
#endif
 
#undef HAVE_MEMALIGN
#ifdef HAVE_MEMALIGN
extern void* memalign(size_t, size_t);
#undef opj_aligned_malloc
#define opj_aligned_malloc(size) memalign(16, (size))
#undef opj_aligned_free
#define opj_aligned_free(m) free(m)
#endif
 
#undef HAVE_POSIX_MEMALIGN
#ifdef HAVE_POSIX_MEMALIGN
#undef opj_aligned_malloc
extern int posix_memalign(void**, size_t, size_t);
 
static INLINE void* __attribute__ ((malloc)) opj_aligned_malloc(size_t size){
void* mem = NULL;
posix_memalign(&mem, 16, size);
return mem;
}
#undef opj_aligned_free
#define opj_aligned_free(m) free(m)
#endif
 
#ifdef ALLOC_PERF_OPT
#undef opj_aligned_malloc
#define opj_aligned_malloc(size) opj_malloc(size)
#undef opj_aligned_free
#define opj_aligned_free(m) opj_free(m)
#endif
 
/**
Reallocate memory blocks.
@param m Pointer to previously allocated memory block
@param s New size in bytes
@return Returns a void pointer to the reallocated (and possibly moved) memory block
*/
#ifdef ALLOC_PERF_OPT
void * OPJ_CALLCONV opj_realloc(void * m, size_t s);
#else
#define opj_realloc(m, s) realloc(m, s)
#endif
 
/**
Deallocates or frees a memory block.
@param m Previously allocated memory block to be freed
*/
#ifdef ALLOC_PERF_OPT
void OPJ_CALLCONV opj_free(void * m);
#else
#define opj_free(m) free(m)
#endif
 
#ifdef __GNUC__
#pragma GCC poison malloc calloc realloc free
#endif
 
/* ----------------------------------------------------------------------- */
/*@}*/
 
/*@}*/
 
#endif /* __OPJ_MALLOC_H */
 
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libopenjpeg/pi.c
0,0 → 1,963
/*
* Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2007, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2006-2007, Parvatha Elangovan
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
 
#include "opj_includes.h"
 
/** @defgroup PI PI - Implementation of a packet iterator */
/*@{*/
 
/** @name Local static functions */
/*@{*/
 
/**
Get next packet in layer-resolution-component-precinct order.
@param pi packet iterator to modify
@return returns false if pi pointed to the last packet or else returns true
*/
static bool pi_next_lrcp(opj_pi_iterator_t * pi);
/**
Get next packet in resolution-layer-component-precinct order.
@param pi packet iterator to modify
@return returns false if pi pointed to the last packet or else returns true
*/
static bool pi_next_rlcp(opj_pi_iterator_t * pi);
/**
Get next packet in resolution-precinct-component-layer order.
@param pi packet iterator to modify
@return returns false if pi pointed to the last packet or else returns true
*/
static bool pi_next_rpcl(opj_pi_iterator_t * pi);
/**
Get next packet in precinct-component-resolution-layer order.
@param pi packet iterator to modify
@return returns false if pi pointed to the last packet or else returns true
*/
static bool pi_next_pcrl(opj_pi_iterator_t * pi);
/**
Get next packet in component-precinct-resolution-layer order.
@param pi packet iterator to modify
@return returns false if pi pointed to the last packet or else returns true
*/
static bool pi_next_cprl(opj_pi_iterator_t * pi);
 
/*@}*/
 
/*@}*/
 
/*
==========================================================
local functions
==========================================================
*/
 
static bool pi_next_lrcp(opj_pi_iterator_t * pi) {
opj_pi_comp_t *comp = NULL;
opj_pi_resolution_t *res = NULL;
long index = 0;
if (!pi->first) {
comp = &pi->comps[pi->compno];
res = &comp->resolutions[pi->resno];
goto LABEL_SKIP;
} else {
pi->first = 0;
}
 
for (pi->layno = pi->poc.layno0; pi->layno < pi->poc.layno1; pi->layno++) {
for (pi->resno = pi->poc.resno0; pi->resno < pi->poc.resno1;
pi->resno++) {
for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) {
comp = &pi->comps[pi->compno];
if (pi->resno >= comp->numresolutions) {
continue;
}
res = &comp->resolutions[pi->resno];
if (!pi->tp_on){
pi->poc.precno1 = res->pw * res->ph;
}
for (pi->precno = pi->poc.precno0; pi->precno < pi->poc.precno1; pi->precno++) {
index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p;
if (!pi->include[index]) {
pi->include[index] = 1;
return true;
}
LABEL_SKIP:;
}
}
}
}
return false;
}
 
static bool pi_next_rlcp(opj_pi_iterator_t * pi) {
opj_pi_comp_t *comp = NULL;
opj_pi_resolution_t *res = NULL;
long index = 0;
 
if (!pi->first) {
comp = &pi->comps[pi->compno];
res = &comp->resolutions[pi->resno];
goto LABEL_SKIP;
} else {
pi->first = 0;
}
 
for (pi->resno = pi->poc.resno0; pi->resno < pi->poc.resno1; pi->resno++) {
for (pi->layno = pi->poc.layno0; pi->layno < pi->poc.layno1; pi->layno++) {
for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) {
comp = &pi->comps[pi->compno];
if (pi->resno >= comp->numresolutions) {
continue;
}
res = &comp->resolutions[pi->resno];
if(!pi->tp_on){
pi->poc.precno1 = res->pw * res->ph;
}
for (pi->precno = pi->poc.precno0; pi->precno < pi->poc.precno1; pi->precno++) {
index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p;
if (!pi->include[index]) {
pi->include[index] = 1;
return true;
}
LABEL_SKIP:;
}
}
}
}
return false;
}
 
static bool pi_next_rpcl(opj_pi_iterator_t * pi) {
opj_pi_comp_t *comp = NULL;
opj_pi_resolution_t *res = NULL;
long index = 0;
 
if (!pi->first) {
goto LABEL_SKIP;
} else {
int compno, resno;
pi->first = 0;
pi->dx = 0;
pi->dy = 0;
for (compno = 0; compno < pi->numcomps; compno++) {
comp = &pi->comps[compno];
for (resno = 0; resno < comp->numresolutions; resno++) {
int dx, dy;
res = &comp->resolutions[resno];
dx = comp->dx * (1 << (res->pdx + comp->numresolutions - 1 - resno));
dy = comp->dy * (1 << (res->pdy + comp->numresolutions - 1 - resno));
pi->dx = !pi->dx ? dx : int_min(pi->dx, dx);
pi->dy = !pi->dy ? dy : int_min(pi->dy, dy);
}
}
}
if (!pi->tp_on){
pi->poc.ty0 = pi->ty0;
pi->poc.tx0 = pi->tx0;
pi->poc.ty1 = pi->ty1;
pi->poc.tx1 = pi->tx1;
}
for (pi->resno = pi->poc.resno0; pi->resno < pi->poc.resno1; pi->resno++) {
for (pi->y = pi->poc.ty0; pi->y < pi->poc.ty1; pi->y += pi->dy - (pi->y % pi->dy)) {
for (pi->x = pi->poc.tx0; pi->x < pi->poc.tx1; pi->x += pi->dx - (pi->x % pi->dx)) {
for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) {
int levelno;
int trx0, try0;
int trx1, try1;
int rpx, rpy;
int prci, prcj;
comp = &pi->comps[pi->compno];
if (pi->resno >= comp->numresolutions) {
continue;
}
res = &comp->resolutions[pi->resno];
levelno = comp->numresolutions - 1 - pi->resno;
trx0 = int_ceildiv(pi->tx0, comp->dx << levelno);
try0 = int_ceildiv(pi->ty0, comp->dy << levelno);
trx1 = int_ceildiv(pi->tx1, comp->dx << levelno);
try1 = int_ceildiv(pi->ty1, comp->dy << levelno);
rpx = res->pdx + levelno;
rpy = res->pdy + levelno;
if (!((pi->y % (comp->dy << rpy) == 0) || ((pi->y == pi->ty0) && ((try0 << levelno) % (1 << rpy))))){
continue;
}
if (!((pi->x % (comp->dx << rpx) == 0) || ((pi->x == pi->tx0) && ((trx0 << levelno) % (1 << rpx))))){
continue;
}
if ((res->pw==0)||(res->ph==0)) continue;
if ((trx0==trx1)||(try0==try1)) continue;
prci = int_floordivpow2(int_ceildiv(pi->x, comp->dx << levelno), res->pdx)
- int_floordivpow2(trx0, res->pdx);
prcj = int_floordivpow2(int_ceildiv(pi->y, comp->dy << levelno), res->pdy)
- int_floordivpow2(try0, res->pdy);
pi->precno = prci + prcj * res->pw;
for (pi->layno = pi->poc.layno0; pi->layno < pi->poc.layno1; pi->layno++) {
index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p;
if (!pi->include[index]) {
pi->include[index] = 1;
return true;
}
LABEL_SKIP:;
}
}
}
}
}
return false;
}
 
static bool pi_next_pcrl(opj_pi_iterator_t * pi) {
opj_pi_comp_t *comp = NULL;
opj_pi_resolution_t *res = NULL;
long index = 0;
 
if (!pi->first) {
comp = &pi->comps[pi->compno];
goto LABEL_SKIP;
} else {
int compno, resno;
pi->first = 0;
pi->dx = 0;
pi->dy = 0;
for (compno = 0; compno < pi->numcomps; compno++) {
comp = &pi->comps[compno];
for (resno = 0; resno < comp->numresolutions; resno++) {
int dx, dy;
res = &comp->resolutions[resno];
dx = comp->dx * (1 << (res->pdx + comp->numresolutions - 1 - resno));
dy = comp->dy * (1 << (res->pdy + comp->numresolutions - 1 - resno));
pi->dx = !pi->dx ? dx : int_min(pi->dx, dx);
pi->dy = !pi->dy ? dy : int_min(pi->dy, dy);
}
}
}
if (!pi->tp_on){
pi->poc.ty0 = pi->ty0;
pi->poc.tx0 = pi->tx0;
pi->poc.ty1 = pi->ty1;
pi->poc.tx1 = pi->tx1;
}
for (pi->y = pi->poc.ty0; pi->y < pi->poc.ty1; pi->y += pi->dy - (pi->y % pi->dy)) {
for (pi->x = pi->poc.tx0; pi->x < pi->poc.tx1; pi->x += pi->dx - (pi->x % pi->dx)) {
for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) {
comp = &pi->comps[pi->compno];
for (pi->resno = pi->poc.resno0; pi->resno < int_min(pi->poc.resno1, comp->numresolutions); pi->resno++) {
int levelno;
int trx0, try0;
int trx1, try1;
int rpx, rpy;
int prci, prcj;
res = &comp->resolutions[pi->resno];
levelno = comp->numresolutions - 1 - pi->resno;
trx0 = int_ceildiv(pi->tx0, comp->dx << levelno);
try0 = int_ceildiv(pi->ty0, comp->dy << levelno);
trx1 = int_ceildiv(pi->tx1, comp->dx << levelno);
try1 = int_ceildiv(pi->ty1, comp->dy << levelno);
rpx = res->pdx + levelno;
rpy = res->pdy + levelno;
if (!((pi->y % (comp->dy << rpy) == 0) || ((pi->y == pi->ty0) && ((try0 << levelno) % (1 << rpy))))){
continue;
}
if (!((pi->x % (comp->dx << rpx) == 0) || ((pi->x == pi->tx0) && ((trx0 << levelno) % (1 << rpx))))){
continue;
}
if ((res->pw==0)||(res->ph==0)) continue;
if ((trx0==trx1)||(try0==try1)) continue;
prci = int_floordivpow2(int_ceildiv(pi->x, comp->dx << levelno), res->pdx)
- int_floordivpow2(trx0, res->pdx);
prcj = int_floordivpow2(int_ceildiv(pi->y, comp->dy << levelno), res->pdy)
- int_floordivpow2(try0, res->pdy);
pi->precno = prci + prcj * res->pw;
for (pi->layno = pi->poc.layno0; pi->layno < pi->poc.layno1; pi->layno++) {
index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p;
if (!pi->include[index]) {
pi->include[index] = 1;
return true;
}
LABEL_SKIP:;
}
}
}
}
}
return false;
}
 
static bool pi_next_cprl(opj_pi_iterator_t * pi) {
opj_pi_comp_t *comp = NULL;
opj_pi_resolution_t *res = NULL;
long index = 0;
 
if (!pi->first) {
comp = &pi->comps[pi->compno];
goto LABEL_SKIP;
} else {
pi->first = 0;
}
 
for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) {
int resno;
comp = &pi->comps[pi->compno];
pi->dx = 0;
pi->dy = 0;
for (resno = 0; resno < comp->numresolutions; resno++) {
int dx, dy;
res = &comp->resolutions[resno];
dx = comp->dx * (1 << (res->pdx + comp->numresolutions - 1 - resno));
dy = comp->dy * (1 << (res->pdy + comp->numresolutions - 1 - resno));
pi->dx = !pi->dx ? dx : int_min(pi->dx, dx);
pi->dy = !pi->dy ? dy : int_min(pi->dy, dy);
}
if (!pi->tp_on){
pi->poc.ty0 = pi->ty0;
pi->poc.tx0 = pi->tx0;
pi->poc.ty1 = pi->ty1;
pi->poc.tx1 = pi->tx1;
}
for (pi->y = pi->poc.ty0; pi->y < pi->poc.ty1; pi->y += pi->dy - (pi->y % pi->dy)) {
for (pi->x = pi->poc.tx0; pi->x < pi->poc.tx1; pi->x += pi->dx - (pi->x % pi->dx)) {
for (pi->resno = pi->poc.resno0; pi->resno < int_min(pi->poc.resno1, comp->numresolutions); pi->resno++) {
int levelno;
int trx0, try0;
int trx1, try1;
int rpx, rpy;
int prci, prcj;
res = &comp->resolutions[pi->resno];
levelno = comp->numresolutions - 1 - pi->resno;
trx0 = int_ceildiv(pi->tx0, comp->dx << levelno);
try0 = int_ceildiv(pi->ty0, comp->dy << levelno);
trx1 = int_ceildiv(pi->tx1, comp->dx << levelno);
try1 = int_ceildiv(pi->ty1, comp->dy << levelno);
rpx = res->pdx + levelno;
rpy = res->pdy + levelno;
if (!((pi->y % (comp->dy << rpy) == 0) || ((pi->y == pi->ty0) && ((try0 << levelno) % (1 << rpy))))){
continue;
}
if (!((pi->x % (comp->dx << rpx) == 0) || ((pi->x == pi->tx0) && ((trx0 << levelno) % (1 << rpx))))){
continue;
}
if ((res->pw==0)||(res->ph==0)) continue;
if ((trx0==trx1)||(try0==try1)) continue;
prci = int_floordivpow2(int_ceildiv(pi->x, comp->dx << levelno), res->pdx)
- int_floordivpow2(trx0, res->pdx);
prcj = int_floordivpow2(int_ceildiv(pi->y, comp->dy << levelno), res->pdy)
- int_floordivpow2(try0, res->pdy);
pi->precno = prci + prcj * res->pw;
for (pi->layno = pi->poc.layno0; pi->layno < pi->poc.layno1; pi->layno++) {
index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p;
if (!pi->include[index]) {
pi->include[index] = 1;
return true;
}
LABEL_SKIP:;
}
}
}
}
}
return false;
}
 
/*
==========================================================
Packet iterator interface
==========================================================
*/
 
opj_pi_iterator_t *pi_create_decode(opj_image_t *image, opj_cp_t *cp, int tileno) {
int p, q;
int compno, resno, pino;
opj_pi_iterator_t *pi = NULL;
opj_tcp_t *tcp = NULL;
opj_tccp_t *tccp = NULL;
 
tcp = &cp->tcps[tileno];
 
pi = (opj_pi_iterator_t*) opj_calloc((tcp->numpocs + 1), sizeof(opj_pi_iterator_t));
if(!pi) {
/* TODO: throw an error */
return NULL;
}
 
for (pino = 0; pino < tcp->numpocs + 1; pino++) { /* change */
int maxres = 0;
int maxprec = 0;
p = tileno % cp->tw;
q = tileno / cp->tw;
 
pi[pino].tx0 = int_max(cp->tx0 + p * cp->tdx, image->x0);
pi[pino].ty0 = int_max(cp->ty0 + q * cp->tdy, image->y0);
pi[pino].tx1 = int_min(cp->tx0 + (p + 1) * cp->tdx, image->x1);
pi[pino].ty1 = int_min(cp->ty0 + (q + 1) * cp->tdy, image->y1);
pi[pino].numcomps = image->numcomps;
 
pi[pino].comps = (opj_pi_comp_t*) opj_calloc(image->numcomps, sizeof(opj_pi_comp_t));
if(!pi[pino].comps) {
/* TODO: throw an error */
pi_destroy(pi, cp, tileno);
return NULL;
}
for (compno = 0; compno < pi->numcomps; compno++) {
int tcx0, tcy0, tcx1, tcy1;
opj_pi_comp_t *comp = &pi[pino].comps[compno];
tccp = &tcp->tccps[compno];
comp->dx = image->comps[compno].dx;
comp->dy = image->comps[compno].dy;
comp->numresolutions = tccp->numresolutions;
 
comp->resolutions = (opj_pi_resolution_t*) opj_calloc(comp->numresolutions, sizeof(opj_pi_resolution_t));
if(!comp->resolutions) {
/* TODO: throw an error */
pi_destroy(pi, cp, tileno);
return NULL;
}
 
tcx0 = int_ceildiv(pi->tx0, comp->dx);
tcy0 = int_ceildiv(pi->ty0, comp->dy);
tcx1 = int_ceildiv(pi->tx1, comp->dx);
tcy1 = int_ceildiv(pi->ty1, comp->dy);
if (comp->numresolutions > maxres) {
maxres = comp->numresolutions;
}
 
for (resno = 0; resno < comp->numresolutions; resno++) {
int levelno;
int rx0, ry0, rx1, ry1;
int px0, py0, px1, py1;
opj_pi_resolution_t *res = &comp->resolutions[resno];
if (tccp->csty & J2K_CCP_CSTY_PRT) {
res->pdx = tccp->prcw[resno];
res->pdy = tccp->prch[resno];
} else {
res->pdx = 15;
res->pdy = 15;
}
levelno = comp->numresolutions - 1 - resno;
rx0 = int_ceildivpow2(tcx0, levelno);
ry0 = int_ceildivpow2(tcy0, levelno);
rx1 = int_ceildivpow2(tcx1, levelno);
ry1 = int_ceildivpow2(tcy1, levelno);
px0 = int_floordivpow2(rx0, res->pdx) << res->pdx;
py0 = int_floordivpow2(ry0, res->pdy) << res->pdy;
px1 = int_ceildivpow2(rx1, res->pdx) << res->pdx;
py1 = int_ceildivpow2(ry1, res->pdy) << res->pdy;
res->pw = (rx0==rx1)?0:((px1 - px0) >> res->pdx);
res->ph = (ry0==ry1)?0:((py1 - py0) >> res->pdy);
if (res->pw*res->ph > maxprec) {
maxprec = res->pw*res->ph;
}
}
}
tccp = &tcp->tccps[0];
pi[pino].step_p = 1;
pi[pino].step_c = maxprec * pi[pino].step_p;
pi[pino].step_r = image->numcomps * pi[pino].step_c;
pi[pino].step_l = maxres * pi[pino].step_r;
if (pino == 0) {
pi[pino].include = (short int*) opj_calloc(image->numcomps * maxres * tcp->numlayers * maxprec, sizeof(short int));
if(!pi[pino].include) {
/* TODO: throw an error */
pi_destroy(pi, cp, tileno);
return NULL;
}
}
else {
pi[pino].include = pi[pino - 1].include;
}
if (tcp->POC == 0) {
pi[pino].first = 1;
pi[pino].poc.resno0 = 0;
pi[pino].poc.compno0 = 0;
pi[pino].poc.layno1 = tcp->numlayers;
pi[pino].poc.resno1 = maxres;
pi[pino].poc.compno1 = image->numcomps;
pi[pino].poc.prg = tcp->prg;
} else {
pi[pino].first = 1;
pi[pino].poc.resno0 = tcp->pocs[pino].resno0;
pi[pino].poc.compno0 = tcp->pocs[pino].compno0;
pi[pino].poc.layno1 = tcp->pocs[pino].layno1;
pi[pino].poc.resno1 = tcp->pocs[pino].resno1;
pi[pino].poc.compno1 = tcp->pocs[pino].compno1;
pi[pino].poc.prg = tcp->pocs[pino].prg;
}
pi[pino].poc.layno0 = 0;
pi[pino].poc.precno0 = 0;
pi[pino].poc.precno1 = maxprec;
}
return pi;
}
 
 
opj_pi_iterator_t *pi_initialise_encode(opj_image_t *image, opj_cp_t *cp, int tileno, J2K_T2_MODE t2_mode){
int p, q, pino;
int compno, resno;
int maxres = 0;
int maxprec = 0;
opj_pi_iterator_t *pi = NULL;
opj_tcp_t *tcp = NULL;
opj_tccp_t *tccp = NULL;
tcp = &cp->tcps[tileno];
 
pi = (opj_pi_iterator_t*) opj_calloc((tcp->numpocs + 1), sizeof(opj_pi_iterator_t));
if(!pi) { return NULL;}
pi->tp_on = cp->tp_on;
 
for(pino = 0;pino < tcp->numpocs+1 ; pino ++){
p = tileno % cp->tw;
q = tileno / cp->tw;
 
pi[pino].tx0 = int_max(cp->tx0 + p * cp->tdx, image->x0);
pi[pino].ty0 = int_max(cp->ty0 + q * cp->tdy, image->y0);
pi[pino].tx1 = int_min(cp->tx0 + (p + 1) * cp->tdx, image->x1);
pi[pino].ty1 = int_min(cp->ty0 + (q + 1) * cp->tdy, image->y1);
pi[pino].numcomps = image->numcomps;
pi[pino].comps = (opj_pi_comp_t*) opj_calloc(image->numcomps, sizeof(opj_pi_comp_t));
if(!pi[pino].comps) {
pi_destroy(pi, cp, tileno);
return NULL;
}
for (compno = 0; compno < pi[pino].numcomps; compno++) {
int tcx0, tcy0, tcx1, tcy1;
opj_pi_comp_t *comp = &pi[pino].comps[compno];
tccp = &tcp->tccps[compno];
comp->dx = image->comps[compno].dx;
comp->dy = image->comps[compno].dy;
comp->numresolutions = tccp->numresolutions;
 
comp->resolutions = (opj_pi_resolution_t*) opj_malloc(comp->numresolutions * sizeof(opj_pi_resolution_t));
if(!comp->resolutions) {
pi_destroy(pi, cp, tileno);
return NULL;
}
 
tcx0 = int_ceildiv(pi[pino].tx0, comp->dx);
tcy0 = int_ceildiv(pi[pino].ty0, comp->dy);
tcx1 = int_ceildiv(pi[pino].tx1, comp->dx);
tcy1 = int_ceildiv(pi[pino].ty1, comp->dy);
if (comp->numresolutions > maxres) {
maxres = comp->numresolutions;
}
 
for (resno = 0; resno < comp->numresolutions; resno++) {
int levelno;
int rx0, ry0, rx1, ry1;
int px0, py0, px1, py1;
opj_pi_resolution_t *res = &comp->resolutions[resno];
if (tccp->csty & J2K_CCP_CSTY_PRT) {
res->pdx = tccp->prcw[resno];
res->pdy = tccp->prch[resno];
} else {
res->pdx = 15;
res->pdy = 15;
}
levelno = comp->numresolutions - 1 - resno;
rx0 = int_ceildivpow2(tcx0, levelno);
ry0 = int_ceildivpow2(tcy0, levelno);
rx1 = int_ceildivpow2(tcx1, levelno);
ry1 = int_ceildivpow2(tcy1, levelno);
px0 = int_floordivpow2(rx0, res->pdx) << res->pdx;
py0 = int_floordivpow2(ry0, res->pdy) << res->pdy;
px1 = int_ceildivpow2(rx1, res->pdx) << res->pdx;
py1 = int_ceildivpow2(ry1, res->pdy) << res->pdy;
res->pw = (rx0==rx1)?0:((px1 - px0) >> res->pdx);
res->ph = (ry0==ry1)?0:((py1 - py0) >> res->pdy);
 
if (res->pw*res->ph > maxprec) {
maxprec = res->pw * res->ph;
}
}
}
tccp = &tcp->tccps[0];
pi[pino].step_p = 1;
pi[pino].step_c = maxprec * pi[pino].step_p;
pi[pino].step_r = image->numcomps * pi[pino].step_c;
pi[pino].step_l = maxres * pi[pino].step_r;
for (compno = 0; compno < pi->numcomps; compno++) {
opj_pi_comp_t *comp = &pi->comps[compno];
for (resno = 0; resno < comp->numresolutions; resno++) {
int dx, dy;
opj_pi_resolution_t *res = &comp->resolutions[resno];
dx = comp->dx * (1 << (res->pdx + comp->numresolutions - 1 - resno));
dy = comp->dy * (1 << (res->pdy + comp->numresolutions - 1 - resno));
pi[pino].dx = !pi->dx ? dx : int_min(pi->dx, dx);
pi[pino].dy = !pi->dy ? dy : int_min(pi->dy, dy);
}
}
 
if (pino == 0) {
pi[pino].include = (short int*) opj_calloc(tcp->numlayers * pi[pino].step_l, sizeof(short int));
if(!pi[pino].include) {
pi_destroy(pi, cp, tileno);
return NULL;
}
}
else {
pi[pino].include = pi[pino - 1].include;
}
/* Generation of boundaries for each prog flag*/
if(tcp->POC && ( cp->cinema || ((!cp->cinema) && (t2_mode == FINAL_PASS)))){
tcp->pocs[pino].compS= tcp->pocs[pino].compno0;
tcp->pocs[pino].compE= tcp->pocs[pino].compno1;
tcp->pocs[pino].resS = tcp->pocs[pino].resno0;
tcp->pocs[pino].resE = tcp->pocs[pino].resno1;
tcp->pocs[pino].layE = tcp->pocs[pino].layno1;
tcp->pocs[pino].prg = tcp->pocs[pino].prg1;
if (pino > 0)
tcp->pocs[pino].layS = (tcp->pocs[pino].layE > tcp->pocs[pino - 1].layE) ? tcp->pocs[pino - 1].layE : 0;
}else {
tcp->pocs[pino].compS= 0;
tcp->pocs[pino].compE= image->numcomps;
tcp->pocs[pino].resS = 0;
tcp->pocs[pino].resE = maxres;
tcp->pocs[pino].layS = 0;
tcp->pocs[pino].layE = tcp->numlayers;
tcp->pocs[pino].prg = tcp->prg;
}
tcp->pocs[pino].prcS = 0;
tcp->pocs[pino].prcE = maxprec;;
tcp->pocs[pino].txS = pi[pino].tx0;
tcp->pocs[pino].txE = pi[pino].tx1;
tcp->pocs[pino].tyS = pi[pino].ty0;
tcp->pocs[pino].tyE = pi[pino].ty1;
tcp->pocs[pino].dx = pi[pino].dx;
tcp->pocs[pino].dy = pi[pino].dy;
}
return pi;
}
 
 
 
void pi_destroy(opj_pi_iterator_t *pi, opj_cp_t *cp, int tileno) {
int compno, pino;
opj_tcp_t *tcp = &cp->tcps[tileno];
if(pi) {
for (pino = 0; pino < tcp->numpocs + 1; pino++) {
if(pi[pino].comps) {
for (compno = 0; compno < pi->numcomps; compno++) {
opj_pi_comp_t *comp = &pi[pino].comps[compno];
if(comp->resolutions) {
opj_free(comp->resolutions);
}
}
opj_free(pi[pino].comps);
}
}
if(pi->include) {
opj_free(pi->include);
}
opj_free(pi);
}
}
 
bool pi_next(opj_pi_iterator_t * pi) {
switch (pi->poc.prg) {
case LRCP:
return pi_next_lrcp(pi);
case RLCP:
return pi_next_rlcp(pi);
case RPCL:
return pi_next_rpcl(pi);
case PCRL:
return pi_next_pcrl(pi);
case CPRL:
return pi_next_cprl(pi);
case PROG_UNKNOWN:
return false;
}
return false;
}
 
bool pi_create_encode( opj_pi_iterator_t *pi, opj_cp_t *cp,int tileno, int pino,int tpnum, int tppos, J2K_T2_MODE t2_mode,int cur_totnum_tp){
char prog[4];
int i;
int incr_top=1,resetX=0;
opj_tcp_t *tcps =&cp->tcps[tileno];
opj_poc_t *tcp= &tcps->pocs[pino];
 
pi[pino].first = 1;
pi[pino].poc.prg = tcp->prg;
 
switch(tcp->prg){
case CPRL: strncpy(prog, "CPRL",4);
break;
case LRCP: strncpy(prog, "LRCP",4);
break;
case PCRL: strncpy(prog, "PCRL",4);
break;
case RLCP: strncpy(prog, "RLCP",4);
break;
case RPCL: strncpy(prog, "RPCL",4);
break;
case PROG_UNKNOWN:
return true;
}
 
if(!(cp->tp_on && ((!cp->cinema && (t2_mode == FINAL_PASS)) || cp->cinema))){
pi[pino].poc.resno0 = tcp->resS;
pi[pino].poc.resno1 = tcp->resE;
pi[pino].poc.compno0 = tcp->compS;
pi[pino].poc.compno1 = tcp->compE;
pi[pino].poc.layno0 = tcp->layS;
pi[pino].poc.layno1 = tcp->layE;
pi[pino].poc.precno0 = tcp->prcS;
pi[pino].poc.precno1 = tcp->prcE;
pi[pino].poc.tx0 = tcp->txS;
pi[pino].poc.ty0 = tcp->tyS;
pi[pino].poc.tx1 = tcp->txE;
pi[pino].poc.ty1 = tcp->tyE;
}else {
if( tpnum < cur_totnum_tp){
for(i=3;i>=0;i--){
switch(prog[i]){
case 'C':
if (i > tppos){
pi[pino].poc.compno0 = tcp->compS;
pi[pino].poc.compno1 = tcp->compE;
}else{
if (tpnum == 0){
tcp->comp_t = tcp->compS;
pi[pino].poc.compno0 = tcp->comp_t;
pi[pino].poc.compno1 = tcp->comp_t+1;
tcp->comp_t+=1;
}else{
if (incr_top == 1){
if(tcp->comp_t ==tcp->compE){
tcp->comp_t = tcp->compS;
pi[pino].poc.compno0 = tcp->comp_t;
pi[pino].poc.compno1 = tcp->comp_t+1;
tcp->comp_t+=1;
incr_top=1;
}else{
pi[pino].poc.compno0 = tcp->comp_t;
pi[pino].poc.compno1 = tcp->comp_t+1;
tcp->comp_t+=1;
incr_top=0;
}
}else{
pi[pino].poc.compno0 = tcp->comp_t-1;
pi[pino].poc.compno1 = tcp->comp_t;
}
}
}
break;
 
case 'R':
if (i > tppos){
pi[pino].poc.resno0 = tcp->resS;
pi[pino].poc.resno1 = tcp->resE;
}else{
if (tpnum == 0){
tcp->res_t = tcp->resS;
pi[pino].poc.resno0 = tcp->res_t;
pi[pino].poc.resno1 = tcp->res_t+1;
tcp->res_t+=1;
}else{
if (incr_top == 1){
if(tcp->res_t==tcp->resE){
tcp->res_t = tcp->resS;
pi[pino].poc.resno0 = tcp->res_t;
pi[pino].poc.resno1 = tcp->res_t+1;
tcp->res_t+=1;
incr_top=1;
}else{
pi[pino].poc.resno0 = tcp->res_t;
pi[pino].poc.resno1 = tcp->res_t+1;
tcp->res_t+=1;
incr_top=0;
}
}else{
pi[pino].poc.resno0 = tcp->res_t - 1;
pi[pino].poc.resno1 = tcp->res_t;
}
}
}
break;
 
case 'L':
if (i > tppos){
pi[pino].poc.layno0 = tcp->layS;
pi[pino].poc.layno1 = tcp->layE;
}else{
if (tpnum == 0){
tcp->lay_t = tcp->layS;
pi[pino].poc.layno0 = tcp->lay_t;
pi[pino].poc.layno1 = tcp->lay_t+1;
tcp->lay_t+=1;
}else{
if (incr_top == 1){
if(tcp->lay_t == tcp->layE){
tcp->lay_t = tcp->layS;
pi[pino].poc.layno0 = tcp->lay_t;
pi[pino].poc.layno1 = tcp->lay_t+1;
tcp->lay_t+=1;
incr_top=1;
}else{
pi[pino].poc.layno0 = tcp->lay_t;
pi[pino].poc.layno1 = tcp->lay_t+1;
tcp->lay_t+=1;
incr_top=0;
}
}else{
pi[pino].poc.layno0 = tcp->lay_t - 1;
pi[pino].poc.layno1 = tcp->lay_t;
}
}
}
break;
 
case 'P':
switch(tcp->prg){
case LRCP:
case RLCP:
if (i > tppos){
pi[pino].poc.precno0 = tcp->prcS;
pi[pino].poc.precno1 = tcp->prcE;
}else{
if (tpnum == 0){
tcp->prc_t = tcp->prcS;
pi[pino].poc.precno0 = tcp->prc_t;
pi[pino].poc.precno1 = tcp->prc_t+1;
tcp->prc_t+=1;
}else{
if (incr_top == 1){
if(tcp->prc_t == tcp->prcE){
tcp->prc_t = tcp->prcS;
pi[pino].poc.precno0 = tcp->prc_t;
pi[pino].poc.precno1 = tcp->prc_t+1;
tcp->prc_t+=1;
incr_top=1;
}else{
pi[pino].poc.precno0 = tcp->prc_t;
pi[pino].poc.precno1 = tcp->prc_t+1;
tcp->prc_t+=1;
incr_top=0;
}
}else{
pi[pino].poc.precno0 = tcp->prc_t - 1;
pi[pino].poc.precno1 = tcp->prc_t;
}
}
}
break;
default:
if (i > tppos){
pi[pino].poc.tx0 = tcp->txS;
pi[pino].poc.ty0 = tcp->tyS;
pi[pino].poc.tx1 = tcp->txE;
pi[pino].poc.ty1 = tcp->tyE;
}else{
if (tpnum == 0){
tcp->tx0_t = tcp->txS;
tcp->ty0_t = tcp->tyS;
pi[pino].poc.tx0 = tcp->tx0_t;
pi[pino].poc.tx1 = tcp->tx0_t + tcp->dx - (tcp->tx0_t % tcp->dx);
pi[pino].poc.ty0 = tcp->ty0_t;
pi[pino].poc.ty1 = tcp->ty0_t + tcp->dy - (tcp->ty0_t % tcp->dy);
tcp->tx0_t = pi[pino].poc.tx1;
tcp->ty0_t = pi[pino].poc.ty1;
}else{
if (incr_top == 1){
if(tcp->tx0_t >= tcp->txE){
if(tcp->ty0_t >= tcp->tyE){
tcp->ty0_t = tcp->tyS;
pi[pino].poc.ty0 = tcp->ty0_t;
pi[pino].poc.ty1 = tcp->ty0_t + tcp->dy - (tcp->ty0_t % tcp->dy);
tcp->ty0_t = pi[pino].poc.ty1;
incr_top=1;resetX=1;
}else{
pi[pino].poc.ty0 = tcp->ty0_t;
pi[pino].poc.ty1 = tcp->ty0_t + tcp->dy - (tcp->ty0_t % tcp->dy);
tcp->ty0_t = pi[pino].poc.ty1;
incr_top=0;resetX=1;
}
if(resetX==1){
tcp->tx0_t = tcp->txS;
pi[pino].poc.tx0 = tcp->tx0_t;
pi[pino].poc.tx1 = tcp->tx0_t + tcp->dx- (tcp->tx0_t % tcp->dx);
tcp->tx0_t = pi[pino].poc.tx1;
}
}else{
pi[pino].poc.tx0 = tcp->tx0_t;
pi[pino].poc.tx1 = tcp->tx0_t + tcp->dx- (tcp->tx0_t % tcp->dx);
tcp->tx0_t = pi[pino].poc.tx1;
pi[pino].poc.ty0 = tcp->ty0_t - tcp->dy - (tcp->ty0_t % tcp->dy);
pi[pino].poc.ty1 = tcp->ty0_t ;
incr_top=0;
}
}else{
pi[pino].poc.tx0 = tcp->tx0_t - tcp->dx - (tcp->tx0_t % tcp->dx);
pi[pino].poc.tx1 = tcp->tx0_t ;
pi[pino].poc.ty0 = tcp->ty0_t - tcp->dy - (tcp->ty0_t % tcp->dy);
pi[pino].poc.ty1 = tcp->ty0_t ;
}
}
}
break;
}
break;
}
}
}
}
return false;
}
 
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libopenjpeg/pi.h
0,0 → 1,156
/*
* Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2007, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
 
#ifndef __PI_H
#define __PI_H
/**
@file pi.h
@brief Implementation of a packet iterator (PI)
 
The functions in PI.C have for goal to realize a packet iterator that permits to get the next
packet following the progression order and change of it. The functions in PI.C are used
by some function in T2.C.
*/
 
/** @defgroup PI PI - Implementation of a packet iterator */
/*@{*/
 
/**
FIXME: documentation
*/
typedef struct opj_pi_resolution {
int pdx, pdy;
int pw, ph;
} opj_pi_resolution_t;
 
/**
FIXME: documentation
*/
typedef struct opj_pi_comp {
int dx, dy;
/** number of resolution levels */
int numresolutions;
opj_pi_resolution_t *resolutions;
} opj_pi_comp_t;
 
/**
Packet iterator
*/
typedef struct opj_pi_iterator {
/** Enabling Tile part generation*/
char tp_on;
/** precise if the packet has been already used (usefull for progression order change) */
short int *include;
/** layer step used to localize the packet in the include vector */
int step_l;
/** resolution step used to localize the packet in the include vector */
int step_r;
/** component step used to localize the packet in the include vector */
int step_c;
/** precinct step used to localize the packet in the include vector */
int step_p;
/** component that identify the packet */
int compno;
/** resolution that identify the packet */
int resno;
/** precinct that identify the packet */
int precno;
/** layer that identify the packet */
int layno;
/** 0 if the first packet */
int first;
/** progression order change information */
opj_poc_t poc;
/** number of components in the image */
int numcomps;
/** Components*/
opj_pi_comp_t *comps;
int tx0, ty0, tx1, ty1;
int x, y, dx, dy;
} opj_pi_iterator_t;
 
/** @name Exported functions */
/*@{*/
/* ----------------------------------------------------------------------- */
/**
Create a packet iterator for Encoder
@param image Raw image for which the packets will be listed
@param cp Coding parameters
@param tileno Number that identifies the tile for which to list the packets
@param t2_mode If == 0 In Threshold calculation ,If == 1 Final pass
@return Returns a packet iterator that points to the first packet of the tile
@see pi_destroy
*/
opj_pi_iterator_t *pi_initialise_encode(opj_image_t *image, opj_cp_t *cp, int tileno,J2K_T2_MODE t2_mode);
/**
Modify the packet iterator for enabling tile part generation
@param pi Handle to the packet iterator generated in pi_initialise_encode
@param cp Coding parameters
@param tileno Number that identifies the tile for which to list the packets
@param pino Iterator index for pi
@param tpnum Tile part number of the current tile
@param tppos The position of the tile part flag in the progression order
@param t2_mode If == 0 In Threshold calculation ,If == 1 Final pass
@param cur_totnum_tp The total number of tile parts in the current tile
@return Returns true if an error is detected
*/
bool pi_create_encode(opj_pi_iterator_t *pi, opj_cp_t *cp,int tileno, int pino,int tpnum, int tppos, J2K_T2_MODE t2_mode,int cur_totnum_tp);
/**
Create a packet iterator for Decoder
@param image Raw image for which the packets will be listed
@param cp Coding parameters
@param tileno Number that identifies the tile for which to list the packets
@return Returns a packet iterator that points to the first packet of the tile
@see pi_destroy
*/
opj_pi_iterator_t *pi_create_decode(opj_image_t * image, opj_cp_t * cp, int tileno);
 
/**
Destroy a packet iterator
@param pi Previously created packet iterator
@param cp Coding parameters
@param tileno Number that identifies the tile for which the packets were listed
@see pi_create
*/
void pi_destroy(opj_pi_iterator_t *pi, opj_cp_t *cp, int tileno);
 
/**
Modify the packet iterator to point to the next packet
@param pi Packet iterator to modify
@return Returns false if pi pointed to the last packet or else returns true
*/
bool pi_next(opj_pi_iterator_t * pi);
/* ----------------------------------------------------------------------- */
/*@}*/
 
/*@}*/
 
#endif /* __PI_H */
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libopenjpeg/raw.c
0,0 → 1,87
/*
* Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2007, Professor Benoit Macq
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
 
#include "opj_includes.h"
 
/*
==========================================================
local functions
==========================================================
*/
 
 
/*
==========================================================
RAW encoding interface
==========================================================
*/
 
opj_raw_t* raw_create(void) {
opj_raw_t *raw = (opj_raw_t*)opj_malloc(sizeof(opj_raw_t));
return raw;
}
 
void raw_destroy(opj_raw_t *raw) {
if(raw) {
opj_free(raw);
}
}
 
int raw_numbytes(opj_raw_t *raw) {
return raw->bp - raw->start;
}
 
void raw_init_dec(opj_raw_t *raw, unsigned char *bp, int len) {
raw->start = bp;
raw->lenmax = len;
raw->len = 0;
raw->c = 0;
raw->ct = 0;
}
 
int raw_decode(opj_raw_t *raw) {
int d;
if (raw->ct == 0) {
raw->ct = 8;
if (raw->len == raw->lenmax) {
raw->c = 0xff;
} else {
if (raw->c == 0xff) {
raw->ct = 7;
}
raw->c = *(raw->start + raw->len);
raw->len++;
}
}
raw->ct--;
d = (raw->c >> raw->ct) & 0x01;
return d;
}
 
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libopenjpeg/raw.h
0,0 → 1,100
/*
* Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2007, Professor Benoit Macq
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
 
#ifndef __RAW_H
#define __RAW_H
/**
@file raw.h
@brief Implementation of operations for raw encoding (RAW)
 
The functions in RAW.C have for goal to realize the operation of raw encoding linked
with the corresponding mode switch.
*/
 
/** @defgroup RAW RAW - Implementation of operations for raw encoding */
/*@{*/
 
/**
RAW encoding operations
*/
typedef struct opj_raw {
/** temporary buffer where bits are coded or decoded */
unsigned char c;
/** number of bits already read or free to write */
unsigned int ct;
/** maximum length to decode */
unsigned int lenmax;
/** length decoded */
unsigned int len;
/** pointer to the current position in the buffer */
unsigned char *bp;
/** pointer to the start of the buffer */
unsigned char *start;
/** pointer to the end of the buffer */
unsigned char *end;
} opj_raw_t;
 
/** @name Exported functions */
/*@{*/
/* ----------------------------------------------------------------------- */
/**
Create a new RAW handle
@return Returns a new RAW handle if successful, returns NULL otherwise
*/
opj_raw_t* raw_create(void);
/**
Destroy a previously created RAW handle
@param raw RAW handle to destroy
*/
void raw_destroy(opj_raw_t *raw);
/**
Return the number of bytes written/read since initialisation
@param raw RAW handle to destroy
@return Returns the number of bytes already encoded
*/
int raw_numbytes(opj_raw_t *raw);
/**
Initialize the decoder
@param raw RAW handle
@param bp Pointer to the start of the buffer from which the bytes will be read
@param len Length of the input buffer
*/
void raw_init_dec(opj_raw_t *raw, unsigned char *bp, int len);
/**
Decode a symbol using raw-decoder. Cfr p.506 TAUBMAN
@param raw RAW handle
@return Returns the decoded symbol (0 or 1)
*/
int raw_decode(opj_raw_t *raw);
/* ----------------------------------------------------------------------- */
/*@}*/
 
/*@}*/
 
#endif /* __RAW_H */
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libopenjpeg/t1.c
0,0 → 1,1581
/*
* Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2007, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2007, Callum Lerwick <seg@haxxed.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
 
#include "opj_includes.h"
#include "t1_luts.h"
 
/** @defgroup T1 T1 - Implementation of the tier-1 coding */
/*@{*/
 
/** @name Local static functions */
/*@{*/
 
static INLINE char t1_getctxno_zc(int f, int orient);
static char t1_getctxno_sc(int f);
static INLINE int t1_getctxno_mag(int f);
static char t1_getspb(int f);
static short t1_getnmsedec_sig(int x, int bitpos);
static short t1_getnmsedec_ref(int x, int bitpos);
static void t1_updateflags(flag_t *flagsp, int s, int stride);
/**
Encode significant pass
*/
static void t1_enc_sigpass_step(
opj_t1_t *t1,
flag_t *flagsp,
int *datap,
int orient,
int bpno,
int one,
int *nmsedec,
char type,
int vsc);
/**
Decode significant pass
*/
static INLINE void t1_dec_sigpass_step_raw(
opj_t1_t *t1,
flag_t *flagsp,
int *datap,
int orient,
int oneplushalf,
int vsc);
static INLINE void t1_dec_sigpass_step_mqc(
opj_t1_t *t1,
flag_t *flagsp,
int *datap,
int orient,
int oneplushalf);
static INLINE void t1_dec_sigpass_step_mqc_vsc(
opj_t1_t *t1,
flag_t *flagsp,
int *datap,
int orient,
int oneplushalf,
int vsc);
/**
Encode significant pass
*/
static void t1_enc_sigpass(
opj_t1_t *t1,
int bpno,
int orient,
int *nmsedec,
char type,
int cblksty);
/**
Decode significant pass
*/
static void t1_dec_sigpass_raw(
opj_t1_t *t1,
int bpno,
int orient,
int cblksty);
static void t1_dec_sigpass_mqc(
opj_t1_t *t1,
int bpno,
int orient);
static void t1_dec_sigpass_mqc_vsc(
opj_t1_t *t1,
int bpno,
int orient);
/**
Encode refinement pass
*/
static void t1_enc_refpass_step(
opj_t1_t *t1,
flag_t *flagsp,
int *datap,
int bpno,
int one,
int *nmsedec,
char type,
int vsc);
/**
Decode refinement pass
*/
static void INLINE t1_dec_refpass_step_raw(
opj_t1_t *t1,
flag_t *flagsp,
int *datap,
int poshalf,
int neghalf,
int vsc);
static void INLINE t1_dec_refpass_step_mqc(
opj_t1_t *t1,
flag_t *flagsp,
int *datap,
int poshalf,
int neghalf);
static void INLINE t1_dec_refpass_step_mqc_vsc(
opj_t1_t *t1,
flag_t *flagsp,
int *datap,
int poshalf,
int neghalf,
int vsc);
 
/**
Encode refinement pass
*/
static void t1_enc_refpass(
opj_t1_t *t1,
int bpno,
int *nmsedec,
char type,
int cblksty);
/**
Decode refinement pass
*/
static void t1_dec_refpass_raw(
opj_t1_t *t1,
int bpno,
int cblksty);
static void t1_dec_refpass_mqc(
opj_t1_t *t1,
int bpno);
static void t1_dec_refpass_mqc_vsc(
opj_t1_t *t1,
int bpno);
/**
Encode clean-up pass
*/
static void t1_enc_clnpass_step(
opj_t1_t *t1,
flag_t *flagsp,
int *datap,
int orient,
int bpno,
int one,
int *nmsedec,
int partial,
int vsc);
/**
Decode clean-up pass
*/
static void t1_dec_clnpass_step_partial(
opj_t1_t *t1,
flag_t *flagsp,
int *datap,
int orient,
int oneplushalf);
static void t1_dec_clnpass_step(
opj_t1_t *t1,
flag_t *flagsp,
int *datap,
int orient,
int oneplushalf);
static void t1_dec_clnpass_step_vsc(
opj_t1_t *t1,
flag_t *flagsp,
int *datap,
int orient,
int oneplushalf,
int partial,
int vsc);
/**
Encode clean-up pass
*/
static void t1_enc_clnpass(
opj_t1_t *t1,
int bpno,
int orient,
int *nmsedec,
int cblksty);
/**
Decode clean-up pass
*/
static void t1_dec_clnpass(
opj_t1_t *t1,
int bpno,
int orient,
int cblksty);
static double t1_getwmsedec(
int nmsedec,
int compno,
int level,
int orient,
int bpno,
int qmfbid,
double stepsize,
int numcomps,
int mct);
/**
Encode 1 code-block
@param t1 T1 handle
@param cblk Code-block coding parameters
@param orient
@param compno Component number
@param level
@param qmfbid
@param stepsize
@param cblksty Code-block style
@param numcomps
@param mct
@param tile
*/
static void t1_encode_cblk(
opj_t1_t *t1,
opj_tcd_cblk_enc_t* cblk,
int orient,
int compno,
int level,
int qmfbid,
double stepsize,
int cblksty,
int numcomps,
int mct,
opj_tcd_tile_t * tile);
/**
Decode 1 code-block
@param t1 T1 handle
@param cblk Code-block coding parameters
@param orient
@param roishift Region of interest shifting value
@param cblksty Code-block style
*/
static void t1_decode_cblk(
opj_t1_t *t1,
opj_tcd_cblk_dec_t* cblk,
int orient,
int roishift,
int cblksty);
 
/*@}*/
 
/*@}*/
 
/* ----------------------------------------------------------------------- */
 
static char t1_getctxno_zc(int f, int orient) {
return lut_ctxno_zc[(orient << 8) | (f & T1_SIG_OTH)];
}
 
static char t1_getctxno_sc(int f) {
return lut_ctxno_sc[(f & (T1_SIG_PRIM | T1_SGN)) >> 4];
}
 
static int t1_getctxno_mag(int f) {
int tmp1 = (f & T1_SIG_OTH) ? T1_CTXNO_MAG + 1 : T1_CTXNO_MAG;
int tmp2 = (f & T1_REFINE) ? T1_CTXNO_MAG + 2 : tmp1;
return (tmp2);
}
 
static char t1_getspb(int f) {
return lut_spb[(f & (T1_SIG_PRIM | T1_SGN)) >> 4];
}
 
static short t1_getnmsedec_sig(int x, int bitpos) {
if (bitpos > T1_NMSEDEC_FRACBITS) {
return lut_nmsedec_sig[(x >> (bitpos - T1_NMSEDEC_FRACBITS)) & ((1 << T1_NMSEDEC_BITS) - 1)];
}
return lut_nmsedec_sig0[x & ((1 << T1_NMSEDEC_BITS) - 1)];
}
 
static short t1_getnmsedec_ref(int x, int bitpos) {
if (bitpos > T1_NMSEDEC_FRACBITS) {
return lut_nmsedec_ref[(x >> (bitpos - T1_NMSEDEC_FRACBITS)) & ((1 << T1_NMSEDEC_BITS) - 1)];
}
 
return lut_nmsedec_ref0[x & ((1 << T1_NMSEDEC_BITS) - 1)];
}
 
static void t1_updateflags(flag_t *flagsp, int s, int stride) {
flag_t *np = flagsp - stride;
flag_t *sp = flagsp + stride;
 
static const flag_t mod[] = {
T1_SIG_S, T1_SIG_S|T1_SGN_S,
T1_SIG_E, T1_SIG_E|T1_SGN_E,
T1_SIG_W, T1_SIG_W|T1_SGN_W,
T1_SIG_N, T1_SIG_N|T1_SGN_N
};
 
np[-1] |= T1_SIG_SE;
np[0] |= mod[s];
np[1] |= T1_SIG_SW;
 
flagsp[-1] |= mod[s+2];
flagsp[0] |= T1_SIG;
flagsp[1] |= mod[s+4];
 
sp[-1] |= T1_SIG_NE;
sp[0] |= mod[s+6];
sp[1] |= T1_SIG_NW;
}
 
static void t1_enc_sigpass_step(
opj_t1_t *t1,
flag_t *flagsp,
int *datap,
int orient,
int bpno,
int one,
int *nmsedec,
char type,
int vsc)
{
int v, flag;
opj_mqc_t *mqc = t1->mqc; /* MQC component */
flag = vsc ? ((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*flagsp);
if ((flag & T1_SIG_OTH) && !(flag & (T1_SIG | T1_VISIT))) {
v = int_abs(*datap) & one ? 1 : 0;
mqc_setcurctx(mqc, t1_getctxno_zc(flag, orient)); /* ESSAI */
if (type == T1_TYPE_RAW) { /* BYPASS/LAZY MODE */
mqc_bypass_enc(mqc, v);
} else {
mqc_encode(mqc, v);
}
if (v) {
v = *datap < 0 ? 1 : 0;
*nmsedec += t1_getnmsedec_sig(int_abs(*datap), bpno + T1_NMSEDEC_FRACBITS);
mqc_setcurctx(mqc, t1_getctxno_sc(flag)); /* ESSAI */
if (type == T1_TYPE_RAW) { /* BYPASS/LAZY MODE */
mqc_bypass_enc(mqc, v);
} else {
mqc_encode(mqc, v ^ t1_getspb(flag));
}
t1_updateflags(flagsp, v, t1->flags_stride);
}
*flagsp |= T1_VISIT;
}
}
 
static INLINE void t1_dec_sigpass_step_raw(
opj_t1_t *t1,
flag_t *flagsp,
int *datap,
int orient,
int oneplushalf,
int vsc)
{
int v, flag;
opj_raw_t *raw = t1->raw; /* RAW component */
flag = vsc ? ((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*flagsp);
if ((flag & T1_SIG_OTH) && !(flag & (T1_SIG | T1_VISIT))) {
if (raw_decode(raw)) {
v = raw_decode(raw); /* ESSAI */
*datap = v ? -oneplushalf : oneplushalf;
t1_updateflags(flagsp, v, t1->flags_stride);
}
*flagsp |= T1_VISIT;
}
} /* VSC and BYPASS by Antonin */
 
static INLINE void t1_dec_sigpass_step_mqc(
opj_t1_t *t1,
flag_t *flagsp,
int *datap,
int orient,
int oneplushalf)
{
int v, flag;
opj_mqc_t *mqc = t1->mqc; /* MQC component */
flag = *flagsp;
if ((flag & T1_SIG_OTH) && !(flag & (T1_SIG | T1_VISIT))) {
mqc_setcurctx(mqc, t1_getctxno_zc(flag, orient));
if (mqc_decode(mqc)) {
mqc_setcurctx(mqc, t1_getctxno_sc(flag));
v = mqc_decode(mqc) ^ t1_getspb(flag);
*datap = v ? -oneplushalf : oneplushalf;
t1_updateflags(flagsp, v, t1->flags_stride);
}
*flagsp |= T1_VISIT;
}
} /* VSC and BYPASS by Antonin */
 
static INLINE void t1_dec_sigpass_step_mqc_vsc(
opj_t1_t *t1,
flag_t *flagsp,
int *datap,
int orient,
int oneplushalf,
int vsc)
{
int v, flag;
opj_mqc_t *mqc = t1->mqc; /* MQC component */
flag = vsc ? ((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*flagsp);
if ((flag & T1_SIG_OTH) && !(flag & (T1_SIG | T1_VISIT))) {
mqc_setcurctx(mqc, t1_getctxno_zc(flag, orient));
if (mqc_decode(mqc)) {
mqc_setcurctx(mqc, t1_getctxno_sc(flag));
v = mqc_decode(mqc) ^ t1_getspb(flag);
*datap = v ? -oneplushalf : oneplushalf;
t1_updateflags(flagsp, v, t1->flags_stride);
}
*flagsp |= T1_VISIT;
}
} /* VSC and BYPASS by Antonin */
 
static void t1_enc_sigpass(
opj_t1_t *t1,
int bpno,
int orient,
int *nmsedec,
char type,
int cblksty)
{
int i, j, k, one, vsc;
*nmsedec = 0;
one = 1 << (bpno + T1_NMSEDEC_FRACBITS);
for (k = 0; k < t1->h; k += 4) {
for (i = 0; i < t1->w; ++i) {
for (j = k; j < k + 4 && j < t1->h; ++j) {
vsc = ((cblksty & J2K_CCP_CBLKSTY_VSC) && (j == k + 3 || j == t1->h - 1)) ? 1 : 0;
t1_enc_sigpass_step(
t1,
&t1->flags[((j+1) * t1->flags_stride) + i + 1],
&t1->data[(j * t1->w) + i],
orient,
bpno,
one,
nmsedec,
type,
vsc);
}
}
}
}
 
static void t1_dec_sigpass_raw(
opj_t1_t *t1,
int bpno,
int orient,
int cblksty)
{
int i, j, k, one, half, oneplushalf, vsc;
one = 1 << bpno;
half = one >> 1;
oneplushalf = one | half;
for (k = 0; k < t1->h; k += 4) {
for (i = 0; i < t1->w; ++i) {
for (j = k; j < k + 4 && j < t1->h; ++j) {
vsc = ((cblksty & J2K_CCP_CBLKSTY_VSC) && (j == k + 3 || j == t1->h - 1)) ? 1 : 0;
t1_dec_sigpass_step_raw(
t1,
&t1->flags[((j+1) * t1->flags_stride) + i + 1],
&t1->data[(j * t1->w) + i],
orient,
oneplushalf,
vsc);
}
}
}
} /* VSC and BYPASS by Antonin */
 
static void t1_dec_sigpass_mqc(
opj_t1_t *t1,
int bpno,
int orient)
{
int i, j, k, one, half, oneplushalf;
int *data1 = t1->data;
flag_t *flags1 = &t1->flags[1];
one = 1 << bpno;
half = one >> 1;
oneplushalf = one | half;
for (k = 0; k < (t1->h & ~3); k += 4) {
for (i = 0; i < t1->w; ++i) {
int *data2 = data1 + i;
flag_t *flags2 = flags1 + i;
flags2 += t1->flags_stride;
t1_dec_sigpass_step_mqc(t1, flags2, data2, orient, oneplushalf);
data2 += t1->w;
flags2 += t1->flags_stride;
t1_dec_sigpass_step_mqc(t1, flags2, data2, orient, oneplushalf);
data2 += t1->w;
flags2 += t1->flags_stride;
t1_dec_sigpass_step_mqc(t1, flags2, data2, orient, oneplushalf);
data2 += t1->w;
flags2 += t1->flags_stride;
t1_dec_sigpass_step_mqc(t1, flags2, data2, orient, oneplushalf);
data2 += t1->w;
}
data1 += t1->w << 2;
flags1 += t1->flags_stride << 2;
}
for (i = 0; i < t1->w; ++i) {
int *data2 = data1 + i;
flag_t *flags2 = flags1 + i;
for (j = k; j < t1->h; ++j) {
flags2 += t1->flags_stride;
t1_dec_sigpass_step_mqc(t1, flags2, data2, orient, oneplushalf);
data2 += t1->w;
}
}
} /* VSC and BYPASS by Antonin */
 
static void t1_dec_sigpass_mqc_vsc(
opj_t1_t *t1,
int bpno,
int orient)
{
int i, j, k, one, half, oneplushalf, vsc;
one = 1 << bpno;
half = one >> 1;
oneplushalf = one | half;
for (k = 0; k < t1->h; k += 4) {
for (i = 0; i < t1->w; ++i) {
for (j = k; j < k + 4 && j < t1->h; ++j) {
vsc = (j == k + 3 || j == t1->h - 1) ? 1 : 0;
t1_dec_sigpass_step_mqc_vsc(
t1,
&t1->flags[((j+1) * t1->flags_stride) + i + 1],
&t1->data[(j * t1->w) + i],
orient,
oneplushalf,
vsc);
}
}
}
} /* VSC and BYPASS by Antonin */
 
static void t1_enc_refpass_step(
opj_t1_t *t1,
flag_t *flagsp,
int *datap,
int bpno,
int one,
int *nmsedec,
char type,
int vsc)
{
int v, flag;
opj_mqc_t *mqc = t1->mqc; /* MQC component */
flag = vsc ? ((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*flagsp);
if ((flag & (T1_SIG | T1_VISIT)) == T1_SIG) {
*nmsedec += t1_getnmsedec_ref(int_abs(*datap), bpno + T1_NMSEDEC_FRACBITS);
v = int_abs(*datap) & one ? 1 : 0;
mqc_setcurctx(mqc, t1_getctxno_mag(flag)); /* ESSAI */
if (type == T1_TYPE_RAW) { /* BYPASS/LAZY MODE */
mqc_bypass_enc(mqc, v);
} else {
mqc_encode(mqc, v);
}
*flagsp |= T1_REFINE;
}
}
 
static INLINE void t1_dec_refpass_step_raw(
opj_t1_t *t1,
flag_t *flagsp,
int *datap,
int poshalf,
int neghalf,
int vsc)
{
int v, t, flag;
opj_raw_t *raw = t1->raw; /* RAW component */
flag = vsc ? ((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*flagsp);
if ((flag & (T1_SIG | T1_VISIT)) == T1_SIG) {
v = raw_decode(raw);
t = v ? poshalf : neghalf;
*datap += *datap < 0 ? -t : t;
*flagsp |= T1_REFINE;
}
} /* VSC and BYPASS by Antonin */
 
static INLINE void t1_dec_refpass_step_mqc(
opj_t1_t *t1,
flag_t *flagsp,
int *datap,
int poshalf,
int neghalf)
{
int v, t, flag;
opj_mqc_t *mqc = t1->mqc; /* MQC component */
flag = *flagsp;
if ((flag & (T1_SIG | T1_VISIT)) == T1_SIG) {
mqc_setcurctx(mqc, t1_getctxno_mag(flag)); /* ESSAI */
v = mqc_decode(mqc);
t = v ? poshalf : neghalf;
*datap += *datap < 0 ? -t : t;
*flagsp |= T1_REFINE;
}
} /* VSC and BYPASS by Antonin */
 
static INLINE void t1_dec_refpass_step_mqc_vsc(
opj_t1_t *t1,
flag_t *flagsp,
int *datap,
int poshalf,
int neghalf,
int vsc)
{
int v, t, flag;
opj_mqc_t *mqc = t1->mqc; /* MQC component */
flag = vsc ? ((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*flagsp);
if ((flag & (T1_SIG | T1_VISIT)) == T1_SIG) {
mqc_setcurctx(mqc, t1_getctxno_mag(flag)); /* ESSAI */
v = mqc_decode(mqc);
t = v ? poshalf : neghalf;
*datap += *datap < 0 ? -t : t;
*flagsp |= T1_REFINE;
}
} /* VSC and BYPASS by Antonin */
 
static void t1_enc_refpass(
opj_t1_t *t1,
int bpno,
int *nmsedec,
char type,
int cblksty)
{
int i, j, k, one, vsc;
*nmsedec = 0;
one = 1 << (bpno + T1_NMSEDEC_FRACBITS);
for (k = 0; k < t1->h; k += 4) {
for (i = 0; i < t1->w; ++i) {
for (j = k; j < k + 4 && j < t1->h; ++j) {
vsc = ((cblksty & J2K_CCP_CBLKSTY_VSC) && (j == k + 3 || j == t1->h - 1)) ? 1 : 0;
t1_enc_refpass_step(
t1,
&t1->flags[((j+1) * t1->flags_stride) + i + 1],
&t1->data[(j * t1->w) + i],
bpno,
one,
nmsedec,
type,
vsc);
}
}
}
}
 
static void t1_dec_refpass_raw(
opj_t1_t *t1,
int bpno,
int cblksty)
{
int i, j, k, one, poshalf, neghalf;
int vsc;
one = 1 << bpno;
poshalf = one >> 1;
neghalf = bpno > 0 ? -poshalf : -1;
for (k = 0; k < t1->h; k += 4) {
for (i = 0; i < t1->w; ++i) {
for (j = k; j < k + 4 && j < t1->h; ++j) {
vsc = ((cblksty & J2K_CCP_CBLKSTY_VSC) && (j == k + 3 || j == t1->h - 1)) ? 1 : 0;
t1_dec_refpass_step_raw(
t1,
&t1->flags[((j+1) * t1->flags_stride) + i + 1],
&t1->data[(j * t1->w) + i],
poshalf,
neghalf,
vsc);
}
}
}
} /* VSC and BYPASS by Antonin */
 
static void t1_dec_refpass_mqc(
opj_t1_t *t1,
int bpno)
{
int i, j, k, one, poshalf, neghalf;
int *data1 = t1->data;
flag_t *flags1 = &t1->flags[1];
one = 1 << bpno;
poshalf = one >> 1;
neghalf = bpno > 0 ? -poshalf : -1;
for (k = 0; k < (t1->h & ~3); k += 4) {
for (i = 0; i < t1->w; ++i) {
int *data2 = data1 + i;
flag_t *flags2 = flags1 + i;
flags2 += t1->flags_stride;
t1_dec_refpass_step_mqc(t1, flags2, data2, poshalf, neghalf);
data2 += t1->w;
flags2 += t1->flags_stride;
t1_dec_refpass_step_mqc(t1, flags2, data2, poshalf, neghalf);
data2 += t1->w;
flags2 += t1->flags_stride;
t1_dec_refpass_step_mqc(t1, flags2, data2, poshalf, neghalf);
data2 += t1->w;
flags2 += t1->flags_stride;
t1_dec_refpass_step_mqc(t1, flags2, data2, poshalf, neghalf);
data2 += t1->w;
}
data1 += t1->w << 2;
flags1 += t1->flags_stride << 2;
}
for (i = 0; i < t1->w; ++i) {
int *data2 = data1 + i;
flag_t *flags2 = flags1 + i;
for (j = k; j < t1->h; ++j) {
flags2 += t1->flags_stride;
t1_dec_refpass_step_mqc(t1, flags2, data2, poshalf, neghalf);
data2 += t1->w;
}
}
} /* VSC and BYPASS by Antonin */
 
static void t1_dec_refpass_mqc_vsc(
opj_t1_t *t1,
int bpno)
{
int i, j, k, one, poshalf, neghalf;
int vsc;
one = 1 << bpno;
poshalf = one >> 1;
neghalf = bpno > 0 ? -poshalf : -1;
for (k = 0; k < t1->h; k += 4) {
for (i = 0; i < t1->w; ++i) {
for (j = k; j < k + 4 && j < t1->h; ++j) {
vsc = ((j == k + 3 || j == t1->h - 1)) ? 1 : 0;
t1_dec_refpass_step_mqc_vsc(
t1,
&t1->flags[((j+1) * t1->flags_stride) + i + 1],
&t1->data[(j * t1->w) + i],
poshalf,
neghalf,
vsc);
}
}
}
} /* VSC and BYPASS by Antonin */
 
static void t1_enc_clnpass_step(
opj_t1_t *t1,
flag_t *flagsp,
int *datap,
int orient,
int bpno,
int one,
int *nmsedec,
int partial,
int vsc)
{
int v, flag;
opj_mqc_t *mqc = t1->mqc; /* MQC component */
flag = vsc ? ((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*flagsp);
if (partial) {
goto LABEL_PARTIAL;
}
if (!(*flagsp & (T1_SIG | T1_VISIT))) {
mqc_setcurctx(mqc, t1_getctxno_zc(flag, orient));
v = int_abs(*datap) & one ? 1 : 0;
mqc_encode(mqc, v);
if (v) {
LABEL_PARTIAL:
*nmsedec += t1_getnmsedec_sig(int_abs(*datap), bpno + T1_NMSEDEC_FRACBITS);
mqc_setcurctx(mqc, t1_getctxno_sc(flag));
v = *datap < 0 ? 1 : 0;
mqc_encode(mqc, v ^ t1_getspb(flag));
t1_updateflags(flagsp, v, t1->flags_stride);
}
}
*flagsp &= ~T1_VISIT;
}
 
static void t1_dec_clnpass_step_partial(
opj_t1_t *t1,
flag_t *flagsp,
int *datap,
int orient,
int oneplushalf)
{
int v, flag;
opj_mqc_t *mqc = t1->mqc; /* MQC component */
flag = *flagsp;
mqc_setcurctx(mqc, t1_getctxno_sc(flag));
v = mqc_decode(mqc) ^ t1_getspb(flag);
*datap = v ? -oneplushalf : oneplushalf;
t1_updateflags(flagsp, v, t1->flags_stride);
*flagsp &= ~T1_VISIT;
} /* VSC and BYPASS by Antonin */
 
static void t1_dec_clnpass_step(
opj_t1_t *t1,
flag_t *flagsp,
int *datap,
int orient,
int oneplushalf)
{
int v, flag;
opj_mqc_t *mqc = t1->mqc; /* MQC component */
flag = *flagsp;
if (!(flag & (T1_SIG | T1_VISIT))) {
mqc_setcurctx(mqc, t1_getctxno_zc(flag, orient));
if (mqc_decode(mqc)) {
mqc_setcurctx(mqc, t1_getctxno_sc(flag));
v = mqc_decode(mqc) ^ t1_getspb(flag);
*datap = v ? -oneplushalf : oneplushalf;
t1_updateflags(flagsp, v, t1->flags_stride);
}
}
*flagsp &= ~T1_VISIT;
} /* VSC and BYPASS by Antonin */
 
static void t1_dec_clnpass_step_vsc(
opj_t1_t *t1,
flag_t *flagsp,
int *datap,
int orient,
int oneplushalf,
int partial,
int vsc)
{
int v, flag;
opj_mqc_t *mqc = t1->mqc; /* MQC component */
flag = vsc ? ((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*flagsp);
if (partial) {
goto LABEL_PARTIAL;
}
if (!(flag & (T1_SIG | T1_VISIT))) {
mqc_setcurctx(mqc, t1_getctxno_zc(flag, orient));
if (mqc_decode(mqc)) {
LABEL_PARTIAL:
mqc_setcurctx(mqc, t1_getctxno_sc(flag));
v = mqc_decode(mqc) ^ t1_getspb(flag);
*datap = v ? -oneplushalf : oneplushalf;
t1_updateflags(flagsp, v, t1->flags_stride);
}
}
*flagsp &= ~T1_VISIT;
}
 
static void t1_enc_clnpass(
opj_t1_t *t1,
int bpno,
int orient,
int *nmsedec,
int cblksty)
{
int i, j, k, one, agg, runlen, vsc;
opj_mqc_t *mqc = t1->mqc; /* MQC component */
*nmsedec = 0;
one = 1 << (bpno + T1_NMSEDEC_FRACBITS);
for (k = 0; k < t1->h; k += 4) {
for (i = 0; i < t1->w; ++i) {
if (k + 3 < t1->h) {
if (cblksty & J2K_CCP_CBLKSTY_VSC) {
agg = !(MACRO_t1_flags(1 + k,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH)
|| MACRO_t1_flags(1 + k + 1,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH)
|| MACRO_t1_flags(1 + k + 2,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH)
|| (MACRO_t1_flags(1 + k + 3,1 + i)
& (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) & (T1_SIG | T1_VISIT | T1_SIG_OTH));
} else {
agg = !(MACRO_t1_flags(1 + k,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH)
|| MACRO_t1_flags(1 + k + 1,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH)
|| MACRO_t1_flags(1 + k + 2,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH)
|| MACRO_t1_flags(1 + k + 3,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH));
}
} else {
agg = 0;
}
if (agg) {
for (runlen = 0; runlen < 4; ++runlen) {
if (int_abs(t1->data[((k + runlen)*t1->w) + i]) & one)
break;
}
mqc_setcurctx(mqc, T1_CTXNO_AGG);
mqc_encode(mqc, runlen != 4);
if (runlen == 4) {
continue;
}
mqc_setcurctx(mqc, T1_CTXNO_UNI);
mqc_encode(mqc, runlen >> 1);
mqc_encode(mqc, runlen & 1);
} else {
runlen = 0;
}
for (j = k + runlen; j < k + 4 && j < t1->h; ++j) {
vsc = ((cblksty & J2K_CCP_CBLKSTY_VSC) && (j == k + 3 || j == t1->h - 1)) ? 1 : 0;
t1_enc_clnpass_step(
t1,
&t1->flags[((j+1) * t1->flags_stride) + i + 1],
&t1->data[(j * t1->w) + i],
orient,
bpno,
one,
nmsedec,
agg && (j == k + runlen),
vsc);
}
}
}
}
 
static void t1_dec_clnpass(
opj_t1_t *t1,
int bpno,
int orient,
int cblksty)
{
int i, j, k, one, half, oneplushalf, agg, runlen, vsc;
int segsym = cblksty & J2K_CCP_CBLKSTY_SEGSYM;
opj_mqc_t *mqc = t1->mqc; /* MQC component */
one = 1 << bpno;
half = one >> 1;
oneplushalf = one | half;
if (cblksty & J2K_CCP_CBLKSTY_VSC) {
for (k = 0; k < t1->h; k += 4) {
for (i = 0; i < t1->w; ++i) {
if (k + 3 < t1->h) {
agg = !(MACRO_t1_flags(1 + k,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH)
|| MACRO_t1_flags(1 + k + 1,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH)
|| MACRO_t1_flags(1 + k + 2,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH)
|| (MACRO_t1_flags(1 + k + 3,1 + i)
& (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) & (T1_SIG | T1_VISIT | T1_SIG_OTH));
} else {
agg = 0;
}
if (agg) {
mqc_setcurctx(mqc, T1_CTXNO_AGG);
if (!mqc_decode(mqc)) {
continue;
}
mqc_setcurctx(mqc, T1_CTXNO_UNI);
runlen = mqc_decode(mqc);
runlen = (runlen << 1) | mqc_decode(mqc);
} else {
runlen = 0;
}
for (j = k + runlen; j < k + 4 && j < t1->h; ++j) {
vsc = (j == k + 3 || j == t1->h - 1) ? 1 : 0;
t1_dec_clnpass_step_vsc(
t1,
&t1->flags[((j+1) * t1->flags_stride) + i + 1],
&t1->data[(j * t1->w) + i],
orient,
oneplushalf,
agg && (j == k + runlen),
vsc);
}
}
}
} else {
int *data1 = t1->data;
flag_t *flags1 = &t1->flags[1];
for (k = 0; k < (t1->h & ~3); k += 4) {
for (i = 0; i < t1->w; ++i) {
int *data2 = data1 + i;
flag_t *flags2 = flags1 + i;
agg = !(MACRO_t1_flags(1 + k,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH)
|| MACRO_t1_flags(1 + k + 1,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH)
|| MACRO_t1_flags(1 + k + 2,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH)
|| MACRO_t1_flags(1 + k + 3,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH));
if (agg) {
mqc_setcurctx(mqc, T1_CTXNO_AGG);
if (!mqc_decode(mqc)) {
continue;
}
mqc_setcurctx(mqc, T1_CTXNO_UNI);
runlen = mqc_decode(mqc);
runlen = (runlen << 1) | mqc_decode(mqc);
flags2 += runlen * t1->flags_stride;
data2 += runlen * t1->w;
for (j = k + runlen; j < k + 4 && j < t1->h; ++j) {
flags2 += t1->flags_stride;
if (agg && (j == k + runlen)) {
t1_dec_clnpass_step_partial(t1, flags2, data2, orient, oneplushalf);
} else {
t1_dec_clnpass_step(t1, flags2, data2, orient, oneplushalf);
}
data2 += t1->w;
}
} else {
flags2 += t1->flags_stride;
t1_dec_clnpass_step(t1, flags2, data2, orient, oneplushalf);
data2 += t1->w;
flags2 += t1->flags_stride;
t1_dec_clnpass_step(t1, flags2, data2, orient, oneplushalf);
data2 += t1->w;
flags2 += t1->flags_stride;
t1_dec_clnpass_step(t1, flags2, data2, orient, oneplushalf);
data2 += t1->w;
flags2 += t1->flags_stride;
t1_dec_clnpass_step(t1, flags2, data2, orient, oneplushalf);
data2 += t1->w;
}
}
data1 += t1->w << 2;
flags1 += t1->flags_stride << 2;
}
for (i = 0; i < t1->w; ++i) {
int *data2 = data1 + i;
flag_t *flags2 = flags1 + i;
for (j = k; j < t1->h; ++j) {
flags2 += t1->flags_stride;
t1_dec_clnpass_step(t1, flags2, data2, orient, oneplushalf);
data2 += t1->w;
}
}
}
 
if (segsym) {
int v = 0;
mqc_setcurctx(mqc, T1_CTXNO_UNI);
v = mqc_decode(mqc);
v = (v << 1) | mqc_decode(mqc);
v = (v << 1) | mqc_decode(mqc);
v = (v << 1) | mqc_decode(mqc);
/*
if (v!=0xa) {
opj_event_msg(t1->cinfo, EVT_WARNING, "Bad segmentation symbol %x\n", v);
}
*/
}
} /* VSC and BYPASS by Antonin */
 
 
/** mod fixed_quality */
static double t1_getwmsedec(
int nmsedec,
int compno,
int level,
int orient,
int bpno,
int qmfbid,
double stepsize,
int numcomps,
int mct)
{
double w1, w2, wmsedec;
if (qmfbid == 1) {
w1 = (mct && numcomps==3) ? mct_getnorm(compno) : 1.0;
w2 = dwt_getnorm(level, orient);
} else { /* if (qmfbid == 0) */
w1 = (mct && numcomps==3) ? mct_getnorm_real(compno) : 1.0;
w2 = dwt_getnorm_real(level, orient);
}
wmsedec = w1 * w2 * stepsize * (1 << bpno);
wmsedec *= wmsedec * nmsedec / 8192.0;
return wmsedec;
}
 
static bool allocate_buffers(
opj_t1_t *t1,
int w,
int h)
{
int datasize=w * h;
int flagssize;
 
if(datasize > t1->datasize){
opj_aligned_free(t1->data);
t1->data = (int*) opj_aligned_malloc(datasize * sizeof(int));
if(!t1->data){
return false;
}
t1->datasize=datasize;
}
memset(t1->data,0,datasize * sizeof(int));
 
t1->flags_stride=w+2;
flagssize=t1->flags_stride * (h+2);
 
if(flagssize > t1->flagssize){
opj_aligned_free(t1->flags);
t1->flags = (flag_t*) opj_aligned_malloc(flagssize * sizeof(flag_t));
if(!t1->flags){
return false;
}
t1->flagssize=flagssize;
}
memset(t1->flags,0,flagssize * sizeof(flag_t));
 
t1->w=w;
t1->h=h;
 
return true;
}
 
/** mod fixed_quality */
static void t1_encode_cblk(
opj_t1_t *t1,
opj_tcd_cblk_enc_t* cblk,
int orient,
int compno,
int level,
int qmfbid,
double stepsize,
int cblksty,
int numcomps,
int mct,
opj_tcd_tile_t * tile)
{
double cumwmsedec = 0.0;
 
opj_mqc_t *mqc = t1->mqc; /* MQC component */
 
int passno, bpno, passtype;
int nmsedec = 0;
int i, max;
char type = T1_TYPE_MQ;
double tempwmsedec;
 
max = 0;
for (i = 0; i < t1->w * t1->h; ++i) {
int tmp = abs(t1->data[i]);
max = int_max(max, tmp);
}
 
cblk->numbps = max ? (int_floorlog2(max) + 1) - T1_NMSEDEC_FRACBITS : 0;
bpno = cblk->numbps - 1;
passtype = 2;
mqc_resetstates(mqc);
mqc_setstate(mqc, T1_CTXNO_UNI, 0, 46);
mqc_setstate(mqc, T1_CTXNO_AGG, 0, 3);
mqc_setstate(mqc, T1_CTXNO_ZC, 0, 4);
mqc_init_enc(mqc, cblk->data);
for (passno = 0; bpno >= 0; ++passno) {
opj_tcd_pass_t *pass = &cblk->passes[passno];
int correction = 3;
type = ((bpno < (cblk->numbps - 4)) && (passtype < 2) && (cblksty & J2K_CCP_CBLKSTY_LAZY)) ? T1_TYPE_RAW : T1_TYPE_MQ;
switch (passtype) {
case 0:
t1_enc_sigpass(t1, bpno, orient, &nmsedec, type, cblksty);
break;
case 1:
t1_enc_refpass(t1, bpno, &nmsedec, type, cblksty);
break;
case 2:
t1_enc_clnpass(t1, bpno, orient, &nmsedec, cblksty);
/* code switch SEGMARK (i.e. SEGSYM) */
if (cblksty & J2K_CCP_CBLKSTY_SEGSYM)
mqc_segmark_enc(mqc);
break;
}
/* fixed_quality */
tempwmsedec = t1_getwmsedec(nmsedec, compno, level, orient, bpno, qmfbid, stepsize, numcomps, mct);
cumwmsedec += tempwmsedec;
tile->distotile += tempwmsedec;
/* Code switch "RESTART" (i.e. TERMALL) */
if ((cblksty & J2K_CCP_CBLKSTY_TERMALL) && !((passtype == 2) && (bpno - 1 < 0))) {
if (type == T1_TYPE_RAW) {
mqc_flush(mqc);
correction = 1;
/* correction = mqc_bypass_flush_enc(); */
} else { /* correction = mqc_restart_enc(); */
mqc_flush(mqc);
correction = 1;
}
pass->term = 1;
} else {
if (((bpno < (cblk->numbps - 4) && (passtype > 0))
|| ((bpno == (cblk->numbps - 4)) && (passtype == 2))) && (cblksty & J2K_CCP_CBLKSTY_LAZY)) {
if (type == T1_TYPE_RAW) {
mqc_flush(mqc);
correction = 1;
/* correction = mqc_bypass_flush_enc(); */
} else { /* correction = mqc_restart_enc(); */
mqc_flush(mqc);
correction = 1;
}
pass->term = 1;
} else {
pass->term = 0;
}
}
if (++passtype == 3) {
passtype = 0;
bpno--;
}
if (pass->term && bpno > 0) {
type = ((bpno < (cblk->numbps - 4)) && (passtype < 2) && (cblksty & J2K_CCP_CBLKSTY_LAZY)) ? T1_TYPE_RAW : T1_TYPE_MQ;
if (type == T1_TYPE_RAW)
mqc_bypass_init_enc(mqc);
else
mqc_restart_init_enc(mqc);
}
pass->distortiondec = cumwmsedec;
pass->rate = mqc_numbytes(mqc) + correction; /* FIXME */
/* Code-switch "RESET" */
if (cblksty & J2K_CCP_CBLKSTY_RESET)
mqc_reset_enc(mqc);
}
/* Code switch "ERTERM" (i.e. PTERM) */
if (cblksty & J2K_CCP_CBLKSTY_PTERM)
mqc_erterm_enc(mqc);
else /* Default coding */ if (!(cblksty & J2K_CCP_CBLKSTY_LAZY))
mqc_flush(mqc);
cblk->totalpasses = passno;
 
for (passno = 0; passno<cblk->totalpasses; passno++) {
opj_tcd_pass_t *pass = &cblk->passes[passno];
if (pass->rate > mqc_numbytes(mqc))
pass->rate = mqc_numbytes(mqc);
/*Preventing generation of FF as last data byte of a pass*/
if((pass->rate>1) && (cblk->data[pass->rate - 1] == 0xFF)){
pass->rate--;
}
pass->len = pass->rate - (passno == 0 ? 0 : cblk->passes[passno - 1].rate);
}
}
 
static void t1_decode_cblk(
opj_t1_t *t1,
opj_tcd_cblk_dec_t* cblk,
int orient,
int roishift,
int cblksty)
{
opj_raw_t *raw = t1->raw; /* RAW component */
opj_mqc_t *mqc = t1->mqc; /* MQC component */
 
int bpno, passtype;
int segno, passno;
char type = T1_TYPE_MQ; /* BYPASS mode */
 
if(!allocate_buffers(
t1,
cblk->x1 - cblk->x0,
cblk->y1 - cblk->y0))
{
return;
}
 
bpno = roishift + cblk->numbps - 1;
passtype = 2;
mqc_resetstates(mqc);
mqc_setstate(mqc, T1_CTXNO_UNI, 0, 46);
mqc_setstate(mqc, T1_CTXNO_AGG, 0, 3);
mqc_setstate(mqc, T1_CTXNO_ZC, 0, 4);
for (segno = 0; segno < cblk->numsegs; ++segno) {
opj_tcd_seg_t *seg = &cblk->segs[segno];
/* BYPASS mode */
type = ((bpno <= (cblk->numbps - 1) - 4) && (passtype < 2) && (cblksty & J2K_CCP_CBLKSTY_LAZY)) ? T1_TYPE_RAW : T1_TYPE_MQ;
/* FIXME: slviewer gets here with a null pointer. Why? Partially downloaded and/or corrupt textures? */
if(seg->data == NULL){
continue;
}
if (type == T1_TYPE_RAW) {
raw_init_dec(raw, (*seg->data) + seg->dataindex, seg->len);
} else {
mqc_init_dec(mqc, (*seg->data) + seg->dataindex, seg->len);
}
for (passno = 0; passno < seg->numpasses; ++passno) {
switch (passtype) {
case 0:
if (type == T1_TYPE_RAW) {
t1_dec_sigpass_raw(t1, bpno+1, orient, cblksty);
} else {
if (cblksty & J2K_CCP_CBLKSTY_VSC) {
t1_dec_sigpass_mqc_vsc(t1, bpno+1, orient);
} else {
t1_dec_sigpass_mqc(t1, bpno+1, orient);
}
}
break;
case 1:
if (type == T1_TYPE_RAW) {
t1_dec_refpass_raw(t1, bpno+1, cblksty);
} else {
if (cblksty & J2K_CCP_CBLKSTY_VSC) {
t1_dec_refpass_mqc_vsc(t1, bpno+1);
} else {
t1_dec_refpass_mqc(t1, bpno+1);
}
}
break;
case 2:
t1_dec_clnpass(t1, bpno+1, orient, cblksty);
break;
}
if ((cblksty & J2K_CCP_CBLKSTY_RESET) && type == T1_TYPE_MQ) {
mqc_resetstates(mqc);
mqc_setstate(mqc, T1_CTXNO_UNI, 0, 46);
mqc_setstate(mqc, T1_CTXNO_AGG, 0, 3);
mqc_setstate(mqc, T1_CTXNO_ZC, 0, 4);
}
if (++passtype == 3) {
passtype = 0;
bpno--;
}
}
}
}
 
/* ----------------------------------------------------------------------- */
 
opj_t1_t* t1_create(opj_common_ptr cinfo) {
opj_t1_t *t1 = (opj_t1_t*) opj_malloc(sizeof(opj_t1_t));
if(!t1)
return NULL;
 
t1->cinfo = cinfo;
/* create MQC and RAW handles */
t1->mqc = mqc_create();
t1->raw = raw_create();
 
t1->data=NULL;
t1->flags=NULL;
t1->datasize=0;
t1->flagssize=0;
 
return t1;
}
 
void t1_destroy(opj_t1_t *t1) {
if(t1) {
/* destroy MQC and RAW handles */
mqc_destroy(t1->mqc);
raw_destroy(t1->raw);
opj_aligned_free(t1->data);
opj_aligned_free(t1->flags);
opj_free(t1);
}
}
 
void t1_encode_cblks(
opj_t1_t *t1,
opj_tcd_tile_t *tile,
opj_tcp_t *tcp)
{
int compno, resno, bandno, precno, cblkno;
 
tile->distotile = 0; /* fixed_quality */
 
for (compno = 0; compno < tile->numcomps; ++compno) {
opj_tcd_tilecomp_t* tilec = &tile->comps[compno];
opj_tccp_t* tccp = &tcp->tccps[compno];
int tile_w = tilec->x1 - tilec->x0;
 
for (resno = 0; resno < tilec->numresolutions; ++resno) {
opj_tcd_resolution_t *res = &tilec->resolutions[resno];
 
for (bandno = 0; bandno < res->numbands; ++bandno) {
opj_tcd_band_t* restrict band = &res->bands[bandno];
 
for (precno = 0; precno < res->pw * res->ph; ++precno) {
opj_tcd_precinct_t *prc = &band->precincts[precno];
 
for (cblkno = 0; cblkno < prc->cw * prc->ch; ++cblkno) {
opj_tcd_cblk_enc_t* cblk = &prc->cblks.enc[cblkno];
int* restrict datap;
int* restrict tiledp;
int cblk_w;
int cblk_h;
int i, j;
 
int x = cblk->x0 - band->x0;
int y = cblk->y0 - band->y0;
if (band->bandno & 1) {
opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1];
x += pres->x1 - pres->x0;
}
if (band->bandno & 2) {
opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1];
y += pres->y1 - pres->y0;
}
 
if(!allocate_buffers(
t1,
cblk->x1 - cblk->x0,
cblk->y1 - cblk->y0))
{
return;
}
 
datap=t1->data;
cblk_w = t1->w;
cblk_h = t1->h;
 
tiledp=&tilec->data[(y * tile_w) + x];
if (tccp->qmfbid == 1) {
for (j = 0; j < cblk_h; ++j) {
for (i = 0; i < cblk_w; ++i) {
int tmp = tiledp[(j * tile_w) + i];
datap[(j * cblk_w) + i] = tmp << T1_NMSEDEC_FRACBITS;
}
}
} else { /* if (tccp->qmfbid == 0) */
for (j = 0; j < cblk_h; ++j) {
for (i = 0; i < cblk_w; ++i) {
int tmp = tiledp[(j * tile_w) + i];
datap[(j * cblk_w) + i] =
fix_mul(
tmp,
8192 * 8192 / ((int) floor(band->stepsize * 8192))) >> (11 - T1_NMSEDEC_FRACBITS);
}
}
}
 
t1_encode_cblk(
t1,
cblk,
band->bandno,
compno,
tilec->numresolutions - 1 - resno,
tccp->qmfbid,
band->stepsize,
tccp->cblksty,
tile->numcomps,
tcp->mct,
tile);
 
} /* cblkno */
} /* precno */
} /* bandno */
} /* resno */
} /* compno */
}
 
void t1_decode_cblks(
opj_t1_t* t1,
opj_tcd_tilecomp_t* tilec,
opj_tccp_t* tccp)
{
int resno, bandno, precno, cblkno;
 
int tile_w = tilec->x1 - tilec->x0;
 
for (resno = 0; resno < tilec->numresolutions; ++resno) {
opj_tcd_resolution_t* res = &tilec->resolutions[resno];
 
for (bandno = 0; bandno < res->numbands; ++bandno) {
opj_tcd_band_t* restrict band = &res->bands[bandno];
 
for (precno = 0; precno < res->pw * res->ph; ++precno) {
opj_tcd_precinct_t* precinct = &band->precincts[precno];
 
for (cblkno = 0; cblkno < precinct->cw * precinct->ch; ++cblkno) {
opj_tcd_cblk_dec_t* cblk = &precinct->cblks.dec[cblkno];
int* restrict datap;
int cblk_w, cblk_h;
int x, y;
int i, j;
 
t1_decode_cblk(
t1,
cblk,
band->bandno,
tccp->roishift,
tccp->cblksty);
 
x = cblk->x0 - band->x0;
y = cblk->y0 - band->y0;
if (band->bandno & 1) {
opj_tcd_resolution_t* pres = &tilec->resolutions[resno - 1];
x += pres->x1 - pres->x0;
}
if (band->bandno & 2) {
opj_tcd_resolution_t* pres = &tilec->resolutions[resno - 1];
y += pres->y1 - pres->y0;
}
 
datap=t1->data;
cblk_w = t1->w;
cblk_h = t1->h;
 
if (tccp->roishift) {
int thresh = 1 << tccp->roishift;
for (j = 0; j < cblk_h; ++j) {
for (i = 0; i < cblk_w; ++i) {
int val = datap[(j * cblk_w) + i];
int mag = abs(val);
if (mag >= thresh) {
mag >>= tccp->roishift;
datap[(j * cblk_w) + i] = val < 0 ? -mag : mag;
}
}
}
}
 
if (tccp->qmfbid == 1) {
int* restrict tiledp = &tilec->data[(y * tile_w) + x];
for (j = 0; j < cblk_h; ++j) {
for (i = 0; i < cblk_w; ++i) {
int tmp = datap[(j * cblk_w) + i];
((int*)tiledp)[(j * tile_w) + i] = tmp / 2;
}
}
} else { /* if (tccp->qmfbid == 0) */
float* restrict tiledp = (float*) &tilec->data[(y * tile_w) + x];
for (j = 0; j < cblk_h; ++j) {
float* restrict tiledp2 = tiledp;
for (i = 0; i < cblk_w; ++i) {
float tmp = *datap * band->stepsize;
*tiledp2 = tmp;
datap++;
tiledp2++;
}
tiledp += tile_w;
}
}
opj_free(cblk->data);
opj_free(cblk->segs);
} /* cblkno */
opj_free(precinct->cblks.dec);
} /* precno */
} /* bandno */
} /* resno */
}
 
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libopenjpeg/t1.h
0,0 → 1,147
/*
* Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2007, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __T1_H
#define __T1_H
/**
@file t1.h
@brief Implementation of the tier-1 coding (coding of code-block coefficients) (T1)
 
The functions in T1.C have for goal to realize the tier-1 coding operation. The functions
in T1.C are used by some function in TCD.C.
*/
 
/** @defgroup T1 T1 - Implementation of the tier-1 coding */
/*@{*/
 
/* ----------------------------------------------------------------------- */
#define T1_NMSEDEC_BITS 7
 
#define T1_SIG_NE 0x0001 /**< Context orientation : North-East direction */
#define T1_SIG_SE 0x0002 /**< Context orientation : South-East direction */
#define T1_SIG_SW 0x0004 /**< Context orientation : South-West direction */
#define T1_SIG_NW 0x0008 /**< Context orientation : North-West direction */
#define T1_SIG_N 0x0010 /**< Context orientation : North direction */
#define T1_SIG_E 0x0020 /**< Context orientation : East direction */
#define T1_SIG_S 0x0040 /**< Context orientation : South direction */
#define T1_SIG_W 0x0080 /**< Context orientation : West direction */
#define T1_SIG_OTH (T1_SIG_N|T1_SIG_NE|T1_SIG_E|T1_SIG_SE|T1_SIG_S|T1_SIG_SW|T1_SIG_W|T1_SIG_NW)
#define T1_SIG_PRIM (T1_SIG_N|T1_SIG_E|T1_SIG_S|T1_SIG_W)
 
#define T1_SGN_N 0x0100
#define T1_SGN_E 0x0200
#define T1_SGN_S 0x0400
#define T1_SGN_W 0x0800
#define T1_SGN (T1_SGN_N|T1_SGN_E|T1_SGN_S|T1_SGN_W)
 
#define T1_SIG 0x1000
#define T1_REFINE 0x2000
#define T1_VISIT 0x4000
 
#define T1_NUMCTXS_ZC 9
#define T1_NUMCTXS_SC 5
#define T1_NUMCTXS_MAG 3
#define T1_NUMCTXS_AGG 1
#define T1_NUMCTXS_UNI 1
 
#define T1_CTXNO_ZC 0
#define T1_CTXNO_SC (T1_CTXNO_ZC+T1_NUMCTXS_ZC)
#define T1_CTXNO_MAG (T1_CTXNO_SC+T1_NUMCTXS_SC)
#define T1_CTXNO_AGG (T1_CTXNO_MAG+T1_NUMCTXS_MAG)
#define T1_CTXNO_UNI (T1_CTXNO_AGG+T1_NUMCTXS_AGG)
#define T1_NUMCTXS (T1_CTXNO_UNI+T1_NUMCTXS_UNI)
 
#define T1_NMSEDEC_FRACBITS (T1_NMSEDEC_BITS-1)
 
#define T1_TYPE_MQ 0 /**< Normal coding using entropy coder */
#define T1_TYPE_RAW 1 /**< No encoding the information is store under raw format in codestream (mode switch RAW)*/
 
/* ----------------------------------------------------------------------- */
 
typedef short flag_t;
 
/**
Tier-1 coding (coding of code-block coefficients)
*/
typedef struct opj_t1 {
/** codec context */
opj_common_ptr cinfo;
 
/** MQC component */
opj_mqc_t *mqc;
/** RAW component */
opj_raw_t *raw;
 
int *data;
flag_t *flags;
int w;
int h;
int datasize;
int flagssize;
int flags_stride;
} opj_t1_t;
 
#define MACRO_t1_flags(x,y) t1->flags[((x)*(t1->flags_stride))+(y)]
 
/** @name Exported functions */
/*@{*/
/* ----------------------------------------------------------------------- */
/**
Create a new T1 handle
and initialize the look-up tables of the Tier-1 coder/decoder
@return Returns a new T1 handle if successful, returns NULL otherwise
@see t1_init_luts
*/
opj_t1_t* t1_create(opj_common_ptr cinfo);
/**
Destroy a previously created T1 handle
@param t1 T1 handle to destroy
*/
void t1_destroy(opj_t1_t *t1);
/**
Encode the code-blocks of a tile
@param t1 T1 handle
@param tile The tile to encode
@param tcp Tile coding parameters
*/
void t1_encode_cblks(opj_t1_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp);
/**
Decode the code-blocks of a tile
@param t1 T1 handle
@param tilec The tile to decode
@param tccp Tile coding parameters
*/
void t1_decode_cblks(opj_t1_t* t1, opj_tcd_tilecomp_t* tilec, opj_tccp_t* tccp);
/* ----------------------------------------------------------------------- */
/*@}*/
 
/*@}*/
 
#endif /* __T1_H */
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libopenjpeg/t1_generate_luts.c
0,0 → 1,275
/*
* Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2007, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2007, Callum Lerwick <seg@haxxed.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
 
#include "opj_includes.h"
#include <math.h>
 
static int t1_init_ctxno_zc(int f, int orient) {
int h, v, d, n, t, hv;
n = 0;
h = ((f & T1_SIG_W) != 0) + ((f & T1_SIG_E) != 0);
v = ((f & T1_SIG_N) != 0) + ((f & T1_SIG_S) != 0);
d = ((f & T1_SIG_NW) != 0) + ((f & T1_SIG_NE) != 0) + ((f & T1_SIG_SE) != 0) + ((f & T1_SIG_SW) != 0);
 
switch (orient) {
case 2:
t = h;
h = v;
v = t;
case 0:
case 1:
if (!h) {
if (!v) {
if (!d)
n = 0;
else if (d == 1)
n = 1;
else
n = 2;
} else if (v == 1) {
n = 3;
} else {
n = 4;
}
} else if (h == 1) {
if (!v) {
if (!d)
n = 5;
else
n = 6;
} else {
n = 7;
}
} else
n = 8;
break;
case 3:
hv = h + v;
if (!d) {
if (!hv) {
n = 0;
} else if (hv == 1) {
n = 1;
} else {
n = 2;
}
} else if (d == 1) {
if (!hv) {
n = 3;
} else if (hv == 1) {
n = 4;
} else {
n = 5;
}
} else if (d == 2) {
if (!hv) {
n = 6;
} else {
n = 7;
}
} else {
n = 8;
}
break;
}
 
return (T1_CTXNO_ZC + n);
}
 
static int t1_init_ctxno_sc(int f) {
int hc, vc, n;
n = 0;
 
hc = int_min(((f & (T1_SIG_E | T1_SGN_E)) ==
T1_SIG_E) + ((f & (T1_SIG_W | T1_SGN_W)) == T1_SIG_W),
1) - int_min(((f & (T1_SIG_E | T1_SGN_E)) ==
(T1_SIG_E | T1_SGN_E)) +
((f & (T1_SIG_W | T1_SGN_W)) ==
(T1_SIG_W | T1_SGN_W)), 1);
 
vc = int_min(((f & (T1_SIG_N | T1_SGN_N)) ==
T1_SIG_N) + ((f & (T1_SIG_S | T1_SGN_S)) == T1_SIG_S),
1) - int_min(((f & (T1_SIG_N | T1_SGN_N)) ==
(T1_SIG_N | T1_SGN_N)) +
((f & (T1_SIG_S | T1_SGN_S)) ==
(T1_SIG_S | T1_SGN_S)), 1);
 
if (hc < 0) {
hc = -hc;
vc = -vc;
}
if (!hc) {
if (vc == -1)
n = 1;
else if (!vc)
n = 0;
else
n = 1;
} else if (hc == 1) {
if (vc == -1)
n = 2;
else if (!vc)
n = 3;
else
n = 4;
}
 
return (T1_CTXNO_SC + n);
}
 
static int t1_init_spb(int f) {
int hc, vc, n;
 
hc = int_min(((f & (T1_SIG_E | T1_SGN_E)) ==
T1_SIG_E) + ((f & (T1_SIG_W | T1_SGN_W)) == T1_SIG_W),
1) - int_min(((f & (T1_SIG_E | T1_SGN_E)) ==
(T1_SIG_E | T1_SGN_E)) +
((f & (T1_SIG_W | T1_SGN_W)) ==
(T1_SIG_W | T1_SGN_W)), 1);
 
vc = int_min(((f & (T1_SIG_N | T1_SGN_N)) ==
T1_SIG_N) + ((f & (T1_SIG_S | T1_SGN_S)) == T1_SIG_S),
1) - int_min(((f & (T1_SIG_N | T1_SGN_N)) ==
(T1_SIG_N | T1_SGN_N)) +
((f & (T1_SIG_S | T1_SGN_S)) ==
(T1_SIG_S | T1_SGN_S)), 1);
 
if (!hc && !vc)
n = 0;
else
n = (!(hc > 0 || (!hc && vc > 0)));
 
return n;
}
 
void dump_array16(int array[],int size){
int i;
--size;
for (i = 0; i < size; ++i) {
printf("0x%04x, ", array[i]);
if(!((i+1)&0x7))
printf("\n ");
}
printf("0x%04x\n};\n\n", array[size]);
}
 
int main(){
int i, j;
double u, v, t;
 
int lut_ctxno_zc[1024];
int lut_nmsedec_sig[1 << T1_NMSEDEC_BITS];
int lut_nmsedec_sig0[1 << T1_NMSEDEC_BITS];
int lut_nmsedec_ref[1 << T1_NMSEDEC_BITS];
int lut_nmsedec_ref0[1 << T1_NMSEDEC_BITS];
 
printf("/* This file was automatically generated by t1_generate_luts.c */\n\n");
 
// lut_ctxno_zc
for (j = 0; j < 4; ++j) {
for (i = 0; i < 256; ++i) {
int orient = j;
if (orient == 2) {
orient = 1;
} else if (orient == 1) {
orient = 2;
}
lut_ctxno_zc[(orient << 8) | i] = t1_init_ctxno_zc(i, j);
}
}
 
printf("static char lut_ctxno_zc[1024] = {\n ");
for (i = 0; i < 1023; ++i) {
printf("%i, ", lut_ctxno_zc[i]);
if(!((i+1)&0x1f))
printf("\n ");
}
printf("%i\n};\n\n", lut_ctxno_zc[1023]);
 
// lut_ctxno_sc
printf("static char lut_ctxno_sc[256] = {\n ");
for (i = 0; i < 255; ++i) {
printf("0x%x, ", t1_init_ctxno_sc(i << 4));
if(!((i+1)&0xf))
printf("\n ");
}
printf("0x%x\n};\n\n", t1_init_ctxno_sc(255 << 4));
 
// lut_spb
printf("static char lut_spb[256] = {\n ");
for (i = 0; i < 255; ++i) {
printf("%i, ", t1_init_spb(i << 4));
if(!((i+1)&0x1f))
printf("\n ");
}
printf("%i\n};\n\n", t1_init_spb(255 << 4));
 
/* FIXME FIXME FIXME */
/* fprintf(stdout,"nmsedec luts:\n"); */
for (i = 0; i < (1 << T1_NMSEDEC_BITS); ++i) {
t = i / pow(2, T1_NMSEDEC_FRACBITS);
u = t;
v = t - 1.5;
lut_nmsedec_sig[i] =
int_max(0,
(int) (floor((u * u - v * v) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) / pow(2, T1_NMSEDEC_FRACBITS) * 8192.0));
lut_nmsedec_sig0[i] =
int_max(0,
(int) (floor((u * u) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) / pow(2, T1_NMSEDEC_FRACBITS) * 8192.0));
u = t - 1.0;
if (i & (1 << (T1_NMSEDEC_BITS - 1))) {
v = t - 1.5;
} else {
v = t - 0.5;
}
lut_nmsedec_ref[i] =
int_max(0,
(int) (floor((u * u - v * v) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) / pow(2, T1_NMSEDEC_FRACBITS) * 8192.0));
lut_nmsedec_ref0[i] =
int_max(0,
(int) (floor((u * u) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) / pow(2, T1_NMSEDEC_FRACBITS) * 8192.0));
}
 
printf("static short lut_nmsedec_sig[1 << T1_NMSEDEC_BITS] = {\n ");
dump_array16(lut_nmsedec_sig, 1 << T1_NMSEDEC_BITS);
 
printf("static short lut_nmsedec_sig0[1 << T1_NMSEDEC_BITS] = {\n ");
dump_array16(lut_nmsedec_sig0, 1 << T1_NMSEDEC_BITS);
 
printf("static short lut_nmsedec_ref[1 << T1_NMSEDEC_BITS] = {\n ");
dump_array16(lut_nmsedec_ref, 1 << T1_NMSEDEC_BITS);
 
printf("static short lut_nmsedec_ref0[1 << T1_NMSEDEC_BITS] = {\n ");
dump_array16(lut_nmsedec_ref0, 1 << T1_NMSEDEC_BITS);
 
return 0;
}
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libopenjpeg/t1_luts.h
0,0 → 1,143
/* This file was automatically generated by t1_generate_luts.c */
 
static char lut_ctxno_zc[1024] = {
0, 1, 1, 2, 1, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
0, 1, 1, 2, 1, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
0, 1, 1, 2, 1, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
0, 3, 3, 6, 3, 6, 6, 8, 3, 6, 6, 8, 6, 8, 8, 8, 1, 4, 4, 7, 4, 7, 7, 8, 4, 7, 7, 8, 7, 8, 8, 8,
1, 4, 4, 7, 4, 7, 7, 8, 4, 7, 7, 8, 7, 8, 8, 8, 2, 5, 5, 7, 5, 7, 7, 8, 5, 7, 7, 8, 7, 8, 8, 8,
1, 4, 4, 7, 4, 7, 7, 8, 4, 7, 7, 8, 7, 8, 8, 8, 2, 5, 5, 7, 5, 7, 7, 8, 5, 7, 7, 8, 7, 8, 8, 8,
2, 5, 5, 7, 5, 7, 7, 8, 5, 7, 7, 8, 7, 8, 8, 8, 2, 5, 5, 7, 5, 7, 7, 8, 5, 7, 7, 8, 7, 8, 8, 8,
1, 4, 4, 7, 4, 7, 7, 8, 4, 7, 7, 8, 7, 8, 8, 8, 2, 5, 5, 7, 5, 7, 7, 8, 5, 7, 7, 8, 7, 8, 8, 8,
2, 5, 5, 7, 5, 7, 7, 8, 5, 7, 7, 8, 7, 8, 8, 8, 2, 5, 5, 7, 5, 7, 7, 8, 5, 7, 7, 8, 7, 8, 8, 8,
2, 5, 5, 7, 5, 7, 7, 8, 5, 7, 7, 8, 7, 8, 8, 8, 2, 5, 5, 7, 5, 7, 7, 8, 5, 7, 7, 8, 7, 8, 8, 8,
2, 5, 5, 7, 5, 7, 7, 8, 5, 7, 7, 8, 7, 8, 8, 8, 2, 5, 5, 7, 5, 7, 7, 8, 5, 7, 7, 8, 7, 8, 8, 8
};
 
static char lut_ctxno_sc[256] = {
0x9, 0xa, 0xc, 0xd, 0xa, 0xa, 0xd, 0xd, 0xc, 0xd, 0xc, 0xd, 0xd, 0xd, 0xd, 0xd,
0x9, 0xa, 0xc, 0xb, 0xa, 0x9, 0xd, 0xc, 0xc, 0xb, 0xc, 0xb, 0xd, 0xc, 0xd, 0xc,
0x9, 0xa, 0xc, 0xb, 0xa, 0xa, 0xb, 0xb, 0xc, 0xd, 0x9, 0xa, 0xd, 0xd, 0xa, 0xa,
0x9, 0xa, 0xc, 0xd, 0xa, 0x9, 0xb, 0xc, 0xc, 0xb, 0x9, 0xa, 0xd, 0xc, 0xa, 0x9,
0x9, 0xa, 0xc, 0xd, 0xa, 0x9, 0xb, 0xc, 0xc, 0xd, 0xc, 0xd, 0xb, 0xc, 0xb, 0xc,
0x9, 0xa, 0xc, 0xb, 0xa, 0xa, 0xb, 0xb, 0xc, 0xb, 0xc, 0xb, 0xb, 0xb, 0xb, 0xb,
0x9, 0xa, 0xc, 0xb, 0xa, 0x9, 0xd, 0xc, 0xc, 0xd, 0x9, 0xa, 0xb, 0xc, 0xa, 0x9,
0x9, 0xa, 0xc, 0xd, 0xa, 0xa, 0xd, 0xd, 0xc, 0xb, 0x9, 0xa, 0xb, 0xb, 0xa, 0xa,
0x9, 0xa, 0xc, 0xd, 0xa, 0xa, 0xd, 0xd, 0xc, 0xb, 0x9, 0xa, 0xb, 0xb, 0xa, 0xa,
0x9, 0xa, 0xc, 0xb, 0xa, 0x9, 0xd, 0xc, 0xc, 0xd, 0x9, 0xa, 0xb, 0xc, 0xa, 0x9,
0x9, 0xa, 0xc, 0xb, 0xa, 0xa, 0xb, 0xb, 0xc, 0xb, 0xc, 0xb, 0xb, 0xb, 0xb, 0xb,
0x9, 0xa, 0xc, 0xd, 0xa, 0x9, 0xb, 0xc, 0xc, 0xd, 0xc, 0xd, 0xb, 0xc, 0xb, 0xc,
0x9, 0xa, 0xc, 0xd, 0xa, 0x9, 0xb, 0xc, 0xc, 0xb, 0x9, 0xa, 0xd, 0xc, 0xa, 0x9,
0x9, 0xa, 0xc, 0xb, 0xa, 0xa, 0xb, 0xb, 0xc, 0xd, 0x9, 0xa, 0xd, 0xd, 0xa, 0xa,
0x9, 0xa, 0xc, 0xb, 0xa, 0x9, 0xd, 0xc, 0xc, 0xb, 0xc, 0xb, 0xd, 0xc, 0xd, 0xc,
0x9, 0xa, 0xc, 0xd, 0xa, 0xa, 0xd, 0xd, 0xc, 0xd, 0xc, 0xd, 0xd, 0xd, 0xd, 0xd
};
 
static char lut_spb[256] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1,
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0,
0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1,
0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
};
 
static short lut_nmsedec_sig[1 << T1_NMSEDEC_BITS] = {
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0180, 0x0300, 0x0480, 0x0600, 0x0780, 0x0900, 0x0a80,
0x0c00, 0x0d80, 0x0f00, 0x1080, 0x1200, 0x1380, 0x1500, 0x1680,
0x1800, 0x1980, 0x1b00, 0x1c80, 0x1e00, 0x1f80, 0x2100, 0x2280,
0x2400, 0x2580, 0x2700, 0x2880, 0x2a00, 0x2b80, 0x2d00, 0x2e80,
0x3000, 0x3180, 0x3300, 0x3480, 0x3600, 0x3780, 0x3900, 0x3a80,
0x3c00, 0x3d80, 0x3f00, 0x4080, 0x4200, 0x4380, 0x4500, 0x4680,
0x4800, 0x4980, 0x4b00, 0x4c80, 0x4e00, 0x4f80, 0x5100, 0x5280,
0x5400, 0x5580, 0x5700, 0x5880, 0x5a00, 0x5b80, 0x5d00, 0x5e80,
0x6000, 0x6180, 0x6300, 0x6480, 0x6600, 0x6780, 0x6900, 0x6a80,
0x6c00, 0x6d80, 0x6f00, 0x7080, 0x7200, 0x7380, 0x7500, 0x7680
};
 
static short lut_nmsedec_sig0[1 << T1_NMSEDEC_BITS] = {
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0080, 0x0080,
0x0080, 0x0080, 0x0100, 0x0100, 0x0100, 0x0180, 0x0180, 0x0200,
0x0200, 0x0280, 0x0280, 0x0300, 0x0300, 0x0380, 0x0400, 0x0400,
0x0480, 0x0500, 0x0580, 0x0580, 0x0600, 0x0680, 0x0700, 0x0780,
0x0800, 0x0880, 0x0900, 0x0980, 0x0a00, 0x0a80, 0x0b80, 0x0c00,
0x0c80, 0x0d00, 0x0e00, 0x0e80, 0x0f00, 0x1000, 0x1080, 0x1180,
0x1200, 0x1300, 0x1380, 0x1480, 0x1500, 0x1600, 0x1700, 0x1780,
0x1880, 0x1980, 0x1a80, 0x1b00, 0x1c00, 0x1d00, 0x1e00, 0x1f00,
0x2000, 0x2100, 0x2200, 0x2300, 0x2400, 0x2500, 0x2680, 0x2780,
0x2880, 0x2980, 0x2b00, 0x2c00, 0x2d00, 0x2e80, 0x2f80, 0x3100,
0x3200, 0x3380, 0x3480, 0x3600, 0x3700, 0x3880, 0x3a00, 0x3b00,
0x3c80, 0x3e00, 0x3f80, 0x4080, 0x4200, 0x4380, 0x4500, 0x4680,
0x4800, 0x4980, 0x4b00, 0x4c80, 0x4e00, 0x4f80, 0x5180, 0x5300,
0x5480, 0x5600, 0x5800, 0x5980, 0x5b00, 0x5d00, 0x5e80, 0x6080,
0x6200, 0x6400, 0x6580, 0x6780, 0x6900, 0x6b00, 0x6d00, 0x6e80,
0x7080, 0x7280, 0x7480, 0x7600, 0x7800, 0x7a00, 0x7c00, 0x7e00
};
 
static short lut_nmsedec_ref[1 << T1_NMSEDEC_BITS] = {
0x1800, 0x1780, 0x1700, 0x1680, 0x1600, 0x1580, 0x1500, 0x1480,
0x1400, 0x1380, 0x1300, 0x1280, 0x1200, 0x1180, 0x1100, 0x1080,
0x1000, 0x0f80, 0x0f00, 0x0e80, 0x0e00, 0x0d80, 0x0d00, 0x0c80,
0x0c00, 0x0b80, 0x0b00, 0x0a80, 0x0a00, 0x0980, 0x0900, 0x0880,
0x0800, 0x0780, 0x0700, 0x0680, 0x0600, 0x0580, 0x0500, 0x0480,
0x0400, 0x0380, 0x0300, 0x0280, 0x0200, 0x0180, 0x0100, 0x0080,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0080, 0x0100, 0x0180, 0x0200, 0x0280, 0x0300, 0x0380,
0x0400, 0x0480, 0x0500, 0x0580, 0x0600, 0x0680, 0x0700, 0x0780,
0x0800, 0x0880, 0x0900, 0x0980, 0x0a00, 0x0a80, 0x0b00, 0x0b80,
0x0c00, 0x0c80, 0x0d00, 0x0d80, 0x0e00, 0x0e80, 0x0f00, 0x0f80,
0x1000, 0x1080, 0x1100, 0x1180, 0x1200, 0x1280, 0x1300, 0x1380,
0x1400, 0x1480, 0x1500, 0x1580, 0x1600, 0x1680, 0x1700, 0x1780
};
 
static short lut_nmsedec_ref0[1 << T1_NMSEDEC_BITS] = {
0x2000, 0x1f00, 0x1e00, 0x1d00, 0x1c00, 0x1b00, 0x1a80, 0x1980,
0x1880, 0x1780, 0x1700, 0x1600, 0x1500, 0x1480, 0x1380, 0x1300,
0x1200, 0x1180, 0x1080, 0x1000, 0x0f00, 0x0e80, 0x0e00, 0x0d00,
0x0c80, 0x0c00, 0x0b80, 0x0a80, 0x0a00, 0x0980, 0x0900, 0x0880,
0x0800, 0x0780, 0x0700, 0x0680, 0x0600, 0x0580, 0x0580, 0x0500,
0x0480, 0x0400, 0x0400, 0x0380, 0x0300, 0x0300, 0x0280, 0x0280,
0x0200, 0x0200, 0x0180, 0x0180, 0x0100, 0x0100, 0x0100, 0x0080,
0x0080, 0x0080, 0x0080, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0080, 0x0080,
0x0080, 0x0080, 0x0100, 0x0100, 0x0100, 0x0180, 0x0180, 0x0200,
0x0200, 0x0280, 0x0280, 0x0300, 0x0300, 0x0380, 0x0400, 0x0400,
0x0480, 0x0500, 0x0580, 0x0580, 0x0600, 0x0680, 0x0700, 0x0780,
0x0800, 0x0880, 0x0900, 0x0980, 0x0a00, 0x0a80, 0x0b80, 0x0c00,
0x0c80, 0x0d00, 0x0e00, 0x0e80, 0x0f00, 0x1000, 0x1080, 0x1180,
0x1200, 0x1300, 0x1380, 0x1480, 0x1500, 0x1600, 0x1700, 0x1780,
0x1880, 0x1980, 0x1a80, 0x1b00, 0x1c00, 0x1d00, 0x1e00, 0x1f00
};
 
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libopenjpeg/t2.c
0,0 → 1,791
/*
* Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2007, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
 
#include "opj_includes.h"
 
/** @defgroup T2 T2 - Implementation of a tier-2 coding */
/*@{*/
 
/** @name Local static functions */
/*@{*/
 
static void t2_putcommacode(opj_bio_t *bio, int n);
static int t2_getcommacode(opj_bio_t *bio);
/**
Variable length code for signalling delta Zil (truncation point)
@param bio Bit Input/Output component
@param n delta Zil
*/
static void t2_putnumpasses(opj_bio_t *bio, int n);
static int t2_getnumpasses(opj_bio_t *bio);
/**
Encode a packet of a tile to a destination buffer
@param tile Tile for which to write the packets
@param tcp Tile coding parameters
@param pi Packet identity
@param dest Destination buffer
@param len Length of the destination buffer
@param cstr_info Codestream information structure
@param tileno Number of the tile encoded
@return
*/
static int t2_encode_packet(opj_tcd_tile_t *tile, opj_tcp_t *tcp, opj_pi_iterator_t *pi, unsigned char *dest, int len, opj_codestream_info_t *cstr_info, int tileno);
/**
@param cblk
@param index
@param cblksty
@param first
*/
static void t2_init_seg(opj_tcd_cblk_dec_t* cblk, int index, int cblksty, int first);
/**
Decode a packet of a tile from a source buffer
@param t2 T2 handle
@param src Source buffer
@param len Length of the source buffer
@param tile Tile for which to write the packets
@param tcp Tile coding parameters
@param pi Packet identity
@param pack_info Packet information
@return
*/
static int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_tile_t *tile,
opj_tcp_t *tcp, opj_pi_iterator_t *pi, opj_packet_info_t *pack_info);
 
/*@}*/
 
/*@}*/
 
/* ----------------------------------------------------------------------- */
 
/* #define RESTART 0x04 */
 
static void t2_putcommacode(opj_bio_t *bio, int n) {
while (--n >= 0) {
bio_write(bio, 1, 1);
}
bio_write(bio, 0, 1);
}
 
static int t2_getcommacode(opj_bio_t *bio) {
int n;
for (n = 0; bio_read(bio, 1); n++) {
;
}
return n;
}
 
static void t2_putnumpasses(opj_bio_t *bio, int n) {
if (n == 1) {
bio_write(bio, 0, 1);
} else if (n == 2) {
bio_write(bio, 2, 2);
} else if (n <= 5) {
bio_write(bio, 0xc | (n - 3), 4);
} else if (n <= 36) {
bio_write(bio, 0x1e0 | (n - 6), 9);
} else if (n <= 164) {
bio_write(bio, 0xff80 | (n - 37), 16);
}
}
 
static int t2_getnumpasses(opj_bio_t *bio) {
int n;
if (!bio_read(bio, 1))
return 1;
if (!bio_read(bio, 1))
return 2;
if ((n = bio_read(bio, 2)) != 3)
return (3 + n);
if ((n = bio_read(bio, 5)) != 31)
return (6 + n);
return (37 + bio_read(bio, 7));
}
 
static int t2_encode_packet(opj_tcd_tile_t * tile, opj_tcp_t * tcp, opj_pi_iterator_t *pi, unsigned char *dest, int length, opj_codestream_info_t *cstr_info, int tileno) {
int bandno, cblkno;
unsigned char *c = dest;
 
int compno = pi->compno; /* component value */
int resno = pi->resno; /* resolution level value */
int precno = pi->precno; /* precinct value */
int layno = pi->layno; /* quality layer value */
 
opj_tcd_tilecomp_t *tilec = &tile->comps[compno];
opj_tcd_resolution_t *res = &tilec->resolutions[resno];
opj_bio_t *bio = NULL; /* BIO component */
/* <SOP 0xff91> */
if (tcp->csty & J2K_CP_CSTY_SOP) {
c[0] = 255;
c[1] = 145;
c[2] = 0;
c[3] = 4;
c[4] = (tile->packno % 65536) / 256;
c[5] = (tile->packno % 65536) % 256;
c += 6;
}
/* </SOP> */
if (!layno) {
for (bandno = 0; bandno < res->numbands; bandno++) {
opj_tcd_band_t *band = &res->bands[bandno];
opj_tcd_precinct_t *prc = &band->precincts[precno];
tgt_reset(prc->incltree);
tgt_reset(prc->imsbtree);
for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) {
opj_tcd_cblk_enc_t* cblk = &prc->cblks.enc[cblkno];
cblk->numpasses = 0;
tgt_setvalue(prc->imsbtree, cblkno, band->numbps - cblk->numbps);
}
}
}
bio = bio_create();
bio_init_enc(bio, c, length);
bio_write(bio, 1, 1); /* Empty header bit */
/* Writing Packet header */
for (bandno = 0; bandno < res->numbands; bandno++) {
opj_tcd_band_t *band = &res->bands[bandno];
opj_tcd_precinct_t *prc = &band->precincts[precno];
for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) {
opj_tcd_cblk_enc_t* cblk = &prc->cblks.enc[cblkno];
opj_tcd_layer_t *layer = &cblk->layers[layno];
if (!cblk->numpasses && layer->numpasses) {
tgt_setvalue(prc->incltree, cblkno, layno);
}
}
for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) {
opj_tcd_cblk_enc_t* cblk = &prc->cblks.enc[cblkno];
opj_tcd_layer_t *layer = &cblk->layers[layno];
int increment = 0;
int nump = 0;
int len = 0, passno;
/* cblk inclusion bits */
if (!cblk->numpasses) {
tgt_encode(bio, prc->incltree, cblkno, layno + 1);
} else {
bio_write(bio, layer->numpasses != 0, 1);
}
/* if cblk not included, go to the next cblk */
if (!layer->numpasses) {
continue;
}
/* if first instance of cblk --> zero bit-planes information */
if (!cblk->numpasses) {
cblk->numlenbits = 3;
tgt_encode(bio, prc->imsbtree, cblkno, 999);
}
/* number of coding passes included */
t2_putnumpasses(bio, layer->numpasses);
/* computation of the increase of the length indicator and insertion in the header */
for (passno = cblk->numpasses; passno < cblk->numpasses + layer->numpasses; passno++) {
opj_tcd_pass_t *pass = &cblk->passes[passno];
nump++;
len += pass->len;
if (pass->term || passno == (cblk->numpasses + layer->numpasses) - 1) {
increment = int_max(increment, int_floorlog2(len) + 1 - (cblk->numlenbits + int_floorlog2(nump)));
len = 0;
nump = 0;
}
}
t2_putcommacode(bio, increment);
 
/* computation of the new Length indicator */
cblk->numlenbits += increment;
 
/* insertion of the codeword segment length */
for (passno = cblk->numpasses; passno < cblk->numpasses + layer->numpasses; passno++) {
opj_tcd_pass_t *pass = &cblk->passes[passno];
nump++;
len += pass->len;
if (pass->term || passno == (cblk->numpasses + layer->numpasses) - 1) {
bio_write(bio, len, cblk->numlenbits + int_floorlog2(nump));
len = 0;
nump = 0;
}
}
}
}
 
if (bio_flush(bio)) {
bio_destroy(bio);
return -999; /* modified to eliminate longjmp !! */
}
 
c += bio_numbytes(bio);
bio_destroy(bio);
/* <EPH 0xff92> */
if (tcp->csty & J2K_CP_CSTY_EPH) {
c[0] = 255;
c[1] = 146;
c += 2;
}
/* </EPH> */
 
/* << INDEX */
// End of packet header position. Currently only represents the distance to start of packet
// Will be updated later by incrementing with packet start value
if(cstr_info && cstr_info->index_write) {
opj_packet_info_t *info_PK = &cstr_info->tile[tileno].packet[cstr_info->packno];
info_PK->end_ph_pos = (int)(c - dest);
}
/* INDEX >> */
/* Writing the packet body */
for (bandno = 0; bandno < res->numbands; bandno++) {
opj_tcd_band_t *band = &res->bands[bandno];
opj_tcd_precinct_t *prc = &band->precincts[precno];
for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) {
opj_tcd_cblk_enc_t* cblk = &prc->cblks.enc[cblkno];
opj_tcd_layer_t *layer = &cblk->layers[layno];
if (!layer->numpasses) {
continue;
}
if (c + layer->len > dest + length) {
return -999;
}
memcpy(c, layer->data, layer->len);
cblk->numpasses += layer->numpasses;
c += layer->len;
/* << INDEX */
if(cstr_info && cstr_info->index_write) {
opj_packet_info_t *info_PK = &cstr_info->tile[tileno].packet[cstr_info->packno];
info_PK->disto += layer->disto;
if (cstr_info->D_max < info_PK->disto) {
cstr_info->D_max = info_PK->disto;
}
}
/* INDEX >> */
}
}
return (c - dest);
}
 
static void t2_init_seg(opj_tcd_cblk_dec_t* cblk, int index, int cblksty, int first) {
opj_tcd_seg_t* seg;
cblk->segs = (opj_tcd_seg_t*) opj_realloc(cblk->segs, (index + 1) * sizeof(opj_tcd_seg_t));
seg = &cblk->segs[index];
seg->data = NULL;
seg->dataindex = 0;
seg->numpasses = 0;
seg->len = 0;
if (cblksty & J2K_CCP_CBLKSTY_TERMALL) {
seg->maxpasses = 1;
}
else if (cblksty & J2K_CCP_CBLKSTY_LAZY) {
if (first) {
seg->maxpasses = 10;
} else {
seg->maxpasses = (((seg - 1)->maxpasses == 1) || ((seg - 1)->maxpasses == 10)) ? 2 : 1;
}
} else {
seg->maxpasses = 109;
}
}
 
static int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_tile_t *tile,
opj_tcp_t *tcp, opj_pi_iterator_t *pi, opj_packet_info_t *pack_info) {
int bandno, cblkno;
unsigned char *c = src;
 
opj_cp_t *cp = t2->cp;
 
int compno = pi->compno; /* component value */
int resno = pi->resno; /* resolution level value */
int precno = pi->precno; /* precinct value */
int layno = pi->layno; /* quality layer value */
 
opj_tcd_resolution_t* res = &tile->comps[compno].resolutions[resno];
 
unsigned char *hd = NULL;
int present;
opj_bio_t *bio = NULL; /* BIO component */
if (layno == 0) {
for (bandno = 0; bandno < res->numbands; bandno++) {
opj_tcd_band_t *band = &res->bands[bandno];
opj_tcd_precinct_t *prc = &band->precincts[precno];
if ((band->x1-band->x0 == 0)||(band->y1-band->y0 == 0)) continue;
tgt_reset(prc->incltree);
tgt_reset(prc->imsbtree);
for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) {
opj_tcd_cblk_dec_t* cblk = &prc->cblks.dec[cblkno];
cblk->numsegs = 0;
}
}
}
/* SOP markers */
if (tcp->csty & J2K_CP_CSTY_SOP) {
if ((*c) != 0xff || (*(c + 1) != 0x91)) {
opj_event_msg(t2->cinfo, EVT_WARNING, "Expected SOP marker\n");
} else {
c += 6;
}
/** TODO : check the Nsop value */
}
/*
When the marker PPT/PPM is used the packet header are store in PPT/PPM marker
This part deal with this caracteristic
step 1: Read packet header in the saved structure
step 2: Return to codestream for decoding
*/
 
bio = bio_create();
if (cp->ppm == 1) { /* PPM */
hd = cp->ppm_data;
bio_init_dec(bio, hd, cp->ppm_len);
} else if (tcp->ppt == 1) { /* PPT */
hd = tcp->ppt_data;
bio_init_dec(bio, hd, tcp->ppt_len);
} else { /* Normal Case */
hd = c;
bio_init_dec(bio, hd, src+len-hd);
}
present = bio_read(bio, 1);
if (!present) {
bio_inalign(bio);
hd += bio_numbytes(bio);
bio_destroy(bio);
/* EPH markers */
if (tcp->csty & J2K_CP_CSTY_EPH) {
if ((*hd) != 0xff || (*(hd + 1) != 0x92)) {
printf("Error : expected EPH marker\n");
} else {
hd += 2;
}
}
 
/* << INDEX */
// End of packet header position. Currently only represents the distance to start of packet
// Will be updated later by incrementing with packet start value
if(pack_info) {
pack_info->end_ph_pos = (int)(c - src);
}
/* INDEX >> */
if (cp->ppm == 1) { /* PPM case */
cp->ppm_len += cp->ppm_data-hd;
cp->ppm_data = hd;
return (c - src);
}
if (tcp->ppt == 1) { /* PPT case */
tcp->ppt_len+=tcp->ppt_data-hd;
tcp->ppt_data = hd;
return (c - src);
}
return (hd - src);
}
for (bandno = 0; bandno < res->numbands; bandno++) {
opj_tcd_band_t *band = &res->bands[bandno];
opj_tcd_precinct_t *prc = &band->precincts[precno];
if ((band->x1-band->x0 == 0)||(band->y1-band->y0 == 0)) continue;
for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) {
int included, increment, n, segno;
opj_tcd_cblk_dec_t* cblk = &prc->cblks.dec[cblkno];
/* if cblk not yet included before --> inclusion tagtree */
if (!cblk->numsegs) {
included = tgt_decode(bio, prc->incltree, cblkno, layno + 1);
/* else one bit */
} else {
included = bio_read(bio, 1);
}
/* if cblk not included */
if (!included) {
cblk->numnewpasses = 0;
continue;
}
/* if cblk not yet included --> zero-bitplane tagtree */
if (!cblk->numsegs) {
int i, numimsbs;
for (i = 0; !tgt_decode(bio, prc->imsbtree, cblkno, i); i++) {
;
}
numimsbs = i - 1;
cblk->numbps = band->numbps - numimsbs;
cblk->numlenbits = 3;
}
/* number of coding passes */
cblk->numnewpasses = t2_getnumpasses(bio);
increment = t2_getcommacode(bio);
/* length indicator increment */
cblk->numlenbits += increment;
segno = 0;
if (!cblk->numsegs) {
t2_init_seg(cblk, segno, tcp->tccps[compno].cblksty, 1);
} else {
segno = cblk->numsegs - 1;
if (cblk->segs[segno].numpasses == cblk->segs[segno].maxpasses) {
++segno;
t2_init_seg(cblk, segno, tcp->tccps[compno].cblksty, 0);
}
}
n = cblk->numnewpasses;
do {
cblk->segs[segno].numnewpasses = int_min(cblk->segs[segno].maxpasses - cblk->segs[segno].numpasses, n);
cblk->segs[segno].newlen = bio_read(bio, cblk->numlenbits + int_floorlog2(cblk->segs[segno].numnewpasses));
n -= cblk->segs[segno].numnewpasses;
if (n > 0) {
++segno;
t2_init_seg(cblk, segno, tcp->tccps[compno].cblksty, 0);
}
} while (n > 0);
}
}
if (bio_inalign(bio)) {
bio_destroy(bio);
return -999;
}
hd += bio_numbytes(bio);
bio_destroy(bio);
/* EPH markers */
if (tcp->csty & J2K_CP_CSTY_EPH) {
if ((*hd) != 0xff || (*(hd + 1) != 0x92)) {
opj_event_msg(t2->cinfo, EVT_ERROR, "Expected EPH marker\n");
return -999;
} else {
hd += 2;
}
}
 
/* << INDEX */
// End of packet header position. Currently only represents the distance to start of packet
// Will be updated later by incrementing with packet start value
if(pack_info) {
pack_info->end_ph_pos = (int)(hd - src);
}
/* INDEX >> */
if (cp->ppm==1) {
cp->ppm_len+=cp->ppm_data-hd;
cp->ppm_data = hd;
} else if (tcp->ppt == 1) {
tcp->ppt_len+=tcp->ppt_data-hd;
tcp->ppt_data = hd;
} else {
c=hd;
}
for (bandno = 0; bandno < res->numbands; bandno++) {
opj_tcd_band_t *band = &res->bands[bandno];
opj_tcd_precinct_t *prc = &band->precincts[precno];
if ((band->x1-band->x0 == 0)||(band->y1-band->y0 == 0)) continue;
for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) {
opj_tcd_cblk_dec_t* cblk = &prc->cblks.dec[cblkno];
opj_tcd_seg_t *seg = NULL;
if (!cblk->numnewpasses)
continue;
if (!cblk->numsegs) {
seg = &cblk->segs[0];
cblk->numsegs++;
cblk->len = 0;
} else {
seg = &cblk->segs[cblk->numsegs - 1];
if (seg->numpasses == seg->maxpasses) {
seg++;
cblk->numsegs++;
}
}
do {
if (c + seg->newlen > src + len) {
return -999;
}
 
#ifdef USE_JPWL
/* we need here a j2k handle to verify if making a check to
the validity of cblocks parameters is selected from user (-W) */
 
/* let's check that we are not exceeding */
if ((cblk->len + seg->newlen) > 8192) {
opj_event_msg(t2->cinfo, EVT_WARNING,
"JPWL: segment too long (%d) for codeblock %d (p=%d, b=%d, r=%d, c=%d)\n",
seg->newlen, cblkno, precno, bandno, resno, compno);
if (!JPWL_ASSUME) {
opj_event_msg(t2->cinfo, EVT_ERROR, "JPWL: giving up\n");
return -999;
}
seg->newlen = 8192 - cblk->len;
opj_event_msg(t2->cinfo, EVT_WARNING, " - truncating segment to %d\n", seg->newlen);
break;
};
 
#endif /* USE_JPWL */
cblk->data = (unsigned char*) opj_realloc(cblk->data, (cblk->len + seg->newlen) * sizeof(unsigned char*));
memcpy(cblk->data + cblk->len, c, seg->newlen);
if (seg->numpasses == 0) {
seg->data = &cblk->data;
seg->dataindex = cblk->len;
}
c += seg->newlen;
cblk->len += seg->newlen;
seg->len += seg->newlen;
seg->numpasses += seg->numnewpasses;
cblk->numnewpasses -= seg->numnewpasses;
if (cblk->numnewpasses > 0) {
seg++;
cblk->numsegs++;
}
} while (cblk->numnewpasses > 0);
}
}
return (c - src);
}
 
/* ----------------------------------------------------------------------- */
 
int t2_encode_packets(opj_t2_t* t2,int tileno, opj_tcd_tile_t *tile, int maxlayers, unsigned char *dest, int len, opj_codestream_info_t *cstr_info,int tpnum, int tppos,int pino, J2K_T2_MODE t2_mode, int cur_totnum_tp){
unsigned char *c = dest;
int e = 0;
int compno;
opj_pi_iterator_t *pi = NULL;
int poc;
opj_image_t *image = t2->image;
opj_cp_t *cp = t2->cp;
opj_tcp_t *tcp = &cp->tcps[tileno];
int pocno = cp->cinema == CINEMA4K_24? 2: 1;
int maxcomp = cp->max_comp_size > 0 ? image->numcomps : 1;
pi = pi_initialise_encode(image, cp, tileno, t2_mode);
if(!pi) {
/* TODO: throw an error */
return -999;
}
if(t2_mode == THRESH_CALC ){ /* Calculating threshold */
for(compno = 0; compno < maxcomp; compno++ ){
for(poc = 0; poc < pocno ; poc++){
int comp_len = 0;
int tpnum = compno;
if (pi_create_encode(pi, cp,tileno,poc,tpnum,tppos,t2_mode,cur_totnum_tp)) {
opj_event_msg(t2->cinfo, EVT_ERROR, "Error initializing Packet Iterator\n");
pi_destroy(pi, cp, tileno);
return -999;
}
while (pi_next(&pi[poc])) {
if (pi[poc].layno < maxlayers) {
e = t2_encode_packet(tile, &cp->tcps[tileno], &pi[poc], c, dest + len - c, cstr_info, tileno);
comp_len = comp_len + e;
if (e == -999) {
break;
} else {
c += e;
}
}
}
if (e == -999) break;
if (cp->max_comp_size){
if (comp_len > cp->max_comp_size){
e = -999;
break;
}
}
}
if (e == -999) break;
}
}else{ /* t2_mode == FINAL_PASS */
pi_create_encode(pi, cp,tileno,pino,tpnum,tppos,t2_mode,cur_totnum_tp);
while (pi_next(&pi[pino])) {
if (pi[pino].layno < maxlayers) {
e = t2_encode_packet(tile, &cp->tcps[tileno], &pi[pino], c, dest + len - c, cstr_info, tileno);
if (e == -999) {
break;
} else {
c += e;
}
/* INDEX >> */
if(cstr_info) {
if(cstr_info->index_write) {
opj_tile_info_t *info_TL = &cstr_info->tile[tileno];
opj_packet_info_t *info_PK = &info_TL->packet[cstr_info->packno];
if (!cstr_info->packno) {
info_PK->start_pos = info_TL->end_header + 1;
} else {
info_PK->start_pos = ((cp->tp_on | tcp->POC)&& info_PK->start_pos) ? info_PK->start_pos : info_TL->packet[cstr_info->packno - 1].end_pos + 1;
}
info_PK->end_pos = info_PK->start_pos + e - 1;
info_PK->end_ph_pos += info_PK->start_pos - 1; // End of packet header which now only represents the distance
// to start of packet is incremented by value of start of packet
}
cstr_info->packno++;
}
/* << INDEX */
tile->packno++;
}
}
}
pi_destroy(pi, cp, tileno);
if (e == -999) {
return e;
}
return (c - dest);
}
 
int t2_decode_packets(opj_t2_t *t2, unsigned char *src, int len, int tileno, opj_tcd_tile_t *tile, opj_codestream_info_t *cstr_info) {
unsigned char *c = src;
opj_pi_iterator_t *pi;
int pino, e = 0;
int n = 0, curtp = 0;
int tp_start_packno;
 
opj_image_t *image = t2->image;
opj_cp_t *cp = t2->cp;
/* create a packet iterator */
pi = pi_create_decode(image, cp, tileno);
if(!pi) {
/* TODO: throw an error */
return -999;
}
 
tp_start_packno = 0;
for (pino = 0; pino <= cp->tcps[tileno].numpocs; pino++) {
while (pi_next(&pi[pino])) {
if ((cp->layer==0) || (cp->layer>=((pi[pino].layno)+1))) {
opj_packet_info_t *pack_info;
if (cstr_info)
pack_info = &cstr_info->tile[tileno].packet[cstr_info->packno];
else
pack_info = NULL;
e = t2_decode_packet(t2, c, src + len - c, tile, &cp->tcps[tileno], &pi[pino], pack_info);
} else {
e = 0;
}
if(e == -999) return -999;
/* progression in resolution */
image->comps[pi[pino].compno].resno_decoded =
(e > 0) ?
int_max(pi[pino].resno, image->comps[pi[pino].compno].resno_decoded)
: image->comps[pi[pino].compno].resno_decoded;
n++;
 
/* INDEX >> */
if(cstr_info) {
opj_tile_info_t *info_TL = &cstr_info->tile[tileno];
opj_packet_info_t *info_PK = &info_TL->packet[cstr_info->packno];
if (!cstr_info->packno) {
info_PK->start_pos = info_TL->end_header + 1;
} else if (info_TL->packet[cstr_info->packno-1].end_pos >= (int)cstr_info->tile[tileno].tp[curtp].tp_end_pos){ // New tile part
info_TL->tp[curtp].tp_numpacks = cstr_info->packno - tp_start_packno; // Number of packets in previous tile-part
tp_start_packno = cstr_info->packno;
curtp++;
info_PK->start_pos = cstr_info->tile[tileno].tp[curtp].tp_end_header+1;
} else {
info_PK->start_pos = (cp->tp_on && info_PK->start_pos) ? info_PK->start_pos : info_TL->packet[cstr_info->packno - 1].end_pos + 1;
}
info_PK->end_pos = info_PK->start_pos + e - 1;
info_PK->end_ph_pos += info_PK->start_pos - 1; // End of packet header which now only represents the distance
// to start of packet is incremented by value of start of packet
cstr_info->packno++;
}
/* << INDEX */
if (e == -999) { /* ADD */
break;
} else {
c += e;
}
}
}
/* INDEX >> */
if(cstr_info) {
cstr_info->tile[tileno].tp[curtp].tp_numpacks = cstr_info->packno - tp_start_packno; // Number of packets in last tile-part
}
/* << INDEX */
 
/* don't forget to release pi */
pi_destroy(pi, cp, tileno);
if (e == -999) {
return e;
}
return (c - src);
}
 
/* ----------------------------------------------------------------------- */
 
opj_t2_t* t2_create(opj_common_ptr cinfo, opj_image_t *image, opj_cp_t *cp) {
/* create the tcd structure */
opj_t2_t *t2 = (opj_t2_t*)opj_malloc(sizeof(opj_t2_t));
if(!t2) return NULL;
t2->cinfo = cinfo;
t2->image = image;
t2->cp = cp;
 
return t2;
}
 
void t2_destroy(opj_t2_t *t2) {
if(t2) {
opj_free(t2);
}
}
 
 
 
 
 
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libopenjpeg/t2.h
0,0 → 1,105
/*
* Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2007, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __T2_H
#define __T2_H
/**
@file t2.h
@brief Implementation of a tier-2 coding (packetization of code-block data) (T2)
 
*/
 
/** @defgroup T2 T2 - Implementation of a tier-2 coding */
/*@{*/
 
/**
Tier-2 coding
*/
typedef struct opj_t2 {
/** codec context */
opj_common_ptr cinfo;
 
/** Encoding: pointer to the src image. Decoding: pointer to the dst image. */
opj_image_t *image;
/** pointer to the image coding parameters */
opj_cp_t *cp;
} opj_t2_t;
 
/** @name Exported functions */
/*@{*/
/* ----------------------------------------------------------------------- */
 
/**
Encode the packets of a tile to a destination buffer
@param t2 T2 handle
@param tileno number of the tile encoded
@param tile the tile for which to write the packets
@param maxlayers maximum number of layers
@param dest the destination buffer
@param len the length of the destination buffer
@param cstr_info Codestream information structure
@param tpnum Tile part number of the current tile
@param tppos The position of the tile part flag in the progression order
@param pino
@param t2_mode If == 0 In Threshold calculation ,If == 1 Final pass
@param cur_totnum_tp The total number of tile parts in the current tile
*/
int t2_encode_packets(opj_t2_t* t2,int tileno, opj_tcd_tile_t *tile, int maxlayers, unsigned char *dest, int len, opj_codestream_info_t *cstr_info,int tpnum, int tppos,int pino,J2K_T2_MODE t2_mode,int cur_totnum_tp);
/**
Decode the packets of a tile from a source buffer
@param t2 T2 handle
@param src the source buffer
@param len length of the source buffer
@param tileno number that identifies the tile for which to decode the packets
@param tile tile for which to decode the packets
@param cstr_info Codestream information structure
*/
int t2_decode_packets(opj_t2_t *t2, unsigned char *src, int len, int tileno, opj_tcd_tile_t *tile, opj_codestream_info_t *cstr_info);
 
/**
Create a T2 handle
@param cinfo Codec context info
@param image Source or destination image
@param cp Image coding parameters
@return Returns a new T2 handle if successful, returns NULL otherwise
*/
opj_t2_t* t2_create(opj_common_ptr cinfo, opj_image_t *image, opj_cp_t *cp);
/**
Destroy a T2 handle
@param t2 T2 handle to destroy
*/
void t2_destroy(opj_t2_t *t2);
 
/* ----------------------------------------------------------------------- */
/*@}*/
 
/*@}*/
 
#endif /* __T2_H */
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libopenjpeg/tcd.c
0,0 → 1,1516
/*
* Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2007, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2006-2007, Parvatha Elangovan
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
 
#include "opj_includes.h"
 
void tcd_dump(FILE *fd, opj_tcd_t *tcd, opj_tcd_image_t * img) {
int tileno, compno, resno, bandno, precno;//, cblkno;
 
fprintf(fd, "image {\n");
fprintf(fd, " tw=%d, th=%d x0=%d x1=%d y0=%d y1=%d\n",
img->tw, img->th, tcd->image->x0, tcd->image->x1, tcd->image->y0, tcd->image->y1);
 
for (tileno = 0; tileno < img->th * img->tw; tileno++) {
opj_tcd_tile_t *tile = &tcd->tcd_image->tiles[tileno];
fprintf(fd, " tile {\n");
fprintf(fd, " x0=%d, y0=%d, x1=%d, y1=%d, numcomps=%d\n",
tile->x0, tile->y0, tile->x1, tile->y1, tile->numcomps);
for (compno = 0; compno < tile->numcomps; compno++) {
opj_tcd_tilecomp_t *tilec = &tile->comps[compno];
fprintf(fd, " tilec {\n");
fprintf(fd,
" x0=%d, y0=%d, x1=%d, y1=%d, numresolutions=%d\n",
tilec->x0, tilec->y0, tilec->x1, tilec->y1, tilec->numresolutions);
for (resno = 0; resno < tilec->numresolutions; resno++) {
opj_tcd_resolution_t *res = &tilec->resolutions[resno];
fprintf(fd, "\n res {\n");
fprintf(fd,
" x0=%d, y0=%d, x1=%d, y1=%d, pw=%d, ph=%d, numbands=%d\n",
res->x0, res->y0, res->x1, res->y1, res->pw, res->ph, res->numbands);
for (bandno = 0; bandno < res->numbands; bandno++) {
opj_tcd_band_t *band = &res->bands[bandno];
fprintf(fd, " band {\n");
fprintf(fd,
" x0=%d, y0=%d, x1=%d, y1=%d, stepsize=%f, numbps=%d\n",
band->x0, band->y0, band->x1, band->y1, band->stepsize, band->numbps);
for (precno = 0; precno < res->pw * res->ph; precno++) {
opj_tcd_precinct_t *prec = &band->precincts[precno];
fprintf(fd, " prec {\n");
fprintf(fd,
" x0=%d, y0=%d, x1=%d, y1=%d, cw=%d, ch=%d\n",
prec->x0, prec->y0, prec->x1, prec->y1, prec->cw, prec->ch);
/*
for (cblkno = 0; cblkno < prec->cw * prec->ch; cblkno++) {
opj_tcd_cblk_t *cblk = &prec->cblks[cblkno];
fprintf(fd, " cblk {\n");
fprintf(fd,
" x0=%d, y0=%d, x1=%d, y1=%d\n",
cblk->x0, cblk->y0, cblk->x1, cblk->y1);
fprintf(fd, " }\n");
}
*/
fprintf(fd, " }\n");
}
fprintf(fd, " }\n");
}
fprintf(fd, " }\n");
}
fprintf(fd, " }\n");
}
fprintf(fd, " }\n");
}
fprintf(fd, "}\n");
}
 
/* ----------------------------------------------------------------------- */
 
/**
Create a new TCD handle
*/
opj_tcd_t* tcd_create(opj_common_ptr cinfo) {
/* create the tcd structure */
opj_tcd_t *tcd = (opj_tcd_t*)opj_malloc(sizeof(opj_tcd_t));
if(!tcd) return NULL;
tcd->cinfo = cinfo;
tcd->tcd_image = (opj_tcd_image_t*)opj_malloc(sizeof(opj_tcd_image_t));
if(!tcd->tcd_image) {
opj_free(tcd);
return NULL;
}
 
return tcd;
}
 
/**
Destroy a previously created TCD handle
*/
void tcd_destroy(opj_tcd_t *tcd) {
if(tcd) {
opj_free(tcd->tcd_image);
opj_free(tcd);
}
}
 
/* ----------------------------------------------------------------------- */
 
void tcd_malloc_encode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp, int curtileno) {
int tileno, compno, resno, bandno, precno, cblkno;
 
tcd->image = image;
tcd->cp = cp;
tcd->tcd_image->tw = cp->tw;
tcd->tcd_image->th = cp->th;
tcd->tcd_image->tiles = (opj_tcd_tile_t *) opj_malloc(sizeof(opj_tcd_tile_t));
for (tileno = 0; tileno < 1; tileno++) {
opj_tcp_t *tcp = &cp->tcps[curtileno];
int j;
 
/* cfr p59 ISO/IEC FDIS15444-1 : 2000 (18 august 2000) */
int p = curtileno % cp->tw; /* si numerotation matricielle .. */
int q = curtileno / cp->tw; /* .. coordonnees de la tile (q,p) q pour ligne et p pour colonne */
 
/* opj_tcd_tile_t *tile=&tcd->tcd_image->tiles[tileno]; */
opj_tcd_tile_t *tile = tcd->tcd_image->tiles;
 
/* 4 borders of the tile rescale on the image if necessary */
tile->x0 = int_max(cp->tx0 + p * cp->tdx, image->x0);
tile->y0 = int_max(cp->ty0 + q * cp->tdy, image->y0);
tile->x1 = int_min(cp->tx0 + (p + 1) * cp->tdx, image->x1);
tile->y1 = int_min(cp->ty0 + (q + 1) * cp->tdy, image->y1);
tile->numcomps = image->numcomps;
/* tile->PPT=image->PPT; */
 
/* Modification of the RATE >> */
for (j = 0; j < tcp->numlayers; j++) {
tcp->rates[j] = tcp->rates[j] ?
cp->tp_on ?
(((float) (tile->numcomps
* (tile->x1 - tile->x0)
* (tile->y1 - tile->y0)
* image->comps[0].prec))
/(tcp->rates[j] * 8 * image->comps[0].dx * image->comps[0].dy)) - (((tcd->cur_totnum_tp - 1) * 14 )/ tcp->numlayers)
:
((float) (tile->numcomps
* (tile->x1 - tile->x0)
* (tile->y1 - tile->y0)
* image->comps[0].prec))/
(tcp->rates[j] * 8 * image->comps[0].dx * image->comps[0].dy)
: 0;
 
if (tcp->rates[j]) {
if (j && tcp->rates[j] < tcp->rates[j - 1] + 10) {
tcp->rates[j] = tcp->rates[j - 1] + 20;
} else {
if (!j && tcp->rates[j] < 30)
tcp->rates[j] = 30;
}
if(j == (tcp->numlayers-1)){
tcp->rates[j] = tcp->rates[j]- 2;
}
}
}
/* << Modification of the RATE */
tile->comps = (opj_tcd_tilecomp_t *) opj_malloc(image->numcomps * sizeof(opj_tcd_tilecomp_t));
for (compno = 0; compno < tile->numcomps; compno++) {
opj_tccp_t *tccp = &tcp->tccps[compno];
 
opj_tcd_tilecomp_t *tilec = &tile->comps[compno];
 
/* border of each tile component (global) */
tilec->x0 = int_ceildiv(tile->x0, image->comps[compno].dx);
tilec->y0 = int_ceildiv(tile->y0, image->comps[compno].dy);
tilec->x1 = int_ceildiv(tile->x1, image->comps[compno].dx);
tilec->y1 = int_ceildiv(tile->y1, image->comps[compno].dy);
tilec->data = (int *) opj_aligned_malloc((tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0) * sizeof(int));
tilec->numresolutions = tccp->numresolutions;
 
tilec->resolutions = (opj_tcd_resolution_t *) opj_malloc(tilec->numresolutions * sizeof(opj_tcd_resolution_t));
for (resno = 0; resno < tilec->numresolutions; resno++) {
int pdx, pdy;
int levelno = tilec->numresolutions - 1 - resno;
int tlprcxstart, tlprcystart, brprcxend, brprcyend;
int tlcbgxstart, tlcbgystart, brcbgxend, brcbgyend;
int cbgwidthexpn, cbgheightexpn;
int cblkwidthexpn, cblkheightexpn;
 
opj_tcd_resolution_t *res = &tilec->resolutions[resno];
/* border for each resolution level (global) */
res->x0 = int_ceildivpow2(tilec->x0, levelno);
res->y0 = int_ceildivpow2(tilec->y0, levelno);
res->x1 = int_ceildivpow2(tilec->x1, levelno);
res->y1 = int_ceildivpow2(tilec->y1, levelno);
res->numbands = resno == 0 ? 1 : 3;
/* p. 35, table A-23, ISO/IEC FDIS154444-1 : 2000 (18 august 2000) */
if (tccp->csty & J2K_CCP_CSTY_PRT) {
pdx = tccp->prcw[resno];
pdy = tccp->prch[resno];
} else {
pdx = 15;
pdy = 15;
}
/* p. 64, B.6, ISO/IEC FDIS15444-1 : 2000 (18 august 2000) */
tlprcxstart = int_floordivpow2(res->x0, pdx) << pdx;
tlprcystart = int_floordivpow2(res->y0, pdy) << pdy;
brprcxend = int_ceildivpow2(res->x1, pdx) << pdx;
brprcyend = int_ceildivpow2(res->y1, pdy) << pdy;
res->pw = (brprcxend - tlprcxstart) >> pdx;
res->ph = (brprcyend - tlprcystart) >> pdy;
if (resno == 0) {
tlcbgxstart = tlprcxstart;
tlcbgystart = tlprcystart;
brcbgxend = brprcxend;
brcbgyend = brprcyend;
cbgwidthexpn = pdx;
cbgheightexpn = pdy;
} else {
tlcbgxstart = int_ceildivpow2(tlprcxstart, 1);
tlcbgystart = int_ceildivpow2(tlprcystart, 1);
brcbgxend = int_ceildivpow2(brprcxend, 1);
brcbgyend = int_ceildivpow2(brprcyend, 1);
cbgwidthexpn = pdx - 1;
cbgheightexpn = pdy - 1;
}
cblkwidthexpn = int_min(tccp->cblkw, cbgwidthexpn);
cblkheightexpn = int_min(tccp->cblkh, cbgheightexpn);
for (bandno = 0; bandno < res->numbands; bandno++) {
int x0b, y0b, i;
int gain, numbps;
opj_stepsize_t *ss = NULL;
 
opj_tcd_band_t *band = &res->bands[bandno];
 
band->bandno = resno == 0 ? 0 : bandno + 1;
x0b = (band->bandno == 1) || (band->bandno == 3) ? 1 : 0;
y0b = (band->bandno == 2) || (band->bandno == 3) ? 1 : 0;
if (band->bandno == 0) {
/* band border (global) */
band->x0 = int_ceildivpow2(tilec->x0, levelno);
band->y0 = int_ceildivpow2(tilec->y0, levelno);
band->x1 = int_ceildivpow2(tilec->x1, levelno);
band->y1 = int_ceildivpow2(tilec->y1, levelno);
} else {
/* band border (global) */
band->x0 = int_ceildivpow2(tilec->x0 - (1 << levelno) * x0b, levelno + 1);
band->y0 = int_ceildivpow2(tilec->y0 - (1 << levelno) * y0b, levelno + 1);
band->x1 = int_ceildivpow2(tilec->x1 - (1 << levelno) * x0b, levelno + 1);
band->y1 = int_ceildivpow2(tilec->y1 - (1 << levelno) * y0b, levelno + 1);
}
ss = &tccp->stepsizes[resno == 0 ? 0 : 3 * (resno - 1) + bandno + 1];
gain = tccp->qmfbid == 0 ? dwt_getgain_real(band->bandno) : dwt_getgain(band->bandno);
numbps = image->comps[compno].prec + gain;
band->stepsize = (float)((1.0 + ss->mant / 2048.0) * pow(2.0, numbps - ss->expn));
band->numbps = ss->expn + tccp->numgbits - 1; /* WHY -1 ? */
band->precincts = (opj_tcd_precinct_t *) opj_malloc(3 * res->pw * res->ph * sizeof(opj_tcd_precinct_t));
for (i = 0; i < res->pw * res->ph * 3; i++) {
band->precincts[i].imsbtree = NULL;
band->precincts[i].incltree = NULL;
}
for (precno = 0; precno < res->pw * res->ph; precno++) {
int tlcblkxstart, tlcblkystart, brcblkxend, brcblkyend;
 
int cbgxstart = tlcbgxstart + (precno % res->pw) * (1 << cbgwidthexpn);
int cbgystart = tlcbgystart + (precno / res->pw) * (1 << cbgheightexpn);
int cbgxend = cbgxstart + (1 << cbgwidthexpn);
int cbgyend = cbgystart + (1 << cbgheightexpn);
 
opj_tcd_precinct_t *prc = &band->precincts[precno];
 
/* precinct size (global) */
prc->x0 = int_max(cbgxstart, band->x0);
prc->y0 = int_max(cbgystart, band->y0);
prc->x1 = int_min(cbgxend, band->x1);
prc->y1 = int_min(cbgyend, band->y1);
 
tlcblkxstart = int_floordivpow2(prc->x0, cblkwidthexpn) << cblkwidthexpn;
tlcblkystart = int_floordivpow2(prc->y0, cblkheightexpn) << cblkheightexpn;
brcblkxend = int_ceildivpow2(prc->x1, cblkwidthexpn) << cblkwidthexpn;
brcblkyend = int_ceildivpow2(prc->y1, cblkheightexpn) << cblkheightexpn;
prc->cw = (brcblkxend - tlcblkxstart) >> cblkwidthexpn;
prc->ch = (brcblkyend - tlcblkystart) >> cblkheightexpn;
 
prc->cblks.enc = (opj_tcd_cblk_enc_t*) opj_calloc((prc->cw * prc->ch), sizeof(opj_tcd_cblk_enc_t));
prc->incltree = tgt_create(prc->cw, prc->ch);
prc->imsbtree = tgt_create(prc->cw, prc->ch);
for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) {
int cblkxstart = tlcblkxstart + (cblkno % prc->cw) * (1 << cblkwidthexpn);
int cblkystart = tlcblkystart + (cblkno / prc->cw) * (1 << cblkheightexpn);
int cblkxend = cblkxstart + (1 << cblkwidthexpn);
int cblkyend = cblkystart + (1 << cblkheightexpn);
opj_tcd_cblk_enc_t* cblk = &prc->cblks.enc[cblkno];
 
/* code-block size (global) */
cblk->x0 = int_max(cblkxstart, prc->x0);
cblk->y0 = int_max(cblkystart, prc->y0);
cblk->x1 = int_min(cblkxend, prc->x1);
cblk->y1 = int_min(cblkyend, prc->y1);
cblk->data = (unsigned char*) opj_calloc(8192+2, sizeof(unsigned char));
/* FIXME: mqc_init_enc and mqc_byteout underrun the buffer if we don't do this. Why? */
cblk->data += 2;
cblk->layers = (opj_tcd_layer_t*) opj_calloc(100, sizeof(opj_tcd_layer_t));
cblk->passes = (opj_tcd_pass_t*) opj_calloc(100, sizeof(opj_tcd_pass_t));
}
}
}
}
}
}
/* tcd_dump(stdout, tcd, &tcd->tcd_image); */
}
 
void tcd_free_encode(opj_tcd_t *tcd) {
int tileno, compno, resno, bandno, precno, cblkno;
 
for (tileno = 0; tileno < 1; tileno++) {
opj_tcd_tile_t *tile = tcd->tcd_image->tiles;
 
for (compno = 0; compno < tile->numcomps; compno++) {
opj_tcd_tilecomp_t *tilec = &tile->comps[compno];
 
for (resno = 0; resno < tilec->numresolutions; resno++) {
opj_tcd_resolution_t *res = &tilec->resolutions[resno];
 
for (bandno = 0; bandno < res->numbands; bandno++) {
opj_tcd_band_t *band = &res->bands[bandno];
 
for (precno = 0; precno < res->pw * res->ph; precno++) {
opj_tcd_precinct_t *prc = &band->precincts[precno];
 
if (prc->incltree != NULL) {
tgt_destroy(prc->incltree);
prc->incltree = NULL;
}
if (prc->imsbtree != NULL) {
tgt_destroy(prc->imsbtree);
prc->imsbtree = NULL;
}
for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) {
opj_free(prc->cblks.enc[cblkno].data - 2);
opj_free(prc->cblks.enc[cblkno].layers);
opj_free(prc->cblks.enc[cblkno].passes);
}
opj_free(prc->cblks.enc);
} /* for (precno */
opj_free(band->precincts);
band->precincts = NULL;
} /* for (bandno */
} /* for (resno */
opj_free(tilec->resolutions);
tilec->resolutions = NULL;
} /* for (compno */
opj_free(tile->comps);
tile->comps = NULL;
} /* for (tileno */
opj_free(tcd->tcd_image->tiles);
tcd->tcd_image->tiles = NULL;
}
 
void tcd_init_encode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp, int curtileno) {
int tileno, compno, resno, bandno, precno, cblkno;
 
for (tileno = 0; tileno < 1; tileno++) {
opj_tcp_t *tcp = &cp->tcps[curtileno];
int j;
/* cfr p59 ISO/IEC FDIS15444-1 : 2000 (18 august 2000) */
int p = curtileno % cp->tw;
int q = curtileno / cp->tw;
 
opj_tcd_tile_t *tile = tcd->tcd_image->tiles;
/* 4 borders of the tile rescale on the image if necessary */
tile->x0 = int_max(cp->tx0 + p * cp->tdx, image->x0);
tile->y0 = int_max(cp->ty0 + q * cp->tdy, image->y0);
tile->x1 = int_min(cp->tx0 + (p + 1) * cp->tdx, image->x1);
tile->y1 = int_min(cp->ty0 + (q + 1) * cp->tdy, image->y1);
tile->numcomps = image->numcomps;
/* tile->PPT=image->PPT; */
 
/* Modification of the RATE >> */
for (j = 0; j < tcp->numlayers; j++) {
tcp->rates[j] = tcp->rates[j] ?
cp->tp_on ?
(((float) (tile->numcomps
* (tile->x1 - tile->x0)
* (tile->y1 - tile->y0)
* image->comps[0].prec))
/(tcp->rates[j] * 8 * image->comps[0].dx * image->comps[0].dy)) - (((tcd->cur_totnum_tp - 1) * 14 )/ tcp->numlayers)
:
((float) (tile->numcomps
* (tile->x1 - tile->x0)
* (tile->y1 - tile->y0)
* image->comps[0].prec))/
(tcp->rates[j] * 8 * image->comps[0].dx * image->comps[0].dy)
: 0;
 
if (tcp->rates[j]) {
if (j && tcp->rates[j] < tcp->rates[j - 1] + 10) {
tcp->rates[j] = tcp->rates[j - 1] + 20;
} else {
if (!j && tcp->rates[j] < 30)
tcp->rates[j] = 30;
}
}
}
/* << Modification of the RATE */
 
/* tile->comps=(opj_tcd_tilecomp_t*)opj_realloc(tile->comps,image->numcomps*sizeof(opj_tcd_tilecomp_t)); */
for (compno = 0; compno < tile->numcomps; compno++) {
opj_tccp_t *tccp = &tcp->tccps[compno];
opj_tcd_tilecomp_t *tilec = &tile->comps[compno];
 
/* border of each tile component (global) */
tilec->x0 = int_ceildiv(tile->x0, image->comps[compno].dx);
tilec->y0 = int_ceildiv(tile->y0, image->comps[compno].dy);
tilec->x1 = int_ceildiv(tile->x1, image->comps[compno].dx);
tilec->y1 = int_ceildiv(tile->y1, image->comps[compno].dy);
tilec->data = (int *) opj_aligned_malloc((tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0) * sizeof(int));
tilec->numresolutions = tccp->numresolutions;
/* tilec->resolutions=(opj_tcd_resolution_t*)opj_realloc(tilec->resolutions,tilec->numresolutions*sizeof(opj_tcd_resolution_t)); */
for (resno = 0; resno < tilec->numresolutions; resno++) {
int pdx, pdy;
 
int levelno = tilec->numresolutions - 1 - resno;
int tlprcxstart, tlprcystart, brprcxend, brprcyend;
int tlcbgxstart, tlcbgystart, brcbgxend, brcbgyend;
int cbgwidthexpn, cbgheightexpn;
int cblkwidthexpn, cblkheightexpn;
opj_tcd_resolution_t *res = &tilec->resolutions[resno];
 
/* border for each resolution level (global) */
res->x0 = int_ceildivpow2(tilec->x0, levelno);
res->y0 = int_ceildivpow2(tilec->y0, levelno);
res->x1 = int_ceildivpow2(tilec->x1, levelno);
res->y1 = int_ceildivpow2(tilec->y1, levelno);
res->numbands = resno == 0 ? 1 : 3;
 
/* p. 35, table A-23, ISO/IEC FDIS154444-1 : 2000 (18 august 2000) */
if (tccp->csty & J2K_CCP_CSTY_PRT) {
pdx = tccp->prcw[resno];
pdy = tccp->prch[resno];
} else {
pdx = 15;
pdy = 15;
}
/* p. 64, B.6, ISO/IEC FDIS15444-1 : 2000 (18 august 2000) */
tlprcxstart = int_floordivpow2(res->x0, pdx) << pdx;
tlprcystart = int_floordivpow2(res->y0, pdy) << pdy;
brprcxend = int_ceildivpow2(res->x1, pdx) << pdx;
brprcyend = int_ceildivpow2(res->y1, pdy) << pdy;
res->pw = (brprcxend - tlprcxstart) >> pdx;
res->ph = (brprcyend - tlprcystart) >> pdy;
if (resno == 0) {
tlcbgxstart = tlprcxstart;
tlcbgystart = tlprcystart;
brcbgxend = brprcxend;
brcbgyend = brprcyend;
cbgwidthexpn = pdx;
cbgheightexpn = pdy;
} else {
tlcbgxstart = int_ceildivpow2(tlprcxstart, 1);
tlcbgystart = int_ceildivpow2(tlprcystart, 1);
brcbgxend = int_ceildivpow2(brprcxend, 1);
brcbgyend = int_ceildivpow2(brprcyend, 1);
cbgwidthexpn = pdx - 1;
cbgheightexpn = pdy - 1;
}
cblkwidthexpn = int_min(tccp->cblkw, cbgwidthexpn);
cblkheightexpn = int_min(tccp->cblkh, cbgheightexpn);
for (bandno = 0; bandno < res->numbands; bandno++) {
int x0b, y0b;
int gain, numbps;
opj_stepsize_t *ss = NULL;
 
opj_tcd_band_t *band = &res->bands[bandno];
 
band->bandno = resno == 0 ? 0 : bandno + 1;
x0b = (band->bandno == 1) || (band->bandno == 3) ? 1 : 0;
y0b = (band->bandno == 2) || (band->bandno == 3) ? 1 : 0;
if (band->bandno == 0) {
/* band border */
band->x0 = int_ceildivpow2(tilec->x0, levelno);
band->y0 = int_ceildivpow2(tilec->y0, levelno);
band->x1 = int_ceildivpow2(tilec->x1, levelno);
band->y1 = int_ceildivpow2(tilec->y1, levelno);
} else {
band->x0 = int_ceildivpow2(tilec->x0 - (1 << levelno) * x0b, levelno + 1);
band->y0 = int_ceildivpow2(tilec->y0 - (1 << levelno) * y0b, levelno + 1);
band->x1 = int_ceildivpow2(tilec->x1 - (1 << levelno) * x0b, levelno + 1);
band->y1 = int_ceildivpow2(tilec->y1 - (1 << levelno) * y0b, levelno + 1);
}
ss = &tccp->stepsizes[resno == 0 ? 0 : 3 * (resno - 1) + bandno + 1];
gain = tccp->qmfbid == 0 ? dwt_getgain_real(band->bandno) : dwt_getgain(band->bandno);
numbps = image->comps[compno].prec + gain;
band->stepsize = (float)((1.0 + ss->mant / 2048.0) * pow(2.0, numbps - ss->expn));
band->numbps = ss->expn + tccp->numgbits - 1; /* WHY -1 ? */
for (precno = 0; precno < res->pw * res->ph; precno++) {
int tlcblkxstart, tlcblkystart, brcblkxend, brcblkyend;
 
int cbgxstart = tlcbgxstart + (precno % res->pw) * (1 << cbgwidthexpn);
int cbgystart = tlcbgystart + (precno / res->pw) * (1 << cbgheightexpn);
int cbgxend = cbgxstart + (1 << cbgwidthexpn);
int cbgyend = cbgystart + (1 << cbgheightexpn);
opj_tcd_precinct_t *prc = &band->precincts[precno];
 
/* precinct size (global) */
prc->x0 = int_max(cbgxstart, band->x0);
prc->y0 = int_max(cbgystart, band->y0);
prc->x1 = int_min(cbgxend, band->x1);
prc->y1 = int_min(cbgyend, band->y1);
 
tlcblkxstart = int_floordivpow2(prc->x0, cblkwidthexpn) << cblkwidthexpn;
tlcblkystart = int_floordivpow2(prc->y0, cblkheightexpn) << cblkheightexpn;
brcblkxend = int_ceildivpow2(prc->x1, cblkwidthexpn) << cblkwidthexpn;
brcblkyend = int_ceildivpow2(prc->y1, cblkheightexpn) << cblkheightexpn;
prc->cw = (brcblkxend - tlcblkxstart) >> cblkwidthexpn;
prc->ch = (brcblkyend - tlcblkystart) >> cblkheightexpn;
 
opj_free(prc->cblks.enc);
prc->cblks.enc = (opj_tcd_cblk_enc_t*) opj_calloc(prc->cw * prc->ch, sizeof(opj_tcd_cblk_enc_t));
 
if (prc->incltree != NULL) {
tgt_destroy(prc->incltree);
}
if (prc->imsbtree != NULL) {
tgt_destroy(prc->imsbtree);
}
prc->incltree = tgt_create(prc->cw, prc->ch);
prc->imsbtree = tgt_create(prc->cw, prc->ch);
 
for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) {
int cblkxstart = tlcblkxstart + (cblkno % prc->cw) * (1 << cblkwidthexpn);
int cblkystart = tlcblkystart + (cblkno / prc->cw) * (1 << cblkheightexpn);
int cblkxend = cblkxstart + (1 << cblkwidthexpn);
int cblkyend = cblkystart + (1 << cblkheightexpn);
 
opj_tcd_cblk_enc_t* cblk = &prc->cblks.enc[cblkno];
 
/* code-block size (global) */
cblk->x0 = int_max(cblkxstart, prc->x0);
cblk->y0 = int_max(cblkystart, prc->y0);
cblk->x1 = int_min(cblkxend, prc->x1);
cblk->y1 = int_min(cblkyend, prc->y1);
cblk->data = (unsigned char*) opj_calloc(8192+2, sizeof(unsigned char));
/* FIXME: mqc_init_enc and mqc_byteout underrun the buffer if we don't do this. Why? */
cblk->data += 2;
cblk->layers = (opj_tcd_layer_t*) opj_calloc(100, sizeof(opj_tcd_layer_t));
cblk->passes = (opj_tcd_pass_t*) opj_calloc(100, sizeof(opj_tcd_pass_t));
}
} /* precno */
} /* bandno */
} /* resno */
} /* compno */
} /* tileno */
 
/* tcd_dump(stdout, tcd, &tcd->tcd_image); */
}
 
void tcd_malloc_decode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp) {
int i, j, tileno, p, q;
unsigned int x0 = 0, y0 = 0, x1 = 0, y1 = 0, w, h;
 
tcd->image = image;
tcd->tcd_image->tw = cp->tw;
tcd->tcd_image->th = cp->th;
tcd->tcd_image->tiles = (opj_tcd_tile_t *) opj_malloc(cp->tw * cp->th * sizeof(opj_tcd_tile_t));
 
/*
Allocate place to store the decoded data = final image
Place limited by the tile really present in the codestream
*/
 
for (j = 0; j < cp->tileno_size; j++) {
opj_tcd_tile_t *tile;
tileno = cp->tileno[j];
tile = &(tcd->tcd_image->tiles[cp->tileno[tileno]]);
tile->numcomps = image->numcomps;
tile->comps = (opj_tcd_tilecomp_t*) opj_calloc(image->numcomps, sizeof(opj_tcd_tilecomp_t));
}
 
for (i = 0; i < image->numcomps; i++) {
for (j = 0; j < cp->tileno_size; j++) {
opj_tcd_tile_t *tile;
opj_tcd_tilecomp_t *tilec;
/* cfr p59 ISO/IEC FDIS15444-1 : 2000 (18 august 2000) */
tileno = cp->tileno[j];
tile = &(tcd->tcd_image->tiles[cp->tileno[tileno]]);
tilec = &tile->comps[i];
p = tileno % cp->tw; /* si numerotation matricielle .. */
q = tileno / cp->tw; /* .. coordonnees de la tile (q,p) q pour ligne et p pour colonne */
/* 4 borders of the tile rescale on the image if necessary */
tile->x0 = int_max(cp->tx0 + p * cp->tdx, image->x0);
tile->y0 = int_max(cp->ty0 + q * cp->tdy, image->y0);
tile->x1 = int_min(cp->tx0 + (p + 1) * cp->tdx, image->x1);
tile->y1 = int_min(cp->ty0 + (q + 1) * cp->tdy, image->y1);
 
tilec->x0 = int_ceildiv(tile->x0, image->comps[i].dx);
tilec->y0 = int_ceildiv(tile->y0, image->comps[i].dy);
tilec->x1 = int_ceildiv(tile->x1, image->comps[i].dx);
tilec->y1 = int_ceildiv(tile->y1, image->comps[i].dy);
 
x0 = j == 0 ? tilec->x0 : int_min(x0, (unsigned int) tilec->x0);
y0 = j == 0 ? tilec->y0 : int_min(y0, (unsigned int) tilec->x0);
x1 = j == 0 ? tilec->x1 : int_max(x1, (unsigned int) tilec->x1);
y1 = j == 0 ? tilec->y1 : int_max(y1, (unsigned int) tilec->y1);
}
 
w = int_ceildivpow2(x1 - x0, image->comps[i].factor);
h = int_ceildivpow2(y1 - y0, image->comps[i].factor);
 
image->comps[i].w = w;
image->comps[i].h = h;
image->comps[i].x0 = x0;
image->comps[i].y0 = y0;
}
}
 
void tcd_malloc_decode_tile(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp, int tileno, opj_codestream_info_t *cstr_info) {
int compno, resno, bandno, precno, cblkno;
opj_tcp_t *tcp;
opj_tcd_tile_t *tile;
 
tcd->cp = cp;
tcp = &(cp->tcps[cp->tileno[tileno]]);
tile = &(tcd->tcd_image->tiles[cp->tileno[tileno]]);
tileno = cp->tileno[tileno];
for (compno = 0; compno < tile->numcomps; compno++) {
opj_tccp_t *tccp = &tcp->tccps[compno];
opj_tcd_tilecomp_t *tilec = &tile->comps[compno];
/* border of each tile component (global) */
tilec->x0 = int_ceildiv(tile->x0, image->comps[compno].dx);
tilec->y0 = int_ceildiv(tile->y0, image->comps[compno].dy);
tilec->x1 = int_ceildiv(tile->x1, image->comps[compno].dx);
tilec->y1 = int_ceildiv(tile->y1, image->comps[compno].dy);
 
tilec->numresolutions = tccp->numresolutions;
tilec->resolutions = (opj_tcd_resolution_t *) opj_malloc(tilec->numresolutions * sizeof(opj_tcd_resolution_t));
for (resno = 0; resno < tilec->numresolutions; resno++) {
int pdx, pdy;
int levelno = tilec->numresolutions - 1 - resno;
int tlprcxstart, tlprcystart, brprcxend, brprcyend;
int tlcbgxstart, tlcbgystart, brcbgxend, brcbgyend;
int cbgwidthexpn, cbgheightexpn;
int cblkwidthexpn, cblkheightexpn;
opj_tcd_resolution_t *res = &tilec->resolutions[resno];
/* border for each resolution level (global) */
res->x0 = int_ceildivpow2(tilec->x0, levelno);
res->y0 = int_ceildivpow2(tilec->y0, levelno);
res->x1 = int_ceildivpow2(tilec->x1, levelno);
res->y1 = int_ceildivpow2(tilec->y1, levelno);
res->numbands = resno == 0 ? 1 : 3;
/* p. 35, table A-23, ISO/IEC FDIS154444-1 : 2000 (18 august 2000) */
if (tccp->csty & J2K_CCP_CSTY_PRT) {
pdx = tccp->prcw[resno];
pdy = tccp->prch[resno];
} else {
pdx = 15;
pdy = 15;
}
/* p. 64, B.6, ISO/IEC FDIS15444-1 : 2000 (18 august 2000) */
tlprcxstart = int_floordivpow2(res->x0, pdx) << pdx;
tlprcystart = int_floordivpow2(res->y0, pdy) << pdy;
brprcxend = int_ceildivpow2(res->x1, pdx) << pdx;
brprcyend = int_ceildivpow2(res->y1, pdy) << pdy;
res->pw = (res->x0 == res->x1) ? 0 : ((brprcxend - tlprcxstart) >> pdx);
res->ph = (res->y0 == res->y1) ? 0 : ((brprcyend - tlprcystart) >> pdy);
if (resno == 0) {
tlcbgxstart = tlprcxstart;
tlcbgystart = tlprcystart;
brcbgxend = brprcxend;
brcbgyend = brprcyend;
cbgwidthexpn = pdx;
cbgheightexpn = pdy;
} else {
tlcbgxstart = int_ceildivpow2(tlprcxstart, 1);
tlcbgystart = int_ceildivpow2(tlprcystart, 1);
brcbgxend = int_ceildivpow2(brprcxend, 1);
brcbgyend = int_ceildivpow2(brprcyend, 1);
cbgwidthexpn = pdx - 1;
cbgheightexpn = pdy - 1;
}
cblkwidthexpn = int_min(tccp->cblkw, cbgwidthexpn);
cblkheightexpn = int_min(tccp->cblkh, cbgheightexpn);
for (bandno = 0; bandno < res->numbands; bandno++) {
int x0b, y0b;
int gain, numbps;
opj_stepsize_t *ss = NULL;
opj_tcd_band_t *band = &res->bands[bandno];
band->bandno = resno == 0 ? 0 : bandno + 1;
x0b = (band->bandno == 1) || (band->bandno == 3) ? 1 : 0;
y0b = (band->bandno == 2) || (band->bandno == 3) ? 1 : 0;
if (band->bandno == 0) {
/* band border (global) */
band->x0 = int_ceildivpow2(tilec->x0, levelno);
band->y0 = int_ceildivpow2(tilec->y0, levelno);
band->x1 = int_ceildivpow2(tilec->x1, levelno);
band->y1 = int_ceildivpow2(tilec->y1, levelno);
} else {
/* band border (global) */
band->x0 = int_ceildivpow2(tilec->x0 - (1 << levelno) * x0b, levelno + 1);
band->y0 = int_ceildivpow2(tilec->y0 - (1 << levelno) * y0b, levelno + 1);
band->x1 = int_ceildivpow2(tilec->x1 - (1 << levelno) * x0b, levelno + 1);
band->y1 = int_ceildivpow2(tilec->y1 - (1 << levelno) * y0b, levelno + 1);
}
ss = &tccp->stepsizes[resno == 0 ? 0 : 3 * (resno - 1) + bandno + 1];
gain = tccp->qmfbid == 0 ? dwt_getgain_real(band->bandno) : dwt_getgain(band->bandno);
numbps = image->comps[compno].prec + gain;
band->stepsize = (float)(((1.0 + ss->mant / 2048.0) * pow(2.0, numbps - ss->expn)) * 0.5);
band->numbps = ss->expn + tccp->numgbits - 1; /* WHY -1 ? */
band->precincts = (opj_tcd_precinct_t *) opj_malloc(res->pw * res->ph * sizeof(opj_tcd_precinct_t));
for (precno = 0; precno < res->pw * res->ph; precno++) {
int tlcblkxstart, tlcblkystart, brcblkxend, brcblkyend;
int cbgxstart = tlcbgxstart + (precno % res->pw) * (1 << cbgwidthexpn);
int cbgystart = tlcbgystart + (precno / res->pw) * (1 << cbgheightexpn);
int cbgxend = cbgxstart + (1 << cbgwidthexpn);
int cbgyend = cbgystart + (1 << cbgheightexpn);
opj_tcd_precinct_t *prc = &band->precincts[precno];
/* precinct size (global) */
prc->x0 = int_max(cbgxstart, band->x0);
prc->y0 = int_max(cbgystart, band->y0);
prc->x1 = int_min(cbgxend, band->x1);
prc->y1 = int_min(cbgyend, band->y1);
tlcblkxstart = int_floordivpow2(prc->x0, cblkwidthexpn) << cblkwidthexpn;
tlcblkystart = int_floordivpow2(prc->y0, cblkheightexpn) << cblkheightexpn;
brcblkxend = int_ceildivpow2(prc->x1, cblkwidthexpn) << cblkwidthexpn;
brcblkyend = int_ceildivpow2(prc->y1, cblkheightexpn) << cblkheightexpn;
prc->cw = (brcblkxend - tlcblkxstart) >> cblkwidthexpn;
prc->ch = (brcblkyend - tlcblkystart) >> cblkheightexpn;
 
prc->cblks.dec = (opj_tcd_cblk_dec_t*) opj_malloc(prc->cw * prc->ch * sizeof(opj_tcd_cblk_dec_t));
 
prc->incltree = tgt_create(prc->cw, prc->ch);
prc->imsbtree = tgt_create(prc->cw, prc->ch);
for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) {
int cblkxstart = tlcblkxstart + (cblkno % prc->cw) * (1 << cblkwidthexpn);
int cblkystart = tlcblkystart + (cblkno / prc->cw) * (1 << cblkheightexpn);
int cblkxend = cblkxstart + (1 << cblkwidthexpn);
int cblkyend = cblkystart + (1 << cblkheightexpn);
 
opj_tcd_cblk_dec_t* cblk = &prc->cblks.dec[cblkno];
cblk->data = NULL;
cblk->segs = NULL;
/* code-block size (global) */
cblk->x0 = int_max(cblkxstart, prc->x0);
cblk->y0 = int_max(cblkystart, prc->y0);
cblk->x1 = int_min(cblkxend, prc->x1);
cblk->y1 = int_min(cblkyend, prc->y1);
cblk->numsegs = 0;
}
} /* precno */
} /* bandno */
} /* resno */
} /* compno */
/* tcd_dump(stdout, tcd, &tcd->tcd_image); */
}
 
void tcd_makelayer_fixed(opj_tcd_t *tcd, int layno, int final) {
int compno, resno, bandno, precno, cblkno;
int value; /*, matrice[tcd_tcp->numlayers][tcd_tile->comps[0].numresolutions][3]; */
int matrice[10][10][3];
int i, j, k;
 
opj_cp_t *cp = tcd->cp;
opj_tcd_tile_t *tcd_tile = tcd->tcd_tile;
opj_tcp_t *tcd_tcp = tcd->tcp;
 
/*matrice=(int*)opj_malloc(tcd_tcp->numlayers*tcd_tile->comps[0].numresolutions*3*sizeof(int)); */
for (compno = 0; compno < tcd_tile->numcomps; compno++) {
opj_tcd_tilecomp_t *tilec = &tcd_tile->comps[compno];
for (i = 0; i < tcd_tcp->numlayers; i++) {
for (j = 0; j < tilec->numresolutions; j++) {
for (k = 0; k < 3; k++) {
matrice[i][j][k] =
(int) (cp->matrice[i * tilec->numresolutions * 3 + j * 3 + k]
* (float) (tcd->image->comps[compno].prec / 16.0));
}
}
}
for (resno = 0; resno < tilec->numresolutions; resno++) {
opj_tcd_resolution_t *res = &tilec->resolutions[resno];
for (bandno = 0; bandno < res->numbands; bandno++) {
opj_tcd_band_t *band = &res->bands[bandno];
for (precno = 0; precno < res->pw * res->ph; precno++) {
opj_tcd_precinct_t *prc = &band->precincts[precno];
for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) {
opj_tcd_cblk_enc_t *cblk = &prc->cblks.enc[cblkno];
opj_tcd_layer_t *layer = &cblk->layers[layno];
int n;
int imsb = tcd->image->comps[compno].prec - cblk->numbps; /* number of bit-plan equal to zero */
/* Correction of the matrix of coefficient to include the IMSB information */
if (layno == 0) {
value = matrice[layno][resno][bandno];
if (imsb >= value) {
value = 0;
} else {
value -= imsb;
}
} else {
value = matrice[layno][resno][bandno] - matrice[layno - 1][resno][bandno];
if (imsb >= matrice[layno - 1][resno][bandno]) {
value -= (imsb - matrice[layno - 1][resno][bandno]);
if (value < 0) {
value = 0;
}
}
}
if (layno == 0) {
cblk->numpassesinlayers = 0;
}
n = cblk->numpassesinlayers;
if (cblk->numpassesinlayers == 0) {
if (value != 0) {
n = 3 * value - 2 + cblk->numpassesinlayers;
} else {
n = cblk->numpassesinlayers;
}
} else {
n = 3 * value + cblk->numpassesinlayers;
}
layer->numpasses = n - cblk->numpassesinlayers;
if (!layer->numpasses)
continue;
if (cblk->numpassesinlayers == 0) {
layer->len = cblk->passes[n - 1].rate;
layer->data = cblk->data;
} else {
layer->len = cblk->passes[n - 1].rate - cblk->passes[cblk->numpassesinlayers - 1].rate;
layer->data = cblk->data + cblk->passes[cblk->numpassesinlayers - 1].rate;
}
if (final)
cblk->numpassesinlayers = n;
}
}
}
}
}
}
 
void tcd_rateallocate_fixed(opj_tcd_t *tcd) {
int layno;
for (layno = 0; layno < tcd->tcp->numlayers; layno++) {
tcd_makelayer_fixed(tcd, layno, 1);
}
}
 
void tcd_makelayer(opj_tcd_t *tcd, int layno, double thresh, int final) {
int compno, resno, bandno, precno, cblkno, passno;
opj_tcd_tile_t *tcd_tile = tcd->tcd_tile;
 
tcd_tile->distolayer[layno] = 0; /* fixed_quality */
for (compno = 0; compno < tcd_tile->numcomps; compno++) {
opj_tcd_tilecomp_t *tilec = &tcd_tile->comps[compno];
for (resno = 0; resno < tilec->numresolutions; resno++) {
opj_tcd_resolution_t *res = &tilec->resolutions[resno];
for (bandno = 0; bandno < res->numbands; bandno++) {
opj_tcd_band_t *band = &res->bands[bandno];
for (precno = 0; precno < res->pw * res->ph; precno++) {
opj_tcd_precinct_t *prc = &band->precincts[precno];
for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) {
opj_tcd_cblk_enc_t *cblk = &prc->cblks.enc[cblkno];
opj_tcd_layer_t *layer = &cblk->layers[layno];
int n;
if (layno == 0) {
cblk->numpassesinlayers = 0;
}
n = cblk->numpassesinlayers;
for (passno = cblk->numpassesinlayers; passno < cblk->totalpasses; passno++) {
int dr;
double dd;
opj_tcd_pass_t *pass = &cblk->passes[passno];
if (n == 0) {
dr = pass->rate;
dd = pass->distortiondec;
} else {
dr = pass->rate - cblk->passes[n - 1].rate;
dd = pass->distortiondec - cblk->passes[n - 1].distortiondec;
}
if (!dr) {
if (dd != 0)
n = passno + 1;
continue;
}
if (dd / dr >= thresh)
n = passno + 1;
}
layer->numpasses = n - cblk->numpassesinlayers;
if (!layer->numpasses) {
layer->disto = 0;
continue;
}
if (cblk->numpassesinlayers == 0) {
layer->len = cblk->passes[n - 1].rate;
layer->data = cblk->data;
layer->disto = cblk->passes[n - 1].distortiondec;
} else {
layer->len = cblk->passes[n - 1].rate - cblk->passes[cblk->numpassesinlayers - 1].rate;
layer->data = cblk->data + cblk->passes[cblk->numpassesinlayers - 1].rate;
layer->disto = cblk->passes[n - 1].distortiondec - cblk->passes[cblk->numpassesinlayers - 1].distortiondec;
}
tcd_tile->distolayer[layno] += layer->disto; /* fixed_quality */
if (final)
cblk->numpassesinlayers = n;
}
}
}
}
}
}
 
bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_codestream_info_t *cstr_info) {
int compno, resno, bandno, precno, cblkno, passno, layno;
double min, max;
double cumdisto[100]; /* fixed_quality */
const double K = 1; /* 1.1; fixed_quality */
double maxSE = 0;
 
opj_cp_t *cp = tcd->cp;
opj_tcd_tile_t *tcd_tile = tcd->tcd_tile;
opj_tcp_t *tcd_tcp = tcd->tcp;
 
min = DBL_MAX;
max = 0;
tcd_tile->numpix = 0; /* fixed_quality */
for (compno = 0; compno < tcd_tile->numcomps; compno++) {
opj_tcd_tilecomp_t *tilec = &tcd_tile->comps[compno];
tilec->numpix = 0;
 
for (resno = 0; resno < tilec->numresolutions; resno++) {
opj_tcd_resolution_t *res = &tilec->resolutions[resno];
 
for (bandno = 0; bandno < res->numbands; bandno++) {
opj_tcd_band_t *band = &res->bands[bandno];
 
for (precno = 0; precno < res->pw * res->ph; precno++) {
opj_tcd_precinct_t *prc = &band->precincts[precno];
 
for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) {
opj_tcd_cblk_enc_t *cblk = &prc->cblks.enc[cblkno];
 
for (passno = 0; passno < cblk->totalpasses; passno++) {
opj_tcd_pass_t *pass = &cblk->passes[passno];
int dr;
double dd, rdslope;
if (passno == 0) {
dr = pass->rate;
dd = pass->distortiondec;
} else {
dr = pass->rate - cblk->passes[passno - 1].rate;
dd = pass->distortiondec - cblk->passes[passno - 1].distortiondec;
}
if (dr == 0) {
continue;
}
rdslope = dd / dr;
if (rdslope < min) {
min = rdslope;
}
if (rdslope > max) {
max = rdslope;
}
} /* passno */
/* fixed_quality */
tcd_tile->numpix += ((cblk->x1 - cblk->x0) * (cblk->y1 - cblk->y0));
tilec->numpix += ((cblk->x1 - cblk->x0) * (cblk->y1 - cblk->y0));
} /* cbklno */
} /* precno */
} /* bandno */
} /* resno */
maxSE += (((double)(1 << tcd->image->comps[compno].prec) - 1.0)
* ((double)(1 << tcd->image->comps[compno].prec) -1.0))
* ((double)(tilec->numpix));
} /* compno */
/* index file */
if(cstr_info) {
opj_tile_info_t *tile_info = &cstr_info->tile[tcd->tcd_tileno];
tile_info->numpix = tcd_tile->numpix;
tile_info->distotile = tcd_tile->distotile;
tile_info->thresh = (double *) opj_malloc(tcd_tcp->numlayers * sizeof(double));
}
for (layno = 0; layno < tcd_tcp->numlayers; layno++) {
double lo = min;
double hi = max;
int success = 0;
int maxlen = tcd_tcp->rates[layno] ? int_min(((int) ceil(tcd_tcp->rates[layno])), len) : len;
double goodthresh = 0;
double stable_thresh = 0;
int i;
double distotarget; /* fixed_quality */
/* fixed_quality */
distotarget = tcd_tile->distotile - ((K * maxSE) / pow((float)10, tcd_tcp->distoratio[layno] / 10));
/* Don't try to find an optimal threshold but rather take everything not included yet, if
-r xx,yy,zz,0 (disto_alloc == 1 and rates == 0)
-q xx,yy,zz,0 (fixed_quality == 1 and distoratio == 0)
==> possible to have some lossy layers and the last layer for sure lossless */
if ( ((cp->disto_alloc==1) && (tcd_tcp->rates[layno]>0)) || ((cp->fixed_quality==1) && (tcd_tcp->distoratio[layno]>0))) {
opj_t2_t *t2 = t2_create(tcd->cinfo, tcd->image, cp);
double thresh = 0;
 
for (i = 0; i < 128; i++) {
int l = 0;
double distoachieved = 0; /* fixed_quality */
thresh = (lo + hi) / 2;
tcd_makelayer(tcd, layno, thresh, 0);
if (cp->fixed_quality) { /* fixed_quality */
if(cp->cinema){
l = t2_encode_packets(t2,tcd->tcd_tileno, tcd_tile, layno + 1, dest, maxlen, cstr_info,tcd->cur_tp_num,tcd->tp_pos,tcd->cur_pino,THRESH_CALC, tcd->cur_totnum_tp);
if (l == -999) {
lo = thresh;
continue;
}else{
distoachieved = layno == 0 ?
tcd_tile->distolayer[0] : cumdisto[layno - 1] + tcd_tile->distolayer[layno];
if (distoachieved < distotarget) {
hi=thresh;
stable_thresh = thresh;
continue;
}else{
lo=thresh;
}
}
}else{
distoachieved = (layno == 0) ?
tcd_tile->distolayer[0] : (cumdisto[layno - 1] + tcd_tile->distolayer[layno]);
if (distoachieved < distotarget) {
hi = thresh;
stable_thresh = thresh;
continue;
}
lo = thresh;
}
} else {
l = t2_encode_packets(t2, tcd->tcd_tileno, tcd_tile, layno + 1, dest, maxlen, cstr_info,tcd->cur_tp_num,tcd->tp_pos,tcd->cur_pino,THRESH_CALC, tcd->cur_totnum_tp);
/* TODO: what to do with l ??? seek / tell ??? */
/* opj_event_msg(tcd->cinfo, EVT_INFO, "rate alloc: len=%d, max=%d\n", l, maxlen); */
if (l == -999) {
lo = thresh;
continue;
}
hi = thresh;
stable_thresh = thresh;
}
}
success = 1;
goodthresh = stable_thresh == 0? thresh : stable_thresh;
t2_destroy(t2);
} else {
success = 1;
goodthresh = min;
}
if (!success) {
return false;
}
if(cstr_info) { /* Threshold for Marcela Index */
cstr_info->tile[tcd->tcd_tileno].thresh[layno] = goodthresh;
}
tcd_makelayer(tcd, layno, goodthresh, 1);
/* fixed_quality */
cumdisto[layno] = (layno == 0) ? tcd_tile->distolayer[0] : (cumdisto[layno - 1] + tcd_tile->distolayer[layno]);
}
 
return true;
}
 
int tcd_encode_tile(opj_tcd_t *tcd, int tileno, unsigned char *dest, int len, opj_codestream_info_t *cstr_info) {
int compno;
int l, i, numpacks = 0;
opj_tcd_tile_t *tile = NULL;
opj_tcp_t *tcd_tcp = NULL;
opj_cp_t *cp = NULL;
 
opj_tcp_t *tcp = &tcd->cp->tcps[0];
opj_tccp_t *tccp = &tcp->tccps[0];
opj_image_t *image = tcd->image;
opj_t1_t *t1 = NULL; /* T1 component */
opj_t2_t *t2 = NULL; /* T2 component */
 
tcd->tcd_tileno = tileno;
tcd->tcd_tile = tcd->tcd_image->tiles;
tcd->tcp = &tcd->cp->tcps[tileno];
 
tile = tcd->tcd_tile;
tcd_tcp = tcd->tcp;
cp = tcd->cp;
 
if(tcd->cur_tp_num == 0){
tcd->encoding_time = opj_clock(); /* time needed to encode a tile */
/* INDEX >> "Precinct_nb_X et Precinct_nb_Y" */
if(cstr_info) {
opj_tcd_tilecomp_t *tilec_idx = &tile->comps[0]; /* based on component 0 */
for (i = 0; i < tilec_idx->numresolutions; i++) {
opj_tcd_resolution_t *res_idx = &tilec_idx->resolutions[i];
cstr_info->tile[tileno].pw[i] = res_idx->pw;
cstr_info->tile[tileno].ph[i] = res_idx->ph;
numpacks += res_idx->pw * res_idx->ph;
cstr_info->tile[tileno].pdx[i] = tccp->prcw[i];
cstr_info->tile[tileno].pdy[i] = tccp->prch[i];
}
cstr_info->tile[tileno].packet = (opj_packet_info_t*) opj_calloc(cstr_info->numcomps * cstr_info->numlayers * numpacks, sizeof(opj_packet_info_t));
}
/* << INDEX */
/*---------------TILE-------------------*/
for (compno = 0; compno < tile->numcomps; compno++) {
int x, y;
int adjust = image->comps[compno].sgnd ? 0 : 1 << (image->comps[compno].prec - 1);
int offset_x = int_ceildiv(image->x0, image->comps[compno].dx);
int offset_y = int_ceildiv(image->y0, image->comps[compno].dy);
opj_tcd_tilecomp_t *tilec = &tile->comps[compno];
int tw = tilec->x1 - tilec->x0;
int w = int_ceildiv(image->x1 - image->x0, image->comps[compno].dx);
/* extract tile data */
if (tcd_tcp->tccps[compno].qmfbid == 1) {
for (y = tilec->y0; y < tilec->y1; y++) {
/* start of the src tile scanline */
int *data = &image->comps[compno].data[(tilec->x0 - offset_x) + (y - offset_y) * w];
/* start of the dst tile scanline */
int *tile_data = &tilec->data[(y - tilec->y0) * tw];
for (x = tilec->x0; x < tilec->x1; x++) {
*tile_data++ = *data++ - adjust;
}
}
} else if (tcd_tcp->tccps[compno].qmfbid == 0) {
for (y = tilec->y0; y < tilec->y1; y++) {
/* start of the src tile scanline */
int *data = &image->comps[compno].data[(tilec->x0 - offset_x) + (y - offset_y) * w];
/* start of the dst tile scanline */
int *tile_data = &tilec->data[(y - tilec->y0) * tw];
for (x = tilec->x0; x < tilec->x1; x++) {
*tile_data++ = (*data++ - adjust) << 11;
}
}
}
}
/*----------------MCT-------------------*/
if (tcd_tcp->mct) {
int samples = (tile->comps[0].x1 - tile->comps[0].x0) * (tile->comps[0].y1 - tile->comps[0].y0);
if (tcd_tcp->tccps[0].qmfbid == 0) {
mct_encode_real(tile->comps[0].data, tile->comps[1].data, tile->comps[2].data, samples);
} else {
mct_encode(tile->comps[0].data, tile->comps[1].data, tile->comps[2].data, samples);
}
}
/*----------------DWT---------------------*/
for (compno = 0; compno < tile->numcomps; compno++) {
opj_tcd_tilecomp_t *tilec = &tile->comps[compno];
if (tcd_tcp->tccps[compno].qmfbid == 1) {
dwt_encode(tilec);
} else if (tcd_tcp->tccps[compno].qmfbid == 0) {
dwt_encode_real(tilec);
}
}
/*------------------TIER1-----------------*/
t1 = t1_create(tcd->cinfo);
t1_encode_cblks(t1, tile, tcd_tcp);
t1_destroy(t1);
/*-----------RATE-ALLOCATE------------------*/
/* INDEX */
if(cstr_info) {
cstr_info->index_write = 0;
}
if (cp->disto_alloc || cp->fixed_quality) { /* fixed_quality */
/* Normal Rate/distortion allocation */
tcd_rateallocate(tcd, dest, len, cstr_info);
} else {
/* Fixed layer allocation */
tcd_rateallocate_fixed(tcd);
}
}
/*--------------TIER2------------------*/
 
/* INDEX */
if(cstr_info) {
cstr_info->index_write = 1;
}
 
t2 = t2_create(tcd->cinfo, image, cp);
l = t2_encode_packets(t2,tileno, tile, tcd_tcp->numlayers, dest, len, cstr_info,tcd->tp_num,tcd->tp_pos,tcd->cur_pino,FINAL_PASS,tcd->cur_totnum_tp);
t2_destroy(t2);
/*---------------CLEAN-------------------*/
 
if(tcd->cur_tp_num == tcd->cur_totnum_tp - 1){
tcd->encoding_time = opj_clock() - tcd->encoding_time;
opj_event_msg(tcd->cinfo, EVT_INFO, "- tile encoded in %f s\n", tcd->encoding_time);
 
/* cleaning memory */
for (compno = 0; compno < tile->numcomps; compno++) {
opj_tcd_tilecomp_t *tilec = &tile->comps[compno];
opj_aligned_free(tilec->data);
}
}
 
return l;
}
 
bool tcd_decode_tile(opj_tcd_t *tcd, unsigned char *src, int len, int tileno, opj_codestream_info_t *cstr_info) {
int l;
int compno;
int eof = 0;
double tile_time, t1_time, dwt_time;
opj_tcd_tile_t *tile = NULL;
 
opj_t1_t *t1 = NULL; /* T1 component */
opj_t2_t *t2 = NULL; /* T2 component */
tcd->tcd_tileno = tileno;
tcd->tcd_tile = &(tcd->tcd_image->tiles[tileno]);
tcd->tcp = &(tcd->cp->tcps[tileno]);
tile = tcd->tcd_tile;
tile_time = opj_clock(); /* time needed to decode a tile */
opj_event_msg(tcd->cinfo, EVT_INFO, "tile %d of %d\n", tileno + 1, tcd->cp->tw * tcd->cp->th);
 
/* INDEX >> */
if(cstr_info) {
int resno, compno, numprec = 0;
for (compno = 0; compno < cstr_info->numcomps; compno++) {
opj_tcp_t *tcp = &tcd->cp->tcps[0];
opj_tccp_t *tccp = &tcp->tccps[compno];
opj_tcd_tilecomp_t *tilec_idx = &tile->comps[compno];
for (resno = 0; resno < tilec_idx->numresolutions; resno++) {
opj_tcd_resolution_t *res_idx = &tilec_idx->resolutions[resno];
cstr_info->tile[tileno].pw[resno] = res_idx->pw;
cstr_info->tile[tileno].ph[resno] = res_idx->ph;
numprec += res_idx->pw * res_idx->ph;
if (tccp->csty & J2K_CP_CSTY_PRT) {
cstr_info->tile[tileno].pdx[resno] = tccp->prcw[resno];
cstr_info->tile[tileno].pdy[resno] = tccp->prch[resno];
}
else {
cstr_info->tile[tileno].pdx[resno] = 15;
cstr_info->tile[tileno].pdx[resno] = 15;
}
}
}
cstr_info->tile[tileno].packet = (opj_packet_info_t *) opj_malloc(cstr_info->numlayers * numprec * sizeof(opj_packet_info_t));
cstr_info->packno = 0;
}
/* << INDEX */
/*--------------TIER2------------------*/
t2 = t2_create(tcd->cinfo, tcd->image, tcd->cp);
l = t2_decode_packets(t2, src, len, tileno, tile, cstr_info);
t2_destroy(t2);
 
if (l == -999) {
eof = 1;
opj_event_msg(tcd->cinfo, EVT_ERROR, "tcd_decode: incomplete bistream\n");
}
/*------------------TIER1-----------------*/
t1_time = opj_clock(); /* time needed to decode a tile */
t1 = t1_create(tcd->cinfo);
for (compno = 0; compno < tile->numcomps; ++compno) {
opj_tcd_tilecomp_t* tilec = &tile->comps[compno];
/* The +3 is headroom required by the vectorized DWT */
tilec->data = (int*) opj_aligned_malloc((((tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0))+3) * sizeof(int));
t1_decode_cblks(t1, tilec, &tcd->tcp->tccps[compno]);
}
t1_destroy(t1);
t1_time = opj_clock() - t1_time;
opj_event_msg(tcd->cinfo, EVT_INFO, "- tiers-1 took %f s\n", t1_time);
/*----------------DWT---------------------*/
 
dwt_time = opj_clock(); /* time needed to decode a tile */
for (compno = 0; compno < tile->numcomps; compno++) {
opj_tcd_tilecomp_t *tilec = &tile->comps[compno];
int numres2decode;
 
if (tcd->cp->reduce != 0) {
tcd->image->comps[compno].resno_decoded =
tile->comps[compno].numresolutions - tcd->cp->reduce - 1;
if (tcd->image->comps[compno].resno_decoded < 0) {
opj_event_msg(tcd->cinfo, EVT_ERROR, "Error decoding tile. The number of resolutions to remove [%d+1] is higher than the number "
" of resolutions in the original codestream [%d]\nModify the cp_reduce parameter.\n", tcd->cp->reduce, tile->comps[compno].numresolutions);
return false;
}
}
 
numres2decode = tcd->image->comps[compno].resno_decoded + 1;
if(numres2decode > 0){
if (tcd->tcp->tccps[compno].qmfbid == 1) {
dwt_decode(tilec, numres2decode);
} else {
dwt_decode_real(tilec, numres2decode);
}
}
}
dwt_time = opj_clock() - dwt_time;
opj_event_msg(tcd->cinfo, EVT_INFO, "- dwt took %f s\n", dwt_time);
 
/*----------------MCT-------------------*/
 
if (tcd->tcp->mct) {
int n = (tile->comps[0].x1 - tile->comps[0].x0) * (tile->comps[0].y1 - tile->comps[0].y0);
if (tcd->tcp->tccps[0].qmfbid == 1) {
mct_decode(
tile->comps[0].data,
tile->comps[1].data,
tile->comps[2].data,
n);
} else {
mct_decode_real(
(float*)tile->comps[0].data,
(float*)tile->comps[1].data,
(float*)tile->comps[2].data,
n);
}
}
 
/*---------------TILE-------------------*/
 
for (compno = 0; compno < tile->numcomps; ++compno) {
opj_tcd_tilecomp_t* tilec = &tile->comps[compno];
opj_image_comp_t* imagec = &tcd->image->comps[compno];
opj_tcd_resolution_t* res = &tilec->resolutions[imagec->resno_decoded];
int adjust = imagec->sgnd ? 0 : 1 << (imagec->prec - 1);
int min = imagec->sgnd ? -(1 << (imagec->prec - 1)) : 0;
int max = imagec->sgnd ? (1 << (imagec->prec - 1)) - 1 : (1 << imagec->prec) - 1;
 
int tw = tilec->x1 - tilec->x0;
int w = imagec->w;
 
int offset_x = int_ceildivpow2(imagec->x0, imagec->factor);
int offset_y = int_ceildivpow2(imagec->y0, imagec->factor);
 
int i, j;
if(!imagec->data){
imagec->data = (int*) opj_malloc(imagec->w * imagec->h * sizeof(int));
}
if(tcd->tcp->tccps[compno].qmfbid == 1) {
for(j = res->y0; j < res->y1; ++j) {
for(i = res->x0; i < res->x1; ++i) {
int v = tilec->data[i - res->x0 + (j - res->y0) * tw];
v += adjust;
imagec->data[(i - offset_x) + (j - offset_y) * w] = int_clamp(v, min, max);
}
}
}else{
for(j = res->y0; j < res->y1; ++j) {
for(i = res->x0; i < res->x1; ++i) {
float tmp = ((float*)tilec->data)[i - res->x0 + (j - res->y0) * tw];
int v = lrintf(tmp);
v += adjust;
imagec->data[(i - offset_x) + (j - offset_y) * w] = int_clamp(v, min, max);
}
}
}
opj_aligned_free(tilec->data);
}
 
tile_time = opj_clock() - tile_time; /* time needed to decode a tile */
opj_event_msg(tcd->cinfo, EVT_INFO, "- tile decoded in %f s\n", tile_time);
 
if (eof) {
return false;
}
return true;
}
 
void tcd_free_decode(opj_tcd_t *tcd) {
opj_tcd_image_t *tcd_image = tcd->tcd_image;
opj_free(tcd_image->tiles);
}
 
void tcd_free_decode_tile(opj_tcd_t *tcd, int tileno) {
int compno,resno,bandno,precno;
 
opj_tcd_image_t *tcd_image = tcd->tcd_image;
 
opj_tcd_tile_t *tile = &tcd_image->tiles[tileno];
for (compno = 0; compno < tile->numcomps; compno++) {
opj_tcd_tilecomp_t *tilec = &tile->comps[compno];
for (resno = 0; resno < tilec->numresolutions; resno++) {
opj_tcd_resolution_t *res = &tilec->resolutions[resno];
for (bandno = 0; bandno < res->numbands; bandno++) {
opj_tcd_band_t *band = &res->bands[bandno];
for (precno = 0; precno < res->ph * res->pw; precno++) {
opj_tcd_precinct_t *prec = &band->precincts[precno];
if (prec->imsbtree != NULL) tgt_destroy(prec->imsbtree);
if (prec->incltree != NULL) tgt_destroy(prec->incltree);
}
opj_free(band->precincts);
}
}
opj_free(tilec->resolutions);
}
opj_free(tile->comps);
}
 
 
 
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libopenjpeg/tcd.h
0,0 → 1,286
/*
* Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2007, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __TCD_H
#define __TCD_H
/**
@file tcd.h
@brief Implementation of a tile coder/decoder (TCD)
 
The functions in TCD.C have for goal to encode or decode each tile independently from
each other. The functions in TCD.C are used by some function in J2K.C.
*/
 
/** @defgroup TCD TCD - Implementation of a tile coder/decoder */
/*@{*/
 
/**
FIXME: documentation
*/
typedef struct opj_tcd_seg {
unsigned char** data;
int dataindex;
int numpasses;
int len;
int maxpasses;
int numnewpasses;
int newlen;
} opj_tcd_seg_t;
 
/**
FIXME: documentation
*/
typedef struct opj_tcd_pass {
int rate;
double distortiondec;
int term, len;
} opj_tcd_pass_t;
 
/**
FIXME: documentation
*/
typedef struct opj_tcd_layer {
int numpasses; /* Number of passes in the layer */
int len; /* len of information */
double disto; /* add for index (Cfr. Marcela) */
unsigned char *data; /* data */
} opj_tcd_layer_t;
 
/**
FIXME: documentation
*/
typedef struct opj_tcd_cblk_enc {
unsigned char* data; /* Data */
opj_tcd_layer_t* layers; /* layer information */
opj_tcd_pass_t* passes; /* information about the passes */
int x0, y0, x1, y1; /* dimension of the code-blocks : left upper corner (x0, y0) right low corner (x1,y1) */
int numbps;
int numlenbits;
int numpasses; /* number of pass already done for the code-blocks */
int numpassesinlayers; /* number of passes in the layer */
int totalpasses; /* total number of passes */
} opj_tcd_cblk_enc_t;
 
typedef struct opj_tcd_cblk_dec {
unsigned char* data; /* Data */
opj_tcd_seg_t* segs; /* segments informations */
int x0, y0, x1, y1; /* dimension of the code-blocks : left upper corner (x0, y0) right low corner (x1,y1) */
int numbps;
int numlenbits;
int len; /* length */
int numnewpasses; /* number of pass added to the code-blocks */
int numsegs; /* number of segments */
} opj_tcd_cblk_dec_t;
 
/**
FIXME: documentation
*/
typedef struct opj_tcd_precinct {
int x0, y0, x1, y1; /* dimension of the precinct : left upper corner (x0, y0) right low corner (x1,y1) */
int cw, ch; /* number of precinct in width and heigth */
union{ /* code-blocks informations */
opj_tcd_cblk_enc_t* enc;
opj_tcd_cblk_dec_t* dec;
} cblks;
opj_tgt_tree_t *incltree; /* inclusion tree */
opj_tgt_tree_t *imsbtree; /* IMSB tree */
} opj_tcd_precinct_t;
 
/**
FIXME: documentation
*/
typedef struct opj_tcd_band {
int x0, y0, x1, y1; /* dimension of the subband : left upper corner (x0, y0) right low corner (x1,y1) */
int bandno;
opj_tcd_precinct_t *precincts; /* precinct information */
int numbps;
float stepsize;
} opj_tcd_band_t;
 
/**
FIXME: documentation
*/
typedef struct opj_tcd_resolution {
int x0, y0, x1, y1; /* dimension of the resolution level : left upper corner (x0, y0) right low corner (x1,y1) */
int pw, ph;
int numbands; /* number sub-band for the resolution level */
opj_tcd_band_t bands[3]; /* subband information */
} opj_tcd_resolution_t;
 
/**
FIXME: documentation
*/
typedef struct opj_tcd_tilecomp {
int x0, y0, x1, y1; /* dimension of component : left upper corner (x0, y0) right low corner (x1,y1) */
int numresolutions; /* number of resolutions level */
opj_tcd_resolution_t *resolutions; /* resolutions information */
int *data; /* data of the component */
int numpix; /* add fixed_quality */
} opj_tcd_tilecomp_t;
 
/**
FIXME: documentation
*/
typedef struct opj_tcd_tile {
int x0, y0, x1, y1; /* dimension of the tile : left upper corner (x0, y0) right low corner (x1,y1) */
int numcomps; /* number of components in tile */
opj_tcd_tilecomp_t *comps; /* Components information */
int numpix; /* add fixed_quality */
double distotile; /* add fixed_quality */
double distolayer[100]; /* add fixed_quality */
/** packet number */
int packno;
} opj_tcd_tile_t;
 
/**
FIXME: documentation
*/
typedef struct opj_tcd_image {
int tw, th; /* number of tiles in width and heigth */
opj_tcd_tile_t *tiles; /* Tiles information */
} opj_tcd_image_t;
 
/**
Tile coder/decoder
*/
typedef struct opj_tcd {
/** Position of the tilepart flag in Progression order*/
int tp_pos;
/** Tile part number*/
int tp_num;
/** Current tile part number*/
int cur_tp_num;
/** Total number of tileparts of the current tile*/
int cur_totnum_tp;
/** Current Packet iterator number */
int cur_pino;
/** codec context */
opj_common_ptr cinfo;
 
/** info on each image tile */
opj_tcd_image_t *tcd_image;
/** image */
opj_image_t *image;
/** coding parameters */
opj_cp_t *cp;
/** pointer to the current encoded/decoded tile */
opj_tcd_tile_t *tcd_tile;
/** coding/decoding parameters common to all tiles */
opj_tcp_t *tcp;
/** current encoded/decoded tile */
int tcd_tileno;
/** Time taken to encode a tile*/
double encoding_time;
} opj_tcd_t;
 
/** @name Exported functions */
/*@{*/
/* ----------------------------------------------------------------------- */
 
/**
Dump the content of a tcd structure
*/
void tcd_dump(FILE *fd, opj_tcd_t *tcd, opj_tcd_image_t *img);
/**
Create a new TCD handle
@param cinfo Codec context info
@return Returns a new TCD handle if successful returns NULL otherwise
*/
opj_tcd_t* tcd_create(opj_common_ptr cinfo);
/**
Destroy a previously created TCD handle
@param tcd TCD handle to destroy
*/
void tcd_destroy(opj_tcd_t *tcd);
/**
Initialize the tile coder (allocate the memory)
@param tcd TCD handle
@param image Raw image
@param cp Coding parameters
@param curtileno Number that identifies the tile that will be encoded
*/
void tcd_malloc_encode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp, int curtileno);
/**
Free the memory allocated for encoding
@param tcd TCD handle
*/
void tcd_free_encode(opj_tcd_t *tcd);
/**
Initialize the tile coder (reuses the memory allocated by tcd_malloc_encode)
@param tcd TCD handle
@param image Raw image
@param cp Coding parameters
@param curtileno Number that identifies the tile that will be encoded
*/
void tcd_init_encode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp, int curtileno);
/**
Initialize the tile decoder
@param tcd TCD handle
@param image Raw image
@param cp Coding parameters
*/
void tcd_malloc_decode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp);
void tcd_malloc_decode_tile(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp, int tileno, opj_codestream_info_t *cstr_info);
void tcd_makelayer_fixed(opj_tcd_t *tcd, int layno, int final);
void tcd_rateallocate_fixed(opj_tcd_t *tcd);
void tcd_makelayer(opj_tcd_t *tcd, int layno, double thresh, int final);
bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_codestream_info_t *cstr_info);
/**
Encode a tile from the raw image into a buffer
@param tcd TCD handle
@param tileno Number that identifies one of the tiles to be encoded
@param dest Destination buffer
@param len Length of destination buffer
@param cstr_info Codestream information structure
@return
*/
int tcd_encode_tile(opj_tcd_t *tcd, int tileno, unsigned char *dest, int len, opj_codestream_info_t *cstr_info);
/**
Decode a tile from a buffer into a raw image
@param tcd TCD handle
@param src Source buffer
@param len Length of source buffer
@param tileno Number that identifies one of the tiles to be decoded
@param cstr_info Codestream information structure
*/
bool tcd_decode_tile(opj_tcd_t *tcd, unsigned char *src, int len, int tileno, opj_codestream_info_t *cstr_info);
/**
Free the memory allocated for decoding
@param tcd TCD handle
*/
void tcd_free_decode(opj_tcd_t *tcd);
void tcd_free_decode_tile(opj_tcd_t *tcd, int tileno);
 
/* ----------------------------------------------------------------------- */
/*@}*/
 
/*@}*/
 
#endif /* __TCD_H */
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libopenjpeg/tgt.c
0,0 → 1,213
/*
* Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2007, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
 
#include "opj_includes.h"
 
/*
==========================================================
Tag-tree coder interface
==========================================================
*/
 
opj_tgt_tree_t *tgt_create(int numleafsh, int numleafsv) {
int nplh[32];
int nplv[32];
opj_tgt_node_t *node = NULL;
opj_tgt_node_t *parentnode = NULL;
opj_tgt_node_t *parentnode0 = NULL;
opj_tgt_tree_t *tree = NULL;
int i, j, k;
int numlvls;
int n;
 
tree = (opj_tgt_tree_t *) opj_malloc(sizeof(opj_tgt_tree_t));
if(!tree) return NULL;
tree->numleafsh = numleafsh;
tree->numleafsv = numleafsv;
 
numlvls = 0;
nplh[0] = numleafsh;
nplv[0] = numleafsv;
tree->numnodes = 0;
do {
n = nplh[numlvls] * nplv[numlvls];
nplh[numlvls + 1] = (nplh[numlvls] + 1) / 2;
nplv[numlvls + 1] = (nplv[numlvls] + 1) / 2;
tree->numnodes += n;
++numlvls;
} while (n > 1);
/* ADD */
if (tree->numnodes == 0) {
opj_free(tree);
return NULL;
}
 
tree->nodes = (opj_tgt_node_t*) opj_calloc(tree->numnodes, sizeof(opj_tgt_node_t));
if(!tree->nodes) {
opj_free(tree);
return NULL;
}
 
node = tree->nodes;
parentnode = &tree->nodes[tree->numleafsh * tree->numleafsv];
parentnode0 = parentnode;
for (i = 0; i < numlvls - 1; ++i) {
for (j = 0; j < nplv[i]; ++j) {
k = nplh[i];
while (--k >= 0) {
node->parent = parentnode;
++node;
if (--k >= 0) {
node->parent = parentnode;
++node;
}
++parentnode;
}
if ((j & 1) || j == nplv[i] - 1) {
parentnode0 = parentnode;
} else {
parentnode = parentnode0;
parentnode0 += nplh[i];
}
}
}
node->parent = 0;
tgt_reset(tree);
return tree;
}
 
void tgt_destroy(opj_tgt_tree_t *tree) {
opj_free(tree->nodes);
opj_free(tree);
}
 
void tgt_reset(opj_tgt_tree_t *tree) {
int i;
 
if (NULL == tree)
return;
for (i = 0; i < tree->numnodes; i++) {
tree->nodes[i].value = 999;
tree->nodes[i].low = 0;
tree->nodes[i].known = 0;
}
}
 
void tgt_setvalue(opj_tgt_tree_t *tree, int leafno, int value) {
opj_tgt_node_t *node;
node = &tree->nodes[leafno];
while (node && node->value > value) {
node->value = value;
node = node->parent;
}
}
 
void tgt_encode(opj_bio_t *bio, opj_tgt_tree_t *tree, int leafno, int threshold) {
opj_tgt_node_t *stk[31];
opj_tgt_node_t **stkptr;
opj_tgt_node_t *node;
int low;
 
stkptr = stk;
node = &tree->nodes[leafno];
while (node->parent) {
*stkptr++ = node;
node = node->parent;
}
low = 0;
for (;;) {
if (low > node->low) {
node->low = low;
} else {
low = node->low;
}
while (low < threshold) {
if (low >= node->value) {
if (!node->known) {
bio_write(bio, 1, 1);
node->known = 1;
}
break;
}
bio_write(bio, 0, 1);
++low;
}
node->low = low;
if (stkptr == stk)
break;
node = *--stkptr;
}
}
 
int tgt_decode(opj_bio_t *bio, opj_tgt_tree_t *tree, int leafno, int threshold) {
opj_tgt_node_t *stk[31];
opj_tgt_node_t **stkptr;
opj_tgt_node_t *node;
int low;
 
stkptr = stk;
node = &tree->nodes[leafno];
while (node->parent) {
*stkptr++ = node;
node = node->parent;
}
low = 0;
for (;;) {
if (low > node->low) {
node->low = low;
} else {
low = node->low;
}
while (low < threshold && low < node->value) {
if (bio_read(bio, 1)) {
node->value = low;
} else {
++low;
}
}
node->low = low;
if (stkptr == stk) {
break;
}
node = *--stkptr;
}
return (node->value < threshold) ? 1 : 0;
}
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/libopenjpeg/tgt.h
0,0 → 1,114
/*
* Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2007, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
 
#ifndef __TGT_H
#define __TGT_H
/**
@file tgt.h
@brief Implementation of a tag-tree coder (TGT)
 
The functions in TGT.C have for goal to realize a tag-tree coder. The functions in TGT.C
are used by some function in T2.C.
*/
 
/** @defgroup TGT TGT - Implementation of a tag-tree coder */
/*@{*/
 
/**
Tag node
*/
typedef struct opj_tgt_node {
struct opj_tgt_node *parent;
int value;
int low;
int known;
} opj_tgt_node_t;
 
/**
Tag tree
*/
typedef struct opj_tgt_tree {
int numleafsh;
int numleafsv;
int numnodes;
opj_tgt_node_t *nodes;
} opj_tgt_tree_t;
 
/** @name Exported functions */
/*@{*/
/* ----------------------------------------------------------------------- */
/**
Create a tag-tree
@param numleafsh Width of the array of leafs of the tree
@param numleafsv Height of the array of leafs of the tree
@return Returns a new tag-tree if successful, returns NULL otherwise
*/
opj_tgt_tree_t *tgt_create(int numleafsh, int numleafsv);
/**
Destroy a tag-tree, liberating memory
@param tree Tag-tree to destroy
*/
void tgt_destroy(opj_tgt_tree_t *tree);
/**
Reset a tag-tree (set all leaves to 0)
@param tree Tag-tree to reset
*/
void tgt_reset(opj_tgt_tree_t *tree);
/**
Set the value of a leaf of a tag-tree
@param tree Tag-tree to modify
@param leafno Number that identifies the leaf to modify
@param value New value of the leaf
*/
void tgt_setvalue(opj_tgt_tree_t *tree, int leafno, int value);
/**
Encode the value of a leaf of the tag-tree up to a given threshold
@param bio Pointer to a BIO handle
@param tree Tag-tree to modify
@param leafno Number that identifies the leaf to encode
@param threshold Threshold to use when encoding value of the leaf
*/
void tgt_encode(opj_bio_t *bio, opj_tgt_tree_t *tree, int leafno, int threshold);
/**
Decode the value of a leaf of the tag-tree up to a given threshold
@param bio Pointer to a BIO handle
@param tree Tag-tree to decode
@param leafno Number that identifies the leaf to decode
@param threshold Threshold to use when decoding value of the leaf
@return Returns 1 if the node's value < threshold, returns 0 otherwise
*/
int tgt_decode(opj_bio_t *bio, opj_tgt_tree_t *tree, int leafno, int threshold);
/* ----------------------------------------------------------------------- */
/*@}*/
 
/*@}*/
 
#endif /* __TGT_H */
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/pdf/Makefile
0,0 → 1,19
CC = kos32-gcc
LD = kos32-ld
 
SDK_DIR = $(abspath ../../../sdk)
 
CFLAGS = -c -fno-ident -O2 -fomit-frame-pointer -fno-ident -U__WIN32__ -U_Win32 -U_WIN32 -U__MINGW32__ -UWIN32
 
INCLUDES = -I $(SDK_DIR)/sources/newlib/libc/include -I ../fitz -I $(SDK_DIR)/sources/freetype/include
 
PDF_SRC := $(notdir $(wildcard *.c))
OBJECTS = $(patsubst %.c, %.o, $(PDF_SRC))
 
default: $(patsubst %.c,%.o,$(PDF_SRC))
ar rcs libmupdf.a *.o
rm *.o
mv libmupdf.a ../lib
 
%.o : %.c Makefile $(PDF_SRC)
$(CC) $(CFLAGS) $(INCLUDES) -o $@ $<
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/contrib/media/updf/pdf/pdf_font.c
87,7 → 87,10
 
static int ft_kind(FT_Face face)
{
const char *kind = FT_Get_X11_Font_Format(face);
/// STUB ///
//const char *kind = FT_Get_X11_Font_Format(face);
const char *kind = "TrueType";
if (!strcmp(kind, "TrueType"))
return TRUETYPE;
if (!strcmp(kind, "Type 1"))