]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/gil/example/packed_pixel.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / gil / example / packed_pixel.cpp
1 //
2 // Copyright 2005-2007 Adobe Systems Incorporated
3 //
4 // Distributed under the Boost Software License, Version 1.0
5 // See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt
7 //
8 #include <boost/gil/extension/io/jpeg.hpp>
9
10 #include <algorithm>
11
12 // This test file demonstrates how to use packed pixel formats in GIL.
13 // A "packed" pixel is a pixel whose channels are bit ranges.
14 // Here we create an RGB image whose pixel has 16-bits, such as:
15 // bits [0..6] are the blue channel
16 // bits [7..13] are the green channel
17 // bits [14..15] are the red channel
18 // We read a regular 8-bit RGB image, convert it to packed BGR772, convert it back to 8-bit RGB and save it to a file.
19 // Since the red channel is only two bits the color loss should be observable in the result
20 //
21 // This test file also demonstrates how to use bit-aligned images - these are images whose pixels themselves are not byte aligned.
22 // For example, an rgb222 image has a pixel whose size is 6 bits. Bit-aligned images are more complicated than packed images. They
23 // require a special proxy class to represent pixel reference and pixel iterator (packed images use C++ reference and C pointer respectively).
24 // The alignment parameter in the constructor of bit-aligned images is in bit units. For example, if you want your bit-aligned image to have 4-byte
25 // alignment of its rows use alignment of 32, not 4.
26 //
27 // To demonstrate that image view transformations work on packed images, we save the result transposed.
28
29 using namespace boost;
30 using namespace boost::gil;
31
32 int main() {
33 bgr8_image_t img;
34 read_image("test.jpg",img, jpeg_tag{});
35
36 ////////////////////////////////
37 // define a bgr772 image. It is a "packed" image - its channels are not byte-aligned, but its pixels are.
38 ////////////////////////////////
39
40 using bgr772_image_t = packed_image3_type<uint16_t, 7,7,2, bgr_layout_t>::type;
41 bgr772_image_t bgr772_img(img.dimensions());
42 copy_and_convert_pixels(const_view(img),view(bgr772_img));
43
44 // Save the result. JPEG I/O does not support the packed pixel format, so convert it back to 8-bit RGB
45 write_view("out-packed_pixel_bgr772.jpg",color_converted_view<bgr8_pixel_t>(transposed_view(const_view(bgr772_img))), jpeg_tag{});
46
47 ////////////////////////////////
48 // define a gray1 image (one-bit per pixel). It is a "bit-aligned" image - its pixels are not byte aligned.
49 ////////////////////////////////
50
51 using gray1_image_t = bit_aligned_image1_type<1, gray_layout_t>::type;
52 gray1_image_t gray1_img(img.dimensions());
53 copy_and_convert_pixels(const_view(img),view(gray1_img));
54
55 // Save the result. JPEG I/O does not support the packed pixel format, so convert it back to 8-bit RGB
56 write_view("out-packed_pixel_gray1.jpg",color_converted_view<gray8_pixel_t>(transposed_view(const_view(gray1_img))), jpeg_tag{});
57
58 return 0;
59 }