diff --git a/linux/Makefile.am b/linux/Makefile.am index b1348db5..6158d4bf 100644 --- a/linux/Makefile.am +++ b/linux/Makefile.am @@ -156,7 +156,6 @@ ccextractor_SOURCES = \ ../src/lib_ccx/ccx_encoders_smptett.c \ ../src/lib_ccx/ccx_encoders_splitbysentence.c \ ../src/lib_ccx/ccx_encoders_spupng.c \ - ../src/lib_ccx/ccx_encoders_spupng.h \ ../src/lib_ccx/ccx_encoders_srt.c \ ../src/lib_ccx/ccx_encoders_ssa.c \ ../src/lib_ccx/ccx_encoders_structs.h \ @@ -208,8 +207,6 @@ ccextractor_SOURCES = \ ../src/lib_ccx/params.c \ ../src/lib_ccx/params_dump.c \ ../src/lib_ccx/sequencing.c \ - ../src/lib_ccx/spupng_encoder.c \ - ../src/lib_ccx/spupng_encoder.h \ ../src/lib_ccx/stdintmsc.h \ ../src/lib_ccx/stream_functions.c \ ../src/lib_ccx/teletext.h \ @@ -268,12 +265,52 @@ ccextractor_SOURCES = \ ../src/extractors/extractor.c \ ../src/extractors/extractor.h \ ../src/wrappers/wrapper.c \ - ../src/wrappers/wrapper.h - + ../src/wrappers/wrapper.h \ + ../src/freetype/autofit/autofit.c \ + ../src/freetype/base/ftbase.c \ + ../src/freetype/base/ftbbox.c \ + ../src/freetype/base/ftbdf.c \ + ../src/freetype/base/ftbitmap.c \ + ../src/freetype/base/ftcid.c \ + ../src/freetype/base/ftfntfmt.c \ + ../src/freetype/base/ftfstype.c \ + ../src/freetype/base/ftgasp.c \ + ../src/freetype/base/ftglyph.c \ + ../src/freetype/base/ftgxval.c \ + ../src/freetype/base/ftinit.c \ + ../src/freetype/base/ftlcdfil.c \ + ../src/freetype/base/ftmm.c \ + ../src/freetype/base/ftotval.c \ + ../src/freetype/base/ftpatent.c \ + ../src/freetype/base/ftpfr.c \ + ../src/freetype/base/ftstroke.c \ + ../src/freetype/base/ftsynth.c \ + ../src/freetype/base/ftsystem.c \ + ../src/freetype/base/fttype1.c \ + ../src/freetype/base/ftwinfnt.c \ + ../src/freetype/bdf/bdf.c \ + ../src/freetype/bzip2/ftbzip2.c \ + ../src/freetype/cache/ftcache.c \ + ../src/freetype/cff/cff.c \ + ../src/freetype/cid/type1cid.c \ + ../src/freetype/gzip/ftgzip.c \ + ../src/freetype/lzw/ftlzw.c \ + ../src/freetype/pcf/pcf.c \ + ../src/freetype/pfr/pfr.c \ + ../src/freetype/psaux/psaux.c \ + ../src/freetype/pshinter/pshinter.c \ + ../src/freetype/psnames/psnames.c \ + ../src/freetype/raster/raster.c \ + ../src/freetype/sfnt/sfnt.c \ + ../src/freetype/smooth/smooth.c \ + ../src/freetype/truetype/truetype.c \ + ../src/freetype/type1/type1.c \ + ../src/freetype/type42/type42.c \ + ../src/freetype/winfonts/winfnt.c -ccextractor_CFLAGS = -std=gnu99 -Wno-write-strings -D_FILE_OFFSET_BITS=64 -DVERSION_FILE_PRESENT +ccextractor_CFLAGS = -std=gnu99 -Wno-write-strings -D_FILE_OFFSET_BITS=64 -DVERSION_FILE_PRESENT -DFT2_BUILD_LIBRARY -ccextractor_CPPFLAGS =-I../src/lib_ccx/ -I../src/gpacmp4/ -I../src/libpng/ -I../src/zlib/ -I../src/zvbi/ -I../src/lib_hash/ -I../src/protobuf-c/ -I../src/utf8proc/ -I../src/ +ccextractor_CPPFLAGS =-I../src/lib_ccx/ -I../src/gpacmp4/ -I../src/libpng/ -I../src/zlib/ -I../src/zvbi/ -I../src/lib_hash/ -I../src/protobuf-c/ -I../src/utf8proc/ -I../src/ -I../src/freetype/include/ ccextractor_LDADD=-lm diff --git a/linux/build b/linux/build index 98856fe2..0eefed16 100755 --- a/linux/build +++ b/linux/build @@ -1,6 +1,6 @@ #!/bin/bash -BLD_FLAGS="-std=gnu99 -Wno-write-strings -DGPAC_CONFIG_LINUX -D_FILE_OFFSET_BITS=64 -DVERSION_FILE_PRESENT -DENABLE_OCR" -BLD_INCLUDE="-I../src -I /usr/include/leptonica/ -I /usr/include/tesseract/ -I../src/lib_ccx/ -I../src/gpacmp4/ -I../src/libpng/ -I../src/zlib/ -I../src/zvbi -I../src/lib_hash -I../src/protobuf-c -I../src/utf8proc" +BLD_FLAGS="-std=gnu99 -Wno-write-strings -DGPAC_CONFIG_LINUX -D_FILE_OFFSET_BITS=64 -DVERSION_FILE_PRESENT -DENABLE_OCR -DFT2_BUILD_LIBRARY" +BLD_INCLUDE="-I../src -I /usr/include/leptonica/ -I /usr/include/tesseract/ -I../src/lib_ccx/ -I../src/gpacmp4/ -I../src/libpng/ -I../src/zlib/ -I../src/zvbi -I../src/lib_hash -I../src/protobuf-c -I../src/utf8proc -I../src/freetype/include" SRC_LIBPNG="$(find ../src/libpng/ -name '*.c')" SRC_ZLIB="$(find ../src/zlib/ -name '*.c')" SRC_ZVBI="$(find ../src/zvbi/ -name '*.c')" @@ -9,9 +9,50 @@ SRC_GPAC="$(find ../src/gpacmp4/ -name '*.c')" SRC_HASH="$(find ../src/lib_hash/ -name '*.c')" SRC_PROTOBUF="$(find ../src/protobuf-c/ -name '*.c')" SRC_UTF8PROC="../src/utf8proc/utf8proc.c" +SRC_FREETYPE="../src/freetype/autofit/autofit.c + ../src/freetype/base/ftbase.c + ../src/freetype/base/ftbbox.c + ../src/freetype/base/ftbdf.c + ../src/freetype/base/ftbitmap.c + ../src/freetype/base/ftcid.c + ../src/freetype/base/ftfntfmt.c + ../src/freetype/base/ftfstype.c + ../src/freetype/base/ftgasp.c + ../src/freetype/base/ftglyph.c + ../src/freetype/base/ftgxval.c + ../src/freetype/base/ftinit.c + ../src/freetype/base/ftlcdfil.c + ../src/freetype/base/ftmm.c + ../src/freetype/base/ftotval.c + ../src/freetype/base/ftpatent.c + ../src/freetype/base/ftpfr.c + ../src/freetype/base/ftstroke.c + ../src/freetype/base/ftsynth.c + ../src/freetype/base/ftsystem.c + ../src/freetype/base/fttype1.c + ../src/freetype/base/ftwinfnt.c + ../src/freetype/bdf/bdf.c + ../src/freetype/bzip2/ftbzip2.c + ../src/freetype/cache/ftcache.c + ../src/freetype/cff/cff.c + ../src/freetype/cid/type1cid.c + ../src/freetype/gzip/ftgzip.c + ../src/freetype/lzw/ftlzw.c + ../src/freetype/pcf/pcf.c + ../src/freetype/pfr/pfr.c + ../src/freetype/psaux/psaux.c + ../src/freetype/pshinter/pshinter.c + ../src/freetype/psnames/psnames.c + ../src/freetype/raster/raster.c + ../src/freetype/sfnt/sfnt.c + ../src/freetype/smooth/smooth.c + ../src/freetype/truetype/truetype.c + ../src/freetype/type1/type1.c + ../src/freetype/type42/type42.c + ../src/freetype/winfonts/winfnt.c" API_WRAPPERS="$(find ../src/wrappers/ -name '*.c')" API_EXTRACTORS="$(find ../src/extractors/ -name '*.c')" -BLD_SOURCES="../src/ccextractor.c $SRC_CCX $SRC_GPAC $SRC_ZLIB $SRC_ZVBI $SRC_LIBPNG $SRC_HASH $SRC_PROTOBUF $SRC_UTF8PROC $API_WRAPPERS $API_EXTRACTORS" +BLD_SOURCES="../src/ccextractor.c $SRC_CCX $SRC_GPAC $SRC_ZLIB $SRC_ZVBI $SRC_LIBPNG $SRC_HASH $SRC_PROTOBUF $SRC_UTF8PROC $API_WRAPPERS $API_EXTRACTORS $SRC_FREETYPE" BLD_LINKER="-lm -zmuldefs -l tesseract -l lept" ./pre-build.sh diff --git a/linux/build_hardsubx b/linux/build_hardsubx index 0bfbf5f6..478a83d8 100755 --- a/linux/build_hardsubx +++ b/linux/build_hardsubx @@ -1,6 +1,6 @@ #!/bin/bash -BLD_FLAGS="-g -std=gnu99 -Wno-write-strings -DGPAC_CONFIG_LINUX -D_FILE_OFFSET_BITS=64 -DVERSION_FILE_PRESENT -DENABLE_OCR -DENABLE_HARDSUBX" -BLD_INCLUDE="-I../src -I /usr/local/include -I /usr/include/leptonica/ -I /usr/include/tesseract/ -I../src/lib_ccx/ -I../src/gpacmp4/ -I../src/libpng/ -I../src/zlib/ -I../src/zvbi -I../src/lib_hash -I../src/protobuf-c" +BLD_FLAGS="-g -std=gnu99 -Wno-write-strings -DGPAC_CONFIG_LINUX -D_FILE_OFFSET_BITS=64 -DVERSION_FILE_PRESENT -DENABLE_OCR -DENABLE_HARDSUBX -DFT2_BUILD_LIBRARY" +BLD_INCLUDE="-I../src -I /usr/local/include -I /usr/include/leptonica/ -I /usr/include/tesseract/ -I../src/lib_ccx/ -I../src/gpacmp4/ -I../src/libpng/ -I../src/zlib/ -I../src/zvbi -I../src/lib_hash -I../src/protobuf-c -I../src/freetype/include" SRC_LIBPNG="$(find ../src/libpng/ -name '*.c')" SRC_ZLIB="$(find ../src/zlib/ -name '*.c')" SRC_ZVBI="$(find ../src/zvbi/ -name '*.c')" @@ -8,11 +8,52 @@ SRC_CCX="$(find ../src/lib_ccx/ -name '*.c')" SRC_GPAC="$(find ../src/gpacmp4/ -name '*.c')" SRC_HASH="$(find ../src/lib_hash/ -name '*.c')" SRC_UTF8="../src/utf8proc/utf8proc.c" +SRC_FREETYPE="../src/freetype/autofit/autofit.c + ../src/freetype/base/ftbase.c + ../src/freetype/base/ftbbox.c + ../src/freetype/base/ftbdf.c + ../src/freetype/base/ftbitmap.c + ../src/freetype/base/ftcid.c + ../src/freetype/base/ftfntfmt.c + ../src/freetype/base/ftfstype.c + ../src/freetype/base/ftgasp.c + ../src/freetype/base/ftglyph.c + ../src/freetype/base/ftgxval.c + ../src/freetype/base/ftinit.c + ../src/freetype/base/ftlcdfil.c + ../src/freetype/base/ftmm.c + ../src/freetype/base/ftotval.c + ../src/freetype/base/ftpatent.c + ../src/freetype/base/ftpfr.c + ../src/freetype/base/ftstroke.c + ../src/freetype/base/ftsynth.c + ../src/freetype/base/ftsystem.c + ../src/freetype/base/fttype1.c + ../src/freetype/base/ftwinfnt.c + ../src/freetype/bdf/bdf.c + ../src/freetype/bzip2/ftbzip2.c + ../src/freetype/cache/ftcache.c + ../src/freetype/cff/cff.c + ../src/freetype/cid/type1cid.c + ../src/freetype/gzip/ftgzip.c + ../src/freetype/lzw/ftlzw.c + ../src/freetype/pcf/pcf.c + ../src/freetype/pfr/pfr.c + ../src/freetype/psaux/psaux.c + ../src/freetype/pshinter/pshinter.c + ../src/freetype/psnames/psnames.c + ../src/freetype/raster/raster.c + ../src/freetype/sfnt/sfnt.c + ../src/freetype/smooth/smooth.c + ../src/freetype/truetype/truetype.c + ../src/freetype/type1/type1.c + ../src/freetype/type42/type42.c + ../src/freetype/winfonts/winfnt.c" API_WRAPPERS="$(find ../src/wrappers/ -name '*.c')" API_EXTRACTORS="$(find ../src/extractors/ -name '*.c')" SRC_PROTOBUF="$(find ../src/protobuf-c/ -name '*.c')" protobuf-c -BLD_SOURCES="../src/ccextractor.c $SRC_CCX $SRC_GPAC $SRC_ZLIB $SRC_ZVBI $SRC_LIBPNG $SRC_HASH $SRC_UTF8 $SRC_PROTOBUF $API_WRAPPERS $API_EXTRACTORS" +BLD_SOURCES="../src/ccextractor.c $SRC_CCX $SRC_GPAC $SRC_ZLIB $SRC_ZVBI $SRC_LIBPNG $SRC_HASH $SRC_UTF8 $SRC_PROTOBUF $API_WRAPPERS $API_EXTRACTORS $SRC_FREETYPE" BLD_LINKER="-lm -zmuldefs -l tesseract -l lept -L/usr/local/lib -lswscale -lavutil -pthread -lavformat -lavcodec -lxcb-shm -lxcb -lX11 -llzma -lz -lswresample" ./pre-build.sh diff --git a/linux/builddebug b/linux/builddebug index a14d9770..f4ba1f3d 100755 --- a/linux/builddebug +++ b/linux/builddebug @@ -1,6 +1,6 @@ #!/bin/bash -BLD_FLAGS="-g -std=gnu99 -Wno-write-strings -DGPAC_CONFIG_LINUX -D_FILE_OFFSET_BITS=64 -DVERSION_FILE_PRESENT -DENABLE_OCR" -BLD_INCLUDE="-I../src -I /usr/include/leptonica/ -I /usr/include/tesseract/ -I../src/lib_ccx/ -I../src/gpacmp4/ -I../src/libpng/ -I../src/zlib/ -I../src/zvbi -I../src/lib_hash -I../src/protobuf-c -I../src/utf8proc" +BLD_FLAGS="-g -std=gnu99 -Wno-write-strings -DGPAC_CONFIG_LINUX -D_FILE_OFFSET_BITS=64 -DVERSION_FILE_PRESENT -DENABLE_OCR -DFT2_BUILD_LIBRARY" +BLD_INCLUDE="-I../src -I /usr/include/leptonica/ -I /usr/include/tesseract/ -I../src/lib_ccx/ -I../src/gpacmp4/ -I../src/libpng/ -I../src/zlib/ -I../src/zvbi -I../src/lib_hash -I../src/protobuf-c -I../src/utf8proc -I../src/freetype/include" SRC_LIBPNG="$(find ../src/libpng/ -name '*.c')" SRC_ZLIB="$(find ../src/zlib/ -name '*.c')" SRC_ZVBI="$(find ../src/zvbi/ -name '*.c')" @@ -9,9 +9,50 @@ SRC_GPAC="$(find ../src/gpacmp4/ -name '*.c')" SRC_HASH="$(find ../src/lib_hash/ -name '*.c')" SRC_PROTOBUF="$(find ../src/protobuf-c/ -name '*.c')" SRC_UTF8PROC="../src/utf8proc/utf8proc.c" +SRC_FREETYPE="../src/freetype/autofit/autofit.c + ../src/freetype/base/ftbase.c + ../src/freetype/base/ftbbox.c + ../src/freetype/base/ftbdf.c + ../src/freetype/base/ftbitmap.c + ../src/freetype/base/ftcid.c + ../src/freetype/base/ftfntfmt.c + ../src/freetype/base/ftfstype.c + ../src/freetype/base/ftgasp.c + ../src/freetype/base/ftglyph.c + ../src/freetype/base/ftgxval.c + ../src/freetype/base/ftinit.c + ../src/freetype/base/ftlcdfil.c + ../src/freetype/base/ftmm.c + ../src/freetype/base/ftotval.c + ../src/freetype/base/ftpatent.c + ../src/freetype/base/ftpfr.c + ../src/freetype/base/ftstroke.c + ../src/freetype/base/ftsynth.c + ../src/freetype/base/ftsystem.c + ../src/freetype/base/fttype1.c + ../src/freetype/base/ftwinfnt.c + ../src/freetype/bdf/bdf.c + ../src/freetype/bzip2/ftbzip2.c + ../src/freetype/cache/ftcache.c + ../src/freetype/cff/cff.c + ../src/freetype/cid/type1cid.c + ../src/freetype/gzip/ftgzip.c + ../src/freetype/lzw/ftlzw.c + ../src/freetype/pcf/pcf.c + ../src/freetype/pfr/pfr.c + ../src/freetype/psaux/psaux.c + ../src/freetype/pshinter/pshinter.c + ../src/freetype/psnames/psnames.c + ../src/freetype/raster/raster.c + ../src/freetype/sfnt/sfnt.c + ../src/freetype/smooth/smooth.c + ../src/freetype/truetype/truetype.c + ../src/freetype/type1/type1.c + ../src/freetype/type42/type42.c + ../src/freetype/winfonts/winfnt.c" API_WRAPPERS="$(find ../src/wrappers/ -name '*.c')" API_EXTRACTORS="$(find ../src/extractors/ -name '*.c')" -BLD_SOURCES="../src/ccextractor.c $SRC_CCX $SRC_GPAC $SRC_ZLIB $SRC_ZVBI $SRC_LIBPNG $SRC_HASH $SRC_PROTOBUF $SRC_UTF8PROC $API_WRAPPERS $API_EXTRACTORS" +BLD_SOURCES="../src/ccextractor.c $SRC_CCX $SRC_GPAC $SRC_ZLIB $SRC_ZVBI $SRC_LIBPNG $SRC_HASH $SRC_PROTOBUF $SRC_UTF8PROC $API_WRAPPERS $API_EXTRACTORS $SRC_FREETYPE" BLD_LINKER="-lm -zmuldefs -l tesseract -l lept" ./pre-build.sh diff --git a/mac/Makefile.am b/mac/Makefile.am index 05923049..c7a2e8fa 100644 --- a/mac/Makefile.am +++ b/mac/Makefile.am @@ -156,7 +156,6 @@ ccextractor_SOURCES = \ ../src/lib_ccx/ccx_encoders_smptett.c \ ../src/lib_ccx/ccx_encoders_splitbysentence.c \ ../src/lib_ccx/ccx_encoders_spupng.c \ - ../src/lib_ccx/ccx_encoders_spupng.h \ ../src/lib_ccx/ccx_encoders_srt.c \ ../src/lib_ccx/ccx_encoders_ssa.c \ ../src/lib_ccx/ccx_encoders_structs.h \ @@ -208,8 +207,6 @@ ccextractor_SOURCES = \ ../src/lib_ccx/params.c \ ../src/lib_ccx/params_dump.c \ ../src/lib_ccx/sequencing.c \ - ../src/lib_ccx/spupng_encoder.c \ - ../src/lib_ccx/spupng_encoder.h \ ../src/lib_ccx/stdintmsc.h \ ../src/lib_ccx/stream_functions.c \ ../src/lib_ccx/teletext.h \ @@ -268,12 +265,53 @@ ccextractor_SOURCES = \ ../src/extractors/extractor.c \ ../src/extractors/extractor.h \ ../src/wrappers/wrapper.c \ - ../src/wrappers/wrapper.h + ../src/wrappers/wrapper.h \ + ../src/freetype/autofit/autofit.c \ + ../src/freetype/base/ftbase.c \ + ../src/freetype/base/ftbbox.c \ + ../src/freetype/base/ftbdf.c \ + ../src/freetype/base/ftbitmap.c \ + ../src/freetype/base/ftcid.c \ + ../src/freetype/base/ftfntfmt.c \ + ../src/freetype/base/ftfstype.c \ + ../src/freetype/base/ftgasp.c \ + ../src/freetype/base/ftglyph.c \ + ../src/freetype/base/ftgxval.c \ + ../src/freetype/base/ftinit.c \ + ../src/freetype/base/ftlcdfil.c \ + ../src/freetype/base/ftmm.c \ + ../src/freetype/base/ftotval.c \ + ../src/freetype/base/ftpatent.c \ + ../src/freetype/base/ftpfr.c \ + ../src/freetype/base/ftstroke.c \ + ../src/freetype/base/ftsynth.c \ + ../src/freetype/base/ftsystem.c \ + ../src/freetype/base/fttype1.c \ + ../src/freetype/base/ftwinfnt.c \ + ../src/freetype/bdf/bdf.c \ + ../src/freetype/bzip2/ftbzip2.c \ + ../src/freetype/cache/ftcache.c \ + ../src/freetype/cff/cff.c \ + ../src/freetype/cid/type1cid.c \ + ../src/freetype/gzip/ftgzip.c \ + ../src/freetype/lzw/ftlzw.c \ + ../src/freetype/pcf/pcf.c \ + ../src/freetype/pfr/pfr.c \ + ../src/freetype/psaux/psaux.c \ + ../src/freetype/pshinter/pshinter.c \ + ../src/freetype/psnames/psnames.c \ + ../src/freetype/raster/raster.c \ + ../src/freetype/sfnt/sfnt.c \ + ../src/freetype/smooth/smooth.c \ + ../src/freetype/truetype/truetype.c \ + ../src/freetype/type1/type1.c \ + ../src/freetype/type42/type42.c \ + ../src/freetype/winfonts/winfnt.c -ccextractor_CFLAGS = -std=gnu99 -Wno-write-strings -D_FILE_OFFSET_BITS=64 -DVERSION_FILE_PRESENT +ccextractor_CFLAGS = -std=gnu99 -Wno-write-strings -D_FILE_OFFSET_BITS=64 -DVERSION_FILE_PRESENT -DFT2_BUILD_LIBRARY -ccextractor_CPPFLAGS =-I../src/lib_ccx/ -I../src/gpacmp4/ -I../src/libpng/ -I../src/zlib/ -I../src/zvbi/ -I../src/lib_hash/ -I../src/protobuf-c/ -I../src/utf8proc/ -I../src/ +ccextractor_CPPFLAGS =-I../src/lib_ccx/ -I../src/gpacmp4/ -I../src/libpng/ -I../src/zlib/ -I../src/zvbi/ -I../src/lib_hash/ -I../src/protobuf-c/ -I../src/utf8proc/ -I../src/ -I../src/freetype/include/ ccextractor_LDADD=-lm diff --git a/mac/build.command b/mac/build.command index 89a747b5..ee59ee44 100755 --- a/mac/build.command +++ b/mac/build.command @@ -1,8 +1,8 @@ #!/bin/bash cd `dirname $0` -BLD_FLAGS="-std=gnu99 -Wno-write-strings -DGPAC_CONFIG_DARWIN -D_FILE_OFFSET_BITS=64 -DVERSION_FILE_PRESENT -Dfopen64=fopen -Dopen64=open -Dlseek64=lseek" +BLD_FLAGS="-std=gnu99 -Wno-write-strings -DGPAC_CONFIG_DARWIN -D_FILE_OFFSET_BITS=64 -DVERSION_FILE_PRESENT -Dfopen64=fopen -Dopen64=open -Dlseek64=lseek -DFT2_BUILD_LIBRARY" [[ $1 = "OCR" ]] && BLD_FLAGS="$BLD_FLAGS -DENABLE_OCR" -BLD_INCLUDE="-I../src/ -I../src/lib_ccx -I../src/gpacmp4 -I../src/lib_hash -I../src/libpng -I../src/utf8proc -I../src/protobuf-c -I../src/zlib -I../src/zvbi" +BLD_INCLUDE="-I../src/ -I../src/lib_ccx -I../src/gpacmp4 -I../src/lib_hash -I../src/libpng -I../src/utf8proc -I../src/protobuf-c -I../src/zlib -I../src/zvbi -I../src/freetype/include" [[ $1 = "OCR" ]] && BLD_INCLUDE="$BLD_INCLUDE `pkg-config --cflags --silence-errors tesseract`" SRC_CCX="$(find ../src/lib_ccx -name '*.c')" SRC_GPAC="$(find ../src/gpacmp4 -name '*.c')" @@ -14,8 +14,48 @@ SRC_ZLIB="$(find ../src/zlib -name '*.c')" SRC_ZVBI="$(find ../src/zvbi -name '*.c')" API_WRAPPERS="$(find ../src/wrappers/ -name '*.c')" API_EXTRACTORS="$(find ../src/extractors/ -name '*.c')" - -BLD_SOURCES="../src/ccextractor.c $SRC_API $SRC_CCX $SRC_GPAC $SRC_LIB_HASH $SRC_LIBPNG $SRC_PROTOBUF $SRC_UTF8 $SRC_ZLIB $SRC_ZVBI $API_WRAPPERS $API_EXTRACTORS" +SRC_FREETYPE="../src/freetype/autofit/autofit.c \ + ../src/freetype/base/ftbase.c \ + ../src/freetype/base/ftbbox.c \ + ../src/freetype/base/ftbdf.c \ + ../src/freetype/base/ftbitmap.c \ + ../src/freetype/base/ftcid.c \ + ../src/freetype/base/ftfntfmt.c \ + ../src/freetype/base/ftfstype.c \ + ../src/freetype/base/ftgasp.c \ + ../src/freetype/base/ftglyph.c \ + ../src/freetype/base/ftgxval.c \ + ../src/freetype/base/ftinit.c \ + ../src/freetype/base/ftlcdfil.c \ + ../src/freetype/base/ftmm.c \ + ../src/freetype/base/ftotval.c \ + ../src/freetype/base/ftpatent.c \ + ../src/freetype/base/ftpfr.c \ + ../src/freetype/base/ftstroke.c \ + ../src/freetype/base/ftsynth.c \ + ../src/freetype/base/ftsystem.c \ + ../src/freetype/base/fttype1.c \ + ../src/freetype/base/ftwinfnt.c \ + ../src/freetype/bdf/bdf.c \ + ../src/freetype/bzip2/ftbzip2.c \ + ../src/freetype/cache/ftcache.c \ + ../src/freetype/cff/cff.c \ + ../src/freetype/cid/type1cid.c \ + ../src/freetype/gzip/ftgzip.c \ + ../src/freetype/lzw/ftlzw.c \ + ../src/freetype/pcf/pcf.c \ + ../src/freetype/pfr/pfr.c \ + ../src/freetype/psaux/psaux.c \ + ../src/freetype/pshinter/pshinter.c \ + ../src/freetype/psnames/psnames.c \ + ../src/freetype/raster/raster.c \ + ../src/freetype/sfnt/sfnt.c \ + ../src/freetype/smooth/smooth.c \ + ../src/freetype/truetype/truetype.c \ + ../src/freetype/type1/type1.c \ + ../src/freetype/type42/type42.c \ + ../src/freetype/winfonts/winfnt.c" +BLD_SOURCES="../src/ccextractor.c $SRC_API $SRC_CCX $SRC_GPAC $SRC_LIB_HASH $SRC_LIBPNG $SRC_PROTOBUF $SRC_UTF8 $SRC_ZLIB $SRC_ZVBI $SRC_FREETYPE $API_WRAPPERS $API_EXTRACTORS" BLD_LINKER="-lm -liconv" [[ $1 = "OCR" ]] && BLD_LINKER="$BLD_LINKER `pkg-config --libs --silence-errors tesseract` `pkg-config --libs --silence-errors lept`" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 23a2b47f..66bb0aa6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -39,7 +39,7 @@ configure_file ( "${PROJECT_SOURCE_DIR}/lib_ccx/compile_info_real.h" ) -add_definitions(-DVERSION_FILE_PRESENT) +add_definitions(-DVERSION_FILE_PRESENT -DFT2_BUILD_LIBRARY) include_directories ("${PROJECT_SOURCE_DIR}") include_directories ("${PROJECT_SOURCE_DIR}/lib_ccx/") @@ -52,6 +52,7 @@ include_directories ("${PROJECT_SOURCE_DIR}/extractors/") include_directories ("${PROJECT_SOURCE_DIR}/wrappers/") include_directories ("${PROJECT_SOURCE_DIR}/libpng/") include_directories ("${PROJECT_SOURCE_DIR}/zlib/") +include_directories ("${PROJECT_SOURCE_DIR}/freetype/include/") aux_source_directory ("${PROJECT_SOURCE_DIR}/protobuf-c/" SOURCEFILE) aux_source_directory ("${PROJECT_SOURCE_DIR}/zvbi/" SOURCEFILE) aux_source_directory ("${PROJECT_SOURCE_DIR}/lib_hash/" SOURCEFILE) @@ -60,6 +61,49 @@ aux_source_directory ("${PROJECT_SOURCE_DIR}/wrappers/" SOURCEFILE) aux_source_directory ("${PROJECT_SOURCE_DIR}/libpng/" SOURCEFILE) aux_source_directory ("${PROJECT_SOURCE_DIR}/zlib/" SOURCEFILE) +set(FREETYPE_SOURCE + ${PROJECT_SOURCE_DIR}/freetype/autofit/autofit.c + ${PROJECT_SOURCE_DIR}/freetype/base/ftbase.c + ${PROJECT_SOURCE_DIR}/freetype/base/ftbbox.c + ${PROJECT_SOURCE_DIR}/freetype/base/ftbdf.c + ${PROJECT_SOURCE_DIR}/freetype/base/ftbitmap.c + ${PROJECT_SOURCE_DIR}/freetype/base/ftcid.c + ${PROJECT_SOURCE_DIR}/freetype/base/ftfntfmt.c + ${PROJECT_SOURCE_DIR}/freetype/base/ftfstype.c + ${PROJECT_SOURCE_DIR}/freetype/base/ftgasp.c + ${PROJECT_SOURCE_DIR}/freetype/base/ftglyph.c + ${PROJECT_SOURCE_DIR}/freetype/base/ftgxval.c + ${PROJECT_SOURCE_DIR}/freetype/base/ftinit.c + ${PROJECT_SOURCE_DIR}/freetype/base/ftlcdfil.c + ${PROJECT_SOURCE_DIR}/freetype/base/ftmm.c + ${PROJECT_SOURCE_DIR}/freetype/base/ftotval.c + ${PROJECT_SOURCE_DIR}/freetype/base/ftpatent.c + ${PROJECT_SOURCE_DIR}/freetype/base/ftpfr.c + ${PROJECT_SOURCE_DIR}/freetype/base/ftstroke.c + ${PROJECT_SOURCE_DIR}/freetype/base/ftsynth.c + ${PROJECT_SOURCE_DIR}/freetype/base/ftsystem.c + ${PROJECT_SOURCE_DIR}/freetype/base/fttype1.c + ${PROJECT_SOURCE_DIR}/freetype/base/ftwinfnt.c + ${PROJECT_SOURCE_DIR}/freetype/bdf/bdf.c + ${PROJECT_SOURCE_DIR}/freetype/bzip2/ftbzip2.c + ${PROJECT_SOURCE_DIR}/freetype/cache/ftcache.c + ${PROJECT_SOURCE_DIR}/freetype/cff/cff.c + ${PROJECT_SOURCE_DIR}/freetype/cid/type1cid.c + ${PROJECT_SOURCE_DIR}/freetype/gzip/ftgzip.c + ${PROJECT_SOURCE_DIR}/freetype/lzw/ftlzw.c + ${PROJECT_SOURCE_DIR}/freetype/pcf/pcf.c + ${PROJECT_SOURCE_DIR}/freetype/pfr/pfr.c + ${PROJECT_SOURCE_DIR}/freetype/psaux/psaux.c + ${PROJECT_SOURCE_DIR}/freetype/pshinter/pshinter.c + ${PROJECT_SOURCE_DIR}/freetype/psnames/psnames.c + ${PROJECT_SOURCE_DIR}/freetype/raster/raster.c + ${PROJECT_SOURCE_DIR}/freetype/sfnt/sfnt.c + ${PROJECT_SOURCE_DIR}/freetype/smooth/smooth.c + ${PROJECT_SOURCE_DIR}/freetype/truetype/truetype.c + ${PROJECT_SOURCE_DIR}/freetype/type1/type1.c + ${PROJECT_SOURCE_DIR}/freetype/type42/type42.c + ${PROJECT_SOURCE_DIR}/freetype/winfonts/winfnt.c + ) #Windows specific libraries and linker flags if(WIN32) include_directories ("${PROJECT_SOURCE_DIR}/win_spec_incld/") @@ -90,7 +134,7 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") endif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") -set (EXTRA_LIBS ${EXTRA_LIBS} -lz) +set (EXTRA_LIBS ${EXTRA_LIBS} -lz -lm) find_package (PkgConfig) @@ -149,7 +193,7 @@ if (PKG_CONFIG_FOUND AND WITH_SHARING) set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DENABLE_SHARING") endif (PKG_CONFIG_FOUND AND WITH_SHARING) -add_executable (ccextractor ${SOURCEFILE}) +add_executable (ccextractor ${SOURCEFILE} ${FREETYPE_SOURCE}) target_link_libraries (ccextractor ${EXTRA_LIBS}) target_include_directories (ccextractor PUBLIC ${EXTRA_INCLUDES}) diff --git a/src/ccextractor.c b/src/ccextractor.c index fd907645..f6850090 100644 --- a/src/ccextractor.c +++ b/src/ccextractor.c @@ -569,7 +569,6 @@ void run(PyObject * reporter, char * line, int encoding) PyObject_CallObject((PyObject*)reporter, args); } #endif - int main(int argc, char* argv[]) { struct ccx_s_options* api_options = api_init_options(); diff --git a/src/lib_ccx/ccx_common_option.h b/src/lib_ccx/ccx_common_option.h index 9ebf826f..6c8b557a 100644 --- a/src/lib_ccx/ccx_common_option.h +++ b/src/lib_ccx/ccx_common_option.h @@ -71,6 +71,9 @@ struct encoder_cfg int program_number; unsigned char in_format; int nospupngocr; // 1 if we don't want to OCR bitmaps to add the text as comments in the XML file in spupng + + // text -> png (text render) + char *render_font; // The font used to render text if needed (e.g. teletext->spupng) //CEA-708 int services_enabled[CCX_DTVCC_MAX_SERVICES]; diff --git a/src/lib_ccx/ccx_encoders_common.c b/src/lib_ccx/ccx_encoders_common.c index a756f462..2f377781 100644 --- a/src/lib_ccx/ccx_encoders_common.c +++ b/src/lib_ccx/ccx_encoders_common.c @@ -1,7 +1,5 @@ #include "ccx_decoders_common.h" #include "ccx_encoders_common.h" -#include "spupng_encoder.h" -#include "ccx_encoders_spupng.h" #include "utility.h" #include "ocr.h" #include "ccx_decoders_608.h" diff --git a/src/lib_ccx/ccx_encoders_common.h b/src/lib_ccx/ccx_encoders_common.h index 0ace23b7..5a7c4bfd 100644 --- a/src/lib_ccx/ccx_encoders_common.h +++ b/src/lib_ccx/ccx_encoders_common.h @@ -17,6 +17,10 @@ if (ctx->buffer == NULL) { fatal(EXIT_NOT_ENOUGH_MEMORY, "Not enough memory for reallocating buffer, bailing out\n"); } \ } +// CC page dimensions +#define ROWS 15 +#define COLUMNS 32 + typedef struct ccx_dtvcc_writer_ctx { int fd; @@ -170,6 +174,7 @@ int write_cc_buffer_as_ssa (struct eia608_screen *data, struct encode int write_cc_buffer_as_webvtt (struct eia608_screen *data, struct encoder_ctx *context); int write_cc_buffer_as_sami (struct eia608_screen *data, struct encoder_ctx *context); int write_cc_buffer_as_smptett (struct eia608_screen *data, struct encoder_ctx *context); +int write_cc_buffer_as_spupng (struct eia608_screen *data, struct encoder_ctx *context); void write_cc_buffer_to_gui (struct eia608_screen *data, struct encoder_ctx *context); int write_cc_buffer_as_g608 (struct eia608_screen *data, struct encoder_ctx *context); diff --git a/src/lib_ccx/ccx_encoders_curl.c b/src/lib_ccx/ccx_encoders_curl.c index a2ecf208..cb85e82d 100644 --- a/src/lib_ccx/ccx_encoders_curl.c +++ b/src/lib_ccx/ccx_encoders_curl.c @@ -1,8 +1,6 @@ #ifdef WITH_LIBCURL #include "ccx_decoders_common.h" #include "ccx_encoders_common.h" -#include "spupng_encoder.h" -#include "ccx_encoders_spupng.h" #include "utility.h" #include "ocr.h" #include "ccx_decoders_608.h" diff --git a/src/lib_ccx/ccx_encoders_sami.c b/src/lib_ccx/ccx_encoders_sami.c index 01e71d57..31783de4 100644 --- a/src/lib_ccx/ccx_encoders_sami.c +++ b/src/lib_ccx/ccx_encoders_sami.c @@ -2,7 +2,6 @@ #include "ccx_common_option.h" #include "ccx_encoders_common.h" #include "png.h" -#include "spupng_encoder.h" #include "ocr.h" #include "utility.h" #include "ccx_encoders_helpers.h" diff --git a/src/lib_ccx/ccx_encoders_smptett.c b/src/lib_ccx/ccx_encoders_smptett.c index 42b30f2a..9e088696 100644 --- a/src/lib_ccx/ccx_encoders_smptett.c +++ b/src/lib_ccx/ccx_encoders_smptett.c @@ -25,7 +25,6 @@ #include "ccx_common_option.h" #include "ccx_encoders_common.h" #include "png.h" -#include "spupng_encoder.h" #include "ocr.h" #include "utility.h" #include "ccx_encoders_helpers.h" diff --git a/src/lib_ccx/ccx_encoders_spupng.c b/src/lib_ccx/ccx_encoders_spupng.c index d228238a..adca914b 100644 --- a/src/lib_ccx/ccx_encoders_spupng.c +++ b/src/lib_ccx/ccx_encoders_spupng.c @@ -1,295 +1,885 @@ -#include -#include -#include "ccx_encoders_spupng.h" +#include "ccfont2.xbm" // CC font from libzvbi +#include "ccx_common_common.h" +#include "ccx_encoders_common.h" +#include "png.h" +#include +#include FT_FREETYPE_H +#include "lib_ccx.h" #include "ccx_encoders_helpers.h" +#include +#ifdef ENABLE_OCR +#include "ocr.h" +#undef OCR_DEBUG +#endif -void draw_str(char *str, uint8_t * canvas, int rowstride) +/* Closed Caption character cell dimensions */ +#define CCW 16 +#define CCH 26 /* line doubled */ + +// TODO: To make them customizable +#define FONT_SIZE 20 +#define CANVAS_WIDTH 600 + +FT_Library ft_library = NULL; +FT_Face face = NULL; + +struct spupng_t { - char *ptr; - uint8_t* cell; - uint8_t pen[2]; - int i = 0; - pen[0] = COL_BLACK; - pen[1] = COL_WHITE; - for (ptr = str; *ptr != '\0'; ptr++) - { - cell = canvas + ((i+1) * CCW); - draw_char_indexed(cell, rowstride, pen, 0, 0, 0); - i++; - } - + FILE* fpxml; + FILE* fppng; + char* dirname; + char* pngfile; + char* relative_path_png; + int fileIndex; + int xOffset; + int yOffset; +}; + +#define CCPL (ccfont2_width / CCW * ccfont2_height / CCH) + +static int initialized = 0; + +void spupng_init_font() +{ + uint8_t *t, *p; + int i, j; + + /* de-interleave font image (puts all chars in row 0) */ + if (!(t = (uint8_t*)malloc(ccfont2_width * ccfont2_height / 8))) + ccx_common_logging.fatal_ftn(EXIT_NOT_ENOUGH_MEMORY, "spupng_init_font: Memory allocation failed"); + + for (p = t, i = 0; i < CCH; i++) + for (j = 0; j < ccfont2_height; p += ccfont2_width / 8, j += CCH) + memcpy(p, ccfont2_bits + (j + i) * ccfont2_width / 8, + ccfont2_width / 8); + + memcpy(ccfont2_bits, t, ccfont2_width * ccfont2_height / 8); + free(t); } -void draw_row(struct eia608_screen* data, int row, uint8_t * canvas, int rowstride) + +struct spupng_t *spunpg_init(struct ccx_s_write *out) { - int column; - int unicode = 0; - uint8_t pen[2]; - uint8_t* cell; - int first = -1; - int last = 0; + struct spupng_t *sp = (struct spupng_t *) malloc(sizeof(struct spupng_t)); + if (NULL == sp) + ccx_common_logging.fatal_ftn(EXIT_NOT_ENOUGH_MEMORY, "spunpg_init: Memory allocation failed (sp)"); - pen[0] = COL_BLACK; + if (!initialized) + { + initialized = 1; + spupng_init_font(); + } - for (column = 0; column < COLUMNS ; column++) { + if ((sp->fpxml = fdopen(out->fh, "w")) == NULL) + { + ccx_common_logging.fatal_ftn(CCX_COMMON_EXIT_FILE_CREATION_FAILED, "Cannot open %s: %s\n", + out->filename, strerror(errno)); + } + sp->dirname = (char *)malloc( + sizeof(char) * (strlen(out->filename) + 3)); + if (NULL == sp->dirname) + ccx_common_logging.fatal_ftn(EXIT_NOT_ENOUGH_MEMORY, "spunpg_init: Memory allocation failed (sp->dirname)"); - if (COL_TRANSPARENT != data->colors[row][column]) + strcpy(sp->dirname, out->filename); + char* p = strrchr(sp->dirname, '.'); + if (NULL == p) + p = sp->dirname + strlen(sp->dirname); + *p = '\0'; + strcat(sp->dirname, ".d"); + if (0 != mkdir(sp->dirname, 0777)) + { + if (errno != EEXIST) { - cell = canvas + ((column+1) * CCW); - get_char_in_unicode((unsigned char*)&unicode, data->characters[row][column]); - pen[1] = data->colors[row][column]; + ccx_common_logging.fatal_ftn(CCX_COMMON_EXIT_FILE_CREATION_FAILED, "Cannot create %s: %s\n", + sp->dirname, strerror(errno)); + } + // If dirname isn't a directory or if we don't have write permission, + // the first attempt to create a .png file will fail and we'll XXxit. + } - int attr = data->fonts[row][column]; - draw_char_indexed(cell, rowstride, pen, unicode, (attr & FONT_ITALICS) != 0, (attr & FONT_UNDERLINED) != 0); - if (first < 0) - { - // draw a printable space before the first non-space char - first = column; - if (unicode != 0x20) - { - cell = canvas + ((first) * CCW); - draw_char_indexed(cell, rowstride, pen, 0x20, 0, 0); - } - } - last = column; + // enough to append /subNNNN.png + sp->pngfile = (char *)malloc(sizeof(char) * (strlen(sp->dirname) + 13)); + sp->relative_path_png = (char *)malloc(sizeof(char) * (strlen(sp->dirname) + 13)); + + if (NULL == sp->pngfile || NULL == sp->relative_path_png) + ccx_common_logging.fatal_ftn(EXIT_NOT_ENOUGH_MEMORY, "spunpg_init: Memory allocation failed (sp->pngfile)"); + sp->fileIndex = 0; + sprintf(sp->pngfile, "%s/sub%04d.png", sp->dirname, sp->fileIndex); + + // Make relative path + char* last_slash = strrchr(sp->dirname, '/'); + if (last_slash == NULL) last_slash = strrchr(sp->dirname, '\\'); + if (last_slash != NULL) + sprintf(sp->relative_path_png, "%s/sub%04d.png", last_slash + 1, sp->fileIndex); + else // do NOT do sp->relative_path_png = sp->pngfile (to avoid double free). + strcpy(sp->relative_path_png, sp->pngfile); + + // For NTSC closed captions and 720x480 DVD subtitle resolution: + // Each character is 16x26. + // 15 rows by 32 columns, plus 2 columns for left & right padding + // So each .png image will be 16*34 wide and 26*15 high, or 544x390 + // To center image in 720x480 DVD screen, offset image by 88 and 45 + // Need to keep yOffset even to prevent flicker on interlaced displays + // Would need to do something different for PAL format and teletext. + sp->xOffset = 88; + sp->yOffset = 46; + + return sp; +} + +void spunpg_free(struct spupng_t *sp) +{ + free(sp->dirname); + free(sp->pngfile); + free(sp->relative_path_png); + free(sp); +} + +void spupng_write_header(struct spupng_t *sp, int multiple_files, char *first_input_file) +{ + fprintf(sp->fpxml, "\n\n"); + if (multiple_files) + fprintf(sp->fpxml, "\n", first_input_file); +} + +void spupng_write_footer(struct spupng_t *sp) +{ + fprintf(sp->fpxml, "\n\n"); + fflush(sp->fpxml); + fclose(sp->fpxml); +} + +void write_spumux_header(struct encoder_ctx *ctx, struct ccx_s_write *out) +{ + if (0 == out->spupng_data) + out->spupng_data = spunpg_init(out); + + spupng_write_header((struct spupng_t*)out->spupng_data, ctx->multiple_files, ctx->first_input_file); + + if (ctx->write_format == CCX_OF_RAW) { // WARN: Memory leak with this flag, free by hand. Maybe bug. + spupng_write_footer(out->spupng_data); + spunpg_free(out->spupng_data); + } +} + +void write_spumux_footer(struct ccx_s_write *out) +{ + if (0 != out->spupng_data) + { + struct spupng_t *sp = (struct spupng_t *) out->spupng_data; + + spupng_write_footer(sp); + spunpg_free(sp); + + out->spupng_data = 0; + out->fh = -1; + } +} + +void write_sputag_open(struct spupng_t *sp, LLONG ms_start, LLONG ms_end) +{ + fprintf(sp->fpxml, "fpxml, " end=\"%.3f\"", ((double)ms_end) / 1000); + fprintf(sp->fpxml, " image=\"%s\"", sp->relative_path_png); + fprintf(sp->fpxml, " xoffset=\"%d\"", sp->xOffset); + fprintf(sp->fpxml, " yoffset=\"%d\"", sp->yOffset); + fprintf(sp->fpxml, ">\n"); +} + +void write_sputag_close(struct spupng_t *sp) +{ + fprintf(sp->fpxml, "\n"); +} +void write_spucomment(struct spupng_t *sp, const char *str) +{ + fprintf(sp->fpxml, "\n", str); +} + +char* get_spupng_filename(void *ctx) +{ + struct spupng_t *sp = (struct spupng_t *)ctx; + return sp->pngfile; +} +void inc_spupng_fileindex(void *ctx) +{ + struct spupng_t *sp = (struct spupng_t *)ctx; + sp->fileIndex++; + sprintf(sp->pngfile, "%s/sub%04d.png", sp->dirname, sp->fileIndex); +} +void set_spupng_offset(void *ctx, int x, int y) +{ + struct spupng_t *sp = (struct spupng_t *)ctx; + sp->xOffset = x; + sp->yOffset = y; +} +int save_spupng(const char *filename, uint8_t *bitmap, int w, int h, + png_color *palette, png_byte *alpha, int nb_color) +{ + FILE *f = NULL; + png_structp png_ptr = NULL; + png_infop info_ptr = NULL; + png_bytep* row_pointer = NULL; + int i, j, ret = 0; + int k = 0; + if (!h) + h = 1; + if (!w) + w = 1; + + f = fopen(filename, "wb"); + if (!f) + { + ccx_common_logging.log_ftn("DVB:unable to open %s in write mode \n", filename); + ret = -1; + goto end; + } + + png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); + if (!png_ptr) + { + ccx_common_logging.log_ftn("DVB:unable to create png write struct\n"); + goto end; + } + if (!(info_ptr = png_create_info_struct(png_ptr))) + { + ccx_common_logging.log_ftn("DVB:unable to create png info struct\n"); + ret = -1; + goto end; + } + + row_pointer = (png_bytep*)malloc(sizeof(png_bytep) * h); + if (!row_pointer) + { + ccx_common_logging.log_ftn("DVB: unable to allocate row_pointer\n"); + ret = -1; + goto end; + } + memset(row_pointer, 0, sizeof(png_bytep) * h); + png_init_io(png_ptr, f); + + png_set_IHDR(png_ptr, info_ptr, w, h, + /* bit_depth */8, + PNG_COLOR_TYPE_PALETTE, + PNG_INTERLACE_NONE, + PNG_COMPRESSION_TYPE_DEFAULT, + PNG_FILTER_TYPE_DEFAULT); + + png_set_PLTE(png_ptr, info_ptr, palette, nb_color); + png_set_tRNS(png_ptr, info_ptr, alpha, nb_color, NULL); + + for (i = 0; i < h; i++) + { + row_pointer[i] = (png_byte*)malloc( + png_get_rowbytes(png_ptr, info_ptr)); + if (row_pointer[i] == NULL) + break; + } + if (i != h) + { + ccx_common_logging.log_ftn("DVB: unable to allocate row_pointer internals\n"); + ret = -1; + goto end; + } + png_write_info(png_ptr, info_ptr); + for (i = 0; i < h; i++) + { + for (j = 0; j < png_get_rowbytes(png_ptr, info_ptr); j++) + { + if (bitmap) + k = bitmap[i * w + (j)]; + else + k = 0; + row_pointer[i][j] = k; } } - // draw a printable space after the last non-space char - // unicode should still contain the last character - // check whether it is a space - if (unicode != 0x20) + + png_write_image(png_ptr, row_pointer); + + png_write_end(png_ptr, info_ptr); +end: if (row_pointer) +{ + for (i = 0; i < h; i++) + freep(&row_pointer[i]); + freep(&row_pointer); +} + png_destroy_write_struct(&png_ptr, &info_ptr); + if (f) + fclose(f); + return ret; + +} +/** +* alpha value 255 means completely opaque +* alpha value 0 means completely transparent +* r g b all 0 means black +* r g b all 255 means white +*/ +int mapclut_paletee(png_color *palette, png_byte *alpha, uint32_t *clut, + uint8_t depth) +{ + for (int i = 0; i < depth; i++) { - cell = canvas + ((last+2) * CCW); - draw_char_indexed(cell, rowstride, pen, 0x20, 0, 0); + palette[i].red = ((clut[i] >> 16) & 0xff); + palette[i].green = ((clut[i] >> 8) & 0xff); + palette[i].blue = (clut[i] & 0xff); + alpha[i] = ((clut[i] >> 24) & 0xff); } -} - -static png_color palette[10] = -{ - { 0xff, 0xff, 0xff }, // COL_WHITE = 0, - { 0x00, 0xff, 0x00 }, // COL_GREEN = 1, - { 0x00, 0x00, 0xff }, // COL_BLUE = 2, - { 0x00, 0xff, 0xff }, // COL_CYAN = 3, - { 0xff, 0x00, 0x00 }, // COL_RED = 4, - { 0xff, 0xff, 0x00 }, // COL_YELLOW = 5, - { 0xff, 0x00, 0xff }, // COL_MAGENTA = 6, - { 0xff, 0xff, 0xff }, // COL_USERDEFINED = 7, - { 0x00, 0x00, 0x00 }, // COL_BLACK = 8 - { 0x00, 0x00, 0x00 } // COL_TRANSPARENT = 9 -}; - -static png_byte alpha[10] = -{ - 255, - 255, - 255, - 255, - 255, - 255, - 255, - 255, - 255, - 0 -}; - -int spupng_write_png(struct spupng_t *sp, struct eia608_screen* data, - png_structp png_ptr, png_infop info_ptr, - png_bytep image, - png_bytep* row_pointer, - unsigned int ww, unsigned int wh) -{ - unsigned int i; - - if (setjmp(png_jmpbuf(png_ptr))) - return 0; - - png_init_io (png_ptr, sp->fppng); - - png_set_IHDR (png_ptr, - info_ptr, - ww, - wh, - /* bit_depth */ 8, - PNG_COLOR_TYPE_PALETTE, - PNG_INTERLACE_NONE, - PNG_COMPRESSION_TYPE_DEFAULT, - PNG_FILTER_TYPE_DEFAULT); - - png_set_PLTE (png_ptr, info_ptr, palette, sizeof(palette) / sizeof(palette[0])); - png_set_tRNS (png_ptr, info_ptr, alpha, sizeof(alpha) / sizeof(alpha[0]), NULL); - - png_set_gAMA (png_ptr, info_ptr, 1.0 / 2.2); - - png_write_info (png_ptr, info_ptr); - - for (i = 0; i < wh; i++) - row_pointer[i] = image + i * ww; - - png_write_image (png_ptr, row_pointer); - - png_write_end (png_ptr, info_ptr); - - return 1; -} - -int spupng_export_png(struct spupng_t *sp, struct eia608_screen* data) -{ - png_structp png_ptr; - png_infop info_ptr; - png_bytep *row_pointer; - png_bytep image; - int ww, wh, rowstride, row_adv; - int row; - - assert ((sizeof(png_byte) == sizeof(uint8_t)) - && (sizeof(*image) == sizeof(uint8_t))); - - // Allow space at beginning and end of each row for a padding space - ww = CCW * (COLUMNS+2); - wh = CCH * ROWS; - row_adv = (COLUMNS+2) * CCW * CCH; - - rowstride = ww * sizeof(*image); - - if (!(row_pointer = (png_bytep*)malloc(sizeof(*row_pointer) * wh))) { - mprint("Unable to allocate %d byte buffer.\n", - sizeof(*row_pointer) * wh); - return 0; +#if OCR_DEBUG + ccx_common_logging.log_ftn("Colors present in original Image\n"); + for (int i = 0; i < depth; i++) + { + ccx_common_logging.log_ftn("%02d)r %03d g %03d b %03d a %03d\n", + i, palette[i].red, palette[i].green, palette[i].blue, alpha[i]); } - - if (!(image = (png_bytep)malloc(wh * ww * sizeof(*image)))) { - mprint("Unable to allocate %d KB image buffer.", - wh * ww * sizeof(*image) / 1024); - free(row_pointer); - return 0; - } - // Initialize image to transparent - memset(image, COL_TRANSPARENT, wh * ww * sizeof(*image)); - - /* draw the image */ - - for (row = 0; row < ROWS; row++) { - if (data->row_used[row]) - draw_row(data, row, image + row * row_adv, rowstride); - } - - /* Now save the image */ - - if (!(png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, - NULL, NULL, NULL))) - goto unknown_error; - - if (!(info_ptr = png_create_info_struct(png_ptr))) { - png_destroy_write_struct(&png_ptr, (png_infopp) NULL); - goto unknown_error; - } - - if (!spupng_write_png (sp, data, png_ptr, info_ptr, image, row_pointer, ww, wh)) { - png_destroy_write_struct (&png_ptr, &info_ptr); - goto write_error; - } - - png_destroy_write_struct (&png_ptr, &info_ptr); - - free (row_pointer); - - free (image); - - return 1; - -write_error: - -unknown_error: - free (row_pointer); - - free (image); - +#endif return 0; } -int spupng_export_string2png(struct spupng_t *sp, char *str) +int write_cc_bitmap_as_spupng(struct cc_subtitle *sub, struct encoder_ctx *context) { - png_structp png_ptr; - png_infop info_ptr; - png_bytep *row_pointer; - png_bytep image; - int ww, wh, rowstride, row_adv; - int row = 0; + struct spupng_t *sp = (struct spupng_t *)context->out->spupng_data; + int x_pos, y_pos, width, height, i; + int x, y, y_off, x_off, ret = 0; + uint8_t *pbuf; + char *filename; + struct cc_bitmap* rect; + png_color *palette = NULL; + png_byte *alpha = NULL; + int wrote_opentag = 1; - assert ((sizeof(png_byte) == sizeof(uint8_t)) - && (sizeof(*image) == sizeof(uint8_t))); + x_pos = -1; + y_pos = -1; + width = 0; + height = 0; - // Allow space at beginning and end of each row for a padding space - ww = CCW * (COLUMNS+2); - wh = CCH * ROWS; - row_adv = (COLUMNS+2) * CCW * CCH; + if (sub->data == NULL) + return 0; - rowstride = ww * sizeof(*image); + write_sputag_open(sp, sub->start_time, sub->end_time - 1); - if (!(row_pointer = (png_bytep*)malloc(sizeof(*row_pointer) * wh))) { - mprint("Unable to allocate %d byte buffer.\n", - sizeof(*row_pointer) * wh); + if (sub->nb_data == 0 && (sub->flags & SUB_EOD_MARKER)) + { + context->prev_start = -1; + if (wrote_opentag) + write_sputag_close(sp); return 0; } + rect = sub->data; + for (i = 0; i < sub->nb_data; i++) + { + if (x_pos == -1) + { + x_pos = rect[i].x; + y_pos = rect[i].y; + width = rect[i].w; + height = rect[i].h; + } + else + { + if (x_pos > rect[i].x) + { + width += (x_pos - rect[i].x); + x_pos = rect[i].x; + } - if (!(image = (png_bytep)malloc(wh * ww * sizeof(*image)))) { - mprint("Unable to allocate %d KB image buffer.", - wh * ww * sizeof(*image) / 1024); - free(row_pointer); - return 0; + if (rect[i].y < y_pos) + { + height += (y_pos - rect[i].y); + y_pos = rect[i].y; + } + + if (rect[i].x + rect[i].w > x_pos + width) + { + width = rect[i].x + rect[i].w - x_pos; + } + + if (rect[i].y + rect[i].h > y_pos + height) + { + height = rect[i].y + rect[i].h - y_pos; + } + + } } - // Initialize image to transparent - memset(image, COL_TRANSPARENT, wh * ww * sizeof(*image)); + inc_spupng_fileindex(sp); + filename = get_spupng_filename(sp); + set_spupng_offset(sp, x_pos, y_pos); + if (sub->flags & SUB_EOD_MARKER) + context->prev_start = sub->start_time; + pbuf = (uint8_t*)malloc(width * height); + memset(pbuf, 0x0, width * height); - /* draw the image */ - draw_str(str, image + row * row_adv, rowstride); + for (i = 0; i < sub->nb_data; i++) + { + x_off = rect[i].x - x_pos; + y_off = rect[i].y - y_pos; + for (y = 0; y < rect[i].h; y++) + { + for (x = 0; x < rect[i].w; x++) + pbuf[((y + y_off) * width) + x_off + x] = rect[i].data[0][y * rect[i].w + x]; - /* Now save the image */ - - if (!(png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, - NULL, NULL, NULL))) - goto unknown_error; - - if (!(info_ptr = png_create_info_struct(png_ptr))) { - png_destroy_write_struct(&png_ptr, (png_infopp) NULL); - goto unknown_error; + } } -#if 0 - if (!spupng_write_png (sp, data, png_ptr, info_ptr, image, row_pointer, ww, wh)) { - png_destroy_write_struct (&png_ptr, &info_ptr); - goto write_error; + palette = (png_color*)malloc(rect[0].nb_colors * sizeof(png_color)); + if (!palette) + { + ret = -1; + goto end; + } + alpha = (png_byte*)malloc(rect[0].nb_colors * sizeof(png_byte)); + if (!alpha) + { + ret = -1; + goto end; + } + + /* TODO do rectangle wise, one color table should not be used for all rectangles */ + mapclut_paletee(palette, alpha, (uint32_t *)rect[0].data[1], rect[0].nb_colors); +#ifdef ENABLE_OCR + if (!context->nospupngocr) + { + char *str; + str = paraof_ocrtext(sub, context->encoded_crlf, context->encoded_crlf_length); + if (str) + { + write_spucomment(sp, str); + freep(&str); + } } #endif - png_destroy_write_struct (&png_ptr, &info_ptr); + save_spupng(filename, pbuf, width, height, palette, alpha, rect[0].nb_colors); + freep(&pbuf); - free (row_pointer); - free (image); +end: + if (wrote_opentag) + write_sputag_close(sp); + for (i = 0, rect = sub->data; i < sub->nb_data; i++, rect++) + { + freep(rect->data); + freep(rect->data + 1); + } + sub->nb_data = 0; + freep(&sub->data); + freep(&palette); + freep(&alpha); + freep(&pbuf); + return ret; +} + +struct pixel_t { + unsigned char r, g, b, a; +}; + +// Write the buffer to a file named filename +// Return 1 on success. +int write_image(struct pixel_t *buffer, FILE* fp, int width, int height) +{ + int ret_code = 1; + png_structp png_ptr = NULL; + png_infop info_ptr = NULL; + png_bytep row = NULL; + + if (!(png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL))) { + mprint("\nUnknown error encountered!\n"); + ret_code = 0; + goto finalise; + } + if (!(info_ptr = png_create_info_struct(png_ptr))) { + mprint("\nUnknown error encountered!\n"); + ret_code = 0; + goto finalise; + } + + png_init_io(png_ptr, fp); + + // Write header + png_set_IHDR(png_ptr, info_ptr, width, height, + 8, PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE, + PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); + + png_write_info(png_ptr, info_ptr); + + // Allocate memory for one row (4 bytes per pixel - RGBA) + row = (png_bytep)malloc(4 * width * sizeof(png_byte)); + + // Write image data + int x, y; + for (y = 0; y> 24)\ + | (((uint32_t)(A) & 0x00ff0000) >> 8)\ + | (((uint32_t)(A) & 0x0000ff00) << 8)\ + | (((uint32_t)(A) & 0x000000ff) << 24)) + +// Generate PNG file from an UTF-32 string (str) +// Convert first if it is UTF-8 string! +// PNG file will be stored at output +// Return 1 on success. +int spupng_export_string2png(struct spupng_t *sp, uint32_t *str, FILE* output) +{ + // Init FreeType if it hasn't been inited yet. + if (ft_library==NULL){ + int error; + if (error = FT_Init_FreeType(&ft_library)) + { + mprint("\nFailed to init freetype, error code: %d\n", error); + return 0; + } + if (error = FT_New_Face(ft_library, ccx_options.enc_cfg.render_font, 0, &face)) + { + mprint("\n\nFailed to init freetype when trying to init face, error code: %d\n", error); + mprint("It's usually caused by the specified font is not found: %s \n", ccx_options.enc_cfg.render_font); + mprint("If this is the case, please use -font to manually specify a font that exists. \n\n"); + return 0; + } + if (error = FT_Set_Pixel_Sizes(face, 0, FONT_SIZE)) + { + mprint("\nFailed to init freetype when trying to set size, error code: %d\n", error); + return 0; + } + } + + int canvas_width = CANVAS_WIDTH; + int canvas_height = FONT_SIZE * 3.5; + int line_height = FONT_SIZE * 1.0; + int extender = FONT_SIZE * 0.2; // to prevent characters like $ (exceed baseline) from being cut + int line_spacing = FONT_SIZE * 0.3; + + int cursor_x = 0; + int cursor_y = line_height * 2; + + // Allocate buffer + // Note: (0, 0) of buffer is at the top left corner. + struct pixel_t *buffer = malloc(canvas_width * canvas_height * sizeof(struct pixel_t)); + if (buffer == NULL) { + mprint("\nFailed to alloc memory for buffer. Need %d bytes.\n", + canvas_width * canvas_height * sizeof(struct pixel_t)); + } + memset(buffer, 0, canvas_width*canvas_height * sizeof(struct pixel_t)); + + FT_GlyphSlot slot = face->glyph; + + // Render characters to image + for (uint32_t *iter = str; *iter; ++iter) + { + uint32_t current_char_code = BigtoLittle32(*iter); // Convert big-endian and little-endian + + if (FT_Load_Char(face, current_char_code, FT_LOAD_RENDER)) continue; // ignore errors + unsigned char* bitmap = slot->bitmap.buffer; + + // Handle '\n' + if (current_char_code == '\n') { +// mprint("\n'\\n' line break"); + black_background(buffer, canvas_width, 0, cursor_y - line_height - extender, cursor_x, line_height + extender * 2); + center_justify(buffer, canvas_width, cursor_y - line_height - extender, cursor_x, line_height + extender * 2); + cursor_x = 0; + cursor_y += line_height + line_spacing; + continue; + } + + // Expand canvas if needed + while (cursor_y - slot->bitmap_top + line_height + line_spacing + extender * 2 >= canvas_height) { + int old_height = canvas_height; + canvas_height += line_height + line_spacing + extender * 2; + struct pixel_t* new_buffer = realloc(buffer, canvas_width * canvas_height * sizeof(struct pixel_t)); + if (new_buffer == NULL) { + mprint("\nFailed to alloc memory for buffer. Need %d bytes.\n", + canvas_width * canvas_height * sizeof(struct pixel_t)); + return 0; + } + memset(new_buffer + old_height * canvas_width, 0, (canvas_height-old_height) * canvas_width * sizeof(struct pixel_t)); + buffer = new_buffer; + + } + + // Characters such as ' ' don't have bitmap. + if (bitmap != NULL) { + + int width = slot->bitmap.width; + int height = slot->bitmap.rows; + + // TODO: this kind of line break may break characters in the middle! + if ((cursor_x + (slot->advance.x >> 6)) > canvas_width) { // Time for a line-break! + // But before that, let's center justify the subtitle. + // Valid subtitle area: (0, cursor_y) to (cursor_x, cursor_y + line_height) + black_background(buffer, canvas_width, 0, cursor_y - line_height - extender, cursor_x, line_height + extender * 2); + center_justify(buffer, canvas_width, cursor_y - line_height - extender, cursor_x, line_height + extender * 2); + + // Set the cursor + cursor_x = 0; + cursor_y += line_height + line_spacing; + } + + draw_to_buffer(buffer, canvas_width, slot->bitmap, cursor_x, cursor_y - slot->bitmap_top); + + } + + /* + mprint("\nDrawing [%c] (%d), advance %d,%d, at %d,%d. bitmap_top=%d", + current_char_code, current_char_code, slot->advance.x >> 6, slot->advance.y >> 6, cursor_x, cursor_y, slot->bitmap_top); + */ + + // Increase pen position + cursor_x += slot->advance.x >> 6; + cursor_y += slot->advance.y >> 6; + } + // Draw black background + black_background(buffer, canvas_width, 0, cursor_y - line_height - extender, cursor_x, line_height + extender * 2); + // Center justify the last line. + center_justify(buffer, canvas_width, cursor_y - line_height - extender, cursor_x, line_height + extender * 2); + + /* + // Draw a blue bar at the beginning of every line. + // Debug purpose only + for (int x = 0; x < 10; x++) for (int y = 0; y < canvas_height; y++) { + struct pixel_t p; p.b = (y / line_height) * 25; p.a = 255; p.g = p.r = 0; + buffer[x + y * canvas_width] = p; + } + */ + + // Save image + write_image(buffer, output, canvas_width, canvas_height); + + free(buffer); return 1; +} +// Convert EIA608 Data(buffer) to string +// out must have at least 256 characters' space +// Return value is the length of the output string +int eia608_to_str(struct encoder_ctx *context, struct eia608_screen *data, char *out) { -unknown_error: - free (row_pointer); + int str_len = 0; + int first = 1; + for (int row = 0; row < ROWS; row++) + { + if (data->row_used[row]) + { + size_t len = get_decoder_line_encoded(context, context->subline, row, data); - free (image); + unsigned char* start = context->subline; + + if (start!=NULL) { + // Remove the space at the beginning of the subtitle + while ((*start == ' ' || *start == '\n') && len-->0) + start++; + } + + // Check for characters that spumux won't parse + // null chars will be changed to space + // pairs of dashes will be changed to underscores + for (unsigned char* ptr = start; ptr < start + len; ptr++) + { + switch (*ptr) + { + case 0: + *ptr = ' '; + break; + case '-': + if (*(ptr + 1) == '-') + { + *ptr++ = '_'; + *ptr = '_'; + } + break; + } + } + + // Remove the space at the end of the subtitle + if (start != NULL) { + unsigned char *end = start; + while (*end && end - start < len && end - start >= 0) end++; // Find the end + while ((*end==' '||*end=='\n'||*end=='\0')&&len-->0) end--; // `len` is changed + len++; + } + + if (!first) { // Add '\n' if it is not the first line. + strcat(out, "\n"); + str_len += 2; + } + first = 0; + strncat(out, start, len); + str_len += len; + } + } + return str_len; +} + +// The function will NOT free src. +// You need to free the src and return value yourself! +uint32_t* utf8_to_utf32(char* src) { + // Convert UTF-8 to UTF-32 for generating bitmap. + size_t len_src, len_dst; + + len_src = strlen(src); + len_dst = (len_src + 2) * 4; // one for FEFF and one for \0 + + char* string_utf32 = (char *)calloc(len_dst, 1); + size_t inbufbytesleft = len_src; + size_t outbufbytesleft = len_dst; + char* inbuf = src; + char* outbuf = string_utf32; + + iconv_t cd = iconv_open("UTF-32", "UTF-8"); + int result = iconv(cd, &inbuf, &inbufbytesleft, &outbuf, &outbufbytesleft); + if (result == -1) mprint("iconv failed to convert UTF-8 to UTF-32. errno is %d\n", errno); + iconv_close(cd); + + return string_utf32; +} + +// string needs to be in UTF-8 encoding. +// This function will take care of encoding. +int spupng_write_string(struct spupng_t *sp, char *string, LLONG start_time, LLONG end_time, + struct encoder_ctx *context) +{ + LLONG ms_start = start_time + context->subs_delay; + if (ms_start < 0) + { + dbg_print(CCX_DMT_VERBOSE, "Negative start\n"); + return 0; + } + + LLONG ms_end = end_time + context->subs_delay; + + sprintf(sp->pngfile, "%s/sub%04d.png", sp->dirname, sp->fileIndex++); + if ((sp->fppng = fopen(sp->pngfile, "wb")) == NULL) + { + fatal(CCX_COMMON_EXIT_FILE_CREATION_FAILED, "Cannot open %s: %s\n", + sp->pngfile, strerror(errno)); + } + + uint32_t* string_utf32 = utf8_to_utf32(string); + if (!spupng_export_string2png(sp, string_utf32, sp->fppng)) + { + free(string_utf32); + fatal(CCX_COMMON_EXIT_FILE_CREATION_FAILED, "Cannot write %s: %s\n", + sp->pngfile, strerror(errno)); + } + free(string_utf32); + fclose(sp->fppng); + write_sputag_open(sp, ms_start, ms_end); + write_spucomment(sp, string); + write_sputag_close(sp); + return 1; +} + +int write_cc_subtitle_as_spupng(struct cc_subtitle *sub, struct encoder_ctx *context) +{ + struct spupng_t *sp = (struct spupng_t *) context->out->spupng_data; + if (!sp) + return -1; + + if (sub->type == CC_TEXT) + { + spupng_write_string(sp, sub->data, sub->start_time, sub->end_time, context); + } return 0; } int spupng_write_ccbuffer(struct spupng_t *sp, struct eia608_screen* data, - struct encoder_ctx *context) + struct encoder_ctx *context) { int row; int empty_buf = 1; - char str[256] = ""; - int str_len = 0; + char str[512] = ""; + + // Check if it has negative start. LLONG ms_start = data->start_time + context->subs_delay; if (ms_start < 0) { dbg_print(CCX_DMT_VERBOSE, "Negative start\n"); return 0; } + + // Check if it is blank page. for (row = 0; row < 15; row++) { if (data->row_used[row]) @@ -298,114 +888,19 @@ int spupng_write_ccbuffer(struct spupng_t *sp, struct eia608_screen* data, break; } } + if (empty_buf) { dbg_print(CCX_DMT_VERBOSE, "Blank page\n"); return 0; } - LLONG ms_end = data->end_time; + eia608_to_str(context, data, str); - sprintf(sp->pngfile, "%s/sub%04d.png", sp->dirname, sp->fileIndex++); - if ((sp->fppng = fopen(sp->pngfile, "wb")) == NULL) - { - fatal(CCX_COMMON_EXIT_FILE_CREATION_FAILED, "Cannot open %s: %s\n", - sp->pngfile, strerror(errno)); - } - if (!spupng_export_png(sp, data)) - { - fatal(CCX_COMMON_EXIT_FILE_CREATION_FAILED, "Cannot write %s: %s\n", - sp->pngfile, strerror(errno)); - } - fclose(sp->fppng); - write_sputag_open(sp,ms_start,ms_end); - for (row = 0; row < ROWS; row++) - { - if (data->row_used[row]) - { - int len = get_decoder_line_encoded(context, context->subline, row, data); - // Check for characters that spumux won't parse - // null chars will be changed to space - // pairs of dashes will be changed to underscores - for (unsigned char* ptr = context->subline; ptr < context->subline+len; ptr++) - { - switch (*ptr) - { - case 0: - *ptr = ' '; - break; - case '-': - if (*(ptr+1) == '-') - { - *ptr++ = '_'; - *ptr = '_'; - } - break; - } - } - if (str_len + len + 3 > 256 ) - { - mprint("WARNING: Possible Loss of data\n"); - break; - } - strncat(str, (const char*)context->subline, len); - strncat(str,"\n",3); - str_len = str_len + len + 2; - } - } - - write_spucomment(sp,str); - write_sputag_close(sp); - return 1; + return spupng_write_string(context->out->spupng_data, str, data->start_time, data->end_time, context); } -int spupng_write_string(struct spupng_t *sp, char *string, LLONG start_time, LLONG end_time, - struct encoder_ctx *context) -{ - - char str[256] = ""; - LLONG ms_start = start_time + context->subs_delay; - if (ms_start < 0) - { - dbg_print(CCX_DMT_VERBOSE, "Negative start\n"); - return 0; - } - - - LLONG ms_end = end_time; - - sprintf(sp->pngfile, "%s/sub%04d.png", sp->dirname, sp->fileIndex++); - if ((sp->fppng = fopen(sp->pngfile, "wb")) == NULL) - { - fatal(CCX_COMMON_EXIT_FILE_CREATION_FAILED, "Cannot open %s: %s\n", - sp->pngfile, strerror(errno)); - } - if (!spupng_export_string2png(sp, str)) - { - fatal(CCX_COMMON_EXIT_FILE_CREATION_FAILED, "Cannot write %s: %s\n", - sp->pngfile, strerror(errno)); - } - fclose(sp->fppng); - write_sputag_open(sp,ms_start,ms_end); - write_spucomment(sp,str); - write_sputag_close(sp); - return 1; -} -int write_cc_subtitle_as_spupng(struct cc_subtitle *sub, struct encoder_ctx *context) -{ - struct spupng_t *sp = (struct spupng_t *) context->out->spupng_data; - if (!sp) - return -1; - - if(sub->type == CC_TEXT) - { - spupng_write_string(sp, sub->data, sub->start_time, sub->end_time, context); - } - - return 0; -} - -int write_cc_buffer_as_spupng(struct eia608_screen *data,struct encoder_ctx *context) +int write_cc_buffer_as_spupng(struct eia608_screen *data, struct encoder_ctx *context) { struct spupng_t *sp = (struct spupng_t *) context->out->spupng_data; if (NULL != sp) diff --git a/src/lib_ccx/ccx_encoders_spupng.h b/src/lib_ccx/ccx_encoders_spupng.h deleted file mode 100644 index e19a39bc..00000000 --- a/src/lib_ccx/ccx_encoders_spupng.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef __608_SPUPNG_H__ -#define __608_SPUPNG_H__ - -#include "lib_ccx.h" -#include "spupng_encoder.h" -#include "ccx_encoders_common.h" - -int write_cc_buffer_as_spupng(struct eia608_screen *data,struct encoder_ctx *context); - -#endif /* __608_SPUPNG_H__ */ diff --git a/src/lib_ccx/ccx_encoders_transcript.c b/src/lib_ccx/ccx_encoders_transcript.c index 5f1bf79c..9f469228 100644 --- a/src/lib_ccx/ccx_encoders_transcript.c +++ b/src/lib_ccx/ccx_encoders_transcript.c @@ -1,7 +1,5 @@ #include "ccx_decoders_common.h" #include "ccx_encoders_common.h" -#include "spupng_encoder.h" -#include "ccx_encoders_spupng.h" #include "utility.h" #include "ocr.h" #include "ccx_decoders_608.h" diff --git a/src/lib_ccx/ocr.c b/src/lib_ccx/ocr.c index 0770825e..4c82834a 100644 --- a/src/lib_ccx/ocr.c +++ b/src/lib_ccx/ocr.c @@ -5,7 +5,6 @@ #include "ccx_common_constants.h" #include "allheaders.h" #include -#include "spupng_encoder.h" #include "ccx_encoders_helpers.h" #include "ocr.h" #undef OCR_DEBUG diff --git a/src/lib_ccx/params.c b/src/lib_ccx/params.c index a3818a46..ea3fbbfa 100644 --- a/src/lib_ccx/params.c +++ b/src/lib_ccx/params.c @@ -13,6 +13,14 @@ #include "hardsubx.h" #endif +#ifdef _WIN32 +#define DEFAULT_FONT_PATH "C:\\Windows\\Fonts\\calibri.ttf" +#elif __APPLE__ // MacOS +#define DEFAULT_FONT_PATH "/System/Library/Fonts/Helvetica.ttc" +#else // Assume linux +#define DEFAULT_FONT_PATH "/usr/share/fonts/truetype/noto/NotoSans-Regular.ttf" +#endif + static int inputfile_capacity=0; int process_cap_file (char *filename) @@ -616,8 +624,9 @@ void print_usage (void) mprint (" ISO-639-2 form (like \"fre\" for french) or a language\n"); mprint (" code followed by a dash and a country code for specialities\n"); mprint (" in languages (like \"fre-ca\" for Canadian French).\n"); - mprint (" -nospupngocr When processing DVB don't use the OCR to write the text as"); + mprint (" -nospupngocr When processing DVB don't use the OCR to write the text as\n"); mprint (" comments in the XML file.\n"); + mprint (" -font: Specify the font that is used when generating png files\n"); mprint ("\n"); mprint ("Options that affect how ccextractor reads and writes (buffering):\n"); @@ -2323,6 +2332,13 @@ int parse_parameters (struct ccx_s_options *opt, int argc, char *argv[]) i++; continue; } + + if (strcmp(argv[i], "-font") == 0 && ienc_cfg.render_font = argv[i + 1]; + i++; + continue; + } #ifdef WITH_LIBCURL if (strcmp (argv[i],"-curlposturl")==0 && ienc_cfg.no_type_setting = opt->notypesetting; opt->enc_cfg.subs_delay = opt->subs_delay; opt->enc_cfg.gui_mode_reports = opt->gui_mode_reports; + if(opt->enc_cfg.render_font==NULL) + opt->enc_cfg.render_font = DEFAULT_FONT_PATH; if(opt->output_filename && opt->multiprogram == CCX_FALSE) opt->enc_cfg.output_filename = strdup(opt->output_filename); else diff --git a/src/lib_ccx/spupng_encoder.c b/src/lib_ccx/spupng_encoder.c deleted file mode 100644 index 788b0b58..00000000 --- a/src/lib_ccx/spupng_encoder.c +++ /dev/null @@ -1,599 +0,0 @@ -#include "ccfont2.xbm" // CC font from libzvbi -#include "spupng_encoder.h" -#include "ccx_common_common.h" -#include "ccx_encoders_common.h" -#include -#ifdef ENABLE_OCR -#include "ocr.h" -#undef OCR_DEBUG -#endif - -#define CCPL (ccfont2_width / CCW * ccfont2_height / CCH) - -static int initialized = 0; - -void spupng_init_font() -{ - uint8_t *t, *p; - int i, j; - - /* de-interleave font image (puts all chars in row 0) */ - if (!(t = (uint8_t*)malloc(ccfont2_width * ccfont2_height / 8))) - ccx_common_logging.fatal_ftn(EXIT_NOT_ENOUGH_MEMORY, "spupng_init_font: Memory allocation failed"); - - for (p = t, i = 0; i < CCH; i++) - for (j = 0; j < ccfont2_height; p += ccfont2_width / 8, j += CCH) - memcpy(p, ccfont2_bits + (j + i) * ccfont2_width / 8, - ccfont2_width / 8); - - memcpy(ccfont2_bits, t, ccfont2_width * ccfont2_height / 8); - free(t); -} - -struct spupng_t *spunpg_init(struct ccx_s_write *out) -{ - struct spupng_t *sp = (struct spupng_t *) malloc(sizeof(struct spupng_t)); - if (NULL == sp) - ccx_common_logging.fatal_ftn(EXIT_NOT_ENOUGH_MEMORY, "spunpg_init: Memory allocation failed (sp)"); - - if (!initialized) - { - initialized = 1; - spupng_init_font(); - } - - if ((sp->fpxml = fdopen(out->fh, "w")) == NULL) - { - ccx_common_logging.fatal_ftn(CCX_COMMON_EXIT_FILE_CREATION_FAILED, "Cannot open %s: %s\n", - out->filename, strerror(errno)); - } - sp->dirname = (char *) malloc( - sizeof(char) * (strlen(out->filename) + 3)); - if (NULL == sp->dirname) - ccx_common_logging.fatal_ftn(EXIT_NOT_ENOUGH_MEMORY, "spunpg_init: Memory allocation failed (sp->dirname)"); - - strcpy(sp->dirname, out->filename); - char* p = strrchr(sp->dirname, '.'); - if (NULL == p) - p = sp->dirname + strlen(sp->dirname); - *p = '\0'; - strcat(sp->dirname, ".d"); - if (0 != mkdir(sp->dirname, 0777)) - { - if (errno != EEXIST) - { - ccx_common_logging.fatal_ftn(CCX_COMMON_EXIT_FILE_CREATION_FAILED, "Cannot create %s: %s\n", - sp->dirname, strerror(errno)); - } - // If dirname isn't a directory or if we don't have write permission, - // the first attempt to create a .png file will fail and we'll XXxit. - } - - // enough to append /subNNNN.png - sp->pngfile = (char *) malloc(sizeof(char) * (strlen(sp->dirname) + 13)); - if (NULL == sp->pngfile) - ccx_common_logging.fatal_ftn(EXIT_NOT_ENOUGH_MEMORY, "spunpg_init: Memory allocation failed (sp->pngfile)"); - sp->fileIndex = 0; - sprintf(sp->pngfile, "%s/sub%04d.png", sp->dirname, sp->fileIndex); - - // For NTSC closed captions and 720x480 DVD subtitle resolution: - // Each character is 16x26. - // 15 rows by 32 columns, plus 2 columns for left & right padding - // So each .png image will be 16*34 wide and 26*15 high, or 544x390 - // To center image in 720x480 DVD screen, offset image by 88 and 45 - // Need to keep yOffset even to prevent flicker on interlaced displays - // Would need to do something different for PAL format and teletext. - sp->xOffset = 88; - sp->yOffset = 46; - - return sp; -} -void spunpg_free(struct spupng_t *sp) -{ - free(sp->dirname); - free(sp->pngfile); - free(sp); -} - -void spupng_write_header(struct spupng_t *sp,int multiple_files,char *first_input_file) -{ - fprintf(sp->fpxml, "\n\n"); - if (multiple_files) - fprintf(sp->fpxml, "\n", first_input_file); -} - -void spupng_write_footer(struct spupng_t *sp) -{ - fprintf(sp->fpxml, "\n\n"); - fflush(sp->fpxml); - fclose(sp->fpxml); -} - -void write_spumux_header(struct encoder_ctx *ctx, struct ccx_s_write *out) -{ - if (0 == out->spupng_data) - out->spupng_data = spunpg_init(out); - - spupng_write_header((struct spupng_t*)out->spupng_data, ctx->multiple_files, ctx->first_input_file); - - if (ctx->write_format == CCX_OF_RAW) { // WARN: Memory leak with this flag, free by hand. Maybe bug. - spupng_write_footer(out->spupng_data); - spunpg_free(out->spupng_data); - } -} - -void write_spumux_footer(struct ccx_s_write *out) -{ - if (0 != out->spupng_data) - { - struct spupng_t *sp = (struct spupng_t *) out->spupng_data; - - spupng_write_footer(sp); - spunpg_free(sp); - - out->spupng_data = 0; - out->fh = -1; - } -} - -/** - * @internal - * @param p Plane of @a canvas_type char, short, int. - * @param i Index. - * - * @return - * Pixel @a i in plane @a p. - */ -#define peek(p, i) \ -((canvas_type == sizeof(uint8_t)) ? ((uint8_t *)(p))[i] : \ - ((canvas_type == sizeof(uint16_t)) ? ((uint16_t *)(p))[i] : \ - ((uint32_t *)(p))[i])) - -/** - * @internal - * @param p Plane of @a canvas_type char, short, int. - * @param i Index. - * @param v Value. - * - * Set pixel @a i in plane @a p to value @a v. - */ -#define poke(p, i, v) \ -((canvas_type == sizeof(uint8_t)) ? (((uint8_t *)(p))[i] = (v)) : \ - ((canvas_type == sizeof(uint16_t)) ? (((uint16_t *)(p))[i] = (v)) : \ - (((uint32_t *)(p))[i] = (v)))) - -/** - * @internal - * @param c Unicode. - * @param italic @c TRUE to switch to slanted character set. - * - * Translate Unicode character to glyph number in ccfont2 image. - * - * @return - * Glyph number. - */ -static unsigned int unicode_ccfont2(unsigned int c, int italic) -{ - static const unsigned short specials[] = { - 0x00E1, 0x00E9, - 0x00ED, 0x00F3, 0x00FA, 0x00E7, 0x00F7, 0x00D1, 0x00F1, 0x25A0, - 0x00AE, 0x00B0, 0x00BD, 0x00BF, 0x2122, 0x00A2, 0x00A3, 0x266A, - 0x00E0, 0x0020, 0x00E8, 0x00E2, 0x00EA, 0x00EE, 0x00F4, 0x00FB }; - unsigned int i; - - if (c < 0x0020) - c = 15; /* invalid */ - else if (c < 0x0080) - /*c = c */; - else - { - for (i = 0; i < sizeof(specials) / sizeof(specials[0]); i++) - { - if (specials[i] == c) - { - c = i + 6; - goto slant; - } - } - c = 15; /* invalid */ - } - -slant: - if (italic) - c += 4 * 32; - - return c; -} - -/** - * @internal - * @param canvas_type sizeof(char, short, int). - * @param canvas Pointer to image plane where the character is to be drawn. - * @param rowstride @a canvas byte distance from line to line. - * @param color Color value of @a canvas_type. - * @param cw Character width in pixels. - * @param ch Character height in pixels. - * - * Draw blank character. -static void -draw_blank(int canvas_type, uint8_t *canvas, unsigned int rowstride, - unsigned int color, int cw, int ch) -{ - int x, y; - - for (y = 0; y < ch; y++) { - for (x = 0; x < cw; x++) - poke(canvas, x, color); - - canvas += rowstride; - } -} -*/ - -/** - * @internal - * @param canvas_type sizeof(char, short, int). - * @param canvas Pointer to image plane where the character is to be drawn. - * @param rowstride @a canvas byte distance from line to line. - * @param pen Pointer to color palette of @a canvas_type (index 0 background - * pixels, index 1 foreground pixels). - * @param font Pointer to font image with width @a cpl x @a cw pixels, height - * @a ch pixels, depth one bit, bit '1' is foreground. - * @param cpl Chars per line (number of characters in @a font image). - * @param cw Character cell width in pixels. - * @param ch Character cell height in pixels. - * @param glyph Glyph number in font image, 0 ... @a cpl - 1. - * @param underline Bit mask of character rows. For each bit - * 1 << (n = 0 ... @a ch - 1) set all of character row n to - * foreground color. - * @param size Size of character, either NORMAL, DOUBLE_WIDTH (draws left - * and right half), DOUBLE_HEIGHT (draws upper half only), - * DOUBLE_SIZE (left and right upper half), DOUBLE_HEIGHT2 - * (lower half), DOUBLE_SIZE2 (left and right lower half). - * - * Draw one character (function template - define a static version with - * constant @a canvas_type, @a font, @a cpl, @a cw, @a ch). - */ -static void draw_char(int canvas_type, uint8_t *canvas, int rowstride, - uint8_t *pen, uint8_t *font, int cpl, int cw, int ch, - int glyph, unsigned int underline) -{ - uint8_t *src; - int shift, x, y; - - assert(cw >= 8 && cw <= 16); - assert(ch >= 1 && ch <= 31); - - x = glyph * cw; - shift = x & 7; - src = font + (x >> 3); - - for (y = 0; y < ch; underline >>= 1, y++) - { - int bits = ~0; - - if (!(underline & 1)) - { -#ifdef __i386__ - bits = (*((uint16_t *) src) >> shift); -#else - /* unaligned/little endian */ - bits = ((src[1] * 256 + src[0]) >> shift); -#endif - } - - for (x = 0; x < cw; bits >>= 1, x++) - poke(canvas, x, peek(pen, bits & 1)); - - canvas += rowstride; - - src += cpl * cw / 8; - } -} - -/* - * PNG and XPM drawing functions (palette-based) - */ -void draw_char_indexed(uint8_t * canvas, int rowstride, uint8_t * pen, - int unicode, int italic, int underline) -{ - draw_char(sizeof(*canvas), canvas, rowstride, - pen, (uint8_t *) ccfont2_bits, CCPL, CCW, CCH, - unicode_ccfont2(unicode, italic), - underline * (3 << 24) /* cell row 24, 25 */); -} - -void write_sputag_open (struct spupng_t *sp,LLONG ms_start,LLONG ms_end) -{ - fprintf(sp->fpxml, "fpxml, " end=\"%.3f\"", ((double)ms_end) / 1000); - fprintf(sp->fpxml, " image=\"%s\"", sp->pngfile); - fprintf(sp->fpxml, " xoffset=\"%d\"", sp->xOffset); - fprintf(sp->fpxml, " yoffset=\"%d\"", sp->yOffset); - fprintf(sp->fpxml, ">\n"); -} - -void write_sputag_close(struct spupng_t *sp) -{ - fprintf(sp->fpxml, "\n"); -} - -void write_spucomment(struct spupng_t *sp,const char *str) -{ - fprintf(sp->fpxml, "\n"); -} - -char* get_spupng_filename(void *ctx) -{ - struct spupng_t *sp = (struct spupng_t *)ctx; - return sp->pngfile; -} -void inc_spupng_fileindex(void *ctx) -{ - struct spupng_t *sp = (struct spupng_t *)ctx; - sp->fileIndex++; - sprintf(sp->pngfile, "%s/sub%04d.png", sp->dirname, sp->fileIndex); -} -void set_spupng_offset(void *ctx,int x,int y) -{ - struct spupng_t *sp = (struct spupng_t *)ctx; - sp->xOffset = x; - sp->yOffset = y; -} -int save_spupng(const char *filename, uint8_t *bitmap, int w, int h, - png_color *palette, png_byte *alpha, int nb_color) -{ - FILE *f = NULL; - png_structp png_ptr = NULL; - png_infop info_ptr = NULL; - png_bytep* row_pointer = NULL; - int i, j, ret = 0; - int k = 0; - if(!h) - h = 1; - if(!w) - w = 1; - - - f = fopen(filename, "wb"); - if (!f) - { - ccx_common_logging.log_ftn("DVB:unable to open %s in write mode \n", filename); - ret = -1; - goto end; - } - - png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL,NULL); - if (!png_ptr) - { - ccx_common_logging.log_ftn("DVB:unable to create png write struct\n"); - goto end; - } - if (!(info_ptr = png_create_info_struct(png_ptr))) - { - ccx_common_logging.log_ftn("DVB:unable to create png info struct\n"); - ret = -1; - goto end; - } - - row_pointer = (png_bytep*) malloc(sizeof(png_bytep) * h); - if (!row_pointer) - { - ccx_common_logging.log_ftn("DVB: unable to allocate row_pointer\n"); - ret = -1; - goto end; - } - memset(row_pointer, 0, sizeof(png_bytep) * h); - png_init_io(png_ptr, f); - - png_set_IHDR(png_ptr, info_ptr, w, h, - /* bit_depth */8, - PNG_COLOR_TYPE_PALETTE, - PNG_INTERLACE_NONE, - PNG_COMPRESSION_TYPE_DEFAULT, - PNG_FILTER_TYPE_DEFAULT); - - png_set_PLTE(png_ptr, info_ptr, palette, nb_color); - png_set_tRNS(png_ptr, info_ptr, alpha, nb_color, NULL); - - for (i = 0; i < h; i++) - { - row_pointer[i] = (png_byte*) malloc( - png_get_rowbytes(png_ptr, info_ptr)); - if (row_pointer[i] == NULL) - break; - } - if (i != h) - { - ccx_common_logging.log_ftn("DVB: unable to allocate row_pointer internals\n"); - ret = -1; - goto end; - } - png_write_info(png_ptr, info_ptr); - for (i = 0; i < h; i++) - { - for (j = 0; j < png_get_rowbytes(png_ptr, info_ptr); j++) - { - if(bitmap) - k = bitmap[i * w + (j)]; - else - k = 0; - row_pointer[i][j] = k; - } - } - - png_write_image(png_ptr, row_pointer); - - png_write_end(png_ptr, info_ptr); - end: if (row_pointer) - { - for (i = 0; i < h; i++) - freep(&row_pointer[i]); - freep(&row_pointer); - } - png_destroy_write_struct(&png_ptr, &info_ptr); - if (f) - fclose(f); - return ret; - -} -/** - * alpha value 255 means completely opaque - * alpha value 0 means completely transparent - * r g b all 0 means black - * r g b all 255 means white - */ -int mapclut_paletee(png_color *palette, png_byte *alpha, uint32_t *clut, - uint8_t depth) -{ - for (int i = 0; i < depth; i++) - { - palette[i].red = ((clut[i] >> 16) & 0xff); - palette[i].green = ((clut[i] >> 8) & 0xff); - palette[i].blue = (clut[i] & 0xff); - alpha[i] = ((clut[i] >> 24) & 0xff); - } -#if OCR_DEBUG - ccx_common_logging.log_ftn("Colors present in original Image\n"); - for (int i = 0; i < depth; i++) - { - ccx_common_logging.log_ftn("%02d)r %03d g %03d b %03d a %03d\n", - i, palette[i].red, palette[i].green, palette[i].blue, alpha[i]); - } -#endif - return 0; -} - -int write_cc_bitmap_as_spupng(struct cc_subtitle *sub, struct encoder_ctx *context) -{ - struct spupng_t *sp = (struct spupng_t *)context->out->spupng_data; - int x_pos, y_pos, width, height, i; - int x, y, y_off, x_off, ret=0; - uint8_t *pbuf; - char *filename; - struct cc_bitmap* rect; - png_color *palette = NULL; - png_byte *alpha = NULL; - int wrote_opentag = 1; - - x_pos = -1; - y_pos = -1; - width = 0; - height = 0; - - if (sub->data == NULL) - return 0; - - write_sputag_open(sp, sub->start_time, sub->end_time - 1); - - if(sub->nb_data == 0 && (sub->flags & SUB_EOD_MARKER)) - { - context->prev_start = -1; - if (wrote_opentag) - write_sputag_close(sp); - return 0; - } - rect = sub->data; - for(i = 0;i < sub->nb_data;i++) - { - if(x_pos == -1) - { - x_pos = rect[i].x; - y_pos = rect[i].y; - width = rect[i].w; - height = rect[i].h; - } - else - { - if(x_pos > rect[i].x) - { - width += (x_pos - rect[i].x); - x_pos = rect[i].x; - } - - if (rect[i].y < y_pos) - { - height += (y_pos - rect[i].y); - y_pos = rect[i].y; - } - - if (rect[i].x + rect[i].w > x_pos + width) - { - width = rect[i].x + rect[i].w - x_pos; - } - - if (rect[i].y + rect[i].h > y_pos + height) - { - height = rect[i].y + rect[i].h - y_pos; - } - - } - } - inc_spupng_fileindex(sp); - filename = get_spupng_filename(sp); - set_spupng_offset(sp, x_pos, y_pos); - if ( sub->flags & SUB_EOD_MARKER ) - context->prev_start = sub->start_time; - pbuf = (uint8_t*) malloc(width * height); - memset(pbuf, 0x0, width * height); - - for(i = 0;i < sub->nb_data;i++) - { - x_off = rect[i].x - x_pos; - y_off = rect[i].y - y_pos; - for (y = 0; y < rect[i].h; y++) - { - for (x = 0; x < rect[i].w; x++) - pbuf[((y + y_off) * width) + x_off + x] = rect[i].data[0][y * rect[i].w + x]; - - } - } - palette = (png_color*) malloc(rect[0].nb_colors * sizeof(png_color)); - if(!palette) - { - ret = -1; - goto end; - } - alpha = (png_byte*) malloc(rect[0].nb_colors * sizeof(png_byte)); - if(!alpha) - { - ret = -1; - goto end; - } - - /* TODO do rectangle wise, one color table should not be used for all rectangles */ - mapclut_paletee(palette, alpha, (uint32_t *)rect[0].data[1],rect[0].nb_colors); -#ifdef ENABLE_OCR - if (!context->nospupngocr) - { - char *str; - str = paraof_ocrtext(sub, context->encoded_crlf, context->encoded_crlf_length); - if (str) - { - write_spucomment(sp, str); - freep(&str); - } - } -#endif - save_spupng(filename,pbuf,width, height, palette, alpha,rect[0].nb_colors); - freep(&pbuf); - - -end: - if (wrote_opentag) - write_sputag_close(sp); - - for(i = 0, rect = sub->data; i < sub->nb_data; i++, rect++) - { - freep(rect->data); - freep(rect->data+1); - } - sub->nb_data = 0; - freep(&sub->data); - freep(&palette); - freep(&alpha); - freep(&pbuf); - return ret; -} diff --git a/src/lib_ccx/spupng_encoder.h b/src/lib_ccx/spupng_encoder.h deleted file mode 100644 index e25d33d0..00000000 --- a/src/lib_ccx/spupng_encoder.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef _SPUPNG_ENCODER_H -#define _SPUPNG_ENCODER_H - -#include "ccx_common_platform.h" -#include "ccx_encoders_structs.h" -#include "png.h" -#include "ccx_encoders_common.h" - -// CC page dimensions -#define ROWS 15 -#define COLUMNS 32 -/* Closed Caption character cell dimensions */ -#define CCW 16 -#define CCH 26 /* line doubled */ - -struct spupng_t -{ - FILE* fpxml; - FILE* fppng; - char* dirname; - char* pngfile; - int fileIndex; - int xOffset; - int yOffset; -}; - -void write_spumux_header(struct encoder_ctx *ctx, struct ccx_s_write *out); -void write_spumux_footer(struct ccx_s_write *out); -void draw_char_indexed(uint8_t * canvas, int rowstride, uint8_t * pen, - int unicode, int italic, int underline); -void write_sputag_open(struct spupng_t *sp,LLONG ms_start,LLONG ms_end); -void write_sputag_close(struct spupng_t *sp); -void write_spucomment(struct spupng_t *sp,const char *str); -char* get_spupng_filename(void *ctx); -void inc_spupng_fileindex(void *ctx); -void set_spupng_offset(void *ctx,int x,int y); -int mapclut_paletee(png_color *palette, png_byte *alpha, uint32_t *clut, - uint8_t depth); -#endif diff --git a/windows/ccextractor.vcxproj b/windows/ccextractor.vcxproj index 539448fe..15672997 100644 --- a/windows/ccextractor.vcxproj +++ b/windows/ccextractor.vcxproj @@ -37,6 +37,7 @@ + @@ -75,7 +76,6 @@ - @@ -93,11 +93,9 @@ - - @@ -127,10 +125,18 @@ + + + + + + + + @@ -222,7 +228,6 @@ - @@ -254,7 +259,6 @@ - @@ -279,6 +283,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -403,8 +444,8 @@ Disabled - ..\src\win_spec_incld;..\src\lib_ccx;..\src\lib_hash;..\src\zvbi;..\src\protobuf-c;..\src\gpacmp4;..\src\win_iconv;..\src\zlib;..\src\libpng;..\src;libs\include;%(AdditionalIncludeDirectories) - WIN32;_DEBUG;_CONSOLE;_FILE_OFFSET_BITS=64;%(PreprocessorDefinitions) + ..\src\freetype\include;..\src\win_spec_incld;..\src\lib_ccx;..\src\lib_hash;..\src\zvbi;..\src\protobuf-c;..\src\gpacmp4;..\src\win_iconv;..\src\zlib;..\src\libpng;..\src;libs\include;%(AdditionalIncludeDirectories) + WIN32;FT2_BUILD_LIBRARY;_DEBUG;_CONSOLE;_FILE_OFFSET_BITS=64;%(PreprocessorDefinitions) true EnableFastChecks MultiThreadedDebug @@ -443,7 +484,7 @@ Disabled - ..\src\win_spec_incld;..\src\lib_ccx;..\src\lib_hash;..\src\zvbi;..\src\protobuf-c;..\src\gpacmp4;..\src\win_iconv;..\src\zlib;..\src\libpng;..\src;libs\include;%(AdditionalIncludeDirectories) + ..\src\freetype\include;..\src\win_spec_incld;..\src\lib_ccx;..\src\lib_hash;..\src\zvbi;..\src\protobuf-c;..\src\gpacmp4;..\src\win_iconv;..\src\zlib;..\src\libpng;..\src;libs\include;%(AdditionalIncludeDirectories) SEGMENT_BY_FILE_TIME;ENABLE_HARDSUBX;ENABLE_OCR;WIN32;_DEBUG;_CONSOLE;_FILE_OFFSET_BITS=64;%(PreprocessorDefinitions) false EnableFastChecks @@ -503,7 +544,7 @@ xcopy /y "$(ProjectDir)libs\lib\libtesseract304d.dll" "$(ProjectDir)$(OutDir)" MaxSpeed - ..\src\win_spec_incld;..\src\lib_ccx;..\src\lib_hash;..\src\zvbi;..\src\protobuf-c;..\src\gpacmp4;..\src\win_iconv;..\src\libpng;..\src\zlib;..\src;libs\include;%(AdditionalIncludeDirectories) + ..\src\freetype\include;..\src\win_spec_incld;..\src\lib_ccx;..\src\lib_hash;..\src\zvbi;..\src\protobuf-c;..\src\gpacmp4;..\src\win_iconv;..\src\libpng;..\src\zlib;..\src;libs\include;%(AdditionalIncludeDirectories) ENABLE_HARDSUBX;VERSION_FILE_PRESENT;ENABLE_OCR;WIN32;NDEBUG;_CONSOLE;_FILE_OFFSET_BITS=64;%(PreprocessorDefinitions) MultiThreaded NotUsing @@ -562,7 +603,7 @@ xcopy /y "$(ProjectDir)libs\lib\libtesseract304d.dll" "$(ProjectDir)$(OutDir)" - ..\src\win_spec_incld;..\src\lib_ccx;..\src\lib_hash;..\src\zvbi;..\src\protobuf-c;..\src\gpacmp4;..\src\win_iconv;..\src\zlib;..\src\libpng;..\src;libs\include;%(AdditionalIncludeDirectories) + ..\src\freetype\include;..\src\win_spec_incld;..\src\lib_ccx;..\src\lib_hash;..\src\zvbi;..\src\protobuf-c;..\src\gpacmp4;..\src\win_iconv;..\src\zlib;..\src\libpng;..\src;libs\include;%(AdditionalIncludeDirectories) VERSION_FILE_PRESENT;WIN32;NDEBUG;_CONSOLE;_FILE_OFFSET_BITS=64;%(PreprocessorDefinitions) MultiThreaded diff --git a/windows/ccextractor.vcxproj.filters b/windows/ccextractor.vcxproj.filters index dede568b..64945dd2 100644 --- a/windows/ccextractor.vcxproj.filters +++ b/windows/ccextractor.vcxproj.filters @@ -31,9 +31,6 @@ {e76a99a9-8a06-4ffb-afa1-f87c057f8448} - - {5af060a0-c719-4d1b-913f-71c4452fbe10} - {955fdac2-43c6-4968-8fce-7d40bad9c712} @@ -88,6 +85,15 @@ {489d2c0b-43e8-4d51-8304-f4e59ee8d253} + + {c08646ce-ae7b-4747-a1e9-9fad759d9ad2} + + + {2c6ca4e0-5f31-46b1-8714-93fb2c28c174} + + + {5af060a0-c719-4d1b-913f-71c4452fbe10} + @@ -166,28 +172,25 @@ Header Files\ccx_common - Header Files\ccx_decoders + Header Files\lib_ccx\ccx_decoders - Header Files\ccx_decoders + Header Files\lib_ccx\ccx_decoders - Header Files\ccx_decoders + Header Files\lib_ccx\ccx_decoders - Header Files\ccx_decoders + Header Files\lib_ccx\ccx_decoders - Header Files\ccx_decoders + Header Files\lib_ccx\ccx_decoders - Header Files\ccx_decoders + Header Files\lib_ccx\ccx_decoders - Header Files\ccx_decoders - - - Header Files\lib_ccx\ccx_encoders + Header Files\lib_ccx\ccx_decoders Header Files\lib_ccx\ccx_encoders @@ -195,20 +198,14 @@ Header Files\lib_ccx\ccx_encoders - - Header Files\lib_ccx\ccx_encoders - - - Header Files\lib_ccx\ccx_encoders - - Header Files\ccx_decoders + Header Files\lib_ccx\ccx_decoders - Header Files\ccx_decoders + Header Files\lib_ccx\ccx_decoders - Header Files\ccx_decoders + Header Files\lib_ccx\ccx_decoders Header Files @@ -366,6 +363,27 @@ Header Files + + Header Files\freetype + + + Header Files\freetype + + + Header Files\freetype + + + Header Files\freetype + + + Header Files\freetype + + + Header Files\freetype + + + Header Files\lib_ccx\ccx_encoders + @@ -476,9 +494,6 @@ Source Files\ccx_encoders - - Source Files\ccx_encoders - Source Files\ccx_common @@ -506,9 +521,6 @@ Source Files\ccx_encoders - - Source Files\ccx_encoders - Source Files\ccx_encoders @@ -827,6 +839,126 @@ Source Files\ccx_encoders + + Source Files + + + Source Files\freetype + + + Source Files\freetype + + + Source Files\freetype + + + Source Files\freetype + + + Source Files\freetype + + + Source Files\freetype + + + Source Files\freetype + + + Source Files\freetype + + + Source Files\freetype + + + Source Files\freetype + + + Source Files\freetype + + + Source Files\freetype + + + Source Files\freetype + + + Source Files\freetype + + + Source Files\freetype + + + Source Files\freetype + + + Source Files\freetype + + + Source Files\freetype + + + Source Files\freetype + + + Source Files\freetype + + + Source Files\freetype + + + Source Files\freetype + + + Source Files\freetype + + + Source Files\freetype + + + Source Files\freetype + + + Source Files\freetype + + + Source Files\freetype + + + Source Files\freetype + + + Source Files\freetype + + + Source Files\freetype + + + Source Files\freetype + + + Source Files\freetype + + + Source Files\freetype + + + Source Files\freetype + + + Source Files\freetype + + + Source Files\freetype + + + Source Files\freetype + + + Source Files\freetype + + + Source Files\ccx_encoders +