MRaster examples 21.0.0.0
Image Processing Library
Loading...
Searching...
No Matches
color_all.cpp
Go to the documentation of this file.
1// -*- Mode:C++; Coding:us-ascii-unix; fill-column:158 -*-
2/*******************************************************************************************************************************************************.H.S.**/
3/**
4 @file color_all.cpp
5 @author Mitch Richling <https://www.mitchr.me>
6 @brief Draw every possible color in 24-bit.@EOL
7 @std C++20
8 @copyright
9 @parblock
10 Copyright (c) 1988-2015, Mitchell Jay Richling <https://www.mitchr.me> All rights reserved.
11
12 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
13
14 1. Redistributions of source code must retain the above copyright notice, this list of conditions, and the following disclaimer.
15
16 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the following disclaimer in the documentation
17 and/or other materials provided with the distribution.
18
19 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software
20 without specific prior written permission.
21
22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
27 DAMAGE.
28 @endparblock
29 @filedetails
30
31 This is a very simple program that plots a point of EVERY possible 24-bit color. This program illustrates how to count by bytes, set colors in byte order,
32 how to avoid all the work and do it with simple integers via setRGBAfromLogPackIntABGR, how to count via Grey code order, and how to reduce to 216 web safe
33 color.
34
35*/
36/*******************************************************************************************************************************************************.H.E.**/
37/** @cond exj */
38
39//--------------------------------------------------------------------------------------------------------------------------------------------------------------
40#include "ramCanvas.hpp"
41
42//--------------------------------------------------------------------------------------------------------------------------------------------------------------
43unsigned long igray(unsigned long n);
44
45//--------------------------------------------------------------------------------------------------------------------------------------------------------------
46int main(void) {
47 std::chrono::time_point<std::chrono::system_clock> startTime = std::chrono::system_clock::now();
48 mjr::ramCanvas3c8b theRamCanvas_iii(4096, 4096);
49 mjr::ramCanvas3c8b theRamCanvas_int(4096, 4096);
50 mjr::ramCanvas3c8b theRamCanvas_gry(4096, 4096);
51 mjr::ramCanvas3c8b theRamCanvas_rgb(4096, 4096);
52 mjr::ramCanvas3c8b theRamCanvas_web(4096, 4096);
53
54 mjr::ramCanvasRGB8b::colorChanType red=0, blue=0, green=0;
55 uint32_t count=0;
56 mjr::ramCanvas3c8b::colorType aColor;
57 for(int y=0;y<theRamCanvas_int.getNumPixY();y++) {
58 for(int x=0;x<theRamCanvas_int.getNumPixX();x++) {
59 aColor.setRGBfromLogPackIntGen(count, 0, 1, 2);
60 theRamCanvas_iii.drawPoint(x, y, aColor);
61 aColor.setRGBfromLogPackIntABGR(count);
62 theRamCanvas_int.drawPoint(x, y, aColor);
63 aColor.setRGBfromLogPackIntABGR(static_cast<mjr::ramCanvas3c8b::colorType::packed4Cint>(igray(count)));
64 theRamCanvas_gry.drawPoint(x, y, aColor);
65 aColor.setChansRGB(red, green, blue);
66 theRamCanvas_rgb.drawPoint(x, y, aColor);
67 aColor.tfrmWebSafeRGB();
68 theRamCanvas_web.drawPoint(x, y, aColor);
69 count++;
70 if(red < 255) {
71 red++;
72 } else {
73 red = 0;
74 if (green < 255) {
75 green++;
76 } else {
77 green = 0;
78 blue++;
79 }
80 }
81
82 }
83 }
84 theRamCanvas_int.writeTIFFfile("color_all_int.tiff");
85 theRamCanvas_iii.writeTIFFfile("color_all_iii.tiff");
86 theRamCanvas_gry.writeTIFFfile("color_all_gry.tiff");
87 theRamCanvas_rgb.writeTIFFfile("color_all_rgb.tiff");
88 theRamCanvas_web.writeTIFFfile("color_all_web.tiff");
89 std::chrono::duration<double> runTime = std::chrono::system_clock::now() - startTime;
90 std::cout << "Total Runtime " << runTime.count() << " sec" << std::endl;
91}
92
93//--------------------------------------------------------------------------------------------------------------------------------------------------------------
94unsigned long igray(unsigned long n) {
95 unsigned long ans = n;
96 unsigned long idiv;
97 int ish = 1;
98 ans=n;
99 for(;;) {
100 ans ^= (idiv=ans>>ish);
101 if(idiv <=1 || ish == 16)
102 return ans;
103 ish <<=1;
104 }
105}
106/** @endcond */
int main(int argc, char *argv[])