bool UndoCache::putData(int level, const DImg& img) const { QFile file(d->cacheFile(level)); KDiskFreeSpaceInfo info = KDiskFreeSpaceInfo::freeSpaceInfo(d->cacheDir); unsigned long fspace = (unsigned long)(info.available()/1024.0/1024.0); kDebug() << "Free space available in Editor cache [" << d->cacheDir << "] in Mbytes: " << fspace; if (file.exists() || !file.open(QIODevice::WriteOnly) || fspace < 1024) // Check if free space is over 1 Gb to put data in cache. { return false; } QDataStream ds(&file); ds << img.width(); ds << img.height(); ds << img.sixteenBit(); ds << img.hasAlpha(); QByteArray ba((const char*)img.bits(), img.numBytes()); ds << ba; file.close(); d->cachedLevels << level; return true; }
void RainDropTool::putPreviewData() { ImageIface* iface = d->previewWidget->imageIface(); DImg imDest = filter()->getTargetImage().smoothScale(iface->previewWidth(), iface->previewHeight()); iface->putPreviewImage(imDest.bits()); d->previewWidget->updatePreview(); }
void ResizeTool::putFinalData() { ImageIface iface(0, 0); DImg targetImage = filter()->getTargetImage(); iface.putOriginalImage(i18n("Resize"), filter()->filterAction(), targetImage.bits(), targetImage.width(), targetImage.height()); }
void BCGFilter::applyBCG(DImg& image) { if (image.isNull()) { return; } applyBCG(image.bits(), image.width(), image.height(), image.sixteenBit()); }
void IccTransform::transform(DImg& image, const TransformDescription& description, DImgLoaderObserver* const observer) { const int bytesDepth = image.bytesDepth(); const int pixels = image.width() * image.height(); // convert ten scanlines in a batch const int pixelsPerStep = image.width() * 10; uchar* data = image.bits(); // see dimgloader.cpp, granularity(). int granularity = 1; if (observer) { granularity = (int)((pixels / (20 * 0.9)) / observer->granularity()); } int checkPoint = pixels; // it is safe to use the same input and output buffer if the format is the same if (description.inputFormat == description.outputFormat) { for (int p = pixels; p > 0; p -= pixelsPerStep) { int pixelsThisStep = qMin(p, pixelsPerStep); int size = pixelsThisStep * bytesDepth; LcmsLock lock; dkCmsDoTransform(d->handle, data, data, pixelsThisStep); data += size; if (observer && p <= checkPoint) { checkPoint -= granularity; observer->progressInfo(&image, 0.1 + 0.9 * (1.0 - float(p) / float(pixels))); } } } else { QVarLengthArray<uchar> buffer(pixelsPerStep * bytesDepth); for (int p = pixels; p > 0; p -= pixelsPerStep) { int pixelsThisStep = qMin(p, pixelsPerStep); int size = pixelsThisStep * bytesDepth; LcmsLock lock; memcpy(buffer.data(), data, size); dkCmsDoTransform(d->handle, buffer.data(), data, pixelsThisStep); data += size; if (observer && p <= checkPoint) { checkPoint -= granularity; observer->progressInfo(&image, 0.1 + 0.9 * (1.0 - float(p) / float(pixels))); } } } }
SharpenFilter::SharpenFilter(DImgThreadedFilter* const parentFilter, const DImg& orgImage, const DImg& destImage, int progressBegin, int progressEnd, double radius, double sigma) : DImgThreadedFilter(parentFilter, orgImage, destImage, progressBegin, progressEnd, parentFilter->filterName() + QLatin1String(": Sharpen")) { m_radius = radius; m_sigma = sigma; // We need to provide support for orgImage == destImage. // The algorithm does not support this out of the box, so use a temporary. if (orgImage.bits() == destImage.bits()) { m_destImage = DImg(destImage.width(), destImage.height(), destImage.sixteenBit()); } filterImage(); if (orgImage.bits() == destImage.bits()) { memcpy(destImage.bits(), m_destImage.bits(), m_destImage.numBytes()); } }
void ImageIface::setPreview(const DImg& img) { if (img.hasAlpha() != previewHasAlpha() || img.sixteenBit() != previewSixteenBit() ) { kDebug() << "Properties of image differs than preview"; return; } uchar* const data = img.bits(); if (!data) { kDebug() << "No preview image data to handle"; return; } d->targetPreviewImage.detach(); d->targetPreviewImage.putImageData(data); }
void HSLFilter::applyHSL(DImg& image) { if (image.isNull()) { return; } bool sixteenBit = image.sixteenBit(); uint numberOfPixels = image.numPixels(); int progress; int hue, sat, lig; double vib = d->settings.vibrance; DColor color; if (sixteenBit) // 16 bits image. { unsigned short* data = (unsigned short*) image.bits(); for (uint i=0; runningFlag() && (i<numberOfPixels); ++i) { color = DColor(data[2], data[1], data[0], 0, sixteenBit); // convert RGB to HSL color.getHSL(&hue, &sat, &lig); // convert HSL to RGB color.setHSL(d->htransfer16[hue], vibranceBias(d->stransfer16[sat], hue, vib, sixteenBit), d->ltransfer16[lig], sixteenBit); data[2] = color.red(); data[1] = color.green(); data[0] = color.blue(); data += 4; progress = (int)(((double)i * 100.0) / numberOfPixels); if ( progress%5 == 0 ) { postProgress( progress ); } } } else // 8 bits image. { uchar* data = image.bits(); for (uint i=0; runningFlag() && (i<numberOfPixels); ++i) { color = DColor(data[2], data[1], data[0], 0, sixteenBit); // convert RGB to HSL color.getHSL(&hue, &sat, &lig); // convert HSL to RGB color.setHSL(d->htransfer[hue], vibranceBias(d->stransfer[sat],hue,vib,sixteenBit), d->ltransfer[lig], sixteenBit); data[2] = color.red(); data[1] = color.green(); data[0] = color.blue(); data += 4; progress = (int)(((double)i * 100.0) / numberOfPixels); if ( progress%5 == 0 ) { postProgress( progress ); } } } }
void UndoManager::getSnapshot(int index, DImg* const img) const { DImg data = d->undoCache->getData(index); // Pass ownership of buffer. If data is null, img will be null img->putImageData(data.width(), data.height(), data.sixteenBit(), data.hasAlpha(), data.bits(), true); }
void RawSettingsBox::setPostProcessedImage(DImg& img) { histogramBox()->histogram()->stopHistogramComputation(); histogramBox()->histogram()->updateData(img.bits(), img.width(), img.height(), img.sixteenBit()); }
void RawSettingsBox::setDemosaicedImage(DImg& img) { d->curveWidget->stopHistogramComputation(); d->curveWidget->updateData(img.bits(), img.width(), img.height(), img.sixteenBit()); }