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

« back to all changes in this revision

Viewing changes to base/gshtscr.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:
11
11
   San Rafael, CA  94903, U.S.A., +1(415)492-9861, for further information.
12
12
*/
13
13
 
14
 
/* $Id: gshtscr.c 11058 2010-04-13 12:15:42Z robin $ */
 
14
/* $Id$ */
15
15
/* Screen (Type 1) halftone processing for Ghostscript library */
16
16
#include "math_.h"
17
17
#include "gx.h"
182
182
/* Forward references */
183
183
static int pick_cell_size(gs_screen_halftone * ph,
184
184
     const gs_matrix * pmat, ulong max_size, uint min_levels, bool accurate,
185
 
                           gx_ht_cell_params_t * phcp);
 
185
                           gx_ht_cell_params_t * phcp);
186
186
 
187
187
/* Allocate a screen enumerator. */
188
188
gs_screen_enum *
420
420
 
421
421
                {
422
422
                    /*
423
 
                     * Compute the error in position between ideal location.
424
 
                     * and the current integer location.
425
 
                     */
 
423
                     * Compute the error in position between ideal location.
 
424
                     * and the current integer location.
 
425
                     */
426
426
 
427
 
                    double error =
428
 
                        (fn0 - p.N) * (fn0 - p.N) + (fm0 - p.M) * (fm0 - p.M);
429
 
                    /*
430
 
                     * Adjust the error by the length of the vector.  This gives
431
 
                     * a slight bias toward larger cell sizzes.
432
 
                     */
433
 
                    error /= p.N * p.N + p.M * p.M;
434
 
                    error = sqrt(error); /* The previous calcs. gave value squared */
 
427
                    double error =
 
428
                        (fn0 - p.N) * (fn0 - p.N) + (fm0 - p.M) * (fm0 - p.M);
 
429
                    /*
 
430
                     * Adjust the error by the length of the vector.  This gives
 
431
                     * a slight bias toward larger cell sizzes.
 
432
                     */
 
433
                    error /= p.N * p.N + p.M * p.M;
 
434
                    error = sqrt(error); /* The previous calcs. gave value squared */
435
435
                    if (error > e_best)
436
436
                        continue;
437
437
                    e_best = error;
493
493
    penum->x = penum->y = 0;
494
494
 
495
495
    if (porder->wse == NULL) {
496
 
        penum->strip = porder->num_levels / porder->width;
497
 
        penum->shift = porder->shift;
498
 
        /*
499
 
         * We want a transformation matrix that maps the parallelogram
500
 
         * (0,0), (U,V), (U-V',V+U'), (-V',U') to the square (+/-1, +/-1).
501
 
         * If the coefficients are [a b c d e f] and we let
502
 
         *      u = U = M/R, v = V = N/R,
503
 
         *      r = -V' = -N'/R', s = U' = M'/R',
504
 
         * then we just need to solve the equations:
505
 
         *      a*0 + c*0 + e = -1      b*0 + d*0 + f = -1
506
 
         *      a*u + c*v + e = 1       b*u + d*v + f = 1
507
 
         *      a*r + c*s + e = -1      b*r + d*s + f = 1
508
 
         * This has the following solution:
509
 
         *      Q = 2 / (M*M' + N*N')
510
 
         *      a = Q * R * M'
511
 
         *      b = -Q * R' * N
512
 
         *      c = Q * R * N'
513
 
         *      d = Q * R' * M
514
 
         *      e = -1
515
 
         *      f = -1
516
 
         */
517
 
        {
518
 
            const int M = porder->params.M, N = porder->params.N, R = porder->params.R;
519
 
            const int M1 = porder->params.M1, N1 = porder->params.N1, R1 = porder->params.R1;
520
 
            double Q = 2.0 / ((long)M * M1 + (long)N * N1);
 
496
        penum->strip = porder->num_levels / porder->width;
 
497
        penum->shift = porder->shift;
 
498
        /*
 
499
         * We want a transformation matrix that maps the parallelogram
 
500
         * (0,0), (U,V), (U-V',V+U'), (-V',U') to the square (+/-1, +/-1).
 
501
         * If the coefficients are [a b c d e f] and we let
 
502
         *      u = U = M/R, v = V = N/R,
 
503
         *      r = -V' = -N'/R', s = U' = M'/R',
 
504
         * then we just need to solve the equations:
 
505
         *      a*0 + c*0 + e = -1      b*0 + d*0 + f = -1
 
506
         *      a*u + c*v + e = 1       b*u + d*v + f = 1
 
507
         *      a*r + c*s + e = -1      b*r + d*s + f = 1
 
508
         * This has the following solution:
 
509
         *      Q = 2 / (M*M' + N*N')
 
510
         *      a = Q * R * M'
 
511
         *      b = -Q * R' * N
 
512
         *      c = Q * R * N'
 
513
         *      d = Q * R' * M
 
514
         *      e = -1
 
515
         *      f = -1
 
516
         */
 
517
        {
 
518
            const int M = porder->params.M, N = porder->params.N, R = porder->params.R;
 
519
            const int M1 = porder->params.M1, N1 = porder->params.N1, R1 = porder->params.R1;
 
520
            double Q = 2.0 / ((long)M * M1 + (long)N * N1);
521
521
 
522
 
            penum->mat.xx = Q * (R * M1);
523
 
            penum->mat.xy = Q * (-R1 * N);
524
 
            penum->mat.yx = Q * (R * N1);
525
 
            penum->mat.yy = Q * (R1 * M);
526
 
            penum->mat.tx = -1.0;
527
 
            penum->mat.ty = -1.0;
528
 
            gs_matrix_invert(&penum->mat, &penum->mat_inv);
529
 
        }
530
 
        if_debug7('h', "[h]Screen: (%dx%d)/%d [%f %f %f %f]\n",
531
 
                  porder->width, porder->height, porder->params.R,
532
 
                  penum->mat.xx, penum->mat.xy,
533
 
                  penum->mat.yx, penum->mat.yy);
 
522
            penum->mat.xx = Q * (R * M1);
 
523
            penum->mat.xy = Q * (-R1 * N);
 
524
            penum->mat.yx = Q * (R * N1);
 
525
            penum->mat.yy = Q * (R1 * M);
 
526
            penum->mat.tx = -1.0;
 
527
            penum->mat.ty = -1.0;
 
528
            gs_matrix_invert(&penum->mat, &penum->mat_inv);
 
529
        }
 
530
        if_debug7('h', "[h]Screen: (%dx%d)/%d [%f %f %f %f]\n",
 
531
                  porder->width, porder->height, porder->params.R,
 
532
                  penum->mat.xx, penum->mat.xy,
 
533
                  penum->mat.yx, penum->mat.yy);
534
534
    }
535
535
    return 0;
536
536
}
545
545
    gs_point spot_center; /* device coords */
546
546
 
547
547
    if (penum->order.wse) {
548
 
        int code;
549
 
        code = gs_wts_screen_enum_currentpoint(penum->order.wse, ppt);
550
 
        return code;
 
548
        int code;
 
549
        code = gs_wts_screen_enum_currentpoint(penum->order.wse, ppt);
 
550
        return code;
551
551
    }
552
552
 
553
553
    if (penum->y >= penum->strip) {     /* all done */
595
595
gs_screen_next(gs_screen_enum * penum, floatp value)
596
596
{
597
597
    if (penum->order.wse) {
598
 
        return gs_wts_screen_enum_next (penum->order.wse, value);
 
598
        return gs_wts_screen_enum_next (penum->order.wse, value);
599
599
    } else {
600
 
        ht_sample_t sample;
601
 
        int width = penum->order.width;
602
 
        gx_ht_bit *bits = (gx_ht_bit *)penum->order.bit_data;
 
600
        ht_sample_t sample;
 
601
        int width = penum->order.width;
 
602
        gx_ht_bit *bits = (gx_ht_bit *)penum->order.bit_data;
603
603
 
604
 
        if (value < -1.0 || value > 1.0)
605
 
            return_error(gs_error_rangecheck);
606
 
        sample = (ht_sample_t) ((value + 1) * max_ht_sample);
 
604
        if (value < -1.0 || value > 1.0)
 
605
            return_error(gs_error_rangecheck);
 
606
        sample = (ht_sample_t) ((value + 1) * max_ht_sample);
607
607
#ifdef DEBUG
608
 
        if (gs_debug_c('H')) {
609
 
            gs_point pt;
 
608
        if (gs_debug_c('H')) {
 
609
            gs_point pt;
610
610
 
611
 
            gs_screen_currentpoint(penum, &pt);
612
 
            dlprintf6("[H]sample x=%d y=%d (%f,%f): %f -> %u\n",
613
 
                      penum->x, penum->y, pt.x, pt.y, value, sample);
614
 
        }
 
611
            gs_screen_currentpoint(penum, &pt);
 
612
            dlprintf6("[H]sample x=%d y=%d (%f,%f): %f -> %u\n",
 
613
                      penum->x, penum->y, pt.x, pt.y, value, sample);
 
614
        }
615
615
#endif
616
 
        bits[penum->y * width + penum->x].mask = sample;
617
 
        if (++(penum->x) >= width)
618
 
            penum->x = 0, ++(penum->y);
619
 
        return 0;
 
616
        bits[penum->y * width + penum->x].mask = sample;
 
617
        if (++(penum->x) >= width)
 
618
            penum->x = 0, ++(penum->y);
 
619
        return 0;
620
620
    }
621
621
}
622
622