在ImageMagick 7的API c++中从PixelPacket移植对像素的访问
Porting access to pixels from PixelPacket in API C++ of ImageMagick 7
我尝试用ImageMagick-7.0.0-Q16-HDRI移植代码。
此代码适用于ImageMagick-6.9.1-Q16:
QString ImageMagick::fromQImage(const QImage &qimage){
if (!qimage.size().isValid()) return "ImageMagick::fromQImage - Empty Qimage";
image = Magick::Image(Magick::Geometry(qimage.width(), qimage.height()), Magick::ColorRGB(0.5, 0.2, 0.3));
double scale = 1 / 255.0;
image.modifyImage();
Magick::PixelPacket *pixels;
Magick::ColorRGB mgc;
for (int y = 0; y < qimage.height(); y++) {
pixels = image.setPixels(0, y, image.columns(), 1);
for (int x = 0; x < qimage.width(); x++) {
QColor pix = qimage.pixel(x, y);
// *pixels++ = Magick::ColorRGB(256 * pix.red(), 256 * pix.green(), 256 * pix.blue());
mgc.red(scale *pix.red());
mgc.green(scale *pix.green());
mgc.blue(scale *pix.blue());
// *pixels++ = Magick::ColorRGB(scale *pix.red(), scale * pix.green(), scale * pix.blue());
pixels[x] = mgc;
}
image.syncPixels();
}
return "";
}
现在我必须使用by http://www.imagemagick.org/script/porting.php代替PixelPacket
:
MagickCore::Quantum *pixels;
在某些情况下:
- pixels[0]-像素 的红色通道
- 像素[1]-像素 的绿色通道
- pixels[2]-像素 的蓝色通道
如何使用SetPixelRed()…代替pixels[x] = mgc;
MagickCore::SetPixelRed((MagickCore::Image*)&image,scale*pix.red(),pixels+x*3);
MagickCore::SetPixelGreen((MagickCore::Image*)&image,scale*pix.green(),pixels+x*3);
MagickCore::SetPixelBlue((MagickCore::Image*)&image,scale*pix.blue(),pixels+x*3);
但是现在呢?
找到下一个解:
size_t imageQuantum = MAGICKCORE_QUANTUM_DEPTH;
size_t toFloatQuantum=(pow(2,imageQuantum)-1);
size_t imageChanells=image.channels();
…
pixels[x*imageChanells]=mgc.red()*toFloatQuantum;
pixels[x*imageChanells+1]=mgc.green()*toFloatQuantum;
pixels[x*imageChanells+2]=mgc.blue()*toFloatQuantum;
这是一个非常好的问题,但是我认为你从错误的角度来处理这个问题。
如果Magick::Pixels.get
返回Quantum
,则只需将QColor
直接应用于值,sync
Magick::Image img(Magick::Geometry(2,2), Magick::Color("white"));
img.modifyImage();
Magick::Pixels view(img);
Magick::Quantum * pixels = view.get(0, 0, 2, 2);
int x,y;
for (y= 0; y < 2 ; y++ ) {
for (x = 0 ; x < 2 ; x++ ) {
// As we starting the pixels as white, we can
// leverage multiplication assignment (*=) operator.
*pixels++ *= pix.red() / 255.0; // Red
*pixels++ *= pix.green()/ 255.0; // Green
*pixels++ *= pix.blue() / 255.0; // Blue
}
}
view.sync()
不需要从MagickCore
中调用任何其他类
相关文章:
- 如何在不产生任何垃圾的情况下获得C中的像素
- 在C++中使用GDAL可以将图像的像素坐标转换为lat,long吗
- 如何在24位SDL_Surface上设置像素的颜色
- 如何从SDL_Surface获取特定像素的颜色
- 如何将CMSampleBufferRef/CIImage/UIImage转换为像素,例如uint8_t[]
- 在C++中查找像素 RGB 数据的最快方法是什么?
- 是否可以从 OpenGL 缓冲区获取原始大小的像素?
- 选择基于另一个垫子的非零像素的cv::Mat的一部分?
- 如何使用 sdl2 快速绘制像素网格?
- 如何在C++中进行像素操作? - Linux
- 他们如何将红外锁定像素转换为镜头前方 1m 的正常平面上的位置
- 访问随机图像像素的快速方法,最多一次
- OpenCV 像素访问点与 at() - 不同的值
- 如何使用 freetype2 访问单色位图中的像素状态
- 尝试渲染像素坐标时,简单线条渲染失败
- 计算另一个图像像素满足条件的像素值的平均值
- 如何返回定义良好的内存部分?例如来自图像数据的像素的颜色值
- 在Qt-cpp中通过像素获取QString的子字符串
- magick 获得像素颜色.PixelPacket似乎不再存在了
- 在ImageMagick 7的API c++中从PixelPacket移植对像素的访问