QString KNMusicLibraryImageManager::insertHashImage(const QImage &image) { //Calculate the meta data of the image(MD4 of image content). QByteArray hashResult= QCryptographicHash::hash(QByteArray((char *)image.bits(), image.byteCount()), QCryptographicHash::Md4); //Get the image key of the image. QString imageHashKey; //Add hash result data to image hash key. for(int i=0; i<hashResult.size(); ++i) { //Get the text string of the current number. QString currentByteText=QString::number((quint8)hashResult.at(i), 16); //Check out the data of image hash key. imageHashKey.append(hashResult.at(i)<16?"0"+currentByteText: currentByteText); } //Check whether the hash is already exists in image list. if(m_hashAlbumArt!=nullptr && !m_hashAlbumArt->contains(imageHashKey)) { //If this image is first time exist in the hash list, save the image //first. m_hashAlbumArt->insert(imageHashKey, QVariant(QPixmap::fromImage(image))); //Ask to save the image. emit requireSaveImage(imageHashKey); } return imageHashKey; }
bool ImageRenderStrategy::render(Content* content, Image* renderImage) { if (!renderImage || !renderImage->pixels() || !renderImage->width() || !renderImage->height()) return false; if ( renderImage->hasAlpha() ) { // we need to swap r and b channels QImage img(renderImage->width(), renderImage->height(), QImage::Format_ARGB32); // Paint into image img.fill(Qt::transparent); QPainter painter(&img); painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform, true); content->paintContent(&painter); painter.end(); QImage swapped = img.rgbSwapped(); const uchar* from = swapped.constBits(); int numFromBytes = swapped.byteCount(); memcpy((uchar*)renderImage->pixels(), from, numFromBytes); return true; } // QImage referencing our Image bits QImage image((uchar*)renderImage->pixels(), renderImage->width(), renderImage->height(), renderImage->bytesPerLine(), QImage::Format_RGB888); // Paint into image QPainter painter(&image); painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform, true); content->paintContent(&painter); painter.end(); return true; }
bool XfitMan::getClientIcon(Window _wid, QPixmap& _pixreturn) const { int format; ulong type, nitems, extra; ulong* data = 0; XGetWindowProperty(QX11Info::display(), _wid, atom("_NET_WM_ICON"), 0, LONG_MAX, False, AnyPropertyType, &type, &format, &nitems, &extra, (uchar**)&data); if (!data) { qDebug() << "Cannot obtain pixmap info from the window"; return false; } QImage img (data[0], data[1], QImage::Format_ARGB32); for (int i=0; i<img.byteCount()/4; ++i) ((uint*)img.bits())[i] = data[i+2]; _pixreturn = QPixmap::fromImage(img); XFree(data); return true; }
QImage Plugin::GetRenderedImage (const QString& formula) { if (FormulasCache_.contains (formula)) return *FormulasCache_.object (formula); const QString& filename = Util::GetTemporaryName ("lc_azoth_modnok.XXXXXX.png"); const int dpiX = XmlSettingsManager::Instance () .property ("HorizontalDPI").toInt (); const int dpiY = XmlSettingsManager::Instance () .property ("VerticalDPI").toInt (); QStringList args; args << QString ("-r %1x%2").arg (dpiX).arg (dpiY); args << QString ("-o %1").arg (filename); // TODO const QString& incPath = QString (); if (!incPath.isEmpty ()) args << (QString ("-x ") + incPath); args << formula; QProcess::execute (ConvScriptPath_, args); QImage img (filename); FormulasCache_.insert (formula, new QImage (filename), img.byteCount () / 1024); QFile (filename).remove (); return img; }
bool XfitMan::getClientIcon(Window _wid, QIcon *icon) const { int format; ulong type, nitems, extra; ulong* data = 0; XGetWindowProperty(QX11Info::display(), _wid, atom("_NET_WM_ICON"), 0, LONG_MAX, False, AnyPropertyType, &type, &format, &nitems, &extra, (uchar**)&data); if (!data) { return false; } ulong* d = data; while (d < data + nitems) { QImage img (d[0], d[1], QImage::Format_ARGB32); d+=2; for (int i=0; i<img.byteCount()/4; ++i, ++d) ((uint*)img.bits())[i] = *d; icon->addPixmap(QPixmap::fromImage(img)); } XFree(data); return true; }
QString BD::calcHash(QImage imagem) const { QByteArray pixels = QByteArray(reinterpret_cast<const char *>(imagem.bits()), imagem.byteCount()); QString hash(QCryptographicHash::hash(pixels, QCryptographicHash::Sha1).toHex()); //coloca a imagem no disco endereçando pelo hash imagem.save(dir_base + hash + ".bmp"); return hash; }
const QByteArray imageToByteArray(const QImage & image) { QByteArray byte_array(image.byteCount(), 0); QBuffer buf(&byte_array); buf.open(QIODevice::WriteOnly); image.save(&buf, "png"); buf.close(); return byte_array; }
void saveImage(char * jsonFile, char * filename) { Lemniscate * lemniscate = new Lemniscate(); JsonHandler * handler = JsonHandler::getInstance(); handler->parseJson(jsonFile); lemniscate->setParams(handler->getParams()); QImage * image = new QImage(handler->getPanelSize(), QImage::Format_RGB888); memset(image->bits(), 255, image->byteCount()); lemniscate->draw(image); image->save(filename); }
int Load::loadImage(QString fileName, int number){ QImage img(fileName); if (img.isNull()) return -1; QImage scaled = img.scaled(buffer->width,buffer->height); QImage rgb = scaled.convertToFormat(QImage::Format_ARGB32); fprintf(stderr,"leng %d %p\n", rgb.byteCount(),buffer->Open(number)); memcpy(buffer->Open(number),rgb.bits(),rgb.byteCount()); buffer->newFrame(number); buffer->frame[number]=-1; }
bool writePGFImageData(const QImage& image, QByteArray& data, int quality, bool verbose) { try { // We will use uncompressed image bytes size to allocate PGF stream in memory. In all case, due to PGF compression ratio, // PGF data will be so far lesser than image raw size. int rawSize = image.byteCount(); CPGFMemoryStream stream(rawSize); if (verbose) kDebug() << "PGF stream memory allocation in bytes: " << rawSize; UINT32 nWrittenBytes = 0; bool ret = writePGFImageDataToStream(image, stream, quality, nWrittenBytes, verbose); int pgfsize = #ifdef PGFCodecVersionID # if PGFCodecVersionID == 0x061224 // Wrap around libpgf 6.12.24 about CPGFMemoryStream bytes size generated to make PGF file data. // It miss 16 bytes at end. This solution fix the problem. Problem have been fixed in 6.12.27. nWrittenBytes + 16; # else nWrittenBytes; # endif #else nWrittenBytes; #endif data = QByteArray((const char*)stream.GetBuffer(), pgfsize); if (!pgfsize) { kDebug() << "Encoded PGF image : data size is null"; ret = false; } else { if (verbose) kDebug() << "data size written : " << pgfsize; } return ret; } catch (IOException& e) { int err = e.error; if (err >= AppError) { err -= AppError; } kDebug() << "Error running libpgf (" << err << ")!"; return false; } }
void mandelbrotcore::MPI_updatePixmap(const QImage &image, double scaleFactor, int instance) { __protocolImage pImage; pImage.scaleFactor = scaleFactor; pImage.height = image.height(); pImage.width = image.width(); pImage.size = image.byteCount(); // lockSend.lock(); memcpy(this->buffer , &pImage, sizeof(__protocolImage)); memcpy(this->buffer + sizeof(__protocolImage), image.bits() , image.byteCount()); // qDebug() << pImage.width << pImage.height << image.byteCount()<< sizeof(__protocolImage); // qDebug() <<"QImage size --> "<<sizeof(__protocolImage) + image.byteCount() << "<" << MPI_BUFFER_SIZE; int rc = MPI_Send(buffer, sizeof(__protocolImage) + image.byteCount(), MPI_BYTE, 0, 1, MPI_COMM_WORLD); // lockSend.unlock(); // qDebug("Qimage-exit"); }
void generateFaceMips(gpu::Texture* texture, QImage& image, gpu::Element formatMip, uint8 face) { #if CPU_MIPMAPS auto numMips = texture->evalNumMips(); for (uint16 level = 1; level < numMips; ++level) { QSize mipSize(texture->evalMipWidth(level), texture->evalMipHeight(level)); image = image.scaled(mipSize); texture->assignStoredMipFace(level, formatMip, image.byteCount(), image.constBits(), face); } #else texture->autoGenerateMips(-1); #endif }
void cross_dissolve(const QImage& I0,const QImage& I1,float s,QImage& Idst) { assert(I0.size()==I1.size()); int bitscnt=I0.byteCount(); const uchar* p0=I0.bits(),*p1=I1.bits(); uchar *pdst=Idst.bits(); while(bitscnt--) { *pdst++=lerp(*p0++,*p1++,s); } }
void run() { YUV4MPEG2 *encoder = new YUV4MPEG2(QGuiApplication::primaryScreen()->grabWindow(0).width(), QGuiApplication::primaryScreen()->grabWindow(0).height(), 24,"/home/petar/test.mpg"); while(recording) { QImage mapa = QGuiApplication::primaryScreen()->grabWindow(0).toImage(); encoder->addFrame(mapa.bits(),mapa.byteCount()); std::this_thread::sleep_for(std::chrono::milliseconds(200)); } }
void AddMarkerDialog::initialize() { _okButton->setEnabled(_editing); _nameEdit->setText(tr("New Marker")); // add name display checkbox to the dialog _nameCheckbox = new QCheckBox(tr("Display name")); _nameCheckbox->setCheckState(Qt::Checked); _customLayout->addWidget(_nameCheckbox); // load marker image QImage image(":/images/marker.png"); QImage glImage = QGLWidget::convertToGLFormat(image); unsigned char* data = new unsigned char[glImage.byteCount()]; for(int i=0; i<glImage.byteCount(); i++) { data[i] = glImage.bits()[i]; } _markerImage = new osg::Image(); _markerImage->setImage(glImage.width(), glImage.height(), 1, 4, GL_RGBA, GL_UNSIGNED_BYTE, data, osg::Image::USE_NEW_DELETE, 1); // setup placemark style _placeStyle.getOrCreate<AltitudeSymbol>()->clamping() = AltitudeSymbol::CLAMP_TO_TERRAIN; // wire up UI events connect(_nameCheckbox, SIGNAL(stateChanged(int)), this, SLOT(onNameCheckStateChanged(int))); connect(_nameEdit, SIGNAL(textChanged(const QString&)), this, SLOT(onNameTextChanged(const QString&))); }
/*============================================================================= MAIN =============================================================================*/ int main() { QImage * img; QTextStream qstdin(stdin); qDebug() << "Enter the file path:"; QString fileName = qstdin.readLine().trimmed(); if( fileName.isNull() || fileName.isEmpty() ){ qDebug() << "Invalid file name (absolute path)\n"; return EXIT_FAILURE; } img = new QImage(fileName); if( img->isNull() ){ qDebug() << "Imagem don't exist\n"; return EXIT_FAILURE; } // Converte para 3bytes por pixel. ter certeza q esta no padrao *img = img->convertToFormat(QImage::Format_RGB888); qDebug() << "======================================================"; qDebug() << "Before: " << img->byteCount()/1024 << "kb" << "; " << img->size(); // Escala para 1/2 e salva para comparacao img->scaled(img->width()/2,img->height()/2).save(fileName + "_scaled.bmp"); // Codifica e salva img = encode(img); img->save(fileName + "_encoded.bmp"); qDebug() << "After: " << img->byteCount()/1024 << "kb" << "; " << img->size(); qDebug() << "======================================================"; return EXIT_SUCCESS; }
bool CCImage::_initWithPngData(void * pData, int nDatalen) { QImage image; bool bRet = image.loadFromData((const uchar*)pData, nDatalen, "PNG"); if (!bRet) return false; // TODO: Better/faster conversion QImage convertedImg = image.convertToFormat( QImage::Format_ARGB32_Premultiplied); convertedImg = convertedImg.rgbSwapped(); m_bPreMulti = true; m_bHasAlpha = convertedImg.hasAlphaChannel(); m_nBitsPerComponent = cocos2d::getBitsPerComponent(convertedImg.format()); m_nHeight = (short)convertedImg.height(); m_nWidth = (short)convertedImg.width(); m_pData = new unsigned char[convertedImg.byteCount()]; memcpy(m_pData, convertedImg.bits(), convertedImg.byteCount()); return bRet; }
void QMapboxGL::addAnnotationIcon(const QString &name, const QImage &sprite) { if (sprite.isNull()) return; const QImage swapped = sprite .rgbSwapped() .convertToFormat(QImage::Format_ARGB32_Premultiplied); auto img = std::make_unique<uint8_t[]>(swapped.byteCount()); memcpy(img.get(), swapped.constBits(), swapped.byteCount()); d_ptr->mapObj->addAnnotationIcon(name.toStdString(), std::make_shared<mbgl::SpriteImage>( mbgl::PremultipliedImage { size_t(swapped.width()), size_t(swapped.height()), std::move(img) }, 1.0)); }
void desaturate(QImage &img) { int length = img.byteCount(); uchar* data = img.bits(); int avg; for (int i = 0; i < length; i += 4) { avg = (data[i] + data[i+1] + data[i+2]) / 3; data[i] = avg; data[i+1] = avg; data[i+2] = avg; } }
void DisplayLinkAdapter::displayImage(const QImage &image) { const dlo_view_t *view = &(mode_info->view); dlo_dot_t dot; dlo_fbuf_t fbuf; OO_NERR(uid); fbuf.width = image.width(); fbuf.height = image.height(); fbuf.stride = fbuf.width; fbuf.fmt = dlo_pixfmt_argb8888; dot.x = 0; if (view->height > fbuf.height) { dlo_rect_t rec; rec.origin.x = 0; rec.origin.y = 0; rec.width = view->width; dot.y = (view->height - fbuf.height) / 2; rec.height = dot.y; OO_ERR(dlo_fill_rect(uid, view, &rec, DLO_RGB(0, 0, 0))); rec.origin.y = fbuf.height + dot.y; rec.height = view->height - rec.origin.y; OO_ERR(dlo_fill_rect(uid, view, &rec, DLO_RGB(0, 0, 0))); } else { dot.y = 0; } fbuf.base = malloc(image.byteCount()); OO_NERR(fbuf.base); memcpy(fbuf.base, image.bits(), image.byteCount()); OO_ERR(dlo_copy_host_bmp(uid, flags, &fbuf, NULL, &dot)); free(fbuf.base); }
gpu::Texture* TextureUsage::process2DTextureColorFromImage(const QImage& srcImage, bool isLinear, bool doCompress, bool generateMips) { bool validAlpha = false; bool alphaAsMask = true; QImage image = process2DImageColor(srcImage, validAlpha, alphaAsMask); gpu::Texture* theTexture = nullptr; if ((image.width() > 0) && (image.height() > 0)) { gpu::Element formatGPU; gpu::Element formatMip; defineColorTexelFormats(formatGPU, formatMip, image, isLinear, doCompress); theTexture = (gpu::Texture::create2D(formatGPU, image.width(), image.height(), gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_LINEAR))); auto usage = gpu::Texture::Usage::Builder().withColor(); if (validAlpha) { usage.withAlpha(); if (alphaAsMask) { usage.withAlphaMask(); } } theTexture->setUsage(usage.build()); theTexture->assignStoredMip(0, formatMip, image.byteCount(), image.constBits()); if (generateMips) { theTexture->autoGenerateMips(-1); auto levels = theTexture->maxMip(); uvec2 size(image.width(), image.height()); for (uint8_t i = 1; i <= levels; ++i) { size >>= 1; size = glm::max(size, uvec2(1)); image = image.scaled(size.x, size.y, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); theTexture->assignStoredMip(i, formatMip, image.byteCount(), image.constBits()); } } }
unsigned long long Distance(Chromosome *dna){ int nBytesImage = sourceImage.byteCount(); QImage imageRender = DrawImage(dna); unsigned long long distance = 0; const unsigned char *original = sourceImage.bits(); const unsigned char *render = imageRender.bits(); // get the distance for (int i = 0; i < nBytesImage; i++) { int temp = original[i] - render[i]; distance += temp*temp; } return distance; }
/// Returns a texture version of an image file gpu::TexturePointer TextureCache::getImageTexture(const QString& path) { QImage image = QImage(path).mirrored(false, true); gpu::Element formatGPU = gpu::Element(gpu::VEC3, gpu::NUINT8, gpu::RGB); gpu::Element formatMip = gpu::Element(gpu::VEC3, gpu::NUINT8, gpu::RGB); if (image.hasAlphaChannel()) { formatGPU = gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA); formatMip = gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::BGRA); } gpu::TexturePointer texture = gpu::TexturePointer( gpu::Texture::create2D(formatGPU, image.width(), image.height(), gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_LINEAR))); texture->assignStoredMip(0, formatMip, image.byteCount(), image.constBits()); texture->autoGenerateMips(-1); return texture; }
int ServiceTestObject::testQImageGrayScale(const QImage& image) { QImage originImage(":/images/finger.png"); if (originImage.width() != image.width() || originImage.height() != image.height()) return -1; for (int y = 0; y < originImage.height(); ++y) for (int x = 0; x < originImage.width(); ++x) if (qRed(originImage.pixel(x, y)) != qRed(image.pixel(x, y)) || qGreen(originImage.pixel(x, y)) != qGreen(image.pixel(x, y)) || qBlue(originImage.pixel(x, y)) != qBlue(image.pixel(x, y))) return -1; return image.byteCount(); }
void DockPixelStreamer::update(const QImage& image) { QImage newImage(size(), image.format()); // Copy Toolbar uchar* dst = newImage.bits(); const QImage& toolbarImage = toolbar_->getImage(); memcpy(dst, toolbarImage.bits(), toolbarImage.byteCount()); dst += toolbarImage.byteCount(); // Copy Flow memcpy(dst, image.bits(), image.byteCount()); emit imageUpdated(newImage); }
PremultipliedImage decodeImage(const std::string& string) { const uint8_t* data = reinterpret_cast<const uint8_t*>(string.data()); const size_t size = string.size(); #if !defined(QT_IMAGE_DECODERS) if (size >= 12) { uint32_t riff_magic = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3]; uint32_t webp_magic = (data[8] << 24) | (data[9] << 16) | (data[10] << 8) | data[11]; if (riff_magic == 0x52494646 && webp_magic == 0x57454250) { return decodeWebP(data, size); } } if (size >= 2) { uint16_t magic = ((data[0] << 8) | data[1]) & 0xffff; if (magic == 0xFFD8) { return decodeJPEG(data, size); } } #endif QImage image = QImage::fromData(data, size) .rgbSwapped() .convertToFormat(QImage::Format_ARGB32_Premultiplied); if (image.isNull()) { throw std::runtime_error("Unsupported image type"); } auto img = std::make_unique<uint8_t[]>(image.byteCount()); memcpy(img.get(), image.constBits(), image.byteCount()); return { { static_cast<uint32_t>(image.width()), static_cast<uint32_t>(image.height()) }, std::move(img) }; }
void KNLibImageBuffer::hashImage(QString identifyData, const QImage &image) { m_hash.clear(); m_imageByteCache.clear(); m_imageByteCache.append((char *)image.bits(), image.byteCount()); m_hashResult=QCryptographicHash::hash(m_imageByteCache, QCryptographicHash::Md4); m_hash.clear(); for(int i=0; i<m_hashResult.size(); i++) { m_hash+=QString::number((quint8)m_hashResult.at(i), 16); } m_imageCache=image; m_identifyData=identifyData; emit hashComplete(); }
static bool isEmpty(const QImage &image) { if (image.format() == QImage::Format_RGB32) return false; Q_ASSERT(image.format() == QImage::Format_ARGB32 || image.format() == QImage::Format_ARGB32_Premultiplied); const QRgb *rgb = reinterpret_cast<const QRgb*>(image.constBits()); const QRgb * const last = rgb + image.byteCount() / 4; for (; rgb != last; ++rgb) if (qAlpha(*rgb) > 0) return false; return true; }
bool JPEGVideo::decodeData(const RsVOIPDataChunk& chunk,QImage& image) { // now see if the frame is a differential frame, or just a reference frame. uint16_t codec = ((unsigned char *)chunk.data)[0] + (((unsigned char *)chunk.data)[1] << 8) ; uint16_t flags = ((unsigned char *)chunk.data)[2] + (((unsigned char *)chunk.data)[3] << 8) ; assert(codec == VideoProcessor::VIDEO_PROCESSOR_CODEC_ID_JPEG_VIDEO) ; // un-compress image data QByteArray qb((char*)&((uint8_t*)chunk.data)[HEADER_SIZE],(int)chunk.size - HEADER_SIZE) ; if(!image.loadFromData(qb,"JPEG")) { std::cerr << "image.loadFromData(): returned an error.: " << std::endl; return false ; } if(flags & JPEG_VIDEO_FLAGS_DIFFERENTIAL_FRAME) { if(_decoded_reference_frame.size() != image.size()) { std::cerr << "Bad reference frame!" << std::endl; return false ; } QImage res = _decoded_reference_frame ; for(int i=0;i<image.byteCount();++i) { int new_val = (int)res.bits()[i] + ((int)image.bits()[i] - 128) ; res.bits()[i] = std::max(0,std::min(255,new_val)) ; } image = res ; } else _decoded_reference_frame = image ; return true ; }
QImage ThumbnailProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize) { QImage image; if (m_thumb32->findImage(id, &image)) { return image; } else { QString filePath; if (id.at(0) == QLatin1Char('Q')) { Xapian::Document doc = m_xapianDB->findDocument(id); if (doc.get_docid() == 0) { return image; } else { filePath = QString::fromStdString(doc.get_value(Database::FilePath)); } } else { filePath = id; } // Load thumbnail // KExiv2Iface::KExiv2Previews preview(filePath); KExiv2Iface::KExiv2 preview(filePath); image = preview.getExifThumbnail(true); if (image.isNull()) { // image = preview.image(); // } else { // Store thumbnail // TODO smooth or fast? image = QImage(filePath).scaled(160, 120, Qt::KeepAspectRatio); // preview. kWarning() << "Could not find preview image for" << filePath << image.isNull(); } // Store the thumbnail into the cache file if (m_thumb32->insertImage(id, image)) { kWarning() << "Added preview for" << image.byteCount() << filePath << id; } else { kWarning() << "FAILED to add preview for" << filePath << id; } } return image; }