summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Melichev <igor.melichev@artifex.com>2005-10-18 09:05:58 +0000
committerIgor Melichev <igor.melichev@artifex.com>2005-10-18 09:05:58 +0000
commitf1d44feecbd99213ac8702f54d4ec5392df27656 (patch)
tree6f55258de15e198207dc412c9063c8f2b81b376d
parentb22a142d0766ad7d32b9a8b29c4bb9fbba18a63c (diff)
downloadghostpdl-f1d44feecbd99213ac8702f54d4ec5392df27656.tar.gz
Fix (pdfwrite) : Indexed colors were distorsed with encryption.
DETAILS : Bug 688313 "pdfwrite : image colors depend on encryption". The old code applied encryption with a wrong (zero) object id to the palette of the indexed color space. After a viewer decrypts the palette with a right object id, colors appear wrong. 1. Use the PS string encoding instead the hexadecimal string encoding while converting the palette to PDF format (gdevpdfc.c). It provides a correct work of the part 3 below. See also part 4 below. 2. Don't apply encryption when adding the palette to cos object (gdevpdfc.c, devs.mak). The old code was hacky, and new one is based on a general convention. 3. Apply encryption with a right object id to the string which represents the palette when writing the cos object to the output PDF file. This is an implicit consequence of using the PS string encoding in the part 1 due to a general convention about applying encryption when writing cos objects to the output file. 4. Disable writing hexadecimal strings because their encryption is not yet implemented (gdevpdfu.c). The generated PDF may become longer in 1-2 kilobytes per palette due to PS encoding is less effective for palettes. This could be optimized with implelenting an encryption method for hexadecimal encoded strings in pdf_put_encoded_hex_string, and undo the part 1. The method should apply 3 filters : hexadecimal string decode, arc4 encode, hexadecimal string encode, because cos object stores strings in the outer format. Delaying this optimization for better times. EXPECTED DIFFERENCES : None. git-svn-id: http://svn.ghostscript.com/ghostscript/trunk@6156 a1074d23-0009-0410-80fe-cf8c14f379e6
-rw-r--r--gs/src/devs.mak2
-rw-r--r--gs/src/gdevpdfc.c19
-rw-r--r--gs/src/gdevpdfo.c2
-rw-r--r--gs/src/gdevpdfu.c2
4 files changed, 7 insertions, 18 deletions
diff --git a/gs/src/devs.mak b/gs/src/devs.mak
index 686a10c26..1b4c3762c 100644
--- a/gs/src/devs.mak
+++ b/gs/src/devs.mak
@@ -848,7 +848,7 @@ $(GLOBJ)gdevpdfb.$(OBJ) : $(GLSRC)gdevpdfb.c\
$(GLOBJ)gdevpdfc.$(OBJ) : $(GLSRC)gdevpdfc.c $(GXERR) $(math__h) $(memory__h)\
$(gdevpdfc_h) $(gdevpdfg_h) $(gdevpdfo_h) $(gdevpdfx_h)\
$(gscie_h) $(gscindex_h) $(gscspace_h) $(gscdevn_h) $(gscsepr_h) $(gsicc_h)\
- $(sstring_h) $(stream_h) $(strimpl_h) $(gxcspace_h) $(sarc4_h)
+ $(sstring_h) $(stream_h) $(strimpl_h) $(gxcspace_h)
$(GLCC) $(GLO_)gdevpdfc.$(OBJ) $(C_) $(GLSRC)gdevpdfc.c
$(GLOBJ)gdevpdfd.$(OBJ) : $(GLSRC)gdevpdfd.c $(math__h) $(memory__h)\
diff --git a/gs/src/gdevpdfc.c b/gs/src/gdevpdfc.c
index f6d59f629..89ddc7406 100644
--- a/gs/src/gdevpdfc.c
+++ b/gs/src/gdevpdfc.c
@@ -34,7 +34,6 @@
#include "strimpl.h"
#include "sstring.h"
#include "gxcspace.h"
-#include "sarc4.h"
#include <assert.h>
/*
@@ -370,8 +369,8 @@ pdf_indexed_color_space(gx_device_pdf *pdev, cos_value_t *pvalue,
int num_entries = pip->hival + 1;
int num_components = gs_color_space_num_components(base_space);
uint table_size = num_entries * num_components;
- /* Guess at the extra space needed for ASCII85 encoding. */
- uint string_size = 1 + table_size * 2 + table_size / 30 + 2;
+ /* Guess at the extra space needed for PS string encoding. */
+ uint string_size = 2 + table_size * 4;
uint string_used;
byte buf[100]; /* arbitrary */
stream_AXE_state st;
@@ -382,13 +381,7 @@ pdf_indexed_color_space(gx_device_pdf *pdev, cos_value_t *pvalue,
gs_color_space cs_gray;
cos_value_t v;
int code;
- stream_arcfour_state sarc4;
- if (pdev->KeyLength) {
- code = pdf_encrypt_init(pdev, pca->id, &sarc4);
- if (code < 0)
- return code;
- }
/* PDF doesn't support Indexed color spaces with more than 256 entries. */
if (num_entries > 256)
return_error(gs_error_rangecheck);
@@ -414,9 +407,9 @@ pdf_indexed_color_space(gx_device_pdf *pdev, cos_value_t *pvalue,
}
swrite_string(&s, table, string_size);
s_init(&es, mem);
- s_init_state((stream_state *)&st, &s_AXE_template, NULL);
+ s_init_state((stream_state *)&st, &s_PSSE_template, NULL);
s_init_filter(&es, (stream_state *)&st, buf, sizeof(buf), &s);
- sputc(&s, '<');
+ sputc(&s, '(');
if (pcs->params.indexed.use_proc) {
gs_client_color cmin, cmax;
byte *pnext = palette;
@@ -448,7 +441,7 @@ pdf_indexed_color_space(gx_device_pdf *pdev, cos_value_t *pvalue,
if (gs_color_space_get_index(base_space) ==
gs_color_space_index_DeviceRGB
) {
- /* Check for an all-gray palette. */
+ /* Check for an all-gray palette3. */
int i;
for (i = table_size; (i -= 3) >= 0; )
@@ -465,8 +458,6 @@ pdf_indexed_color_space(gx_device_pdf *pdev, cos_value_t *pvalue,
base_space = &cs_gray;
}
}
- if (pdev->KeyLength)
- s_arcfour_process_buffer(&sarc4, palette, table_size);
stream_write(&es, palette, table_size);
gs_free_string(mem, palette, table_size, "pdf_color_space(palette)");
sclose(&es);
diff --git a/gs/src/gdevpdfo.c b/gs/src/gdevpdfo.c
index f34c0105b..b983faa31 100644
--- a/gs/src/gdevpdfo.c
+++ b/gs/src/gdevpdfo.c
@@ -522,7 +522,7 @@ cos_array_write(const cos_object_t *pco, gx_device_pdf *pdev, gs_id object_id)
stream_putc(s, '\n');
for (; pcae->index > last_index; ++last_index)
stream_puts(s, "null\n");
- cos_value_write(&pcae->value, pdev);
+ cos_value_write_spaced(&pcae->value, pdev, false, object_id);
}
DISCARD(cos_array_reorder(pca, first));
stream_puts(s, "]");
diff --git a/gs/src/gdevpdfu.c b/gs/src/gdevpdfu.c
index e1398ece3..6236003a8 100644
--- a/gs/src/gdevpdfu.c
+++ b/gs/src/gdevpdfu.c
@@ -1566,10 +1566,8 @@ pdf_write_value(const gx_device_pdf * pdev, const byte * vstr, uint size, gs_id
return pdf_put_composite(pdev, vstr, size, object_id);
else if (size > 1 && vstr[0] == '(')
return pdf_put_encoded_string(pdev, vstr, size, object_id);
-#if 0 /* Reserved for further extension. */
else if (size > 1 && vstr[0] == '<')
return pdf_put_encoded_hex_string(pdev, vstr, size, object_id);
-#endif
stream_write(pdev->strm, vstr, size);
return 0;
}