Beispiel #1
0
void QTFileLoader::save(const std::string& name, RGB24Buffer *input, int quality)
{
    QImageWriter imageWriter(QString(name.c_str()));
    RGB24InterfaceImage imageToSave(input);
    imageWriter.setQuality(quality);
    imageWriter.write(imageToSave);
}
Beispiel #2
0
void CDlgUservCard::on_pbBrowse_clicked()
{
    QString szFile, szFilter("*.PNG *.BMP *.JPG *.JPEG *.PBM *.PGM *.PPM *.XBM *.XPM");
    szFile = CTool::FileDialog(this, QString(), szFilter, tr("Open File"));
    if(szFile.isEmpty())
       return; 

    //TODO:现在只上传小图片,以后增加上传原图  
    //原因是openfire把vcard存在数据库中,导制数据库存性能,网络性能降低  
    QPixmap pixmap(szFile), map;
    int nWidth = pixmap.width();
    int nHeight = pixmap.height();
    if(nWidth > RABBITIM_AVATAR_SIZE)
        nWidth = RABBITIM_AVATAR_SIZE;
    if(nHeight > RABBITIM_AVATAR_SIZE)
        nHeight = RABBITIM_AVATAR_SIZE;
    map = pixmap.scaled(nWidth, nHeight, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
    QImageWriter imageWriter(&m_PhotoBuffer, "png");
    m_PhotoBuffer.open(QIODevice::WriteOnly);
    if(!imageWriter.write(map.toImage()))
        LOG_MODEL_ERROR("CDlgUservCard", "error:%s", imageWriter.errorString().toStdString().c_str());
    m_PhotoBuffer.close();

    ui->lbPhoto->setPixmap(map);
}
Beispiel #3
0
int CUserInfoXmpp::UpdateUserInfo(const QXmppVCardIq &vCard, QString jid)
{
    //if(!vCard.fullName().isEmpty())
    //    m_szName = vCard.fullName();
    m_szNick = vCard.nickName();
    m_Birthday = vCard.birthday();
    m_szEmail = vCard.email();
    m_szDescription = vCard.description();
    if(!jid.isEmpty() && m_szJid.isEmpty())
        m_szJid = jid;

    //保存头像  
    QByteArray photo = vCard.photo();
    QBuffer buffer;
    buffer.setData(photo);
    buffer.open(QIODevice::ReadOnly);
    QImageReader imageReader(&buffer);
    m_imgPhoto = imageReader.read();
    buffer.close();

    //保存头像到本地  
    QImageWriter imageWriter(CGlobal::Instance()->GetFileUserAvatar(GetId()), "png");
    if(!imageWriter.write(GetPhoto()))
        LOG_MODEL_ERROR("CUserInfo", "Save avater error, %s", imageWriter.errorString().toStdString().c_str());

    return 0;
}
Beispiel #4
0
void QTextOdfWriter::writeInlineCharacter(QXmlStreamWriter &writer, const QTextFragment &fragment) const
{
    writer.writeStartElement(drawNS, QString::fromLatin1("frame"));
    if (m_strategy == 0) {
        // don't do anything.
    }
    else if (fragment.charFormat().isImageFormat()) {
        QTextImageFormat imageFormat = fragment.charFormat().toImageFormat();
        writer.writeAttribute(drawNS, QString::fromLatin1("name"), imageFormat.name());

        // vvv  Copy pasted mostly from Qt =================
        QImage image;
        QString name = imageFormat.name();
        if (name.startsWith(QLatin1String(":/"))) // auto-detect resources
            name.prepend(QLatin1String("qrc"));
        QUrl url = QUrl::fromEncoded(name.toUtf8());
        const QVariant data = m_document->resource(QTextDocument::ImageResource, url);
        if (data.type() == QVariant::Image) {
            image = qvariant_cast<QImage>(data);
        } else if (data.type() == QVariant::ByteArray) {
            image.loadFromData(data.toByteArray());
        }

        if (image.isNull()) {
            QString context;
            if (QTextImageHandler::externalLoader)
                image = QTextImageHandler::externalLoader(name, context);

            if (image.isNull()) { // try direct loading
                name = imageFormat.name(); // remove qrc:/ prefix again
                image.load(name);
            }
        }

        // ^^^ Copy pasted mostly from Qt =================
        if (! image.isNull()) {
            QBuffer imageBytes;
            QImageWriter imageWriter(&imageBytes, "png");
            imageWriter.write(image);
            QString filename = m_strategy->createUniqueImageName();
            m_strategy->addFile(filename, QString::fromLatin1("image/png"), imageBytes.data());

            // get the width/height from the format.
            qreal width = (imageFormat.hasProperty(QTextFormat::ImageWidth)) ? imageFormat.width() : image.width();
            writer.writeAttribute(svgNS, QString::fromLatin1("width"), pixelToPoint(width));
            qreal height = (imageFormat.hasProperty(QTextFormat::ImageHeight)) ? imageFormat.height() : image.height();
            writer.writeAttribute(svgNS, QString::fromLatin1("height"), pixelToPoint(height));

            writer.writeStartElement(drawNS, QString::fromLatin1("image"));
            writer.writeAttribute(xlinkNS, QString::fromLatin1("href"), filename);
            writer.writeEndElement(); // image
        }
    }

    writer.writeEndElement(); // frame
}
Beispiel #5
0
bool ExportManager::writeImage(QIODevice *device, const QByteArray &format)
{
    QImageWriter imageWriter(device, format);
    if (!(imageWriter.canWrite())) {
        emit errorMessage(i18n("QImageWriter cannot write image: ") + imageWriter.errorString());
        return false;
    }

    return imageWriter.write(mSavePixmap.toImage());
}
void specialFilter::colorExtract(char *image_path[])
{
	int imageIndex = 0;

	unsigned char *probeImage;
	unsigned char *mappedImage;
	int value;

	setFilepath(image_path[8]);
	probeImage = imageReader();

	setFilepath(image_path[9]);
	mappedImage = imageReader();


	for(value = 0; value < 256; value++)
	{
		redMapping[value] =0;
		blueMapping[value] =0;
		greenMapping[value] = 0;
	}

	for(imageIndex = 0; imageIndex < rowSize*colSize*3;)
	{
		
		redMapping[probeImage[imageIndex]] = mappedImage[imageIndex++];
		greenMapping[probeImage[imageIndex]] = mappedImage[imageIndex++];
		blueMapping[probeImage[imageIndex]] = mappedImage[imageIndex++];
	}

	setFilepath("../redCoarseMap.dat");
	imageWriter(redMapping,256);

	setFilepath("../blueCoarseMap.dat");
	imageWriter(blueMapping,256);
	
	setFilepath("../greenCoarseMap.dat");
	imageWriter(greenMapping,256);

	linearMapping(redMapping);
	linearMapping(blueMapping);
	linearMapping(greenMapping);

	setFilepath("../redFineMap.dat");
	imageWriter(redMapping,256);

	setFilepath("../blueFineMap.dat");
	imageWriter(blueMapping,256);
	
	setFilepath("../greenFineMap.dat");
	imageWriter(greenMapping,256);
	
	delete probeImage;
	delete mappedImage;
}
Beispiel #7
0
void Cropper::mouseReleaseEvent( QMouseEvent *event )
{
    rubberBand->hide();

    setGeometry( QRect( origin, event->pos() ).normalized() );
    QImage croped = image.copy(QRect( origin, event->pos() ).normalized());
    ui->cropimageLabel->setPixmap(QPixmap::fromImage(croped));
    setGeometry( QRect( origin, event->pos() ).normalized() );

    QMessageBox::StandardButton reply;
    reply = QMessageBox::question(this, "Save", "Would you like to save these changes to the image?", QMessageBox::Yes|QMessageBox::No);
    if(reply == QMessageBox::Yes)
    {
        QImageWriter imageWriter(pointAlbum->toElement().firstChildElement("filename").text());
        imageWriter.write(ui->cropimageLabel->pixmap()->toImage());
    }

    this->close();
}
Beispiel #8
0
void MainWindow::saveCurrentImage()
{
    QMessageBox::StandardButton reply;
    reply = QMessageBox::question(this, "Save", "Would you like to save these changes to the image?", QMessageBox::Yes|QMessageBox::No);



    if(reply == QMessageBox::Yes)
    {
        QImageWriter imageWriter(album.toElement().firstChildElement("filename").text());
        imageWriter.write(ui->imageLabel->pixmap()->toImage());
        QImage image(album.toElement().firstChildElement("filename").text());
        ui->imageLabel->setPixmap(QPixmap::fromImage(image));
        ui->statusBar->showMessage("Image saved");
    }
    else
    {
        QImage image(album.toElement().firstChildElement("filename").text());
        ui->imageLabel->setPixmap(QPixmap::fromImage(image));
        ui->statusBar->showMessage("Image changes not saved");
    }
}
Beispiel #9
0
void CDlgUservCard::showEvent(QShowEvent *)
{
    LOG_MODEL_DEBUG("CDlgUservCard", "CDlgUservCard::showEvent");

    if(m_UserInfo.isNull())
        return;

    ui->txtJID->setText(m_UserInfo->GetId());
    ui->txtName->setText(m_UserInfo->GetName());
    ui->txtNick->setText(m_UserInfo->GetNick());
    ui->dateBirthday->setDate(m_UserInfo->GetBirthday());
    ui->txtEmail->setText(m_UserInfo->GetEmail());
    ui->txtDescription->setText(m_UserInfo->GetDescription());

    QImageWriter imageWriter(&m_PhotoBuffer, "png");
    m_PhotoBuffer.open(QIODevice::WriteOnly);
    if(!imageWriter.write(m_UserInfo->GetPhoto()))
        LOG_MODEL_ERROR("CDlgUservCard", "error:%s", imageWriter.errorString().toStdString().c_str());
    m_PhotoBuffer.close();

    QPixmap pixmap;
    pixmap.convertFromImage(m_UserInfo->GetPhoto());
    ui->lbPhoto->setPixmap(pixmap);
    ui->lbPhoto->setScaledContents(true);

    m_Image = CQRCode::QRcodeEncodeUserInfo(m_UserInfo->toString(), m_UserInfo->GetPhoto());
    if(m_Image.isNull())
        ui->gpQRCode->setVisible(false);
    else
    {
        ui->gpQRCode->setVisible(true);
        ui->lbQrencode->setPixmap(QPixmap::fromImage(m_Image));
    }

    ui->pbBrowse->setVisible(m_bModify);
    ui->pbClear->setVisible(m_bModify);
    ui->pbOK->setVisible(m_bModify);
}
////////////////////edge detection/////////////
void processImage::sobelOperator(int subMode, float threshold)
{
	int imageIndex;
	int rowIndex, colIndex;

	int mask_index_x, mask_index_y;
	int imageRowMask, imageColMask;

	int mask[3][3] = {1, 2, 1, 2, 0, 2, 1, 2, 1};

	int rightHandAvg_X = 0;
	int	leftHandAvg_X = 0;
	int	topLvlAvg_Y = 0;
	int	bottomLvlAvg_Y = 0;
	int thresholdValue = 0, newThresh = 0;

	unsigned char *xgradient = new unsigned char[rowSize * colSize];
	unsigned char *ygradient = new unsigned char[rowSize * colSize];

	for(rowIndex = 0; rowIndex < rowSize; rowIndex++)
		for(colIndex = 0; colIndex < colSize; colIndex++)
		{
			for(mask_index_x = -1; mask_index_x < 2; mask_index_x++)
			{
				mask_index_y = -1;
				imageRowMask = rowIndex + mask_index_x;
				imageColMask = colIndex + mask_index_y;
				leftHandAvg_X = leftHandAvg_X + mask[mask_index_x + 1][mask_index_y + 1] * 
					inputImageData[abs(imageRowMask)*colSize + abs(imageColMask)];
			}
			for(mask_index_x = -1; mask_index_x < 2; mask_index_x++)
			{
				mask_index_y = 1;
				imageRowMask = rowIndex + mask_index_x;
				imageColMask = colIndex + mask_index_y;
				rightHandAvg_X = rightHandAvg_X + mask[mask_index_x + 1][mask_index_y + 1] * 
					grayImage[abs(imageRowMask)*colSize + abs(imageColMask)];
			}
			for(mask_index_y = -1; mask_index_y < 2; mask_index_y++)
			{
				mask_index_x = -1;
				imageRowMask = rowIndex + mask_index_x;
				imageColMask = colIndex + mask_index_y;
				topLvlAvg_Y = topLvlAvg_Y + mask[mask_index_x + 1][mask_index_y + 1] * 
					inputImageData[abs(imageRowMask)*colSize + abs(imageColMask)];
			}
			for(mask_index_y = -1; mask_index_y < 2; mask_index_y++)
			{
				mask_index_x = 1;
				imageRowMask = rowIndex + mask_index_x;
				imageColMask = colIndex + mask_index_y;
				bottomLvlAvg_Y = bottomLvlAvg_Y + mask[mask_index_x + 1][mask_index_y + 1] * 
					grayImage[abs(imageRowMask)*colSize + abs(imageColMask)];
			}
			xgradient[rowIndex*colSize+colIndex] = (rightHandAvg_X - leftHandAvg_X)/4;
			ygradient[rowIndex*colSize+colIndex] = (topLvlAvg_Y - bottomLvlAvg_Y)/4;

			rightHandAvg_X = 0;
			leftHandAvg_X = 0;
			topLvlAvg_Y = 0;
			bottomLvlAvg_Y = 0;

			//outputImage[rowIndex*colSize+colIndex] = xgradient[rowIndex*colSize+colIndex];
			//outputImage[rowIndex*colSize+colIndex] = ygradient[rowIndex*colSize+colIndex];
			grayImage[rowIndex*colSize+colIndex] = sqrt((double)(xgradient[rowIndex*colSize+colIndex] * xgradient[rowIndex*colSize+colIndex])
				+ (ygradient[rowIndex*colSize+colIndex] * ygradient[rowIndex*colSize+colIndex]));
		}
	
	thresholdValue = edgeThresholding(threshold);

	if(subMode == 4)
	{
		for(rowIndex = 1; rowIndex < rowSize-1; rowIndex++)
			for(colIndex = 1; colIndex < colSize-1; colIndex++)
			{
				if(xgradient[rowIndex*colSize+colIndex] > ygradient[rowIndex*colSize+colIndex])
				{
					if(grayImage[rowIndex*colSize+colIndex] > grayImage[(rowIndex+1)*colSize+colIndex] &&
						grayImage[rowIndex*colSize+colIndex] > grayImage[(rowIndex-1)*colSize+colIndex] && 
						grayImage[rowIndex*colSize+colIndex] > thresholdValue)
						outputImage[rowIndex*colSize+colIndex] = 0;
					else
						outputImage[rowIndex*colSize+colIndex] = 255;
				}
				else
				{
					if(grayImage[rowIndex*colSize+colIndex] > grayImage[rowIndex*colSize+colIndex+1] &&
						grayImage[rowIndex*colSize+colIndex] > grayImage[rowIndex*colSize+colIndex-1] &&
						grayImage[rowIndex*colSize+colIndex] > thresholdValue)
						outputImage[rowIndex*colSize+colIndex] = 0;
					else
						outputImage[rowIndex*colSize+colIndex] = 255;
				}
			}

	}
	else
	{
		for(rowIndex = 0; rowIndex < rowSize; rowIndex++)
			for(colIndex = 0; colIndex < colSize; colIndex++)
			{
				if(grayImage[rowIndex*colSize+colIndex] < thresholdValue)
					outputImage[rowIndex*colSize+colIndex] = 255;
				else
					outputImage[rowIndex*colSize+colIndex] = 0;
			}
	}

		setFilepath("../xGradMap.raw");
		imageWriter(xgradient);
		
		setFilepath("../yGradMap.raw");
		imageWriter(ygradient);

	delete (xgradient);
	delete (ygradient);
}
Beispiel #11
0
bool PictureShared::identifyAndLoad(const QByteArray& _array)
{
    if (_array.size() < 5) {
        kError(30508) << "Picture is less than 5 bytes long!" << endl;
        return false;
    }

    QByteArray array = _array;

    QString strExtension;
    bool flag = false;

    // Try to find the file type by comparing magic on the first few bytes!
    // ### TODO: could not QImageIO::imageFormat do it too? (At least most of them?)
    if ((array[0] == char(0x89)) && (array[1] == 'P') && (array[2] == 'N') && (array[3] == 'G')) {
        strExtension = "png";
    } else if ((array[0] == char(0xff)) && (array[1] == char(0xd8)) && (array[2] == char(0xff)) && (array[3] == char(0xe0))) {
        strExtension = "jpeg";
    } else if ((array[0] == 'B') && (array[1] == 'M')) {
        strExtension = "bmp";
    } else if ((array[0] == '<') && (array[1] == '?') && (array[2] == 'x') && (array[3] == 'm') && (array[4] == 'l')) {
        strExtension = "svg";
    } else if ((array[0] == 'Q') && (array[1] == 'P') && (array[2] == 'I') && (array[3] == 'C')) {
        strExtension = "qpic";
    } else if ((array[0] == '%') && (array[1] == '!') && (array[2] == 'P') && (array[3] == 'S')) {
        strExtension = "eps";
    } else if ((array[0] == char(0xc5)) && (array[1] == char(0xd0)) && (array[2] == char(0xd3)) && (array[3] == char(0xc6))) {
        // So called "MS-DOS EPS file"
        strExtension = "eps";
    } else if ((array[0] == 'G') && (array[1] == 'I') && (array[2] == 'F') && (array[3] == '8')) {
        // GIF (87a or 89a)
        strExtension = "gif";
    } else if ((array[0] == char(0037)) && (array[1] == char(0213))) {
        // Gzip
        QBuffer buffer(&array);
        buffer.open(QIODevice::ReadOnly);

        const bool flag = loadCompressed(&buffer, "application/x-gzip", "tmp");
        buffer.close();
        return flag;
    } else if ((array[0] == 'B') && (array[1] == 'Z') && (array[2] == 'h')) {
        // BZip2
        QBuffer buffer(&array);
        buffer.open(QIODevice::ReadOnly);
        const bool flag = loadCompressed(&buffer, "application/x-bzip", "tmp");
        buffer.close();
        return flag;
    } else {
        kDebug(30508) << "Cannot identify the type of temp file!"
        << " Trying to convert to PNG! (in PictureShared::loadTmp" << endl;

        // Do not trust QBuffer and do not work directly on the QByteArray array
        // DF: It would be faster to work on array here, and to create a completely
        // different QBuffer for the writing code!
        QBuffer buf(&array);
        if (!buf.open(QIODevice::ReadOnly)) {
            kError(30508) << "Could not open read buffer!" << endl;
            return false;
        }

        QImageReader imageReader(&buf);
        QImage image = imageReader.read();
        if (image.isNull()) {
            kError(30508) << "Could not read image!" << endl;
            return false;
        }
        buf.close();

        if (!buf.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
            kError(30508) << "Could not open write buffer!" << endl;
            return false;
        }

        QImageWriter imageWriter(&buf, "PNG");

        if (!imageWriter.write(image)) {
            kError(30508) << "Could not write converted image!" << endl;
            return false;
        }
        buf.close();

        array = buf.buffer();

        strExtension = "png";
    }

    kDebug(30508) << "Temp file considered to be" << strExtension;

    clearAndSetMode(strExtension);
    if (m_base)
        flag = m_base->loadData(array, strExtension);
    setExtension(strExtension);

    return flag;
}
Beispiel #12
0
void RayTracer::Run()
{
    // Scene Setup -- Generate the camera and scene.
    std::shared_ptr<Camera> currentCamera = storedApplication->CreateCamera();
    std::shared_ptr<Scene> currentScene = storedApplication->CreateScene();
    std::shared_ptr<ColorSampler> currentSampler = storedApplication->CreateSampler();
    std::shared_ptr<Renderer> currentRenderer = storedApplication->CreateRenderer(currentScene, currentSampler);
    assert(currentScene && currentCamera && currentSampler && currentRenderer);

    currentSampler->InitializeSampler(storedApplication.get(), currentScene.get());

    // Scene preprocessing -- generate acceleration structures, etc.
    // After this call, we are guaranteed that the "acceleration" member of the scene and all scene objects within the scene will be non-NULL.
    currentScene->GenerateDefaultAccelerationData();
    currentScene->Finalize();

    currentRenderer->InitializeRenderer();

    // Prepare for Output
    const glm::vec2 currentResolution = storedApplication->GetImageOutputResolution();
    ImageWriter imageWriter(storedApplication->GetOutputFilename(), static_cast<int>(currentResolution.x), static_cast<int>(currentResolution.y));

    // Perform forward ray tracing
    const int maxSamplesPerPixel = storedApplication->GetSamplesPerPixel();
    assert(maxSamplesPerPixel >= 1);

    // for each pixel on the image
    #pragma omp parallel for num_threads(16)
    for (int y = 0; y < static_cast<int>(currentResolution.y); ++y) {
        for (int x = 0; x < static_cast<int>(currentResolution.x); ++x) {
            // lambda that write pixel samples to image?
            imageWriter.SetPixelColor(currentSampler->ComputeSamplesAndColor(maxSamplesPerPixel, 2, [&](glm::vec3 inputSample) {
                const glm::vec3 minRange(-0.5f, -0.5f, 0.f);
                const glm::vec3 maxRange(0.5f, 0.5f, 0.f);
                const glm::vec3 sampleOffset = (maxSamplesPerPixel == 1) ? glm::vec3(0.f, 0.f, 0.f) : minRange + (maxRange - minRange) * inputSample;

                glm::vec2 normalizedCoordinates(static_cast<float>(x) + sampleOffset.x, static_cast<float>(y) + sampleOffset.y);
                normalizedCoordinates /= currentResolution;

                // Construct ray, send it out into the scene and see what we hit.
                std::shared_ptr<Ray> cameraRay = currentCamera->GenerateRayForNormalizedCoordinates(normalizedCoordinates, 
                                                    storedApplication->GetFocusPlane(),
                                                    storedApplication->GetAperture());
                assert(cameraRay);

                IntersectionState rayIntersection(storedApplication->GetMaxReflectionBounces(), storedApplication->GetMaxRefractionBounces());
                bool didHitScene = currentScene->Trace(cameraRay.get(), &rayIntersection);

                // Use the intersection data to compute the BRDF response.
                glm::vec3 sampleColor;
                if (didHitScene) {
                    sampleColor = currentRenderer->ComputeSampleColor(rayIntersection, *cameraRay.get());
                }
                return sampleColor;
            }), x, y);
        }
    }

    // Apply post-processing steps (i.e. tone-mapper, etc.).
    storedApplication->PerformImagePostprocessing(imageWriter);

    // Now copy whatever is in the HDR data and store it in the bitmap that we will save (aka everything will get clamped to be [0.0, 1.0]).
    imageWriter.CopyHDRToBitmap();

    // Save image.
    imageWriter.SaveImage();
}