QImage XCursorThemeData::loadImage (const QString &name, int size) const { if (size == -1) size = XcursorGetDefaultSize(QX11Info::display()); // Load the image XcursorImage *xcimage = xcLoadImage(name, size); if (!xcimage) xcimage = xcLoadImage(findAlternative(name), size); // Fall back to a legacy cursor //if (!xcimage) return LegacyTheme::loadImage(name); if (!xcimage) return QImage(); // Convert the XcursorImage to a QImage, and auto-crop it QImage image((uchar *)xcimage->pixels, xcimage->width, xcimage->height, QImage::Format_ARGB32_Premultiplied); image = autoCropImage(image); XcursorImageDestroy(xcimage); return image; }
QImage XCursorTheme::loadImage(const QString &name, int size) const { if (size <= 0) size = autodetectCursorSize(); // Load the image XcursorImage *xcimage = xcLoadImage(name, size); if (!xcimage) xcimage = xcLoadImage(findAlternative(name), size); if (!xcimage) { return QImage(); } // Convert the XcursorImage to a QImage, and auto-crop it QImage image((uchar *)xcimage->pixels, xcimage->width, xcimage->height, QImage::Format_ARGB32_Premultiplied ); image = autoCropImage(image); XcursorImageDestroy(xcimage); return image; }
int main(int argc, char *argv[]) { image myPic; imageInfo picInfo; int count; char *outputType = NULL; int err; int aCrop = NO; int left = -1, right = -1, top = -1, bottom = -1; double xscale = 1, yscale = 1; double xs2, ys2; int xdim = 0, ydim = 0; int ditherMode = ' '; int mMono = NO; int outType = NO; int scaletofit = NO; int numBits = 1; char *outFile = NULL; char *type = NULL, *ext = NULL; char *p; int nv; double darken = 0; double contrast = 0; double rotate = 0; struct stat sbuf; int blend = NO; static char filename[MAXPATHLEN + 1] = ""; int negative = NO; int enhance = NO; formatInfo fInfo; count = getargs(argc, argv, "nbosabLiRiTiBixdydXiYidcmbpbsbbiDdSbKdfseird", &negative, &outputType, &aCrop, &left, &right, &top, &bottom, &xscale, &yscale, &xdim, &ydim, &ditherMode, &mMono, &outType, &scaletofit, &numBits, &darken, &blend, &contrast, &outFile, &enhance, &rotate ); if (count < 0 || count == argc) { if (count < 0 && -count != '-') fprintf(stderr, "Bad flag: %c\n", -count); fprintf(stderr, "Usage: %s [-options] filename\n" " options:\n" "\tn: make negative\n" "\to: string indicating output format\n" "\ta: auto crop non plotting areas\n" "\tL, R, T, B: specify where to crop picture\n" "\tx, y: specify scale factor in that direction\n" "\tX, Y: specify dimension of picture in that direction\n" "\td: select dither method: (D)ither, (T)hreshold, or (H)alftone\n" "\tm: convert image to monochrome\n" "\tp: dither image for output to printer\n" "\ts: scale image to fill up specified screen\n" "\tb: number of bits to dither to\n" "\tD: how much to brighten image\n" "\tK: contrast level\n" "\tS: blend pixels together when scaling\n" "\tf: file name to save to\n" "\te: contrast for enhance image\n" "\tr: number of degrees to rotate\n" , *argv); exit(1); } for (; count < argc; count++) { if ((err = load_pic(argv[count], &myPic))) { fprintf(stderr, "Cannot load file %s\nError: %s\n", argv[count], picErrorStr(err)); exit(1); } if (!getImageInfo(argv[count], &picInfo)) type = picInfo.extension; if (!outputType) outputType = type; if (!infoForFormat(outputType, &fInfo)) { ext = fInfo.extension; if (scaletofit && !xdim && !ydim && fInfo.maxWidth && fInfo.maxHeight) { xdim = fInfo.maxWidth; ydim = fInfo.maxHeight; } } if (mMono) makeMono(&myPic); if (left >= 0 || right >= 0 || top >= 0 || bottom >= 0) { if (left < 0) left = 0; if (right < 0) right = myPic.width - 1; if (top < 0) top = 0; if (bottom < 0) bottom = myPic.height - 1; cropImage(left, top, right, bottom, &myPic); } if (aCrop) autoCropImage(&myPic, 40); if (rotate) rotateImage(&myPic, (rotate * -3.141592) / 180.0); xs2 = xscale; ys2 = yscale; if (scaletofit) { if (!ydim && xdim) { xs2 = (double) xdim / ((double) myPic.width * xscale) * xscale; ys2 = ((double) xdim / ((double) myPic.width * xscale)) * yscale; } else if (ydim) { xs2 = ((double) ydim / ((double) myPic.height * yscale)) * xscale; ys2 = (double) ydim / ((double) myPic.height * yscale) * yscale; if (xdim && (myPic.width * xs2) > xdim) { xs2 = (double) xdim / ((double) myPic.width * xscale) * xscale; ys2 = ((double) xdim / ((double) myPic.width * xscale)) * yscale; } } } else { if (xdim) xs2 = (double) xdim / (double) myPic.width; if (ydim) ys2 = (double) ydim / (double) myPic.height; } xscale = xs2; yscale = ys2; scaleImage(xscale, yscale, blend, &myPic); if (darken || contrast) adjustImage(&myPic, contrast, darken); if (enhance) { makeMono(&myPic); enhanceImage(&myPic, enhance); } handle_dithering(ditherMode, &myPic, outType, numBits); if (negative) negateImage(&myPic); if (outFile) { strcpy(filename, outFile); if (!stat(filename, &sbuf) && (sbuf.st_mode & S_IFDIR)) { if (filename[strlen(filename) - 1] != '/') strcat(filename, "/"); if ((p = strrchr(argv[count], '/'))) strcat(filename, p + 1); else strcat(filename, argv[count]); } } else strcpy(filename, argv[count]); p = change_extension(filename, type, ext, 0); nv = 2; while (!stat(p, &sbuf)) { p = change_extension(filename, type, ext, nv); nv++; } if ((err = save_pic(p, outputType, &myPic))) { fprintf(stderr, "Cannot save file %s\nError: %s\n", p, picErrorStr(err)); exit(1); } fprintf(stderr, "Saved %s as %s\n", argv[count], p); freeImage(&myPic); } exit(0); return 0; }