~ubuntu-branches/ubuntu/hardy/ghostscript/hardy

« back to all changes in this revision

Viewing changes to src/gdevpsdi.c

  • Committer: Bazaar Package Importer
  • Author(s): Till Kamppeter
  • Date: 2007-11-22 12:17:43 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20071122121743-cd70s3ypq0r243mp
Tags: 8.61.dfsg.1-0ubtuntu1
* New upstream release
  o Final 8.61 release
* debian/patches/09_ijs_krgb_support.dpatch: Adapted to upstream changes.
* debian/rules: Updated CUPS-related variables for "make install" calls.
* debian/rules: Remove /usr/include/ghostscript from the ghostscript
  package, they go into lings-dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
   San Rafael, CA  94903, U.S.A., +1(415)492-9861, for further information.
12
12
*/
13
13
 
14
 
/* $Id: gdevpsdi.c 8022 2007-06-05 22:23:38Z giles $ */
 
14
/* $Id: gdevpsdi.c 8275 2007-10-09 08:28:49Z ken $ */
15
15
/* Image compression for PostScript and PDF writers */
16
16
#include "stdio_.h"             /* for jpeglib.h */
17
17
#include "jpeglib_.h"           /* for sdct.h */
49
49
 * At least one of bpc_in and bpc_out is 8; the other is 1, 2, 4, or 8,
50
50
 * except if bpc_out is 8, bpc_in may be 12.
51
51
 */
52
 
private int
 
52
static int
53
53
pixel_resize(psdf_binary_writer * pbw, int width, int num_components,
54
54
             int bpc_in, int bpc_out)
55
55
{
87
87
    return 0;
88
88
}
89
89
 
90
 
private int
 
90
static int
91
91
convert_color(gx_device *pdev, const gs_color_space *pcs, const gs_imager_state * pis, 
92
92
              gs_client_color *cc, float c[3])
93
93
{
105
105
}
106
106
 
107
107
/* A hewristic choice of DCT compression parameters - see bug 687174. */
108
 
private int 
 
108
static int 
109
109
choose_DCT_params(gx_device *pdev, const gs_color_space *pcs, 
110
110
                  const gs_imager_state * pis, 
111
111
                  gs_c_param_list *list, gs_c_param_list **param, 
121
121
 
122
122
    if (pcs->type->num_components(pcs) != 3)
123
123
        return 0;
124
 
    /* Make a copy of the parameter list since we will modify it. */
125
 
    code = param_list_copy((gs_param_list *)list, (gs_param_list *)*param);
126
 
    if (code < 0)
127
 
        return code;
 
124
    if (*param != NULL) {
 
125
        /* Make a copy of the parameter list since we will modify it. */
 
126
        code = param_list_copy((gs_param_list *)list, (gs_param_list *)*param);
 
127
        if (code < 0)
 
128
            return code;
 
129
    }
128
130
    *param = list;
129
131
 
130
132
    /* Create a local memory device for transforming colors to DeviceRGB. */
206
208
}
207
209
 
208
210
/* Add the appropriate image compression filter, if any. */
209
 
private int
 
211
static int
210
212
setup_image_compression(psdf_binary_writer *pbw, const psdf_image_params *pdip,
211
213
                        const gs_pixel_image_t * pim, const gs_imager_state * pis, 
212
214
                        bool lossless)
255
257
        return gs_error_rangecheck; /* Reject the alternative stream. */   
256
258
    if (pdev->version < psdf_version_ll3 && template == &s_zlibE_template)
257
259
        orig_template = template = lossless_template;
258
 
    if (dict) /* NB: rather than dereference NULL lets continue on without a dict */
 
260
    if (dict != NULL) /* Some interpreters don't supply filter parameters. */
259
261
        gs_c_param_list_read(dict);     /* ensure param list is in read mode */
260
262
    if (template == 0)  /* no compression */
261
263
        return 0;
375
377
}
376
378
 
377
379
/* Determine whether an image should be downsampled. */
378
 
private bool
 
380
static bool
379
381
do_downsample(const psdf_image_params *pdip, const gs_pixel_image_t *pim,
380
382
              floatp resolution)
381
383
{
388
390
/* Add downsampling, antialiasing, and compression filters. */
389
391
/* Uses AntiAlias, Depth, DownsampleThreshold, DownsampleType, Resolution. */
390
392
/* Assumes do_downsampling() is true. */
391
 
private int
 
393
static int
392
394
setup_downsampling(psdf_binary_writer * pbw, const psdf_image_params * pdip,
393
395
                   gs_pixel_image_t * pim, const gs_imager_state * pis, 
394
396
                   floatp resolution, bool lossless)
456
458
            gs_color_space_index_DeviceCMYK;
457
459
}
458
460
 
459
 
private inline void 
 
461
static inline void 
460
462
adjust_auto_filter_strategy(gx_device_psdf *pdev, 
461
463
                psdf_image_params *params, gs_c_param_list *plist, 
462
464
                const gs_pixel_image_t * pim, bool in_line)
473
475
#endif
474
476
}
475
477
 
476
 
private inline void 
 
478
static inline void 
477
479
adjust_auto_filter_strategy_mono(gx_device_psdf *pdev, 
478
480
                psdf_image_params *params, gs_c_param_list *plist, 
479
481
                const gs_pixel_image_t * pim, bool in_line)
523
525
        ncomp = 1;
524
526
    } else {
525
527
        ncomp = gs_color_space_num_components(pim->ColorSpace);
526
 
        if (ncomp == 1) {
527
 
            if (bpc == 1)
528
 
                params = pdev->params.MonoImage;
529
 
            else
530
 
                params = pdev->params.GrayImage;
531
 
            if (params.Depth == -1)
532
 
                params.Depth = bpc;
533
 
        } else {
 
528
        if (pim->ColorSpace->type->index == gs_color_space_index_Indexed) {
534
529
            params = pdev->params.ColorImage;
 
530
            /* Ensure we don't use JPEG on a /Indexed colour space */
 
531
            params.AutoFilter = false;
 
532
            params.Filter = "FlateEncode";
 
533
        } else {
 
534
            if (ncomp == 1) {
 
535
                if (bpc == 1)
 
536
                    params = pdev->params.MonoImage;
 
537
                else
 
538
                    params = pdev->params.GrayImage;
 
539
                if (params.Depth == -1)
 
540
                    params.Depth = bpc;
 
541
            } else {
 
542
                params = pdev->params.ColorImage;
535
543
            /* params.Depth is reset below */
 
544
            }
536
545
        }
537
546
    }
538
547
 
554
563
        resolution = 1.0 / hypot(pt.x / pdev->HWResolution[0],
555
564
                                 pt.y / pdev->HWResolution[1]);
556
565
    }
557
 
    if (ncomp == 1) {
 
566
    if (ncomp == 1 && pim->ColorSpace && pim->ColorSpace->type->index != gs_color_space_index_Indexed) {
558
567
        /* Monochrome, gray, or mask */
559
568
        /* Check for downsampling. */
560
569
        if (do_downsample(&params, pim, resolution)) {