如何使用 OpenImageIO 和 read_tiles() 读取平铺图像
How to read tiled images with OpenImageIO and read_tiles()
我在使用 VisualStudio 和 OIIO 2.0.8 的 Windows 上读取平铺图像时遇到问题。 为了进行测试,我渲染了一个带有选中平铺选项且没有平铺选项的 Arnold 图像。虽然读取扫描线图像工作正常,但平铺渲染不会读取任何内容。我可以在调试模式下看到,tilePixel 数组在读取瓷砖之前和之后根本没有变化。read_tiles调用的结果始终为 true。
也许任何人都可以看看并告诉我是否有明显的问题。
这是我使用的仍然有点混乱的代码。
std::string filename = "C:/daten/images/tiledRender.exr";
auto in = ImageInput::open(filename);
if (in)
{
int tw = spec.tile_width;
int th = spec.tile_height;
int w = spec.width;
int h = spec.height;
int numBytesPerPixel = 3;
size_t numBytesPerImage = w*h*numBytesPerPixel;
size_t numBytesPerLine = w*numBytesPerPixel;
std::vector<unsigned char> pixels(numBytesPerImage, 120);
unsigned char* line = &pixels[0];
unsigned char *bit = image->bits(); //this comes from QImage
if (tw == 0) // no tiles read scanlines
{
qDebug() << "Found scanline rendering.n";
for (int i = 0; i < h; i++)
{
bool success = in->read_scanlines(0, 0, i, i+1, 0, 0, 3, TypeDesc::UCHAR, line);
if (!success)
qDebug() << "read scanline problem at scanline " << i << "n";
line += numBytesPerLine;
}
memcpy(bit, &pixels[0], numBytesPerImage);
}
else {
qDebug() << "Found tiled rendering.n";
int numTilePixels = tw * th;
int numBytesPerTile = numTilePixels * 3;
std::vector<unsigned char> tilePixels(numBytesPerTile, 80);
unsigned char* tilePtr = &tilePixels[0];
for (int x = 0; x < w; x += tw)
{
for (int y = 0; y < h; y += th)
{
int ttw = tw;
int tth = th;
if ((x + tw) >= w)
ttw = w - x;
if ((y + th) >= h)
tth = h - y;
bool success = in->read_tiles(0, 0, x, x+ttw, y, y+tth, 0, 0, 0, 3, TypeDesc::UCHAR, tilePtr);
if (!success)
qDebug() << "read tiles problemn";
}
}
}
解决方案在于读取瓷砖的方式。我必须使用 zEnd = 1,而不是读取 zStart = 0 和 zEnd = 0。
所以代替:
bool success = in->read_tiles(0, 0, x, x+ttw, y, y+tth, 0, 0, 0, 3, TypeDesc::UCHAR, tilePtr);
它必须是
bool success = in->read_tiles(0, 0, x, x+ttw, y, y+tth, 0, 1, 0, 3, TypeDesc::UCHAR, tilePtr);
相关文章:
- 增加 gil 读取图像错误
- 这是我的程序,C++使用 OpenCv 库从数据集中读取图像序列,但它没有运行
- 如何在Visual Studio中使用ITK配置的C 读取图像
- 如何在Android NDK中的硬盘驱动器中读取图像
- 如何在VTK DICOM阅读器中读取图像类型(0008,0008)
- 从C 中的文件中读取图像,然后传递到Libharu的绘制方法
- 从J2ME到C 读取图像
- imread无法读取图像
- 正在从文件-C++中读取图像
- 无法读取图像
- 使用openCV从AmazonS3读取图像
- OpenCV读取图像像素值
- 从内存中读取图像,知道指向内存的指针.VC++
- 读取图像打开CV时遇到问题
- 如何在C++中读取图像并将其绘制为加速图像
- 如何导航文件夹以读取图像
- 如何在c++中读取图像文件并将其存储在内存中(std::string)
- CImg读取图像异常
- 如何使用Poco C++从HTTP服务器响应中读取图像内容
- 为什么ifstream阅读器只读取图像文件的前10个字节