aboutsummaryrefslogtreecommitdiffstats
path: root/woff.c
diff options
context:
space:
mode:
authorLibravatarLarge Libravatar Bram Stein <steinadobecom>2014-11-06 16:22:16 +0100
committerLibravatarLarge Libravatar Bram Stein <steinadobecom>2014-11-06 16:22:16 +0100
commite67716a2725037220a1d1226e12ff6212f1e5031 (patch)
tree97f71a6b06acade510d43491caf6389e5fafbc22 /woff.c
parent64833aa89615b59b25f887443dfd344f24bbe3dc (diff)
downloadsfnt2woff-zopfli-e67716a2725037220a1d1226e12ff6212f1e5031.tar.gz
sfnt2woff-zopfli-e67716a2725037220a1d1226e12ff6212f1e5031.tar.bz2
sfnt2woff-zopfli-e67716a2725037220a1d1226e12ff6212f1e5031.tar.lz
sfnt2woff-zopfli-e67716a2725037220a1d1226e12ff6212f1e5031.zip

Add Zopfli files.

Diffstat (limited to 'woff.c')
-rw-r--r--woff.c32
1 files changed, 22 insertions, 10 deletions
diff --git a/woff.c b/woff.c
index 4dcaadb..0ea8e17 100644
--- a/woff.c
+++ b/woff.c
@@ -41,6 +41,7 @@
#include <stdlib.h>
#include <string.h>
#include <zlib.h>
+#include "zlib_container.h"
#ifdef WOFF_MOZILLA_CLIENT /* define this when building as part of Gecko */
# include "prmem.h"
@@ -251,6 +252,9 @@ woffEncode(const uint8_t * sfntData, uint32_t sfntLen,
*/
#define WOFFDIR ((woffDirEntry *) (woffData + sizeof(woffHeader)))
+ ZopfliOptions options;
+ ZopfliInitOptions(&options);
+
for (order = 0; order < numTables; ++order) {
uLong sourceLen, destLen;
uint32_t sourceOffset;
@@ -277,20 +281,26 @@ woffEncode(const uint8_t * sfntData, uint32_t sfntLen,
if (sourceLen > sfntLen || sourceOffset > sfntLen - sourceLen) {
FAIL(eWOFF_invalid);
}
- destLen = LONGALIGN(compressBound(sourceLen));
- woffData = (uint8_t *) realloc(woffData, tableOffset + destLen);
- if (!woffData) {
- FAIL(eWOFF_out_of_memory);
- }
+ //destLen = LONGALIGN(compressBound(sourceLen));
+ //woffData = (uint8_t *) realloc(woffData, tableOffset + destLen);
+ //if (!woffData) {
+ // FAIL(eWOFF_out_of_memory);
+ //}
+
+ uint8_t* dest = 0;
+
+ ZopfliZlibCompress(&options, (const uint8_t *) (sfntData + sourceOffset), sourceLen, &dest, &destLen);
/* do the compression directly into the WOFF data block */
- if (compress2((Bytef *) (woffData + tableOffset), &destLen,
- (const Bytef *) (sfntData + sourceOffset),
- sourceLen, 9) != Z_OK) {
- FAIL(eWOFF_compression_failure);
- }
+ //if (compress2((Bytef *) (woffData + tableOffset), &destLen,
+ // (const Bytef *) (sfntData + sourceOffset),
+ // sourceLen, 9) != Z_OK) {
+ // FAIL(eWOFF_compression_failure);
+ //}
if (destLen < sourceLen) {
/* compressed table was smaller */
+ woffData = (uint8_t *) realloc(woffData, tableOffset + LONGALIGN(destLen));
+ memcpy(woffData + tableOffset, dest, destLen);
tableOffset += destLen;
WOFFDIR[newIndex].compLen = READ32BE(destLen);
} else {
@@ -310,6 +320,8 @@ woffEncode(const uint8_t * sfntData, uint32_t sfntLen,
WOFFDIR[newIndex].compLen = WOFFDIR[newIndex].origLen;
}
+ free(dest);
+
/* we always realloc woffData to a long-aligned size, so this is safe */
while ((tableOffset & 3) != 0) {
woffData[tableOffset++] = 0;