Support for FlateDecode for image in PDF context, if the zlib library is available

This commit is contained in:
Airy ANDRE 2012-01-20 15:20:01 -08:00
parent 711a189e56
commit bda30de70e
3 changed files with 132 additions and 13 deletions

View File

@ -9523,7 +9523,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "#!/bin/sh\nmkdir -p $DERIVED_FILE_DIR\necho \"\" > $DERIVED_FILE_DIR/O2Defines_FreeType.h\n\nif [ -d /Developer/Cocotron/1.0/Windows/i386/freetype-2.3.5 ]; then\n\techo \"FreeType 2.3.5 present.\"\n\techo \"#define FREETYPE_PRESENT 1\" >> $DERIVED_FILE_DIR/O2Defines_FreeType.h\nelse\n# Create empty libfreetype for link phase\n echo \"FreeType 2.3.5 not found\"\n touch $DERIVED_FILE_DIR/libfreetype.c\n /Developer/Cocotron/1.0/Windows/i386/gcc-4.3.1/bin/i386-mingw32msvc-gcc $DERIVED_FILE_DIR/libfreetype.c -c -o $DERIVED_FILE_DIR/libfreetype.o\n /Developer/Cocotron/1.0/Windows/i386/gcc-4.3.1/bin/i386-mingw32msvc-ar cr $DERIVED_FILE_DIR/libfreetype.a $DERIVED_FILE_DIR/libfreetype.o\nfi\n\necho \"\" > $DERIVED_FILE_DIR/O2Defines_libjpeg.h\nif [ -d /Developer/Cocotron/1.0/Windows/i386/libjpeg ]; then\n\techo \"libjpeg present.\"\n\techo \"#define LIBJPEG_PRESENT 1\" >> $DERIVED_FILE_DIR/O2Defines_libjpeg.h\nelse\n# Create empty libfreetype for link phase\n echo \"libjpeg not found\"\n touch $DERIVED_FILE_DIR/libjpeg.c\n /Developer/Cocotron/1.0/Windows/i386/gcc-4.3.1/bin/i386-mingw32msvc-gcc $DERIVED_FILE_DIR/libjpeg.c -c -o $DERIVED_FILE_DIR/libjpeg.o\n /Developer/Cocotron/1.0/Windows/i386/gcc-4.3.1/bin/i386-mingw32msvc-ar cr $DERIVED_FILE_DIR/libjpeg.a $DERIVED_FILE_DIR/libjpeg.o\nfi\n\n";
shellScript = "#!/bin/sh\nmkdir -p $DERIVED_FILE_DIR\necho \"\" > $DERIVED_FILE_DIR/O2Defines_FreeType.h\n\nif [ -d /Developer/Cocotron/1.0/Windows/i386/freetype-2.3.5 ]; then\n\techo \"FreeType 2.3.5 present.\"\n\techo \"#define FREETYPE_PRESENT 1\" >> $DERIVED_FILE_DIR/O2Defines_FreeType.h\nelse\n# Create empty libfreetype for link phase\n echo \"FreeType 2.3.5 not found\"\n touch $DERIVED_FILE_DIR/libfreetype.c\n /Developer/Cocotron/1.0/Windows/i386/gcc-4.3.1/bin/i386-mingw32msvc-gcc $DERIVED_FILE_DIR/libfreetype.c -c -o $DERIVED_FILE_DIR/libfreetype.o\n /Developer/Cocotron/1.0/Windows/i386/gcc-4.3.1/bin/i386-mingw32msvc-ar cr $DERIVED_FILE_DIR/libfreetype.a $DERIVED_FILE_DIR/libfreetype.o\nfi\n\necho \"\" > $DERIVED_FILE_DIR/O2Defines_libjpeg.h\nif [ -d /Developer/Cocotron/1.0/Windows/i386/libjpeg ]; then\n\techo \"libjpeg present.\"\n\techo \"#define LIBJPEG_PRESENT 1\" >> $DERIVED_FILE_DIR/O2Defines_libjpeg.h\nelse\n# Create empty libfreetype for link phase\n echo \"libjpeg not found\"\n touch $DERIVED_FILE_DIR/libjpeg.c\n /Developer/Cocotron/1.0/Windows/i386/gcc-4.3.1/bin/i386-mingw32msvc-gcc $DERIVED_FILE_DIR/libjpeg.c -c -o $DERIVED_FILE_DIR/libjpeg.o\n /Developer/Cocotron/1.0/Windows/i386/gcc-4.3.1/bin/i386-mingw32msvc-ar cr $DERIVED_FILE_DIR/libjpeg.a $DERIVED_FILE_DIR/libjpeg.o\nfi\n\necho \"\" > $DERIVED_FILE_DIR/O2Defines_zlib.h\nif [ -d /Developer/Cocotron/1.0/Windows/i386/zlib-1.2.5 ]; then\n\techo \"zlib present.\"\n\techo \"#define ZLIB_PRESENT 1\" >> $DERIVED_FILE_DIR/O2Defines_zlib.h\nelse\n# Create empty zlib for link phase\n echo \"zlib not found\"\n touch $DERIVED_FILE_DIR/zlib.c\n /Developer/Cocotron/1.0/Windows/i386/gcc-4.3.1/bin/i386-mingw32msvc-gcc $DERIVED_FILE_DIR/zlib.c -c -o $DERIVED_FILE_DIR/zlib.o\n /Developer/Cocotron/1.0/Windows/i386/gcc-4.3.1/bin/i386-mingw32msvc-ar cr $DERIVED_FILE_DIR/libz.a $DERIVED_FILE_DIR/zlib.o\nfi\n\n";
};
/* End PBXShellScriptBuildPhase section */
@ -11674,7 +11674,11 @@
GCC_UNROLL_LOOPS = NO;
HEADER_SEARCH_PATHS = "$(TARGET_BUILD_DIR)/usr/include";
INFOPLIST_FILE = Info.plist;
LIBRARY_SEARCH_PATHS = /Developer/Cocotron/1.0/Windows/i386/libjpeg/lib;
LIBRARY_SEARCH_PATHS = (
/Developer/Cocotron/1.0/Windows/i386/libjpeg/lib,
"$(LIBRARY_SEARCH_PATHS_QUOTED_FOR_TARGET_1)",
);
LIBRARY_SEARCH_PATHS_QUOTED_FOR_TARGET_1 = "/Developer/Cocotron/1.0/Windows/i386/zlib-1.2.5/lib";
OTHER_CFLAGS = (
"$(OTHER_CFLAGS)",
"-DAPPKIT_INSIDE_BUILD",
@ -11683,6 +11687,7 @@
"-DCGL_INSIDE_BUILD",
);
OTHER_LDFLAGS = (
"-lz",
"-static",
"-ljpeg",
"-shared",
@ -11694,7 +11699,6 @@
"-lopengl32",
"-lcomctl32",
"-lwinmm",
"-Wl,--enable-auto-import",
"-Wl,--export-all-symbols",
"-Wl,--out-implib,$TARGET_BUILD_DIR/AppKit.framework/libAppKit.a",
);
@ -11953,7 +11957,14 @@
GCC_WARN_UNUSED_LABEL = YES;
HEADER_SEARCH_PATHS = "$(TARGET_BUILD_DIR)/usr/include";
INFOPLIST_FILE = Info.plist;
LIBRARY_SEARCH_PATHS = /Developer/Cocotron/1.0/Windows/i386/libjpeg/lib;
LIBRARY_SEARCH_PATHS = (
"/Developer/Cocotron/1.0/Windows/i386/zlib-1.2.5/lib",
/Developer/Cocotron/1.0/Windows/i386/libjpeg/lib,
"$(LIBRARY_SEARCH_PATHS_QUOTED_FOR_TARGET_1)",
"$(LIBRARY_SEARCH_PATHS_QUOTED_1)",
);
LIBRARY_SEARCH_PATHS_QUOTED_1 = "\"$(DEVELOPER_DIR)/Cocotron/1.0/Windows/i386/zlib-1.2.5/lib\"";
LIBRARY_SEARCH_PATHS_QUOTED_FOR_TARGET_1 = "\"$(DEVELOPER_DIR)/Cocotron/1.0/Windows/i386/zlib-1.2.5/lib\"";
OTHER_CFLAGS = (
"$(OTHER_CFLAGS)",
"-DQUARTZCORE_INSIDE_BUILD",

View File

@ -0,0 +1,56 @@
#!/bin/sh
installResources=`pwd`/Resources
scriptResources=$installResources/scripts
productFolder=/Developer/Cocotron/1.0
downloadFolder=$productFolder/Downloads
if [ ""$1"" = "" ];then
targetPlatform="Windows"
else
targetPlatform=$1
fi
if [ ""$2"" = "" ];then
targetArchitecture="i386"
else
targetArchitecture=$2
fi
if [ ""$3"" = "" ];then
gccVersion="4.3.1"
else
gccVersion=$3
fi
BASEDIR=/Developer/Cocotron/1.0/$targetPlatform/$targetArchitecture
BUILD=/tmp/build_zlib
$scriptResources/downloadFilesIfNeeded.sh $downloadFolder http://zlib.net/zlib-1.2.5.tar.bz2
mkdir -p $BUILD
cd $BUILD
tar -xvjf $downloadFolder/zlib-1.2.5.tar.bz2
cd zlib-1.2.5
pwd
GCC=$(echo $BASEDIR/gcc-$gccVersion/bin/*gcc)
RANLIB=$(echo $BASEDIR/gcc-$gccVersion/bin/*ranlib)
AR=$(echo $BASEDIR/gcc-$gccVersion/bin/*ar)
COCOTRON=/Developer/Cocotron/1.0//build/$targetPlatform/$targetArchitecture
INSTALL_PREFIX=/Developer/Cocotron/1.0/Windows/i386/zlib-1.2.5/
BINARY_PATH=$INSTALL_PREFIX/bin
INCLUDE_PATH=$INSTALL_PREFIX/include
LIBRARY_PATH=$INSTALL_PREFIX/lib
make -p BINARY_PATH
make -p LIBRARY_PATH
make -p INCLUDE_PATH
PATH=$COCOTRON/binutils-2.19/binutils:$PATH make -f win32/Makefile.gcc CC=$GCC AR=$AR RANLIB=$RANLIB RCFLAGS="-I /Developer/Cocotron/1.0/PlatformInterfaces/i386-mingw32msvc/include -DGCC_WINDRES" BINARY_PATH=$BINARY_PATH INCLUDE_PATH=$INCLUDE_PATH LIBRARY_PATH=$LIBRARY_PATH SHARED_MODE=1 install

View File

@ -6,6 +6,12 @@
#import <Onyx2D/O2PDFStream.h>
#import <Onyx2D/O2PDFContext.h>
#import "O2Defines_zlib.h"
#if ZLIB_PRESENT
#import <zlib-1.2.5/include/zlib.h>
#endif
@implementation O2Image(PDF)
O2ColorRenderingIntent O2ImageRenderingIntentWithName(const char *name) {
@ -47,6 +53,29 @@ const char *O2ImageNameWithIntent(O2ColorRenderingIntent intent){
O2PDFStream *result=[O2PDFStream pdfStream];
O2PDFDictionary *dictionary=[result dictionary];
#define CHUNK 65536
// Input buffer for image data
uint8_t in[CHUNK + 3]; // CHUNK size + some additional room for rgb
int idx = 0;
#if ZLIB_PRESENT
// allocate deflate state
unsigned have;
z_stream strm;
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
deflateInit(&strm, 9);
// Compressed output buffer
uint8_t out[CHUNK + 3];
#else
// No compression : out buffer = in buffer
uint8_t *out = in;
#endif
const void *bytes = [self directBytes];
[dictionary setNameForKey:"Type" value:"XObject"];
@ -67,10 +96,11 @@ const char *O2ImageNameWithIntent(O2ColorRenderingIntent intent){
/* FIX, generate soft mask for alpha data
[dictionary setObjectForKey:"SMask" value:[softMask encodeReferenceWithContext:context]];
*/
//[dictionary setNameForKey:"Filter" value:"FlateDecode"]; // Zipped
// TODO : we should at least flate encode the data
// And it would be nice if jpg data would stay jpg data (instead of an uncompress stream), as it does
#if ZLIB_PRESENT
[dictionary setNameForKey:"Filter" value:"FlateDecode"];
#endif
// It would be nice if jpg data would stay jpg data (instead of an uncompress stream), as it does
// with Quartz and CGImage
// Export RGB bytes, without the alpha data, in the expected order
@ -112,11 +142,34 @@ const char *O2ImageNameWithIntent(O2ColorRenderingIntent intent){
g = *pixelPtr++;
r = *pixelPtr++;
}
[[result mutableData] appendBytes:&r length: 1];
[[result mutableData] appendBytes:&g length: 1];
[[result mutableData] appendBytes:&b length: 1];
in[idx++] = r;
in[idx++] = g;
in[idx++] = b;
BOOL flush = (i == _height - 1 && j == _width - 1) || (idx > CHUNK);
if (flush) {
#if ZLIB_PRESENT
strm.avail_in = idx;
flush = ((i == _height - 1 && j == _width - 1)) ? Z_FINISH : Z_NO_FLUSH;
strm.next_in = in;
// run deflate() on input until the output buffer is not full
do {
strm.avail_out = idx;
strm.next_out = out;
deflate(&strm, flush);
have = idx - strm.avail_out;
[[result mutableData] appendBytes:out length: have];
} while (strm.avail_out == 0);
#else
[[result mutableData] appendBytes:out length: idx];
#endif
idx = 0;
}
}
}
#if ZLIB_PRESENT
deflateEnd(&strm);
#endif
return [context encodeIndirectPDFObject:result];
}
@ -246,8 +299,7 @@ const char *O2ImageNameWithIntent(O2ColorRenderingIntent intent){
O2DataProviderRelease(provider);
O2ColorSpaceRelease(colorSpace);
return image;
return image;
}
@end