~ubuntu-branches/ubuntu/saucy/argyll/saucy

« back to all changes in this revision

Viewing changes to render/render.c

  • Committer: Package Import Robot
  • Author(s): Christian Marillat
  • Date: 2012-04-25 07:46:07 UTC
  • mfrom: (1.2.2) (13.1.15 sid)
  • Revision ID: package-import@ubuntu.com-20120425074607-yjqadetw8kum9skc
Tags: 1.4.0-4
Should Build-Depends on libusb-dev (Closes: #670329).

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
#include "numlib.h"
28
28
#include "tiffio.h"
29
29
#include "render.h"
 
30
#include "thscreen.h"
30
31
 
31
32
/* ------------------------------------------------------------- */
32
33
/* Utilities */
156
157
        uint16 inkset = 0xffff;
157
158
        char *inknames = NULL;
158
159
        tdata_t *outbuf;
 
160
        unsigned char *tempbuf = NULL;          /* 16 bit buffer for dithering */
 
161
        thscreens *screen = NULL;                       /* dithering object */
159
162
        prim2d *th, **pthp;
160
163
        prim2d **xlist, **ylist;        /* X, Y sorted start lists */
161
164
        int xli, yli;                           /* Indexes into X, Y list */
270
273
        /* Allocate one TIFF line buffer */
271
274
        outbuf = _TIFFmalloc(TIFFScanlineSize(wh));
272
275
 
 
276
        if (s->dpth == bpc8_2d && s->dither) {
 
277
#ifdef NEVER            // For testing by making screen visible
 
278
# define LEVELS 16
 
279
                int i, olevs[LEVELS];
 
280
                for (i = 0; i < LEVELS; i++)
 
281
                        olevs[i] = (int)(i/(LEVELS-1.0) * 255.0 + 0.5);
 
282
                if ((screen = new_thscreens(0, s->ncc, 1.0, 79, scie_16, 8, LEVELS, olevs,
 
283
                                           scoo_l, 0.1, NULL, NULL)) == NULL)
 
284
#else
 
285
                if ((screen = new_thscreens(0, s->ncc, 1.0, 79, scie_16, 8, 256, NULL,
 
286
                                           scoo_l, 0.1, NULL, NULL)) == NULL)
 
287
#endif
 
288
                        return 1;
 
289
                if ((tempbuf = malloc(s->pw * s->ncc * 2)) == NULL)
 
290
                        return 1;
 
291
        }
 
292
 
273
293
        /* To accelerate rendering, we keep sorted Y and X lists, */
274
294
        /* and Y and X active linked lists derived from them. */
275
295
        /* Typically this means that we're calling render on */
437
457
 
438
458
                                /* Translate from render value to output pixel value */
439
459
                                if (s->dpth == bpc8_2d) {
440
 
                                        unsigned char *p = ((unsigned char *)outbuf) + x * s->ncc;
441
 
                                        if (s->csp == lab_2d) {
442
 
                                                cvt_Lab_to_CIELAB8(cc, cc);
443
 
                                                for (j = 0; j < s->ncc; j++)
444
 
                                                        p[j] = (int)(cc[j] + 0.5);
 
460
                                        if (s->dither) {
 
461
                                                unsigned short *p = ((unsigned short *)tempbuf) + x * s->ncc;
 
462
                                                if (s->csp == lab_2d) {
 
463
                                                        cvt_Lab_to_CIELAB16(cc, cc);
 
464
                                                        for (j = 0; j < s->ncc; j++)
 
465
                                                                p[j] = (int)(cc[j] + 0.5);
 
466
                                                } else {
 
467
                                                        for (j = 0; j < s->ncc; j++)
 
468
                                                                p[j] = (int)(65535.0 * cc[j] + 0.5);
 
469
                                                }
445
470
                                        } else {
446
 
                                                for (j = 0; j < s->ncc; j++)
447
 
                                                        p[j] = (int)(255.0 * cc[j] + 0.5);
 
471
                                                unsigned char *p = ((unsigned char *)outbuf) + x * s->ncc;
 
472
                                                if (s->csp == lab_2d) {
 
473
                                                        cvt_Lab_to_CIELAB8(cc, cc);
 
474
                                                        for (j = 0; j < s->ncc; j++)
 
475
                                                                p[j] = (int)(cc[j] + 0.5);
 
476
                                                } else {
 
477
                                                        for (j = 0; j < s->ncc; j++)
 
478
                                                                p[j] = (int)(255.0 * cc[j] + 0.5);
 
479
                                                }
448
480
                                        }
449
481
                                } else {
450
482
                                        unsigned short *p = ((unsigned short *)outbuf) + x * s->ncc;
461
493
                }
462
494
 
463
495
                if (y >= 0) {
 
496
                        if (s->dpth == bpc8_2d && s->dither)
 
497
                                screen->screen(screen, s->pw, 1, 0, y, tempbuf, s->pw * s->ncc * 2,
 
498
                                                       (unsigned char *)outbuf, s->pw * s->ncc);
 
499
 
464
500
                        if (TIFFWriteScanline(wh, outbuf, y, 0) < 0)
465
501
                                error ("Failed to write TIFF file '%s' line %d",filename,y);
466
502
                }
479
515
        free(_pixv0);
480
516
        free(_pixv1);
481
517
 
 
518
        if (tempbuf != NULL)
 
519
                free(tempbuf);
 
520
        if (screen != NULL)
 
521
                screen->del(screen);
482
522
        _TIFFfree(outbuf);
483
523
        TIFFClose(wh);          /* Close Output file */
484
524
 
489
529
 
490
530
/* Constructor */
491
531
render2d *new_render2d(
492
 
double w,
493
 
double h,
494
 
double ma[4],   /* Margines, left, right, top, bottom, NULL for zero */
495
 
double hres,
496
 
double vres,
497
 
colort2d csp,
 
532
double w,               /* width in mm */
 
533
double h,               /* height in mm */
 
534
double ma[4],   /* Margines, left, right, top, bottom, NULL for zero in mm */
 
535
double hres,    /* horizontal resolution in pixels/mm */
 
536
double vres,    /* horizontal resolution in pixels/mm */
 
537
colort2d csp,   /* Color type */
498
538
int nd,                 /* Number of channels if c = ncol */
499
 
depth2d dpth
 
539
depth2d dpth,   /* Pixel depth */
 
540
int dither              /* Dither flag */
500
541
) {
501
542
        render2d *s;
502
543
 
522
563
        s->vres = vres;
523
564
        s->csp = csp;
524
565
        s->dpth = dpth;
 
566
        s->dither = dither;
525
567
 
526
568
        s->del = render2d_del;
527
569
        s->set_defc = render2d_set_defc;