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[3*256];
21 int r, g, b, Y, Cr, Cb;
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 return _remaperror("remap: image has no color map");
73 return _remaperror("remap: can't handle nchans %d", i->nchans);
75 if(i->cmaplen == 3*(1<<j))
78 return _remaperror("remap: can't do colormap size 3*%d", i->cmaplen/3);
79 if(i->cmaplen != 3*256){
80 /* to avoid a range check in loop below, make a full-size cmap */
81 memmove(cmap1, cmap, i->cmaplen);
86 for(j=0; j<i->chanlen; j++){
91 r = (2125*r + 7154*g + 721*b)/10000; /* Poynton page 84 */
95 for(j=0; j<i->chanlen; j++){
97 *outp++ = cmap[3*k+2];
98 *outp++ = cmap[3*k+1];
99 *outp++ = cmap[3*k+0];
106 return _remaperror("remap: can't handle nchans %d", i->nchans);
111 for(j=0; j<i->chanlen; j++){
115 r = (2125*r + 7154*g + 721*b)/10000; /* Poynton page 84 */
119 for(j=0; j<i->chanlen; j++){
128 return _remaperror("remap: can't handle nchans %d", i->nchans);
132 for(j=0; j<i->chanlen; j++){
137 g = (Y-c2*Cb-c3*Cr) >> 11;
152 r = (2125*r + 7154*g + 721*b)/10000;