~ubuntu-branches/ubuntu/oneiric/ghostscript/oneiric

« back to all changes in this revision

Viewing changes to base/gdevimdi.c

  • Committer: Bazaar Package Importer
  • Author(s): Till Kamppeter
  • Date: 2011-07-15 16:49:55 UTC
  • mfrom: (1.1.23 upstream)
  • Revision ID: james.westby@ubuntu.com-20110715164955-uga6qibao6kez05c
Tags: 9.04~dfsg~20110715-0ubuntu1
* New upstream release
   - GIT snapshot from Jult, 12 2011.
* debian/patches/020110406~a54df2d.patch,
  debian/patches/020110408~0791cc8.patch,
  debian/patches/020110408~507cbee.patch,
  debian/patches/020110411~4509a49.patch,
  debian/patches/020110412~78bb9a6.patch,
  debian/patches/020110418~a05ab8a.patch,
  debian/patches/020110420~20b6c78.patch,
  debian/patches/020110420~4ddefa2.patch: Removed upstream patches.
* debian/rules: Generate ABI version number (variable "abi") correctly,
  cutting off repackaging and pre-release parts.
* debian/rules: Added ./lcms2/ directory to DEB_UPSTREAM_REPACKAGE_EXCLUDES.
* debian/copyright: Added lcms2/* to the list of excluded files.
* debian/symbols.common: Updated for new upstream source. Applied patch
  which dpkg-gensymbols generated for debian/libgs9.symbols to this file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* Copyright (C) 1999 Aladdin Enterprises.  All rights reserved.
2
 
  
 
2
 
3
3
  This software is provided AS-IS with no warranty, either express or
4
4
  implied.
5
 
  
 
5
 
6
6
  This software is distributed under license and may not be copied,
7
7
  modified or distributed except as expressly authorized under the terms
8
8
  of the license contained in the file LICENSE in this distribution.
9
 
  
 
9
 
10
10
  For more information about licensing, please refer to
11
11
  http://www.ghostscript.com/licensing/. For information on
12
12
  commercial licensing, go to http://www.artifex.com/licensing/ or
14
14
  San Rafael, CA  94903, U.S.A., +1(415)492-9861.
15
15
*/
16
16
 
17
 
/* $Id: gdevimdi.c 11346 2010-06-01 17:41:20Z mvrhel $ */
 
17
/* $Id$ */
18
18
/* IMDI Device.
19
19
 *
20
20
 * This is an RGB contone device, that outputs the raster
82
82
const gx_device_imdi gs_imdi_device =
83
83
{
84
84
    prn_device_body(gx_device_imdi, imdi_procs, "imdi",
85
 
            DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
86
 
            X_DPI, Y_DPI,
87
 
            0, 0, 0, 0, /* Margins */
88
 
            3, 24, 255, 255, 256, 256, imdi_print_page)
 
85
            DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
 
86
            X_DPI, Y_DPI,
 
87
            0, 0, 0, 0, /* Margins */
 
88
            3, 24, 255, 255, 256, 256, imdi_print_page)
89
89
};
90
90
 
91
91
static double incurve(void *ctx, int ch, double val)
111
111
 
112
112
    /* Open and read profile */
113
113
 
114
 
    idev->icc_link_profile = gsicc_get_profile_handle_file(LINK_ICC_NAME, 
 
114
    idev->icc_link_profile = gsicc_get_profile_handle_file(LINK_ICC_NAME,
115
115
                    strlen(LINK_ICC_NAME), dev->memory);
116
116
 
117
117
    if (idev->icc_link_profile == NULL)
118
118
        return gs_throw(-1, "Could not create link profile for imdi device");
119
119
 
120
120
    if (idev->icc_link_profile->num_comps != 3)
121
 
        return gs_throw1(-1, "profile must have 3 input channels. got %d.", 
 
121
        return gs_throw1(-1, "profile must have 3 input channels. got %d.",
122
122
                    idev->icc_link_profile->num_comps);
123
123
    if (idev->icc_link_profile->num_comps_out != 4)
124
 
        return gs_throw1(-1, "profile must have 4 output channels. got %d.", 
 
124
        return gs_throw1(-1, "profile must have 4 output channels. got %d.",
125
125
                    idev->icc_link_profile->num_comps_out);
126
126
 
127
 
 
128
127
    rendering_params.black_point_comp = false;
129
 
    rendering_params.object_type = GS_DEVICE_DOESNT_SUPPORT_TAGS;  /* Already rendered */
 
128
    rendering_params.graphics_type_tag = GS_UNKNOWN_TAG;  /* Already rendered */
130
129
    rendering_params.rendering_intent = gsPERCEPTUAL;
131
 
    
132
 
    idev->icc_link = gscms_get_link(idev->icc_link_profile, 
 
130
 
 
131
    idev->icc_link = gscms_get_link(idev->icc_link_profile,
133
132
                    NULL, &rendering_params);
134
133
 
135
134
    if (!idev->icc_link)
136
 
        return gs_throw(-1, "could not create ICC link handle");
 
135
        return gs_throw(-1, "could not create ICC link handle");
137
136
 
138
137
    return gdev_prn_open(dev);
139
138
 
140
139
}
141
140
 
142
 
 
143
141
/*
144
142
 * Close device and clean up ICC structures.
145
143
 */
155
153
    return gdev_prn_close(dev);
156
154
}
157
155
 
158
 
 
159
156
/*
160
157
 * Output the page raster.
161
158
 */
193
190
 
194
191
    for (k = 0; k < 4; k++)
195
192
    {
196
 
        char name[256];
197
 
 
198
 
        sprintf(name, "%s.%c.pgm", pdev->fname, "cmyk"[k]);
199
 
 
200
 
        dprintf1("output file: %s\n", name);
201
 
 
202
 
        fp[k] = fopen(name, "wb");
203
 
        if (!fp[k])
204
 
        {
205
 
            code = gs_throw2(-1, "could not open file: %s (%s)", name, strerror(errno));
206
 
            goto cleanup;
207
 
        }
208
 
 
209
 
        fprintf(fp[k], "P5\n%d %d\n255\n", pdev->width, pdev->height);
 
193
        char name[256];
 
194
 
 
195
        sprintf(name, "%s.%c.pgm", pdev->fname, "cmyk"[k]);
 
196
 
 
197
        dprintf1("output file: %s\n", name);
 
198
 
 
199
        fp[k] = gp_fopen(name, "wb");
 
200
        if (!fp[k])
 
201
        {
 
202
            code = gs_throw2(-1, "could not open file: %s (%s)", name, strerror(errno));
 
203
            goto cleanup;
 
204
        }
 
205
 
 
206
        fprintf(fp[k], "P5\n%d %d\n255\n", pdev->width, pdev->height);
210
207
    }
211
208
 
212
209
    /*
218
215
    srcbuffer = gs_malloc(pdev->memory, srcstride, 1, "imdi_print_page(srcbuffer)");
219
216
    if (!srcbuffer)
220
217
    {
221
 
        code = gs_throw1(-1, "outofmem: src buffer %d", srcstride);
222
 
        goto cleanup;
 
218
        code = gs_throw1(-1, "outofmem: src buffer %d", srcstride);
 
219
        goto cleanup;
223
220
    }
224
221
 
225
222
    dstplanes = 4;
227
224
    dstbuffer = gs_malloc(pdev->memory, dststride, 1, "imdi_print_page(dstbuffer)");
228
225
    if (!dstbuffer)
229
226
    {
230
 
        code = gs_throw1(-1, "outofmem: dst buffer %d", dststride);
231
 
        goto cleanup;
 
227
        code = gs_throw1(-1, "outofmem: dst buffer %d", dststride);
 
228
        goto cleanup;
232
229
    }
233
230
 
234
231
    /*
237
234
 
238
235
    for (y = 0; y < pdev->height; y++)
239
236
    {
240
 
        gdev_prn_get_bits(pdev, y, srcbuffer, &srcdata);
 
237
        gdev_prn_get_bits(pdev, y, srcbuffer, &srcdata);
241
238
 
242
 
        /* write rgb to original output file */
243
 
        fwrite(srcdata, 1, srcstride, prn_stream);
 
239
        /* write rgb to original output file */
 
240
        fwrite(srcdata, 1, srcstride, prn_stream);
244
241
 
245
242
#if 1 /* Collect runlengths */
246
243
 
247
 
        {
248
 
        void *inp[1];
249
 
        void *outp[1];
250
 
        int sx, ex;
251
 
        int w = pdev->width;
252
 
 
253
 
        sx = ex = 0;
254
 
 
255
 
        while (sx < w)
256
 
        {
257
 
            inp[0] = srcdata + sx * 3;
258
 
            outp[0] = dstbuffer + sx * 4;
259
 
 
260
 
            while (ex < w && 
261
 
                srcdata[ex * 3 + 0] == srcdata[sx * 3 + 0] &&
262
 
                srcdata[ex * 3 + 1] == srcdata[sx * 3 + 1] &&
263
 
                srcdata[ex * 3 + 2] == srcdata[sx * 3 + 2])
264
 
            {
265
 
                ex ++;
266
 
            }
267
 
 
268
 
            /* same-run */
269
 
            if (ex - sx > 1)
270
 
            {
271
 
                nsame ++; lsame += ex - sx;
 
244
        {
 
245
        void *inp[1];
 
246
        void *outp[1];
 
247
        int sx, ex;
 
248
        int w = pdev->width;
 
249
 
 
250
        sx = ex = 0;
 
251
 
 
252
        while (sx < w)
 
253
        {
 
254
            inp[0] = srcdata + sx * 3;
 
255
            outp[0] = dstbuffer + sx * 4;
 
256
 
 
257
            while (ex < w &&
 
258
                srcdata[ex * 3 + 0] == srcdata[sx * 3 + 0] &&
 
259
                srcdata[ex * 3 + 1] == srcdata[sx * 3 + 1] &&
 
260
                srcdata[ex * 3 + 2] == srcdata[sx * 3 + 2])
 
261
            {
 
262
                ex ++;
 
263
            }
 
264
 
 
265
            /* same-run */
 
266
            if (ex - sx > 1)
 
267
            {
 
268
                nsame ++; lsame += ex - sx;
272
269
 
273
270
                /* Transform the color */
274
271
                gscms_transform_color(idev->icc_link, inp,
275
272
                        outp, 1, NULL);
276
273
 
277
 
                for (x = sx + 1; x < ex; x++)
278
 
                {
279
 
                    dstbuffer[x * 4 + 0] = dstbuffer[sx * 4 + 0];
280
 
                    dstbuffer[x * 4 + 1] = dstbuffer[sx * 4 + 1];
281
 
                    dstbuffer[x * 4 + 2] = dstbuffer[sx * 4 + 2];
282
 
                    dstbuffer[x * 4 + 3] = dstbuffer[sx * 4 + 3];
283
 
                }
284
 
            }
285
 
 
286
 
            /* diff-run */
287
 
            else
288
 
            {
289
 
                ndiff ++;
290
 
 
291
 
                while (ex < w && 
292
 
                        srcdata[ex * 3 + 0] != srcdata[ex * 3 - 3] &&
293
 
                        srcdata[ex * 3 + 1] != srcdata[ex * 3 - 2] &&
294
 
                        srcdata[ex * 3 + 2] != srcdata[ex * 3 - 1])
295
 
                {
296
 
                    ex ++;
297
 
                }
298
 
 
299
 
                ldiff += ex - sx;
 
274
                for (x = sx + 1; x < ex; x++)
 
275
                {
 
276
                    dstbuffer[x * 4 + 0] = dstbuffer[sx * 4 + 0];
 
277
                    dstbuffer[x * 4 + 1] = dstbuffer[sx * 4 + 1];
 
278
                    dstbuffer[x * 4 + 2] = dstbuffer[sx * 4 + 2];
 
279
                    dstbuffer[x * 4 + 3] = dstbuffer[sx * 4 + 3];
 
280
                }
 
281
            }
 
282
 
 
283
            /* diff-run */
 
284
            else
 
285
            {
 
286
                ndiff ++;
 
287
 
 
288
                while (ex < w &&
 
289
                        srcdata[ex * 3 + 0] != srcdata[ex * 3 - 3] &&
 
290
                        srcdata[ex * 3 + 1] != srcdata[ex * 3 - 2] &&
 
291
                        srcdata[ex * 3 + 2] != srcdata[ex * 3 - 1])
 
292
                {
 
293
                    ex ++;
 
294
                }
 
295
 
 
296
                ldiff += ex - sx;
300
297
 
301
298
                /* This needs to be done more efficiently */
302
299
 
311
308
                gscms_transform_color_buffer(idev->icc_link, &input_buff_desc,
312
309
                             &output_buff_desc, inp, outp);
313
310
 
314
 
            }
 
311
            }
315
312
 
316
 
            sx = ex;
317
 
        }
318
 
        }
 
313
            sx = ex;
 
314
        }
 
315
        }
319
316
 
320
317
#endif
321
318
 
322
319
#if 0 /* Call IMDI for entire scanline */
323
 
        void *inp[1];
324
 
        void *outp[1];
 
320
        void *inp[1];
 
321
        void *outp[1];
325
322
 
326
 
        inp[0] = srcdata;
327
 
        outp[0] = dstbuffer;
 
323
        inp[0] = srcdata;
 
324
        outp[0] = dstbuffer;
328
325
 
329
326
        gsicc_init_buffer(&input_buff_desc, 3, 1,
330
327
              false, false, false, 0, width*3,
337
334
        gscms_transform_color_buffer(idev->icc_link, &input_buff_desc,
338
335
                     &output_buff_desc, inp, outp);
339
336
 
340
 
 
341
 
 
342
337
#if 0
343
 
        /* output planar data to auxiliary output files */
344
 
        for (x = 0; x < pdev->width; x++)
345
 
            for (k = 0; k < 4; k++)
346
 
                putc(dstbuffer[x * 4 + k], fp[k]);
 
338
        /* output planar data to auxiliary output files */
 
339
        for (x = 0; x < pdev->width; x++)
 
340
            for (k = 0; k < 4; k++)
 
341
                putc(dstbuffer[x * 4 + k], fp[k]);
347
342
#endif
348
343
#endif
349
344
 
350
345
#if 0 /* Call IMDI for every pixel */
351
 
        for (x = 0; x < pdev->width; x++)
352
 
        {
353
 
            void *inp[1];
354
 
            void *outp[1];
 
346
        for (x = 0; x < pdev->width; x++)
 
347
        {
 
348
            void *inp[1];
 
349
            void *outp[1];
355
350
 
356
 
            inp[0] = srcdata + x * 3;
357
 
            outp[0] = dstbuffer + x * 4;
 
351
            inp[0] = srcdata + x * 3;
 
352
            outp[0] = dstbuffer + x * 4;
358
353
 
359
354
            /* Transform the color */
360
355
            gscms_transform_color(idev->icc_link, inp,
361
356
                    outp, 1, NULL);
362
357
 
363
 
 
364
 
            /* output planar data to auxiliary output files */
365
 
            for (k = 0; k < 4; k++)
366
 
                putc(dstbuffer[x * 4 + k], fp[k]);
367
 
        }
 
358
            /* output planar data to auxiliary output files */
 
359
            for (k = 0; k < 4; k++)
 
360
                putc(dstbuffer[x * 4 + k], fp[k]);
 
361
        }
368
362
#endif
369
363
 
370
364
#if 0 /* Slow but accurate every pixel */
371
365
 
372
 
        for (x = 0; x < pdev->width; x++)
373
 
        {
374
 
            srcpixel[0] = srcdata[x * 3 + 0] / 255.0;
375
 
            srcpixel[1] = srcdata[x * 3 + 1] / 255.0;
376
 
            srcpixel[2] = srcdata[x * 3 + 2] / 255.0;
377
 
 
378
 
            code = idev->luo->lookup(idev->luo, dstpixel, srcpixel);
379
 
            if (code > 1)
380
 
            {
381
 
                code = gs_throw1(-1, "icc lookup failed: %s", idev->icco->err);
382
 
                goto cleanup;
383
 
            }
384
 
 
385
 
            dstbuffer[x * 4 + 0] = dstpixel[0] * 255 + 0.5;
386
 
            dstbuffer[x * 4 + 1] = dstpixel[1] * 255 + 0.5;
387
 
            dstbuffer[x * 4 + 2] = dstpixel[2] * 255 + 0.5;
388
 
            dstbuffer[x * 4 + 3] = dstpixel[3] * 255 + 0.5;
389
 
 
390
 
            /* output planar data to auxiliary output files */
391
 
            for (k = 0; k < 4; k++)
392
 
                putc(dstbuffer[x * 4 + k], fp[k]);
393
 
        }
 
366
        for (x = 0; x < pdev->width; x++)
 
367
        {
 
368
            srcpixel[0] = srcdata[x * 3 + 0] / 255.0;
 
369
            srcpixel[1] = srcdata[x * 3 + 1] / 255.0;
 
370
            srcpixel[2] = srcdata[x * 3 + 2] / 255.0;
 
371
 
 
372
            code = idev->luo->lookup(idev->luo, dstpixel, srcpixel);
 
373
            if (code > 1)
 
374
            {
 
375
                code = gs_throw1(-1, "icc lookup failed: %s", idev->icco->err);
 
376
                goto cleanup;
 
377
            }
 
378
 
 
379
            dstbuffer[x * 4 + 0] = dstpixel[0] * 255 + 0.5;
 
380
            dstbuffer[x * 4 + 1] = dstpixel[1] * 255 + 0.5;
 
381
            dstbuffer[x * 4 + 2] = dstpixel[2] * 255 + 0.5;
 
382
            dstbuffer[x * 4 + 3] = dstpixel[3] * 255 + 0.5;
 
383
 
 
384
            /* output planar data to auxiliary output files */
 
385
            for (k = 0; k < 4; k++)
 
386
                putc(dstbuffer[x * 4 + k], fp[k]);
 
387
        }
394
388
#endif
395
389
    }
396
390
 
397
391
    dprintf4("same=%d/%d diff=%d/%d\n", lsame, nsame, ldiff, ndiff);
398
392
 
399
 
 
400
393
    /*
401
394
     * Cleanup memory and files.
402
395
     */
404
397
cleanup:
405
398
 
406
399
    for (k = 0; k < 4; k++)
407
 
        if (fp[k])
408
 
            fclose(fp[k]);
 
400
        if (fp[k])
 
401
            fclose(fp[k]);
409
402
 
410
403
    if (dstbuffer)
411
 
        gs_free(pdev->memory, dstbuffer, dststride, 1, "imdi_print_page(dstbuffer)");
 
404
        gs_free(pdev->memory, dstbuffer, dststride, 1, "imdi_print_page(dstbuffer)");
412
405
 
413
406
    if (srcbuffer)
414
 
        gs_free(pdev->memory, srcbuffer, srcstride, 1, "imdi_print_page(srcbuffer)");
 
407
        gs_free(pdev->memory, srcbuffer, srcstride, 1, "imdi_print_page(srcbuffer)");
415
408
 
416
409
    return code;
417
410
}
418