8 c1 = 2871, /* 1.402 * 2048 */
9 c2 = 705, /* 0.34414 * 2048 */
10 c3 = 1463, /* 0.71414 * 2048 */
11 c4 = 3629, /* 1.772 * 2048 */
15 totruecolor(Rawimage *i, int chandesc)
20 uchar *rp, *gp, *bp, *cmap, *inp, *outp, cmap1[4*256];
21 int r, g, b, Y, Cr, Cb, psize;
23 if(chandesc!=CY && chandesc!=CRGB24)
24 return _remaperror("remap: can't convert to chandesc %d", chandesc);
27 errstr(err, sizeof err); /* throw it away */
28 im = malloc(sizeof(Rawimage));
31 memset(im, 0, sizeof(Rawimage));
33 im->chanlen = i->chanlen;
35 im->chanlen = 3*i->chanlen;
36 im->chandesc = chandesc;
37 im->chans[0] = malloc(im->chanlen);
38 if(im->chans[0] == nil){
51 return _remaperror("remap: can't recognize channel type %d", i->chandesc);
54 return _remaperror("remap: Y image has %d chans", i->nchans);
56 memmove(im->chans[0], i->chans[0], i->chanlen);
59 /* convert to three color */
61 for(j=0; j<i->chanlen; j++){
71 psize = (i->chandesc == CRGB1) ? 3 : 4;
73 return _remaperror("remap: image has no color map");
75 return _remaperror("remap: can't handle nchans %d", i->nchans);
76 if(i->cmaplen > psize*256)
77 return _remaperror("remap: can't do colormap size %d*%d", psize, i->cmaplen/psize);
78 if(i->cmaplen != psize*256){
79 /* to avoid a range check in loop below, make a full-size cmap */
80 memmove(cmap1, cmap, i->cmaplen);
85 for(j=0; j<i->chanlen; j++){
90 r = (2125*r + 7154*g + 721*b)/10000; /* Poynton page 84 */
94 for(j=0; j<i->chanlen; j++){
105 return _remaperror("remap: can't handle nchans %d", i->nchans);
110 for(j=0; j<i->chanlen; j++){
114 r = (2125*r + 7154*g + 721*b)/10000; /* Poynton page 84 */
118 for(j=0; j<i->chanlen; j++){
127 return _remaperror("remap: can't handle nchans %d", i->nchans);
131 for(j=0; j<i->chanlen; j++){
136 g = (Y-c2*Cb-c3*Cr) >> 11;
151 r = (2125*r + 7154*g + 721*b)/10000;