本文整理汇总了C++中magick::Image::magick方法的典型用法代码示例。如果您正苦于以下问题:C++ Image::magick方法的具体用法?C++ Image::magick怎么用?C++ Image::magick使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类magick::Image
的用法示例。
在下文中一共展示了Image::magick方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: convertImageDpi
void MagickImageLoader::convertImageDpi(Magick::Image& image) {
if (image.magick() == "PDF" | image.magick() == "SVG" || image.magick() == "DJVU") {
//change from default 72 dpi
image.resolutionUnits(Magick::PixelsPerInchResolution);
image.density(Magick::Geometry(MIN_DPI_FOR_VECTOR_FORMAT, MIN_DPI_FOR_VECTOR_FORMAT));
}
}
示例2: onInput
void PipelineStabDetect::onInput(InputImageInfo info, Magick::Image image) {
try {
if (!initialized) {
init(image);
}
if (image.rows() != height || image.columns() != width) {
throw runtime_error(QString("Not uniform image size! %").arg(info.file.fileName()).toStdString());
}
Magick::Blob blob;
// set raw RGBS output format & convert it into a Blob
if (image.depth() > 8)
*err << "Warning: we lost some information by converting to 8bit depth (now " << image.depth() << ")" << endl;
image.depth(8);
image.magick("RGB");
image.write(&blob);
LocalMotions localmotions;
VSFrame frame;
size_t dataLen = blob.length();
Q_ASSERT(fi.planes == 1);
Q_ASSERT(dataLen == image.baseColumns() * image.baseRows() * 3);
if (stabConf->mdConf.show > 0) { // create copy of blob
frame.data[0] = new uint8_t[dataLen];
memcpy(frame.data[0], blob.data(), dataLen);
} else {
frame.data[0] = (uint8_t*) blob.data();
}
frame.linesize[0] = image.baseColumns() * 3;
if (vsMotionDetection(&md, &localmotions, &frame) != VS_OK) {
throw runtime_error("motion detection failed");
} else {
if (vsWriteToFile(&md, f, &localmotions) != VS_OK) {
throw runtime_error("cannot write to transform file");
}
vs_vector_del(&localmotions);
}
if (stabConf->mdConf.show > 0) {
// if we want to store transformations, we have to create new image...
Magick::Geometry g(width, height);
Magick::Blob oblob(frame.data[0], dataLen);
Magick::Image oimage;
oimage.read(oblob, g, 8, "RGB");
delete[] frame.data[0];
emit input(info, oimage);
} else {
emit input(info, image);
}
} catch (exception &e) {
emit error(e.what());
}
}
示例3: convertImageToDib
void MagickImageLoader::convertImageToDib(Magick::Image& image, Magick::Blob& blob) {
image.magick("DIB");
if(image.xResolution() == 0 || image.yResolution() == 0) {
image.resolutionUnits(Magick::PixelsPerInchResolution);
image.density(Magick::Geometry(75, 75));
}
image.write(&blob);
}
示例4: saveToStream
void MagickImageExporter::saveToStream(const ImageRawData& image, std::ostream& os) {
if (image.isNull())
throw Exception("[MagickImageExporter::save] null image given");
if (os.fail())
throw Exception("[MagickImageExporter::save] invalid stream");
Magick::Blob blob(image.data(), image.dataSize());
try {
Magick::Image image;
image.verbose(true);
image.magick("DIB");
image.read(blob);
image.magick(formatToString(format()));
image.write(&blob);
os.write((char*) blob.data(), blob.length());
} catch (Magick::Exception &e) {
std::cerr << e.what() << "\n";
throw Exception("MagickImageExporter::load failed");
}
}
示例5: lItem
ItemSequence_t
ConvertSVGFunction::evaluate(
const ExternalFunction::Arguments_t& aArgs,
const StaticContext* aSctxCtx,
const DynamicContext* aDynCtx) const
{
Magick::Image lImage;
String lSVG = ImageFunction::getOneStringArg(aArgs, 0);
ImageFunction::getImageFromString(aDynCtx, lSVG, lImage, false);
if (lImage.magick().compare("SVG") != 0) {
ImageFunction::throwErrorWithQName(aDynCtx, "IM002", "The passed xs:base64Binary is not an image of type SVG");
}
String lType = ImageFunction::getOneStringArg(aArgs, 1);
lImage.magick(lType.c_str());
String lEncodedContent = ImageFunction::getEncodedStringFromImage(aDynCtx, lImage);
Item lItem( theModule->getItemFactory()->createBase64Binary(lEncodedContent.c_str(), lEncodedContent.size(), true));
ImageFunction::checkIfItemIsNull(lItem);
return ItemSequence_t(new SingletonItemSequence(lItem));
}
示例6: onInput
void WriteFrame::onInput(InputImageInfo info, Magick::Image img) {
QString framePath = outputDir.path() + QDir::separator()
+ leadingZeros(info.frame, FRAME_FILE_LEADING_ZEROS) + QString(".jpeg");
*verboseOutput << "Write frame " << framePath << endl;
if (!dryRun) {
img.compressType(Magick::JPEGCompression);
img.magick( "JPEG" );
img.write(framePath.toStdString());
}
// update image location & emit signal
info.file = QFileInfo(framePath);
emit input(info, img);
}
示例7: target
ResizeTest(std::string fileName) {
source.loadFile(fileName);
for (int i=1; i<99; ++i) {
Magick::Image image = source.getImage();
image.magick("JPEG");
image.quality(50);
Magick::Geometry resizeGeometry;
resizeGeometry.percent(true);
resizeGeometry.width(i);
resizeGeometry.height(i);
image.resize(resizeGeometry);
Magick::Blob blob;
image.write(&blob);
imghash::Source target((char*)blob.data(), blob.length());
images.push_back(target);
}
}
示例8: previewRotate
QImage ImageItem::previewRotate(short degrees)
{
Magick::Image image;
if (m_tempImage) {
m_tempImage->open();
image.read(m_tempImage->fileName().toStdString());
image.magick("jpg");
} else {
image.read(absoluteFilePath().toStdString());
m_tempImage = new QTemporaryFile(qApp);
m_tempImage->open();
}
image.rotate(degrees);
Magick::Blob buffer;
image.write(&buffer);
QImage output;
output.loadFromData((const uchar*) buffer.data(), buffer.length());
output.save(m_tempImage, "JPEG");
m_tempImage->close();
return output;
}
示例9: conv
Magick::Blob ImgMgk::conv(const void *data, size_t length, const std::string &text)
{
Magick::Blob blob1;
Magick::Blob blob(data,length);
try
{
Magick::Image image;
image.read(blob);
image.annotate(text, Magick::SouthEastGravity);
image.magick("JPEG"); // Set JPEG output format
image.write(&blob1);
}
catch( std::exception &error_ )
{
Log::err("Caught exception: %s", error_.what());
return blob;
}
return blob1;
}
示例10: WriteGif
void DrvSDL::WriteGif() {
std::list<Magick::Image> gif;
int num = 0;
for(std::list<Magick::Blob>::iterator it = image_.begin(); it != image_.end(); it++) {
Magick::Image image;
image.magick("RGB");
image.depth(32);
image.size(Magick::Geometry(cols_ * pixels.x, rows_ * pixels.y));
Magick::PixelPacket *pixel_cache = image.getPixels(0, 0, cols_ * pixels.x, rows_ * pixels.y);
for(int n = 0; n < rows_ * pixels.y * cols_ * pixels.x; n++) {
int col = ((int *)(*it).data())[n];
uint8_t *rgb = (uint8_t *) &col;
Magick::PixelPacket *gif_pixel = pixel_cache + n;
*gif_pixel = Magick::ColorRGB(rgb[0] / 256.0, rgb[1] / 256.0, rgb[2] / 256.0);
}
image.syncPixels();
gif.push_back(image);
LCDInfo("Image %d", num++);
}
LCDInfo("Writing GIF image...");
for_each(gif.begin(), gif.end(), Magick::animationDelayImage(ani_speed_ / 10));
Magick::writeImages(gif.begin(), gif.end(), gif_file_);
}
示例11: imageCaptured
void TimeLapseCapture::imageCaptured(QString format, Magick::Blob blob, Magick::Geometry sizeHint) {
bool readRawFromFile = false;
QString framePath = output.path() + QDir::separator()
+ leadingZeros(capturedCnt, FRAME_FILE_LEADING_ZEROS) + "_" + leadingZeros(capturedSubsequence, 2);
if (format == "RGB") {
if (storeRawImages) {
// store RAW RGB data in PPM format
QString pgmHeader = QString("P6\n%1 %2\n255\n").arg(sizeHint.width()).arg(sizeHint.height());
std::string headerStr = pgmHeader.toStdString();
const char *headerBytes = headerStr.c_str();
size_t headerLen = strlen(headerBytes);
if (shutterSpdAlg != NULL && capturedSubsequence == 0) {
Magick::Image capturedImage;
capturedImage.read(blob, sizeHint, 8, "RGB");
shutterSpdAlg->update(capturedImage);
}
framePath += ".ppm";
QFile file(framePath);
file.open(QIODevice::WriteOnly);
file.write(headerBytes, headerLen);
file.write((char*) blob.data(), blob.length());
file.close();
} else {
// convert RGB data to JPEG
Magick::Image capturedImage;
capturedImage.read(blob, sizeHint, 8, "RGB");
if (shutterSpdAlg != NULL && capturedSubsequence == 0) {
shutterSpdAlg->update(capturedImage);
}
QDateTime now = QDateTime::currentDateTime();
QString exifDateTime = now.toString("yyyy:MM:dd HH:mm:ss");\
// ImageMagick don't support writing of exif data
// TODO: setup exif timestamp correctly
capturedImage.attribute("EXIF:DateTime", exifDateTime.toStdString());
//capturedImage.defineValue("EXIF", "DateTime", exifDateTime.toStdString());
capturedImage.compressType(Magick::JPEGCompression);
capturedImage.magick("JPEG");
framePath += ".jpeg";
capturedImage.write(framePath.toStdString());
}
} else {
if (shutterSpdAlg != NULL && capturedSubsequence == 0) {
try {
Magick::Image capturedImage;
capturedImage.read(blob, format.toStdString());
shutterSpdAlg->update(capturedImage);
} catch (const std::exception &e) {
err << "Failed to decode captured image (" << format << "): " << QString::fromUtf8(e.what()) << endl;
readRawFromFile = true;
}
}
// store other formats in device specific format
framePath += "." + format;
QFile file(framePath);
file.open(QIODevice::WriteOnly);
file.write((char*) blob.data(), blob.length());
file.close();
if (readRawFromFile && shutterSpdAlg != NULL && capturedSubsequence == 0) {
/* I don't understand ImageMagick correctly, but it fails with reading RAW files
* from memory blob, but reading from file works (sometimes).
* Maybe, it don't support delegating (dcraw, ufraw...) with memory data...
*/
try {
Magick::Image capturedImage;
capturedImage.read(framePath.toStdString());
shutterSpdAlg->update(capturedImage);
} catch (const std::exception &e) {
err << "Failed to decode captured image (" << framePath << "): " << QString::fromUtf8(e.what()) << endl;
}
}
}
verboseOutput << "Captured frame saved to " << framePath << endl;
capturedSubsequence++;
}
示例12:
void Magick::magickImage::operator()( Magick::Image &image_ ) const
{
image_.magick( _magick );
}
示例13: resize_output_filter
//
// Output filter.
//
static apr_status_t resize_output_filter(ap_filter_t* f, apr_bucket_brigade* in_bb)
{
request_rec* rec =f->r;
resize_conf* conf = (resize_conf*)ap_get_module_config(rec->per_dir_config, &resizeimage_module);
const char* content_type, *target_type = "JPEG";
const char* image_url, *resize_param, *image_hash=NULL;
Magick::Blob blob;
char* vlob = NULL;
size_t vlob_length = 0;
int cache_hit = FALSE;
AP_LOG_VERBOSE(rec, "Incoming %s.", __FUNCTION__);
// Pass thru by request types.
if(rec->status!=HTTP_OK || rec->main!=NULL || rec->header_only
|| (rec->handler!= NULL && strcmp(rec->handler, "default-handler") == 0)) goto PASS_THRU;
AP_LOG_VERBOSE(rec, "-- Checking responce headers.");
// Obtain and erase x-resize-image header or pass through.
image_url = get_and_unset_header(rec->headers_out, X_RESIZE);
if(image_url== NULL || image_url[0]=='\0') {
image_url = get_and_unset_header(rec->err_headers_out, X_RESIZE);
}
if(image_url==NULL || image_url[0]=='\0') goto PASS_THRU;
// Check content-type
content_type = rec->content_type;
if(content_type) {
if(strcasecmp(content_type, "image/jpeg")==0) {
target_type = "JPEG";
} else
if(strcasecmp(content_type, "image/png")==0) {
target_type = "PNG";
} else
if(strcasecmp(content_type, "image/gif")==0) {
target_type = "GIF";
} else goto PASS_THRU;
}
// Resize parameter
resize_param = get_and_unset_header(rec->headers_out, X_RESIZE_PARAM);
if(resize_param==NULL || resize_param[0]=='\0') {
resize_param = get_and_unset_header(rec->err_headers_out, X_RESIZE_PARAM);
}
if(resize_param[0]=='\0') resize_param = NULL;
// Image hash
image_hash = get_and_unset_header(rec->headers_out, X_RESIZE_HASH);
if(image_hash==NULL || image_hash[0]=='\0') {
image_hash = get_and_unset_header(rec->err_headers_out, X_RESIZE_HASH);
}
// Open image and resize.
AP_LOG_INFO(rec, "URL: %s, %s => %s (%s)", image_url, content_type, resize_param, image_hash);
if(image_hash) {
// Try memcached...
image_hash = apr_psprintf(rec->pool, "%s:%s:%s", image_hash, target_type, resize_param);
memcached_return r;
uint32_t flags;
vlob = memcached_get(conf->memc, image_hash, strlen(image_hash), &vlob_length, &flags, &r);
if(r==MEMCACHED_SUCCESS) {
AP_LOG_DEBUG(rec, "Restored from memcached: %s, len=%d", image_hash, vlob_length);
cache_hit = TRUE;
goto WRITE_DATA;
} else {
AP_LOG_DEBUG(rec, "Can't restore from memcached: %s - %s(%d)", image_hash, memcached_strerror(conf->memc, r), r);
}
}
// Reszize
try {
Magick::Image image;
image.read(image_url);
if(resize_param) image.zoom(resize_param);
image.magick(target_type);
image.quality(conf->jpeg_quality);
image.write(&blob);
vlob = (char*)blob.data();
vlob_length = blob.length();
}
catch(Magick::Exception& err) {
AP_LOG_ERR(rec, __FILE__ ": Magick failed: %s", err.what());
goto PASS_THRU;
}
if(image_hash) {
// Store to memcached...
memcached_return r = memcached_set(conf->memc, image_hash, strlen(image_hash), vlob, vlob_length, conf->expire, 0);
if(r==MEMCACHED_SUCCESS) {
AP_LOG_DEBUG(rec, "Stored to memcached: %s(len=%d)", image_hash, vlob_length);
} else {
AP_LOG_DEBUG(rec, "Can't store from memcached: %s(len=%d) - %s(%d)", image_hash, vlob_length,memcached_strerror(conf->memc, r), r);
}
}
//.........这里部分代码省略.........