📄 image.cc
字号:
*(yt++) = (unsigned long) (yg * yg); *(yt++) = (unsigned long) (yb * yb); yr -= dry; yg -= dgy; yb -= dby; } // Combine tables to create gradient#ifdef INTERLACE if (! interlaced) {#endif // INTERLACE // normal egradient for (yt = ytable, y = 0; y < height; y++, yt += 3) { for (xt = xtable, x = 0; x < width; x++) { *(pr++) = (unsigned char) (tr - (rsign * control->getSqrt(*(xt++) + *(yt)))); *(pg++) = (unsigned char) (tg - (gsign * control->getSqrt(*(xt++) + *(yt + 1)))); *(pb++) = (unsigned char) (tb - (bsign * control->getSqrt(*(xt++) + *(yt + 2)))); } }#ifdef INTERLACE } else { // faked interlacing effect unsigned char channel, channel2; for (yt = ytable, y = 0; y < height; y++, yt += 3) { for (xt = xtable, x = 0; x < width; x++) { if (y & 1) { channel = (unsigned char) (tr - (rsign * control->getSqrt(*(xt++) + *(yt)))); channel2 = (channel >> 1) + (channel >> 2); if (channel2 > channel) channel2 = 0; *(pr++) = channel2; channel = (unsigned char) (tg - (gsign * control->getSqrt(*(xt++) + *(yt + 1)))); channel2 = (channel >> 1) + (channel >> 2); if (channel2 > channel) channel2 = 0; *(pg++) = channel2; channel = (unsigned char) (tb - (bsign * control->getSqrt(*(xt++) + *(yt + 2)))); channel2 = (channel >> 1) + (channel >> 2); if (channel2 > channel) channel2 = 0; *(pb++) = channel2; } else { channel = (unsigned char) (tr - (rsign * control->getSqrt(*(xt++) + *(yt)))); channel2 = channel + (channel >> 3); if (channel2 < channel) channel2 = ~0; *(pr++) = channel2; channel = (unsigned char) (tg - (gsign * control->getSqrt(*(xt++) + *(yt + 1)))); channel2 = channel + (channel >> 3); if (channel2 < channel) channel2 = ~0; *(pg++) = channel2; channel = (unsigned char) (tb - (bsign * control->getSqrt(*(xt++) + *(yt + 2)))); channel2 = channel + (channel >> 3); if (channel2 < channel) channel2 = ~0; *(pb++) = channel2; } } } }#endif // INTERLACE}void BImage::pcgradient(void) { // pipe cross gradient - based on original dgradient, written by // Mosfet (mosfet@kde.org) // adapted from kde sources for Blackbox by Brad Hughes float drx, dgx, dbx, dry, dgy, dby, xr, xg, xb, yr, yg, yb; int rsign, gsign, bsign; unsigned char *pr = red, *pg = green, *pb = blue; unsigned int *xt = xtable, *yt = ytable, tr = to->getRed(), tg = to->getGreen(), tb = to->getBlue(); register unsigned int x, y; dry = drx = (float) (to->getRed() - from->getRed()); dgy = dgx = (float) (to->getGreen() - from->getGreen()); dby = dbx = (float) (to->getBlue() - from->getBlue()); rsign = (drx < 0) ? -2 : 2; gsign = (dgx < 0) ? -2 : 2; bsign = (dbx < 0) ? -2 : 2; xr = yr = (drx / 2); xg = yg = (dgx / 2); xb = yb = (dbx / 2); // Create X table drx /= width; dgx /= width; dbx /= width; for (x = 0; x < width; x++) { *(xt++) = (unsigned char) ((xr < 0) ? -xr : xr); *(xt++) = (unsigned char) ((xg < 0) ? -xg : xg); *(xt++) = (unsigned char) ((xb < 0) ? -xb : xb); xr -= drx; xg -= dgx; xb -= dbx; } // Create Y table dry /= height; dgy /= height; dby /= height; for (y = 0; y < height; y++) { *(yt++) = ((unsigned char) ((yr < 0) ? -yr : yr)); *(yt++) = ((unsigned char) ((yg < 0) ? -yg : yg)); *(yt++) = ((unsigned char) ((yb < 0) ? -yb : yb)); yr -= dry; yg -= dgy; yb -= dby; } // Combine tables to create gradient#ifdef INTERLACE if (! interlaced) {#endif // INTERLACE // normal pcgradient for (yt = ytable, y = 0; y < height; y++, yt += 3) { for (xt = xtable, x = 0; x < width; x++) { *(pr++) = (unsigned char) (tr - (rsign * min(*(xt++), *(yt)))); *(pg++) = (unsigned char) (tg - (gsign * min(*(xt++), *(yt + 1)))); *(pb++) = (unsigned char) (tb - (bsign * min(*(xt++), *(yt + 2)))); } }#ifdef INTERLACE } else { // faked interlacing effect unsigned char channel, channel2; for (yt = ytable, y = 0; y < height; y++, yt += 3) { for (xt = xtable, x = 0; x < width; x++) { if (y & 1) { channel = (unsigned char) (tr - (rsign * min(*(xt++), *(yt)))); channel2 = (channel >> 1) + (channel >> 2); if (channel2 > channel) channel2 = 0; *(pr++) = channel2; channel = (unsigned char) (tg - (bsign * min(*(xt++), *(yt + 1)))); channel2 = (channel >> 1) + (channel >> 2); if (channel2 > channel) channel2 = 0; *(pg++) = channel2; channel = (unsigned char) (tb - (gsign * min(*(xt++), *(yt + 2)))); channel2 = (channel >> 1) + (channel >> 2); if (channel2 > channel) channel2 = 0; *(pb++) = channel2; } else { channel = (unsigned char) (tr - (rsign * min(*(xt++), *(yt)))); channel2 = channel + (channel >> 3); if (channel2 < channel) channel2 = ~0; *(pr++) = channel2; channel = (unsigned char) (tg - (gsign * min(*(xt++), *(yt + 1)))); channel2 = channel + (channel >> 3); if (channel2 < channel) channel2 = ~0; *(pg++) = channel2; channel = (unsigned char) (tb - (bsign * min(*(xt++), *(yt + 2)))); channel2 = channel + (channel >> 3); if (channel2 < channel) channel2 = ~0; *(pb++) = channel2; } } } }#endif // INTERLACE}void BImage::cdgradient(void) { // cross diagonal gradient - based on original dgradient, written by // Mosfet (mosfet@kde.org) // adapted from kde sources for Blackbox by Brad Hughes float drx, dgx, dbx, dry, dgy, dby, yr = 0.0, yg = 0.0, yb = 0.0, xr = (float) from->getRed(), xg = (float) from->getGreen(), xb = (float) from->getBlue(); unsigned char *pr = red, *pg = green, *pb = blue; unsigned int w = width * 2, h = height * 2, *xt, *yt; register unsigned int x, y; dry = drx = (float) (to->getRed() - from->getRed()); dgy = dgx = (float) (to->getGreen() - from->getGreen()); dby = dbx = (float) (to->getBlue() - from->getBlue()); // Create X table drx /= w; dgx /= w; dbx /= w; for (xt = (xtable + (width * 3) - 1), x = 0; x < width; x++) { *(xt--) = (unsigned char) xb; *(xt--) = (unsigned char) xg; *(xt--) = (unsigned char) xr; xr += drx; xg += dgx; xb += dbx; } // Create Y table dry /= h; dgy /= h; dby /= h; for (yt = ytable, y = 0; y < height; y++) { *(yt++) = (unsigned char) yr; *(yt++) = (unsigned char) yg; *(yt++) = (unsigned char) yb; yr += dry; yg += dgy; yb += dby; } // Combine tables to create gradient#ifdef INTERLACE if (! interlaced) {#endif // INTERLACE // normal cdgradient for (yt = ytable, y = 0; y < height; y++, yt += 3) { for (xt = xtable, x = 0; x < width; x++) { *(pr++) = *(xt++) + *(yt); *(pg++) = *(xt++) + *(yt + 1); *(pb++) = *(xt++) + *(yt + 2); } }#ifdef INTERLACE } else { // faked interlacing effect unsigned char channel, channel2; for (yt = ytable, y = 0; y < height; y++, yt += 3) { for (xt = xtable, x = 0; x < width; x++) { if (y & 1) { channel = *(xt++) + *(yt); channel2 = (channel >> 1) + (channel >> 2); if (channel2 > channel) channel2 = 0; *(pr++) = channel2; channel = *(xt++) + *(yt + 1); channel2 = (channel >> 1) + (channel >> 2); if (channel2 > channel) channel2 = 0; *(pg++) = channel2; channel = *(xt++) + *(yt + 2); channel2 = (channel >> 1) + (channel >> 2); if (channel2 > channel) channel2 = 0; *(pb++) = channel2; } else { channel = *(xt++) + *(yt); channel2 = channel + (channel >> 3); if (channel2 < channel) channel2 = ~0; *(pr++) = channel2; channel = *(xt++) + *(yt + 1); channel2 = channel + (channel >> 3); if (channel2 < channel) channel2 = ~0; *(pg++) = channel2; channel = *(xt++) + *(yt + 2); channel2 = channel + (channel >> 3); if (channel2 < channel) channel2 = ~0; *(pb++) = channel2; } } } }#endif // INTERLACE}BImageControl::BImageControl(BaseDisplay *dpy, ScreenInfo *scrn, Bool _dither, int _cpc, unsigned long cache_timeout, unsigned long cmax){ basedisplay = dpy; screeninfo = scrn; setDither(_dither); setColorsPerChannel(_cpc); cache_max = cmax;#ifdef TIMEDCACHE if (cache_timeout) { timer = new BTimer(basedisplay, this); timer->setTimeout(cache_timeout); timer->start(); } else timer = (BTimer *) 0;#endif // TIMEDCACHE colors = (XColor *) 0; ncolors = 0; grad_xbuffer = grad_ybuffer = (unsigned int *) 0; grad_buffer_width = grad_buffer_height = 0; sqrt_table = (unsigned long *) 0; screen_depth = screeninfo->getDepth(); window = screeninfo->getRootWindow(); screen_number = screeninfo->getScreenNumber(); int count; XPixmapFormatValues *pmv = XListPixmapFormats(basedisplay->getXDisplay(), &count); root_colormap = DefaultColormap(basedisplay->getXDisplay(), screen_number); if (pmv) { bits_per_pixel = 0; for (int i = 0; i < count; i++) if (pmv[i].depth == screen_depth) { bits_per_pixel = pmv[i].bits_per_pixel; break; } XFree(pmv); } if (bits_per_pixel == 0) bits_per_pixel = screen_depth; if (bits_per_pixel >= 24) setDither(False); red_offset = green_offset = blue_offset = 0; switch (getVisual()->c_class) { case TrueColor: { int i; // compute color tables unsigned long red_mask = getVisual()->red_mask, green_mask = getVisual()->green_mask, blue_mask = getVisual()->blue_mask; while (! (red_mask & 1)) { red_offset++; red_mask >>= 1; } while (! (green_mask & 1)) { green_offset++; green_mask >>= 1; } while (! (blue_mask & 1)) { blue_offset++; blue_mask >>= 1; } red_bits = 255 / red_mask; green_bits = 255 / green_mask; blue_bits = 255 / blue_mask; for (i = 0; i < 256; i++) { red_color_table[i] = i / red_bits; green_color_table[i] = i / green_bits; blue_color_table[i] = i / blue_bits; } } break; case PseudoColor: case StaticColor: { ncolors = colors_per_channel * colors_per_channel * colors_per_channel; if (ncolors > (1 << screen_depth)) { colors_per_channel = (1 << screen_depth) / 3; ncolors = colors_per_channel * colors_per_channel * colors_per_channel; } if (colors_per_channel < 2 || ncolors > (1 << screen_depth)) { fprintf(stderr, "BImageControl::BImageControl: invalid colormap size %d " "(%d/%d/%d) - reducing", ncolors, colors_per_channel, colors_per_channel, colors_per_channel); colors_per_channel = (1 << screen_depth) / 3; } colors = new XColor[ncolors]; if (! colors) { fprintf(stderr, "BImageControl::BImageControl: error allocating " "colormap\n"); exit(1); } int i = 0, ii, p, r, g, b,#ifdef ORDEREDPSEUDO bits = 256 / colors_per_channel;#else // !ORDEREDPSEUDO bits = 255 / (colors_per_channel - 1);#endif // ORDEREDPSEUDO red_bits = green_bits = blue_bits = bits; for (i = 0; i < 256; i++) red_color_table[i] = green_color_table[i] = blue_color_table[i] = i / bits; for (r = 0, i = 0; r < colors_per_channel; r++) for (g = 0; g < colors_per_channel; g++) for (b = 0; b < colors_per_channel; b++, i++) { colors[i].red = (r * 0xffff) / (colors_per_channel - 1); colors[i].green = (g * 0xffff) / (colors_per_channel - 1); colors[i].blue = (b * 0xffff) / (colors_per_channel - 1); ; colors[i].flags = DoRed|DoGreen|DoBlue; } basedisplay->grab(); for (i = 0; i < ncolors; i++) if (! XAllocColor(basedisplay->getXDisplay(), getColormap(), &colors[i])) { fprintf(stderr, "couldn't alloc color %i %i %i\n", colors[i].red, colors[i].green, colors[i].blue); colors[i].flags = 0; } else colors[i].flags = DoRed|DoGreen|DoBlue; basedisplay->ungrab(); XColor icolors[256]; int incolors = (((1 << screen_depth) > 256) ? 256 : (1 << screen_depth)); for (i = 0; i < incolors; i++) icolors[i].pixel = i; XQueryColors(basedisplay->getXDisplay(), getColormap(), icolors, incolors); for (i = 0; i < ncolors; i++) { if (! colors[i].flags) { unsigned long chk = 0xffffffff, pixel, close = 0; p = 2; while (p--) { for (ii = 0; ii < incolors; ii++) { r = (colors[i].red - icolors[i].red) >> 8; g = (colors[i].green - icolors[i].green) >> 8; b = (colors[i].blue - icolors[i].blue) >> 8; pixel = (r * r) + (g * g) + (b * b); if (pixel < chk) { chk = pixel; close = ii; } colors[i].red = icolors[close].red; colors[i].green = icolors[close].green; colors[i].blue = icolors[close].blue; if (XAllocColor(basedisplay->getXDisplay(), getColormap(), &colors[i])) { colors[i].flags = DoRed|DoGreen|DoBlue; break; } } } } } break; } case GrayScale: case StaticGray: {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -