gpt4 book ai didi

c++ - boost::gil 是否支持 10 位图像?

转载 作者:行者123 更新时间:2023-11-30 03:22:00 26 4
gpt4 key购买 nike

我正在尝试从缓冲区中读取 10 位图像并使用 boost::gil 对其进行分析。我注意到存在一个 rgb8_image_t 类型,一个 gray8_image_t 类型,但找不到 gray10_image_t 类型(这是我需要的)。这在gil中存在吗?谢谢!

编辑:使用这些类型定义时:

// reference type
typedef boost::gil::bit_aligned_pixel_reference<unsigned short, boost::mpl::vector1_c<unsigned, 10>, boost::gil::gray_layout_t, true> gray10_ref_t;

// iterator type
typedef boost::gil::bit_aligned_pixel_iterator<gray10_ref_t> gray10_ptr_t;

// pixel type
typedef std::iterator_traits<gray10_ptr_t>::value_type gray10_pixel_t;

// pixel storage to read, contains 3 10-bit gray pixels, all with value of 1 as per the following layout
// spaces show byte breaks, bars show pixel breaks, lsb first
// 10000000 00|100000 0000|1000 00000000
std::uint8_t data[4] = { 0x01, 0x04, 0x10, 0x00 };

// an iterator to the start of the storage
gray10_ptr_t p(&data[0], 0);

// check the expected pixel values
assert(p[0] == 0x01);
assert(p[1] == 0x01);
assert(p[2] == 0x01);

编译时出现以下错误:

untitled.cpp:17:6: error: ‘uint8_t’ in namespace ‘std’ does not name a type 
std::uint8_t data[4] = { 0x01, 0x04, 0x10, 0x00 };
^
untitled.cpp:20:17: error: ‘data’ was not declared in this scope
gray10_ptr_t p(&data[0], 0);
^
In file included from /usr/include/boost/predef/detail/_cassert.h:14:0,
from /usr/include/boost/predef/library/c/_prefix.h:11,
from /usr/include/boost/predef/library/c.h:11,
from /usr/include/boost/predef/library.h:11,
from /usr/include/boost/predef.h:14,
from /usr/include/boost/smart_ptr/detail/yield_k.hpp:28,
from /usr/include/boost/smart_ptr/detail/spinlock_sync.hpp:18,
from /usr/include/boost/smart_ptr/detail/spinlock.hpp:50,
from /usr/include/boost/smart_ptr/detail/spinlock_pool.hpp:25,
from /usr/include/boost/smart_ptr/shared_ptr.hpp:34,
from /usr/include/boost/shared_ptr.hpp:17,
from /usr/include/boost/gil/extension/io/io_error.hpp:23,
from /usr/include/boost/gil/extension/io/tiff_io.hpp:29,
from untitled.cpp:1:
untitled.cpp:23:13: error: expected ‘)’ before ‘==’ token
assert(p[0] == 0x01);
^
untitled.cpp:23:13: error: expected ‘)’ before ‘==’ token
untitled.cpp:24:13: error: expected ‘)’ before ‘==’ token
assert(p[1] == 0x01);
^
untitled.cpp:24:13: error: expected ‘)’ before ‘==’ token
untitled.cpp:25:13: error: expected ‘)’ before ‘==’ token
assert(p[2] == 0x01);
^
untitled.cpp:25:13: error: expected ‘)’ before ‘==’ token

有谁知道如何解决这些问题?谢谢。

最佳答案

没有,但你可以define one yourself .

由于您的像素类型不是字节对齐的,您需要声明一个位对齐的像素和相关类型:

Bit-aligned pixels (and images) are more complex than packed ones. Since packed pixels are byte-aligned, we can use a C++ reference as the reference type to a packed pixel, and a C pointer as an x_iterator over a row of packed pixels. For bit-aligned constructs we need a special reference proxy class (bit_aligned_pixel_reference) and iterator class (bit_aligned_pixel_iterator). The value type of bit-aligned pixels is a packed_pixel.

一个工作示例:

#include <boost/gil.hpp>
#include <boost/mpl/vector.hpp>
#include <cstdint>

int main()
{
// reference type
using gray10_ref_t = boost::gil::bit_aligned_pixel_reference<unsigned short, boost::mpl::vector1_c<unsigned, 10>, boost::gil::gray_layout_t, true>;
// iterator type
using gray10_ptr_t = boost::gil::bit_aligned_pixel_iterator<gray10_ref_t>;
// pixel type
using gray10_pixel_t = std::iterator_traits<gray10_ptr_t>::value_type;

// pixel storage to read, contains 3 10-bit gray pixels, all with value of 1 as per the following layout
// spaces show byte breaks, bars show pixel breaks, lsb first
// 10000000 00|100000 0000|1000 00000000
std::uint8_t data[4] = { 0x01, 0x04, 0x10, 0x00 };

// an iterator to the start of the storage
gray10_ptr_t p(&data[0], 0);

// check the expected pixel values
assert(p[0] == 0x01);
assert(p[1] == 0x01);
assert(p[2] == 0x01);
}

关于c++ - boost::gil 是否支持 10 位图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51562257/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com