void KisImageLoader::run() { typedef QHash<KisImageItem*,Data>::iterator Iterator; QImageReader reader; for(Iterator data=m_data.begin(); data!=m_data.end() && m_run; ++data) { reader.setFileName(data->path); qreal w = m_size; qreal h = m_size; if(reader.supportsOption(QImageIOHandler::Size)) { QSizeF imgSize = reader.size(); if(imgSize.width() > imgSize.height()) { qreal div = m_size / imgSize.width(); h = imgSize.height() * div; } else { qreal div = m_size / imgSize.height(); w = imgSize.width() * div; } } reader.setScaledSize(QSize(w,h)); data->image = reader.read(); data->isLoaded = true; emit sigItemContentChanged(data.key()); } }
bool readImageWithPrescale(QImageReader& reader, QImage& image, double& prescaleFactor) { // used to scale the file before it is actually read to memory prescaleFactor = 1.0; int height = reader.size().height(); if(height > HALF_DECIMATION_THRESHOLD_H) prescaleFactor = 0.5; else if(height > QUARTER_DECIMATION_THRESHOLD_H) prescaleFactor = 0.25; else if(height > EIGHTH_DECIMATION_THRESHOLD_H) prescaleFactor = 0.125; if(prescaleFactor != 1.0) reader.setScaledSize(QSize(reader.size().width() * prescaleFactor, reader.size().height() * prescaleFactor)); return reader.read(&image); }
unsigned long syImgReaderCodec::GetWidth() { if(!m_Reader) { return 0; } int width = m_Reader->size().width(); if(width < 0) { return 0; } return width; }
unsigned long syImgReaderCodec::GetHeight() { if(!m_Reader) { return 0; } int height = m_Reader->size().height(); if(height < 0) { return 0; } return height; }
void imgwidgetThumbThread::setimg(int i){ float multiple = 0;//倍数 QImage img; Image imgFlag72; imgFlag72.load("../bkbig.png"); double tim = static_cast<double>(getTickCount()); QImageReader * imgread = new QImageReader(allImgs.at(i).absoluteFilePath()); tim = ((double)getTickCount()- tim)/getTickFrequency(); //qDebug()<<"tim----------------"<<tim; if(!imgread->canRead()){ imgread->setFileName("../picture_error.png"); } QSize size = imgread->size(); multiple = (imgread->size().width()/72.0>imgread->size().height()/48.0 ?imgread->size().width()/72.0:imgread->size().height()/48.0); if(multiple>0) imgread->setScaledSize(imgread->size()/multiple); int x = (72-imgread->scaledSize().width())/2.0; int y = (48-imgread->scaledSize().height())/2.0; if(imgread->read(&img)) { imgFlag72.painter(img,x,y,72,48); double tim = static_cast<double>(getTickCount()); //imgFlag36 = imgFlag72.copy(18,0,36,48); // tim = ((double)getTickCount()- tim)/getTickFrequency(); // qDebug()<<"tim----------------"<<tim<<i<<selectedNum; emit sendThumb(imgFlag72,img,size,i); } }
void RefImage::thumbFromFile() { QFile file(imagePath()); if (file.exists()) { QImageReader* imageReader = new QImageReader(imagePath()); int imageWidth = imageReader->size().width() * (float)CAROUSEL_HEIGHT/imageReader->size().height(); int imageHeight = CAROUSEL_HEIGHT; imageReader->setScaledSize(QSize(imageWidth, imageHeight)); QImage image; if (imageReader->read(&image)) { insertThumb(QPixmap::fromImage(image)); } else { qDebug() << "read failed"; } } }
void Document::pages( QVector<Okular::Page*> * pagesVector ) { qSort( mEntries.begin(), mEntries.end(), caseSensitiveNaturalOrderLessThen ); QScopedPointer< QIODevice > dev; int count = 0; pagesVector->clear(); pagesVector->resize( mEntries.size() ); QImageReader reader; foreach(const QString &file, mEntries) { if ( mArchive ) { const KArchiveFile *entry = static_cast<const KArchiveFile*>( mArchiveDir->entry( file ) ); if ( entry ) { dev.reset( entry->createDevice() ); } } else if ( mDirectory ) { dev.reset( mDirectory->createDevice( file ) ); } else { dev.reset( mUnrar->createDevice( file ) ); } if ( ! dev.isNull() ) { reader.setDevice( dev.data() ); if ( reader.canRead() ) { QSize pageSize = reader.size(); if ( !pageSize.isValid() ) { const QImage i = reader.read(); if ( !i.isNull() ) pageSize = i.size(); } if ( pageSize.isValid() ) { pagesVector->replace( count, new Okular::Page( count, pageSize.width(), pageSize.height(), Okular::Rotation0 ) ); mPageMap.append(file); count++; } else { qCDebug(OkularComicbookDebug) << "Ignoring" << file << "doesn't seem to be an image even if QImageReader::canRead returned true"; } } } } pagesVector->resize( count ); }
QPixmap loadPixmap(const QString &path) { qreal ratio = 1.0; QPixmap pixmap; const qreal devicePixelRatio = qApp->devicePixelRatio(); if (!qFuzzyCompare(ratio, devicePixelRatio)) { QImageReader reader; reader.setFileName(qt_findAtNxFile(path, devicePixelRatio, &ratio)); if (reader.canRead()) { reader.setScaledSize(reader.size() * (devicePixelRatio / ratio)); pixmap = QPixmap::fromImage(reader.read()); pixmap.setDevicePixelRatio(devicePixelRatio); } } else { pixmap.load(path); } return pixmap; }
QImage PictureHelper::loadQImage(QString url) { QImageReader reader; reader.setFileName(getImagePath(url)); // Resize img if too large (1280x768) QSize imgSize = reader.size(); if (imgSize.width()<imgSize.height()) { if (imgSize.height()>720) { imgSize.setWidth((int)imgSize.width() * 720 / imgSize.height()); imgSize.setHeight(720); reader.setScaledSize(imgSize); } } else if (imgSize.width()>imgSize.height()) { if (imgSize.width() > 720) { imgSize.setHeight((int)imgSize.height() * 720 / imgSize.width()); imgSize.setWidth(720); reader.setScaledSize(imgSize); } } return reader.read(); }
void ImageLoader::run() { typedef QHash<ImageItem*,Data>::iterator Iterator; QImageReader reader; #ifdef Q_OS_WIN for(Iterator data=m_data.begin(); data!=m_data.end() && m_run; ++data) { data->image = QImage(data->path).scaled(m_size, m_size, Qt::KeepAspectRatio, Qt::SmoothTransformation); data->isLoaded = true; emit sigItemContentChanged(data.key()); } #else for(Iterator data=m_data.begin(); data!=m_data.end() && m_run; ++data) { reader.setFileName(data->path); qreal w = m_size; qreal h = m_size; if (reader.supportsOption(QImageIOHandler::Size)) { QSizeF imgSize = reader.size(); if(imgSize.width() > imgSize.height()) { qreal div = m_size / imgSize.width(); h = imgSize.height() * div; } else { qreal div = m_size / imgSize.height(); w = imgSize.width() * div; } } reader.setScaledSize(QSize(w,h)); data->image = reader.read(); data->isLoaded = true; emit sigItemContentChanged(data.key()); } #endif }
void ThumbView::loadThumbsRange() { static bool inProgress = false; static QImageReader thumbReader; static QSize currThumbSize; static int currRowCount; static QString imageFileName; QImage thumb; int currThumb; bool imageReadOk; if (inProgress) { abortOp = true; QTimer::singleShot(0, this, SLOT(loadThumbsRange())); return; } inProgress = true; currRowCount = thumbViewModel->rowCount(); for ( scrolledForward? currThumb = thumbsRangeFirst : currThumb = thumbsRangeLast; (scrolledForward? currThumb <= thumbsRangeLast : currThumb >= thumbsRangeFirst); scrolledForward? ++currThumb : --currThumb) { if (abortOp || thumbViewModel->rowCount() != currRowCount || currThumb < 0) { break; } if (thumbViewModel->item(currThumb)->data(LoadedRole).toBool()) { continue; } imageFileName = thumbViewModel->item(currThumb)->data(FileNameRole).toString(); thumbReader.setFileName(imageFileName); currThumbSize = thumbReader.size(); imageReadOk = false; if (currThumbSize.isValid()) { if (!GData::noEnlargeSmallThumb || (currThumbSize.width() > thumbWidth || currThumbSize.height() > thumbHeight)) { currThumbSize.scale(QSize(thumbWidth, thumbHeight), Qt::KeepAspectRatio); } thumbReader.setScaledSize(currThumbSize); imageReadOk = thumbReader.read(&thumb); } if (imageReadOk) { if (GData::exifThumbRotationEnabled) { imageView->rotateByExifRotation(thumb, imageFileName); currThumbSize = thumb.size(); currThumbSize.scale(QSize(thumbWidth, thumbHeight), Qt::KeepAspectRatio); } thumbViewModel->item(currThumb)->setIcon(QPixmap::fromImage(thumb)); } else { thumbViewModel->item(currThumb)->setIcon(QIcon::fromTheme("image-missing", QIcon(":/images/error_image.png")).pixmap(BAD_IMG_SZ, BAD_IMG_SZ)); currThumbSize.setHeight(BAD_IMG_SZ); currThumbSize.setWidth(BAD_IMG_SZ); } if (GData::thumbsLayout == Compact) { if (GData::showLabels) currThumbSize.setHeight(currThumbSize.height() + QFontMetrics(font()).height() + 5); thumbViewModel->item(currThumb)->setSizeHint(currThumbSize); if (isThumbVisible(thumbViewModel->item(currThumb)->index())) setRowHidden(currThumb, false); } thumbViewModel->item(currThumb)->setData(true, LoadedRole); QApplication::processEvents(); } if (GData::thumbsLayout == Compact && thumbViewModel->rowCount() > 0) { setRowHidden(0 , false); } inProgress = false; abortOp = false; }
void ThumbView::addThumb(QString &imageFullPath) { QStandardItem *thumbIitem = new QStandardItem(); QImageReader thumbReader; QSize hintSize; QSize currThumbSize; static QImage thumb; if (GData::thumbsLayout == Squares) hintSize = QSize(thumbWidth / 2, thumbWidth / 2); else if (GData::thumbsLayout == Classic) hintSize = QSize(thumbWidth, thumbHeight + (GData::showLabels? QFontMetrics(font()).height() + 5 : 0)); thumbFileInfo = QFileInfo(imageFullPath); thumbIitem->setData(true, LoadedRole); thumbIitem->setData(0, SortRole); thumbIitem->setData(thumbFileInfo.filePath(), FileNameRole); if (GData::thumbsLayout != Squares && GData::showLabels) thumbIitem->setData(thumbFileInfo.fileName(), Qt::DisplayRole); thumbReader.setFileName(imageFullPath); currThumbSize = thumbReader.size(); if (currThumbSize.isValid()) { if (!GData::noEnlargeSmallThumb || (currThumbSize.width() > thumbWidth || currThumbSize.height() > thumbHeight)) { currThumbSize.scale(QSize(thumbWidth, thumbHeight), Qt::KeepAspectRatio); } thumbReader.setScaledSize(currThumbSize); thumb = thumbReader.read(); if (GData::exifThumbRotationEnabled) { imageView->rotateByExifRotation(thumb, imageFullPath); currThumbSize = thumb.size(); currThumbSize.scale(QSize(thumbWidth, thumbHeight), Qt::KeepAspectRatio); } thumbIitem->setIcon(QPixmap::fromImage(thumb)); } else { thumbIitem->setIcon(QIcon::fromTheme("image-missing", QIcon(":/images/error_image.png")).pixmap(BAD_IMG_SZ, BAD_IMG_SZ)); currThumbSize.setHeight(BAD_IMG_SZ); currThumbSize.setWidth(BAD_IMG_SZ); } if (GData::thumbsLayout == Compact) { if (GData::showLabels) currThumbSize.setHeight(currThumbSize.height() + QFontMetrics(font()).height() + 5); thumbIitem->setSizeHint(currThumbSize); } else thumbIitem->setSizeHint(hintSize); thumbViewModel->appendRow(thumbIitem); }
/** * Loads the thumbnail from the metadata. * If no thumbnail is embedded, the whole image * is loaded and downsampled in a fast manner. * @param file the file to be loaded * @return QImage the loaded image. Null if no image * could be loaded at all. **/ QImage DkThumbNail::computeIntern(const QFileInfo file, const QSharedPointer<QByteArray> ba, int forceLoad, int maxThumbSize, int minThumbSize, bool rescale) { DkTimer dt; //qDebug() << "[thumb] file: " << file.absoluteFilePath(); // see if we can read the thumbnail from the exif data QImage thumb; DkMetaDataT metaData; try { if (!ba || ba->isEmpty()) metaData.readMetaData(file); else metaData.readMetaData(file, ba); // read the full image if we want to create new thumbnails if (forceLoad != force_save_thumb) thumb = metaData.getThumbnail(); } catch(...) { // do nothing - we'll load the full file } removeBlackBorder(thumb); if (thumb.isNull() && forceLoad == force_exif_thumb) return QImage(); bool exifThumb = !thumb.isNull(); int orientation = metaData.getOrientation(); int imgW = thumb.width(); int imgH = thumb.height(); int tS = minThumbSize; // as found at: http://olliwang.com/2010/01/30/creating-thumbnail-images-in-qt/ QString filePath = (file.isSymLink()) ? file.symLinkTarget() : file.absoluteFilePath(); QImageReader* imageReader; if (!ba || ba->isEmpty()) imageReader = new QImageReader(filePath); else { QBuffer buffer; buffer.setData(ba->data()); buffer.open(QIODevice::ReadOnly); imageReader = new QImageReader(&buffer, QFileInfo(filePath).suffix().toStdString().c_str()); buffer.close(); } if (thumb.isNull() || thumb.width() < tS && thumb.height() < tS) { imgW = imageReader->size().width(); imgH = imageReader->size().height(); // locks the file! } //else if (!thumb.isNull()) // qDebug() << "EXIV thumb loaded: " << thumb.width() << " x " << thumb.height(); if (rescale && (imgW > maxThumbSize || imgH > maxThumbSize)) { if (imgW > imgH) { imgH = (float)maxThumbSize / imgW * imgH; imgW = maxThumbSize; } else if (imgW < imgH) { imgW = (float)maxThumbSize / imgH * imgW; imgH = maxThumbSize; } else { imgW = maxThumbSize; imgH = maxThumbSize; } } if (thumb.isNull() || thumb.width() < tS && thumb.height() < tS || forceLoad == force_full_thumb || forceLoad == force_save_thumb) { // flip size if the image is rotated by 90° if (metaData.isTiff() && abs(orientation) == 90) { int tmpW = imgW; imgW = imgH; imgH = tmpW; qDebug() << "EXIV size is flipped..."; } QSize initialSize = imageReader->size(); imageReader->setScaledSize(QSize(imgW, imgH)); thumb = imageReader->read(); // try to read the image if (thumb.isNull()) { DkBasicLoader loader; if (loader.loadGeneral(file, ba, true, true)) thumb = loader.image(); } // the image is not scaled correctly yet if (rescale && !thumb.isNull() && (imgW == -1 || imgH == -1)) { imgW = thumb.width(); imgH = thumb.height(); if (imgW > maxThumbSize || imgH > maxThumbSize) { if (imgW > imgH) { imgH = (float)maxThumbSize / imgW * imgH; imgW = maxThumbSize; } else if (imgW < imgH) { imgW = (float)maxThumbSize / imgH * imgW; imgH = maxThumbSize; } else { imgW = maxThumbSize; imgH = maxThumbSize; } } thumb = thumb.scaled(QSize(imgW*2, imgH*2), Qt::KeepAspectRatio, Qt::FastTransformation); thumb = thumb.scaled(QSize(imgW, imgH), Qt::KeepAspectRatio, Qt::SmoothTransformation); } // is there a nice solution to do so?? imageReader->setFileName("josef"); // image reader locks the file -> but there should not be one so we just set it to another file... delete imageReader; } else if (rescale) { thumb = thumb.scaled(QSize(imgW, imgH), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); //qDebug() << "thumb loaded from exif..."; } if (orientation != -1 && orientation != 0 && (metaData.isJpg() || metaData.isRaw())) { QTransform rotationMatrix; rotationMatrix.rotate((double)orientation); thumb = thumb.transformed(rotationMatrix); } // save the thumbnail if the caller either forces it, or the save thumb is requested and the image did not have any before if (forceLoad == force_save_thumb || (forceLoad == save_thumb && !exifThumb)) { try { QImage sThumb = thumb.copy(); if (orientation != -1 && orientation != 0) { QTransform rotationMatrix; rotationMatrix.rotate(-(double)orientation); sThumb = sThumb.transformed(rotationMatrix); } metaData.setThumbnail(sThumb); if (!ba || ba->isEmpty()) metaData.saveMetaData(file); else metaData.saveMetaData(file, ba); qDebug() << "[thumb] saved to exif data"; } catch(...) { qDebug() << "Sorry, I could not save the metadata"; } } if (!thumb.isNull()) qDebug() << "[thumb] " << file.fileName() << " loaded in: " << dt.getTotal() << ((exifThumb) ? " from EXIV" : " from File"); //if (!thumb.isNull()) // qDebug() << "thumb: " << thumb.width() << " x " << thumb.height(); return thumb; }
/** * Loads the thumbnail from the metadata. * If no thumbnail is embedded, the whole image * is loaded and downsampled in a fast manner. * @param file the file to be loaded * @param ba the file buffer (can be empty) * @param forceLoad the loading flag (e.g. exiv only) * @param maxThumbSize the maximal thumbnail size to be loaded * @param minThumbSize the minimal thumbnail size to be loaded * @return QImage the loaded image. Null if no image * could be loaded at all. **/ QImage DkThumbNail::computeIntern(const QString& filePath, const QSharedPointer<QByteArray> ba, int forceLoad, int maxThumbSize, int minThumbSize) { DkTimer dt; //qDebug() << "[thumb] file: " << file.absoluteFilePath(); // see if we can read the thumbnail from the exif data QImage thumb; DkMetaDataT metaData; QSharedPointer<QByteArray> baZip = QSharedPointer<QByteArray>(); #ifdef WITH_QUAZIP if (QFileInfo(mFile).dir().path().contains(DkZipContainer::zipMarker())) baZip = DkZipContainer::extractImage(DkZipContainer::decodeZipFile(filePath), DkZipContainer::decodeImageFile(filePath)); #endif try { if (baZip && !baZip->isEmpty()) metaData.readMetaData(filePath, baZip); else if (!ba || ba->isEmpty()) metaData.readMetaData(filePath); else metaData.readMetaData(filePath, ba); // read the full image if we want to create new thumbnails if (forceLoad != force_save_thumb) thumb = metaData.getThumbnail(); } catch(...) { // do nothing - we'll load the full file } removeBlackBorder(thumb); if (thumb.isNull() && forceLoad == force_exif_thumb) return QImage(); bool exifThumb = !thumb.isNull(); int orientation = metaData.getOrientation(); int imgW = thumb.width(); int imgH = thumb.height(); int tS = minThumbSize; // as found at: http://olliwang.com/2010/01/30/creating-thumbnail-images-in-qt/ QFileInfo fInfo(filePath); QString lFilePath = fInfo.isSymLink() ? fInfo.symLinkTarget() : filePath; fInfo = lFilePath; QImageReader* imageReader = 0; if (!ba || ba->isEmpty()) imageReader = new QImageReader(lFilePath); else { QBuffer buffer; buffer.setData(ba->data()); buffer.open(QIODevice::ReadOnly); imageReader = new QImageReader(&buffer, fInfo.suffix().toStdString().c_str()); buffer.close(); } if (thumb.isNull() || (thumb.width() < tS && thumb.height() < tS)) { imgW = imageReader->size().width(); // crash detected: unhandled exception at 0x66850E9A (msvcr110d.dll) in nomacs.exe: 0xC0000005: Access violation reading location 0x0000C788. imgH = imageReader->size().height(); // locks the file! } if (forceLoad != DkThumbNailT::force_exif_thumb && (imgW > maxThumbSize || imgH > maxThumbSize)) { if (imgW > imgH) { imgH = qRound((float)maxThumbSize / imgW * imgH); imgW = maxThumbSize; } else if (imgW < imgH) { imgW = qRound((float)maxThumbSize / imgH * imgW); imgH = maxThumbSize; } else { imgW = maxThumbSize; imgH = maxThumbSize; } } bool rescale = forceLoad == force_save_thumb; if (forceLoad != force_exif_thumb && (thumb.isNull() || thumb.width() < tS && thumb.height() < tS || forceLoad == force_full_thumb || forceLoad == force_save_thumb)) { // braces // flip size if the image is rotated by 90° if (metaData.isTiff() && abs(orientation) == 90) { int tmpW = imgW; imgW = imgH; imgH = tmpW; qDebug() << "EXIF size is flipped..."; } QSize initialSize = imageReader->size(); imageReader->setScaledSize(QSize(imgW, imgH)); thumb = imageReader->read(); // try to read the image if (thumb.isNull()) { DkBasicLoader loader; if (baZip && !baZip->isEmpty()) { if (loader.loadGeneral(lFilePath, baZip, true, true)) thumb = loader.image(); } else { if (loader.loadGeneral(lFilePath, ba, true, true)) thumb = loader.image(); } } // the image is not scaled correctly yet if (rescale && !thumb.isNull() && (imgW == -1 || imgH == -1)) { imgW = thumb.width(); imgH = thumb.height(); if (imgW > maxThumbSize || imgH > maxThumbSize) { if (imgW > imgH) { imgH = qRound((float)maxThumbSize / imgW * imgH); imgW = maxThumbSize; } else if (imgW < imgH) { imgW = qRound((float)maxThumbSize / imgH * imgW); imgH = maxThumbSize; } else { imgW = maxThumbSize; imgH = maxThumbSize; } } thumb = thumb.scaled(QSize(imgW*2, imgH*2), Qt::KeepAspectRatio, Qt::FastTransformation); thumb = thumb.scaled(QSize(imgW, imgH), Qt::KeepAspectRatio, Qt::SmoothTransformation); } // is there a nice solution to do so?? imageReader->setFileName("josef"); // image reader locks the file -> but there should not be one so we just set it to another file... } else if (rescale) { thumb = thumb.scaled(QSize(imgW, imgH), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); } if (imageReader) delete imageReader; if (orientation != -1 && orientation != 0 && (metaData.isJpg() || metaData.isRaw())) { QTransform rotationMatrix; rotationMatrix.rotate((double)orientation); thumb = thumb.transformed(rotationMatrix); } // save the thumbnail if the caller either forces it, or the save thumb is requested and the image did not have any before if (rescale || (forceLoad == save_thumb && !exifThumb)) { try { QImage sThumb = thumb.copy(); if (orientation != -1 && orientation != 0) { QTransform rotationMatrix; rotationMatrix.rotate(-(double)orientation); sThumb = sThumb.transformed(rotationMatrix); } metaData.setThumbnail(sThumb); if (!ba || ba->isEmpty()) metaData.saveMetaData(lFilePath); else metaData.saveMetaData(lFilePath, ba); qDebug() << "[thumb] saved to exif data"; } catch(...) { qDebug() << "Sorry, I could not save the metadata"; } } if (!thumb.isNull()) qDebug() << "[thumb] " << fInfo.fileName() << "(" << thumb.width() << " x " << thumb.height() << ") loaded in: " << dt.getTotal() << ((exifThumb) ? " from EXIV" : " from File"); return thumb; }
bb::ImageData ImageProcessor::start() { //qDebug() << "[ImageProcessor::start] m_imagePath: " << m_imagePath; bb::ImageData imageData; QImage image, swappedImage; QImageReader reader (m_imagePath); QSize scaledSize(ImageProcessor::THUMB_SIZE), originalSize = reader.size(); if(originalSize != ImageProcessor::THUMB_SIZE && originalSize.isValid()){ // now scale it filling the original rectangle by keeping aspect ratio scaledSize.scale(originalSize, Qt::KeepAspectRatio); // set the adjusted clipping rectangle in the middle of the original image QRect clipRect(0, 0, scaledSize.width(), scaledSize.height()); QPoint originalCenterPoint(originalSize.width() / 2, originalSize.height() / 2); clipRect.moveCenter(originalCenterPoint); reader.setClipRect(clipRect); // set requested target size of a thumbnail // as clipping rectangle is of same aspect ration as requestedSize no distortion should happen reader.setScaledSize(ImageProcessor::THUMB_SIZE); if(reader.read(&image) == false){ qWarning() << "[ImageProcessor::start] could not load image file! errorString: " << reader.errorString(); return imageData; } } // get the parent folder of the current image // 0 1 2 3 4 5 6 7 // E.g: /accounts/1000/appdata/com.willthrill.bb10.Wappy.testDev__bb10_Wappy92abc424/shared/photos/wappy/image.jpg QString filePath = reader.fileName(); int count = filePath.count("/"); QString parentFolderName = "/" + filePath.section("/", 5, count - 2, QString::SectionSkipEmpty); // discard file name + 1 QString fileName = "/" + filePath.section("/", -1); //qDebug() << "[ImageProcessor::start] parentFolderName: "<<parentFolderName<<", filePath: "<<filePath << ", count: " << count; // create the parent folder on the data directory if it doesn't exist. QDir parentFolder( QDir::homePath() + parentFolderName); if( !parentFolder.exists()){ parentFolder.mkpath("."); } // save the thumbnail QString p = QDir::homePath() + parentFolderName + fileName; //qDebug() << "[ImageProcessor::start] Saving thumbnail image. File path: " << p; bool ok = image.save(p,"jpg",50); if(!ok){ qWarning() << "[ImageProcessor::start] Could not save thumbnail image!"; } // Swap the image colors due to RGB bit representation swappedImage = image.rgbSwapped(); // Create the Cascades ImageData with the swapped image imageData = bb::ImageData::fromPixels(swappedImage.bits(), bb::PixelFormat::RGBX, swappedImage.width(), swappedImage.height(), swappedImage.bytesPerLine()); return imageData; }
QSizeF HbIconSource::defaultSize() { // If the default size has not been fetched yet, do it now. if (!mDefaultSize.isValid()) { type(); // make sure type is initialized if (mType == "NVG") { #ifndef HB_BOOTSTRAPPED #ifdef HB_NVG_CS_ICON if (!mByteArray) { QFile file(mFilename); if (!file.open(QIODevice::NotOpen | QIODevice::ReadOnly)) { return QSizeF(); } mByteArray = new QByteArray(file.readAll()); } HbNvgEngine nvgEngine; mDefaultSize = nvgEngine.contentDimensions(*mByteArray); #endif // HB_NVG_CS_ICON #else // HB_BOOTSTRAPPED if (!mByteArray) { QFile file(mFilename); if (!file.open(QIODevice::NotOpen | QIODevice::ReadOnly)) { return QSizeF(); } mByteArray = new QByteArray(file.readAll()); } mDefaultSize = nvgContentDimensions(*mByteArray); #endif } else if (mType == "SVG") { QSvgRenderer *renderer = svgRenderer(); if (renderer) { // isValid() is already checked in svgRenderer() mDefaultSize = renderer->defaultSize(); } releaseSvgRenderer(); } else if (mType == "PIC") { if (!mPicture) { mPicture = new QPicture; mPicture->load(mFilename); } mDefaultSize = mPicture->boundingRect().size(); } // Image reader supports getting the default size without rasterizing the image so // using it with the formats that it supports. else if (mType == "MNG" || mType == "GIF" || mType == "JPG" || mType == "PNG") { // Note that QImageReader::canRead() results in opening the file and so the // file will be locked until the QImageReader instance is // destroyed. Therefore the image reader instance must be destroyed as soon // as possible and must not be kept for later use. // Exception: Files on Z drive on Symbian. See canKeepOpen() and releaseImageReader(). QImageReader *reader = imageReader(); if (reader) { // canRead() is already checked in imageReader() if (mType != "MNG") { mDefaultSize = reader->size(); } else { // MNG handler does not support size query so have to render it to get the size QImage img = reader->read(); mDefaultSize = img.size(); } } releaseImageReader(); } else if (mType != "BLOB") { if (!mPixmap) { mPixmap = new QPixmap(mFilename); } mDefaultSize = mPixmap->size(); } } return QSizeF(mDefaultSize); }
QuetzalFieldsDialog::QuetzalFieldsDialog(const char *title, const char *primary, const char *secondary, PurpleRequestFields *fields, const char *ok_text, GCallback ok_cb, const char *cancel_text, GCallback cancel_cb, void *user_data, QWidget *parent) : QuetzalRequestDialog(PURPLE_REQUEST_FIELDS, user_data, parent) { m_ok_cb = (PurpleRequestFieldsCb) ok_cb; m_cancel_cb = (PurpleRequestFieldsCb) cancel_cb; m_fields = fields; DataItem root = createItem(title, primary, secondary); GList *group_it = purple_request_fields_get_groups(m_fields); bool useGroupBox = group_it->next; debug() << "useGroupBox" << useGroupBox; for (; group_it; group_it = group_it->next) { PurpleRequestFieldGroup *group = reinterpret_cast<PurpleRequestFieldGroup*>(group_it->data); DataItem groupItem; if (useGroupBox) groupItem = DataItem(purple_request_field_group_get_title(group)); GList *field_it = purple_request_field_group_get_fields(group); for (; field_it; field_it = field_it->next) { PurpleRequestField *field = reinterpret_cast<PurpleRequestField*>(field_it->data); debug() << field->id << purple_request_field_is_visible(field) << purple_request_field_get_type(field); if (!purple_request_field_is_visible(field)) continue; DataItem item(purple_request_field_get_id(field), purple_request_field_get_label(field), QVariant()); switch (purple_request_field_get_type(field)) { case PURPLE_REQUEST_FIELD_STRING: item.setData(QString::fromUtf8(purple_request_field_string_get_default_value(field))); item.setProperty("multiline", purple_request_field_string_is_multiline(field)); item.setProperty("password", bool(purple_request_field_string_is_masked(field))); item.setReadOnly(!purple_request_field_string_is_editable(field)); debug() << item.name() << item.data() << item.property("password") << item.isReadOnly(); break; case PURPLE_REQUEST_FIELD_INTEGER: item.setData(purple_request_field_int_get_default_value(field)); item.setProperty("minValue", G_MININT); item.setProperty("maxValue", G_MAXINT); break; case PURPLE_REQUEST_FIELD_BOOLEAN: item.setData(bool(purple_request_field_bool_get_default_value(field))); break; case PURPLE_REQUEST_FIELD_CHOICE: { GList *labels = purple_request_field_choice_get_labels(field); QStringList alternatives; for (; labels; labels = labels->next) alternatives << QString::fromUtf8(reinterpret_cast<char*>(labels->data)); item.setData(alternatives.value(purple_request_field_choice_get_default_value(field))); item.setProperty("alternatives", alternatives); } break; case PURPLE_REQUEST_FIELD_LIST: break; case PURPLE_REQUEST_FIELD_LABEL: item.setData(purple_request_field_get_label(field)); item.setReadOnly(true); item.setProperty("hideTitle", true); break; case PURPLE_REQUEST_FIELD_IMAGE: { QImageReader reader; QByteArray data = QByteArray::fromRawData(purple_request_field_image_get_buffer(field), purple_request_field_image_get_size(field)); QBuffer buffer(&data); reader.setDevice(&buffer); QSize imageSize = reader.size(); if (imageSize.isValid()) { imageSize.setWidth(imageSize.width() * purple_request_field_image_get_scale_x(field)); imageSize.setHeight(imageSize.height() * purple_request_field_image_get_scale_y(field)); reader.setScaledSize(imageSize); } item.setData(qVariantFromValue(reader.read())); item.setProperty("imageSize", qVariantFromValue(imageSize)); item.setReadOnly(true); } break; case PURPLE_REQUEST_FIELD_ACCOUNT: break; case PURPLE_REQUEST_FIELD_NONE: default: continue; } item.setProperty("mandatory", purple_request_field_is_required(field)); if (useGroupBox) groupItem.addSubitem(item); else root.addSubitem(item); } if (useGroupBox) root.addSubitem(groupItem); } createItem(root, ok_text, cancel_text); return; }