static QPixmap makeOffline(unsigned flags, const QPixmap &p) { unsigned swapColor = flags & ICON_COLOR_MASK; QImage image = p.convertToImage(); unsigned int *data = (image.depth() > 8) ? (unsigned int *)image.bits() : (unsigned int *)image.colorTable(); int pixels = (image.depth() > 8) ? image.width()*image.height() : image.numColors(); for (int i = 0; i < pixels; i++){ QColor c(qRed(data[i]), qGreen(data[i]), qBlue(data[i])); int a = qAlpha(data[i]); int h, s, v; c.hsv(&h, &s, &v); if (swapColor){ h = (swapColor * 2 - h) & 0xFF; c.setHsv(h, s, v); }else{ c.setHsv(h, 0, v * 3 / 4); } data[i] = qRgba(c.red(), c.green(), c.blue(), a); } QPixmap pict; pict.convertFromImage(image); return pict; }
static bool SetTextureImage(TextureMap* texture, const QImage& image) { const uchar* bits = image.bits(); TextureMap::ImageFormat format; if (image.depth() == 24) { format = TextureMap::B8G8R8; } else if (image.depth() == 32) { format = TextureMap::B8G8R8A8; } else if (image.depth() == 8) { // Convert indexed color (paletted) to RGB before generating a texture QImage rgbImage = image.convertToFormat(QImage::Format_RGB888); return SetTextureImage(texture, rgbImage); } else { return false; } return texture->generate(bits, image.bytesPerLine() * image.height(), image.width(), image.height(), format); }
QPixmap QVNCIntegration::grabWindow(WId window, int x, int y, int width, int height) const { // qDebug() << "QVNCIntegration::grabWindow" << window << x << y << width << height; if (window == 0) { //desktop QImage *desktopImage = mPrimaryScreen->image(); if (x==0 && y == 0 && width < 0 && height < 0) { return QPixmap::fromImage(*desktopImage); } if (width < 0) width = desktopImage->width() - x; if (height < 0) height = desktopImage->height() - y; int bytesPerPixel = desktopImage->depth()/8; //We don't support 1, 2, or 4 bpp QImage img(desktopImage->scanLine(y) + bytesPerPixel*x, width, height, desktopImage->bytesPerLine(), desktopImage->format()); return QPixmap::fromImage(img); } QWidget *win = QWidget::find(window); if (win) { QRect r = win->geometry(); if (width < 0) width = r.width() - x; if (height < 0) height = r.height() - y; QImage *desktopImage = mPrimaryScreen->image(); int bytesPerPixel = desktopImage->depth()/8; //We don't support 1, 2, or 4 bpp QImage img(desktopImage->scanLine(r.top() + y) + bytesPerPixel*(r.left()+x), width, height, desktopImage->bytesPerLine(), desktopImage->format()); return QPixmap::fromImage(img); } return QPixmap(); }
void dimImage(QImage& image) { /* Todo: factor out the < 32bit case, cause this can be done a lot faster * by just processing every second line. */ for (int y = 0; y < image.height(); ++y) { QRgb *sl = (QRgb*)image.scanLine(y); if (y % 2) { if (image.depth() == 32) { for (int x = 0; x < image.width(); ++x) { const int gray = qGray(sl[x]) / 2; sl[x] = qRgba(gray, gray, gray, qAlpha(sl[x])); } } else ::memset(sl, 0, image.bytesPerLine()); } else { if (image.depth() == 32) { for (int x = 0; x < image.width(); ++x) { const int gray = (2 * qGray(sl[x])) / 3; sl[x] = qRgba(gray, gray, gray, qAlpha(sl[x])); } } } } }
void UIMachineView::dimImage(QImage &img) { for (int y = 0; y < img.height(); ++ y) { if (y % 2) { if (img.depth() == 32) { for (int x = 0; x < img.width(); ++ x) { int gray = qGray(img.pixel (x, y)) / 2; img.setPixel(x, y, qRgb (gray, gray, gray)); } } else { ::memset(img.scanLine (y), 0, img.bytesPerLine()); } } else { if (img.depth() == 32) { for (int x = 0; x < img.width(); ++ x) { int gray = (2 * qGray (img.pixel (x, y))) / 3; img.setPixel(x, y, qRgb (gray, gray, gray)); } } } } }
bool readPGFImageData(const QByteArray& data, QImage& img, bool verbose) { try { if (data.isEmpty()) { kDebug() << "PGF image data to decode : size is null"; return false; } CPGFMemoryStream stream((UINT8*)data.data(), (size_t)data.size()); if (verbose) kDebug() << "image data stream size is : " << stream.GetSize(); CPGFImage pgfImg; // NOTE: see bug #273765 : Loading PGF thumbs with OpenMP support through a separated thread do not work properlly with libppgf 6.11.24 pgfImg.ConfigureDecoder(false); pgfImg.Open(&stream); if (verbose) kDebug() << "PGF image is open"; if (pgfImg.Channels() != 4) { kDebug() << "PGF channels not supported"; return false; } img = QImage(pgfImg.Width(), pgfImg.Height(), QImage::Format_ARGB32); pgfImg.Read(); if (verbose) kDebug() << "PGF image is read"; if (QSysInfo::ByteOrder == QSysInfo::BigEndian) { int map[] = {3, 2, 1, 0}; pgfImg.GetBitmap(img.bytesPerLine(), (UINT8*)img.bits(), img.depth(), map); } else { int map[] = {0, 1, 2, 3}; pgfImg.GetBitmap(img.bytesPerLine(), (UINT8*)img.bits(), img.depth(), map); } if (verbose) kDebug() << "PGF image is decoded"; } catch (IOException& e) { int err = e.error; if (err >= AppError) { err -= AppError; } kDebug() << "Error running libpgf (" << err << ")!"; return false; } return true; }
UI_EXPORT QPixmap& intensity(QPixmap &pict, float percent) { QImage image = pict.convertToImage(); int i, tmp, r, g, b; int segColors = image.depth() > 8 ? 256 : image.numColors(); unsigned char *segTbl = new unsigned char[segColors]; int pixels = image.depth() > 8 ? image.width()*image.height() : image.numColors(); unsigned int *data = image.depth() > 8 ? (unsigned int *)image.bits() : (unsigned int *)image.colorTable(); bool brighten = (percent >= 0); if(percent < 0) percent = -percent; if(brighten){ // keep overflow check out of loops for(i=0; i < segColors; ++i){ tmp = (int)(i*percent); if(tmp > 255) tmp = 255; segTbl[i] = (unsigned char)tmp; } } else{ for(i=0; i < segColors; ++i){ tmp = (int)(i*percent); if(tmp < 0) tmp = 0; segTbl[i] = (unsigned char)tmp; } } if(brighten){ // same here for(i=0; i < pixels; ++i){ r = qRed(data[i]); g = qGreen(data[i]); b = qBlue(data[i]); r = r + segTbl[r] > 255 ? 255 : r + segTbl[r]; g = g + segTbl[g] > 255 ? 255 : g + segTbl[g]; b = b + segTbl[b] > 255 ? 255 : b + segTbl[b]; data[i] = qRgb(r, g, b); } } else{ for(i=0; i < pixels; ++i){ r = qRed(data[i]); g = qGreen(data[i]); b = qBlue(data[i]); r = r - segTbl[r] < 0 ? 0 : r - segTbl[r]; g = g - segTbl[g] < 0 ? 0 : g - segTbl[g]; b = b - segTbl[b] < 0 ? 0 : b - segTbl[b]; data[i] = qRgb(r, g, b); } } delete [] segTbl; pict.convertFromImage(image); return pict; }
void ImageImporter::execute() { if (mFilename == "") throw Exception("No filename was supplied to the ImageImporter"); uchar* convertedPixelData; // Load image from disk using Qt QImage image; reportInfo() << "Trying to load image..." << Reporter::end(); if(!image.load(mFilename.c_str())) { throw FileNotFoundException(mFilename); } reportInfo() << "Loaded image with size " << image.width() << " " << image.height() << Reporter::end(); QImage::Format format; if(mGrayscale) { format = QImage::Format_Grayscale8; } else { format = QImage::Format_RGB888; } QImage convertedImage = image.convertToFormat(format); // Get pixel data convertedPixelData = convertedImage.bits(); Image::pointer output = getOutputData<Image>(); std::cout << "image info" << std::endl; std::cout << convertedImage.width() << std::endl; std::cout << convertedImage.depth() << std::endl; std::cout << convertedImage.bytesPerLine() << std::endl; if(convertedImage.width()*convertedImage.depth()/8 != convertedImage.bytesPerLine()) { const int bytesPerPixel = (convertedImage.depth()/8); std::unique_ptr<uchar[]> fixedPixelData = std::make_unique<uchar[]>(image.width()*image.height()); // Misalignment for(int scanline = 0; scanline < image.height(); ++scanline) { std::memcpy( &fixedPixelData[scanline*image.width()*bytesPerPixel], &convertedPixelData[scanline*convertedImage.bytesPerLine()], image.width()*bytesPerPixel ); } output->create( image.width(), image.height(), TYPE_UINT8, mGrayscale ? 1 : 3, getMainDevice(), fixedPixelData.get() ); } else { output->create( image.width(), image.height(), TYPE_UINT8, mGrayscale ? 1 : 3, getMainDevice(), convertedPixelData ); } }
// Check the file for being a readable QImage and set up parameters int iiQImageCheck(ImodImageFile *inFile) { QImage *image; if (!inFile) return IIERR_BAD_CALL; image = new QImage(QString(inFile->filename)); if (image->isNull()) { delete image; return IIERR_NOT_FORMAT; } if (image->depth() < 8) { delete image; b3dError(NULL, "%s is a recognized file type but data type is not " "supported\n", inFile->filename); return IIERR_NO_SUPPORT; } if(inFile->fp) fclose(inFile->fp); inFile->nx = image->width(); inFile->ny = image->height(); inFile->nz = 1; inFile->file = IIFILE_QIMAGE; inFile->type = IITYPE_UBYTE; inFile->amean = 128; inFile->amax = 255; inFile->smax = 255; // Grayscale images have depth 8 and color tables that are gray if (image->depth() == 8 && image->isGrayscale()) { inFile->format = IIFORMAT_LUMINANCE; inFile->readSectionByte = qimageReadSectionByte; inFile->readSectionFloat = qimageReadSectionFloat; inFile->mode = MRC_MODE_BYTE; } else { // Otherwise images will be read as RGB inFile->format = IIFORMAT_RGB; inFile->mode = MRC_MODE_RGB; inFile->readSection = qimageReadSection; } // Imitate TIFF for some of these behaviors - close file, assign image to // header but not fp here, assign to fp when reopen inFile->headerSize = 8; inFile->header = (char *)image; inFile->cleanUp = qimageClose; inFile->reopen = qimageReopen; inFile->close = qimageClose; inFile->fillMrcHeader = tiffFillMrcHeader; return 0; }
void ColibriMainWindow::on_grabTimer_timeout() { QPixmap desktopPixmap = QPixmap::grabWindow( //QApplication::activeWindow()->winId()); QApplication::desktop()->winId()); fprintf(stderr, "%s:%d: desktopImage=%dx%dx%d\n", __func__, __LINE__, desktopPixmap.width(), desktopPixmap.height(), desktopPixmap.depth()); //desktopPixmap.save("/tmp/desktop.png"); //QApplication::activeWindow()->show(); // Crop where the window is fprintf(stderr, "%s:%d: curpos=%dx%d+%dx%d\n", __func__, __LINE__, m_grabRect.x(), m_grabRect.y(), m_grabRect.width(), m_grabRect.height()); QImage desktopImage; desktopImage = ( desktopPixmap.copy(m_grabRect).toImage() ); if(desktopImage.isNull()) { fprintf(stderr, "%s:%d: desktopImage is null !\n", __func__, __LINE__); return; } fprintf(stderr, "%s:%d: desktopImage=%dx%dx%d\n", __func__, __LINE__, desktopImage.width(), desktopImage.height(), desktopImage.depth()); IplImage * iplImage = cvCreateImage(cvSize(desktopImage.width(), desktopImage.height()), IPL_DEPTH_8U, desktopImage.depth()/8); memcpy(iplImage->imageData, (char *)desktopImage.bits(), iplImage->widthStep*iplImage->height); // // We have to set the alpha flag // u8 * alpha = (u8 *) iplImage->imageData; // for(int pos = 3; pos <iplImage->widthStep*iplImage->height; pos+=4) // { // alpha[pos] = 255; // } // cvSaveImage("/dev/shm/unprocessed.png", iplImage); computeImage(iplImage); // cvSaveImage("/dev/shm/processed.png", iplImage); show(); tmReleaseImage(&iplImage); }
cv::Mat QImage2MatDialog::qImage2MatPtr(QImage& qImg) { int qImgWidth = qImg.width(); int qImgHeight = qImg.height(); int qImgDepth = qImg.depth(); int imgChannels = qImgDepth/8; int byterPerLine = qImg.bytesPerLine(); #if 0 qDebug() << qImg.format() << " " << qImg.depth(); #endif cv::Mat mat; if ( qImg.format() == QImage::Format_ARGB32 || qImg.format() == QImage::Format_RGB888 || qImg.format() == QImage::Format_Indexed8 || qImg.format() == QImage::Format_ARGB32_Premultiplied ) { cv::Mat(qImg.height(), qImg.width(), CV_MAKETYPE(CV_8U, qImgDepth/8), cv::Scalar::all(0)).copyTo(mat); uchar* data_qimg = qImg.bits(); uchar* data_mat = (uchar*)mat.data; for ( int i=0; i<qImgHeight; i++ ) for ( int j=0; j<qImgWidth; j++ ) for ( int k=0; k<imgChannels; k++ ) data_mat[(i*qImgWidth+j)*imgChannels + k] = data_qimg[i*byterPerLine+j*imgChannels + k]; data_mat = NULL; data_qimg = NULL; } else if ( qImg.format() == QImage::Format_RGB32 ) { cv::Mat(qImg.height(), qImg.width(), CV_MAKETYPE(CV_8U, 3), cv::Scalar::all(0)).copyTo(mat); uchar* data_qimg = qImg.bits(); uchar* data_mat = (uchar*)mat.data; for ( int i=0; i<qImgHeight; i++ ) { for ( int j=0; j<qImgWidth; j++ ) { data_mat[(i*qImgWidth+j)*3] = data_qimg[i*byterPerLine+j*4]; // B data_mat[(i*qImgWidth+j)*3+1] = data_qimg[i*byterPerLine+j*4+1]; // G data_mat[(i*qImgWidth+j)*3+2] = data_qimg[i*byterPerLine+j*4+2]; // R } } } else { qDebug() << "Image Format Unknown!\n"; } return mat; }
static QImage toRgba(const QImage& image, int alpha) { if ( alpha < 0 || alpha >= 255 ) return image; #if QT_VERSION < 0x040000 QImage alphaImage(image.size(), 32); alphaImage.setAlphaBuffer(true); #else QImage alphaImage(image.size(), QImage::Format_ARGB32); #endif const QRgb mask1 = qRgba(0, 0, 0, alpha); const QRgb mask2 = qRgba(255, 255, 255, 0); const QRgb mask3 = qRgba(0, 0, 0, 255); const int w = image.size().width(); const int h = image.size().height(); if ( image.depth() == 8 ) { for ( int y = 0; y < h; y++ ) { QRgb* alphaLine = (QRgb*)alphaImage.scanLine(y); const unsigned char *line = image.scanLine(y); for ( int x = 0; x < w; x++ ) *alphaLine++ = (image.color(*line++) & mask2) | mask1; } } else if ( image.depth() == 32 ) { for ( int y = 0; y < h; y++ ) { QRgb* alphaLine = (QRgb*)alphaImage.scanLine(y); const QRgb* line = (const QRgb*) image.scanLine(y); for ( int x = 0; x < w; x++ ) { const QRgb rgb = *line++; if ( rgb & mask3 ) // alpha != 0 *alphaLine++ = (rgb & mask2) | mask1; else *alphaLine++ = rgb; } } } return alphaImage; }
void drawOver( QImage& dst, QRect const& dst_rect, QImage const& src, QRect const& src_rect) { if (src_rect.size() != dst_rect.size()) { throw std::invalid_argument("drawOver: source and destination areas have different sizes"); } if (dst.format() != src.format()) { throw std::invalid_argument("drawOver: source and destination have different formats"); } if (dst_rect.intersected(dst.rect()) != dst_rect) { throw std::invalid_argument("drawOver: destination area exceeds the image"); } if (src_rect.intersected(src.rect()) != src_rect) { throw std::invalid_argument("drawOver: source area exceeds the image"); } uint8_t* dst_line = dst.bits(); int const dst_bpl = dst.bytesPerLine(); uint8_t const* src_line = src.bits(); int const src_bpl = src.bytesPerLine(); int const depth = src.depth(); assert(dst.depth() == depth); if (depth % 8 != 0) { assert(depth == 1); // Slow but simple. BinaryImage dst_bin(dst); BinaryImage src_bin(src); rasterOp<RopSrc>(dst_bin, dst_rect, src_bin, src_rect.topLeft()); dst = dst_bin.toQImage().convertToFormat(dst.format()); // FIXME: we are not preserving the color table. return; } int const stripe_bytes = src_rect.width() * depth / 8; dst_line += dst_bpl * dst_rect.top() + dst_rect.left() * depth / 8; src_line += src_bpl * src_rect.top() + src_rect.left() * depth / 8; for (int i = src_rect.height(); i > 0; --i) { memcpy(dst_line, src_line, stripe_bytes); dst_line += dst_bpl; src_line += src_bpl; } }
LabelImage::LabelImage(const QImage& qim): Image<signed char>( qim.width(), qim.height() ) { if (qim.depth() > 8) qWarning( "Image format not supported! Expected 8 bit image!" ); for( int j=0; j<height(); j++ ) for( int i=0; i<width(); i++ ) (*this)(i,j) = qim.pixel( i, j ); }
CGoGN_UTILS_API unsigned char* loadRGB(const std::string& filename, int& w, int& h, int &d, float& vx, float& vy, float& vz, int& tag) { QImage* ptrImg = new QImage(filename.c_str()); if (ptrImg==NULL) return NULL; // get the info of 2D image w = ptrImg->width(); h = ptrImg->height(); unsigned int bpp = ptrImg->depth(); // image OK ? if ((bpp!=24)) return NULL; unsigned char* ptr=ptrImg->bits(); int* ptr_int = reinterpret_cast<int*>(ptr+3*(w*(h-1))); int t = *ptr_int++; if (t!= RGB8) return NULL; tag = *ptr_int++; w = *ptr_int++; h = *ptr_int++; d = *ptr_int++; float* ptr_float = reinterpret_cast<float*>(ptr_int); vx = *ptr_float++; vy = *ptr_float++; vz = *ptr_float++; unsigned char* ptr2 = new unsigned char[3*w*h*d]; memcpy (ptr2, ptr, 3*w*h*d); delete ptrImg; return ptr2; }
CGImageRef qt_mac_image_to_cgimage(const QImage &image) { int bitsPerColor = 8; int bitsPerPixel = 32; if (image.depth() == 1) { bitsPerColor = 1; bitsPerPixel = 1; } QCFType<CGDataProviderRef> provider = CGDataProviderCreateWithData(0, image.bits(), image.bytesPerLine() * image.height(), 0); uint cgflags = kCGImageAlphaPremultipliedFirst; #ifdef kCGBitmapByteOrder32Host //only needed because CGImage.h added symbols in the minor version cgflags |= kCGBitmapByteOrder32Host; #endif CGImageRef cgImage = CGImageCreate(image.width(), image.height(), bitsPerColor, bitsPerPixel, image.bytesPerLine(), QCoreGraphicsPaintEngine::macGenericColorSpace(), cgflags, provider, 0, 0, kCGRenderingIntentDefault); return cgImage; }
/*! Returns a QImage pointer which represents the actual buffer the \a widget is drawn into or 0 if this is unavailable. You must call beginPaint() before you call this function and the returned pointer is only valid until endPaint() is called. */ QImage* QWindowSurface::buffer(const QWidget *widget) { if (widget->window() != window()) return 0; QPaintDevice *pdev = paintDevice(); if (!pdev || pdev->devType() != QInternal::Image) return 0; const QPoint off = offset(widget); QImage *img = static_cast<QImage*>(pdev); QRect rect(off, widget->size()); rect &= QRect(QPoint(), img->size()); if (rect.isEmpty()) return 0; img = new QImage(img->scanLine(rect.y()) + rect.x() * img->depth() / 8, rect.width(), rect.height(), img->bytesPerLine(), img->format()); d_ptr->bufferImages.append(img); return img; }
void QDirectFBPixmapData::fromImage(const QImage &img, Qt::ImageConversionFlags flags) { alpha = QDirectFBPixmapData::hasAlphaChannel(img, flags); imageFormat = alpha ? screen->alphaPixmapFormat() : screen->pixelFormat(); QImage image; if ((flags & ~Qt::NoOpaqueDetection) != Qt::AutoColor) { image = img.convertToFormat(imageFormat, flags); flags = Qt::AutoColor; } else if (img.format() == QImage::Format_RGB32 || img.depth() == 1) { image = img.convertToFormat(imageFormat, flags); } else if (img.format() != imageFormat) { image = img.convertToFormat(imageFormat, flags); } else { image = img; } dfbSurface = screen->createDFBSurface(image, image.format(), QDirectFBScreen::NoPreallocated | QDirectFBScreen::TrackSurface); if (!dfbSurface) { qWarning("QDirectFBPixmapData::fromImage()"); invalidate(); return; } w = image.width(); h = image.height(); is_null = (w <= 0 || h <= 0); d = QDirectFBScreen::depth(imageFormat); setSerialNumber(++global_ser_no); #ifdef QT_NO_DIRECTFB_OPAQUE_DETECTION Q_UNUSED(flags); #endif }
void QDirectFBPixmapData::fromImage(const QImage &i, Qt::ImageConversionFlags flags) { #ifdef QT_NO_DIRECTFB_OPAQUE_DETECTION Q_UNUSED(flags); #endif const QImage img = (i.depth() == 1 ? i.convertToFormat(screen->alphaPixmapFormat()) : i); if (img.hasAlphaChannel() #ifndef QT_NO_DIRECTFB_OPAQUE_DETECTION && (flags & Qt::NoOpaqueDetection || QDirectFBPixmapData::hasAlphaChannel(img)) #endif ) { alpha = true; format = screen->alphaPixmapFormat(); } else { alpha = false; format = screen->pixelFormat(); } dfbSurface = screen->copyToDFBSurface(img, format, QDirectFBScreen::TrackSurface); if (!dfbSurface) { qWarning("QDirectFBPixmapData::fromImage()"); invalidate(); return; } setSerialNumber(++global_ser_no); }
static QPixmap makeInvisible(unsigned flags, const QPixmap &p) { unsigned swapColor = flags & ICON_COLOR_MASK; char shift = (flags >> 8) & 0xFF; QImage image = p.convertToImage(); if (image.depth() != 32) image = image.convertDepth(32); unsigned int *data = (unsigned int*)image.bits(); for (int y = 0; y < image.width(); y++){ int x = image.width() / 2 - (y - image.height() / 2) * 2 / 3 + shift; if (x < 0) x = 0; if (x > image.width()) x = image.width(); unsigned int *line = data + y * (image.width()) + x; for (; x < image.width(); x++, line++){ QColor c(qRed(*line), qGreen(*line), qBlue(*line)); int a = qAlpha(*line); int h, s, v; c.hsv(&h, &s, &v); if (swapColor){ h = (swapColor * 2 - h) & 0xFF; c.setHsv(h, s / 2, v * 3 / 4); }else{ c.setHsv(h, s / 2, v * 3 / 4); } *line = qRgba(c.red(), c.green(), c.blue(), a); } } QPixmap pict; pict.convertFromImage(image); return pict; }
QImage* QS60WindowSurface::buffer(const QWidget *widget) { if (widget->window() != window()) return 0; QPaintDevice *pdev = paintDevice(); if (!pdev) return 0; const QPoint off = offset(widget); QImage *img = &(static_cast<QS60PixmapData *>(d_ptr->device.data_ptr().data())->image); QRect rect(off, widget->size()); rect &= QRect(QPoint(), img->size()); if (rect.isEmpty()) return 0; img = new QImage(img->scanLine(rect.y()) + rect.x() * img->depth() / 8, rect.width(), rect.height(), img->bytesPerLine(), img->format()); d_ptr->bufferImages.append(img); return img; }
QImage fullscreen::clipImage(const QImage& srcImage, QRect rect)//区域截图,将指定位置的图像复制到和选框相同大小的空image上 { QImage image(rect.size(), QImage::Format_RGB32); const QImage* target = &srcImage; QImage targetImg; if ( srcImage.depth() != 32 ) { targetImg = srcImage.convertToFormat(QImage::Format_RGB32); target = &targetImg; } int bytesPerPixel = image.depth() / 8; for ( int i = 0 ; i < image.height() ; ++ i ) { uchar * line = image.scanLine(i); const uchar * srcLine = target->scanLine(rect.top() + i); memcpy(line, srcLine + rect.left() * bytesPerPixel, rect.width() * bytesPerPixel); } return image; }
const QString ImageTransformer:: toTXT(int linelen) { int lineLength = linelen; QString result; if(_DataHandled.width()!=0) { result.clear(); QString mask("@&%$#*:. "); int step = 256/mask.size(); QImage ImageBuf = _DataHandled.scaled(lineLength, lineLength*_DataHandled.height()/_DataHandled.width()); int width = ImageBuf.width(); int height = ImageBuf.height(); int depth = ImageBuf.depth(); if(depth == 32) { toGrayscale(ImageBuf); for(int j=0;j+1<height;j+=2) { for(int i=0;i<width;++i) { result.append(mask[(QColor(ImageBuf.pixel(i,j)).red() + QColor(ImageBuf.pixel(i,j+1)).red())/2/step]); } result.append("\r\n"); } } } return result; }
void SyImageBase::loadQImage(const QImage &imageIn) { SProfileFunction int width = imageIn.width(); int height = imageIn.height(); XVector<float> data; data.resize(width * height); xsize bytesPerPixel = imageIn.depth()/8; const quint8 *pixel = imageIn.bits(); for(int i = 0; i < height; ++i ) { xsize rowPos = i * width; for(int j = 0; j < width; ++j) { data[rowPos+j] = (float)*pixel/255.0f; pixel += bytesPerPixel; } } image.set(width, height, data); postSet(); }
bool ImageCreator::create(const QString &path, int, int, QImage &img) { // create image preview if (!img.load( path )) return false; if (img.depth() != 32) img = img.convertToFormat(img.hasAlphaChannel() ? QImage::Format_ARGB32 : QImage::Format_RGB32); return true; }
static QPixmap swapRG(const QPixmap &p) { QImage image = p.convertToImage(); unsigned int *data = (image.depth() > 8) ? (unsigned int *)image.bits() : (unsigned int *)image.colorTable(); int pixels = (image.depth() > 8) ? image.width()*image.height() : image.numColors(); for (int i = 0; i < pixels; i++){ int r = qRed(data[i]); int g = qGreen(data[i]); int b = qBlue(data[i]); int a = qAlpha(data[i]); data[i] = qRgba(g, r, b, a); } QPixmap pict; pict.convertFromImage(image); return pict; }
static QPixmap makeInactive(const QPixmap &p) { QImage image = p.convertToImage(); unsigned int *data = (image.depth() > 8) ? (unsigned int *)image.bits() : (unsigned int *)image.colorTable(); int pixels = (image.depth() > 8) ? image.width()*image.height() : image.numColors(); for (int i = 0; i < pixels; i++){ QColor c(qRed(data[i]), qGreen(data[i]), qBlue(data[i])); int a = qAlpha(data[i]); int h, s, v; c.hsv(&h, &s, &v); c.setHsv(h, s / 8, v); data[i] = qRgba(c.red(), c.green(), c.blue(), a); } QPixmap pict; pict.convertFromImage(image); return pict; }
QImage QFontEngineDirectWrite::alphaRGBMapForGlyph(glyph_t t, QFixed subPixelPosition, int margin, const QTransform &xform) { QImage mask = imageForGlyph(t, subPixelPosition, margin, xform); return mask.depth() == 32 ? mask : mask.convertToFormat(QImage::Format_RGB32); }
bool readPGFImageData(const QByteArray& data, QImage& img) { try { CPGFMemoryStream stream((UINT8*)data.data(), (size_t)data.size()); CPGFImage pgfImg; pgfImg.Open(&stream); if (pgfImg.Channels() != 4) { kDebug() << "PGF channels not supported"; return false; } img = QImage(pgfImg.Width(), pgfImg.Height(), QImage::Format_ARGB32); pgfImg.Read(); if (QSysInfo::ByteOrder == QSysInfo::BigEndian) { int map[] = {3, 2, 1, 0}; pgfImg.GetBitmap(img.bytesPerLine(), (UINT8*)img.bits(), img.depth(), map); } else { int map[] = {0, 1, 2, 3}; pgfImg.GetBitmap(img.bytesPerLine(), (UINT8*)img.bits(), img.depth(), map); } } catch (IOException& e) { int err = e.error; if (err >= AppError) { err -= AppError; } kDebug() << "Error running libpgf (" << err << ")!"; return false; } return true; }
void BatteryConfig::ConvertIcon(int percent, QPixmap &pm, QPixmap &result) { QImage image = pm.convertToImage(); int w = image.width(); int h = image.height(); int count = 0; QRgb rgb; int x, y; for (x = 0; x < w; x++) for (y = 0; y < h; y++) { rgb = image.pixel(x, y); if (qRed(rgb) == 0xff && qGreen(rgb) == 0xff && qBlue(rgb) == 0xff) count++; } int c = (count*percent)/100; if (percent == 100) { c = count; } else if (percent != 100 && c == count) c = count-1; if (c) { uint ui; QRgb blue = qRgb(0x00,0x00,0xff); if (image.depth() <= 8) { ui = image.numColors(); // this fix thanks to Sven Krumpke image.setNumColors(ui+1); image.setColor(ui, blue); } else { ui = 0xff000000|blue; } for (y = h-1; y >= 0; y--) for (x = 0; x < w; x++) { rgb = image.pixel(x, y); if (qRed(rgb) == 0xff && qGreen(rgb) == 0xff && qBlue(rgb) == 0xff) { image.setPixel(x, y, ui); c--; if (c <= 0) goto quit; } } } quit: result.convertFromImage(image); }