MCPcopy Create free account
hub / github.com/AcademySoftwareFoundation/OpenColorIO / InitImageTexture

Function InitImageTexture

src/apps/ociodisplay/main.cpp:71–147  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

69void UpdateOCIOGLState();
70
71static void InitImageTexture(const char * filename)
72{
73 OCIO::ImageIO img;
74
75 if (filename && *filename)
76 {
77 std::cout << "Loading: " << filename << std::endl;
78
79 try
80 {
81 img.read(filename, OCIO::BIT_DEPTH_F32);
82 }
83 catch (const std::exception &e)
84 {
85 std::cerr << "ERROR: Loading file failed: " << e.what() << std::endl;
86 exit(1);
87 }
88 catch (...)
89 {
90 std::cerr << "ERROR: Loading file failed." << std::endl;
91 exit(1);
92 }
93 }
94 // If no file is provided, use a default gradient texture
95 else
96 {
97 std::cout << "No image specified, loading gradient." << std::endl;
98
99 img.init(512, 512, OCIO::CHANNEL_ORDERING_RGBA, OCIO::BIT_DEPTH_F32);
100
101 float * pixels = (float *)img.getData();
102 const long width = img.getWidth();
103 const long channels = img.getNumChannels();
104
105 for (int y = 0; y < img.getHeight(); ++y)
106 {
107 for (int x = 0; x < img.getWidth(); ++x)
108 {
109 float c = (float)x / ((float)width - 1.0f);
110 pixels[channels * (width * y + x) + 0] = c;
111 pixels[channels * (width * y + x) + 1] = c;
112 pixels[channels * (width * y + x) + 2] = c;
113 pixels[channels * (width * y + x) + 3] = 1.0f;
114 }
115 }
116 }
117
118 OCIO::OglApp::Components comp = OCIO::OglApp::COMPONENTS_RGBA;
119 if (img.getNumChannels() == 4)
120 {
121 comp = OCIO::OglApp::COMPONENTS_RGBA;
122 }
123 else if (img.getNumChannels() == 3)
124 {
125 comp = OCIO::OglApp::COMPONENTS_RGB;
126 }
127 else
128 {

Callers 1

mainFunction · 0.85

Calls 7

initImageMethod · 0.80
readMethod · 0.45
initMethod · 0.45
getDataMethod · 0.45
getWidthMethod · 0.45
getNumChannelsMethod · 0.45
getHeightMethod · 0.45

Tested by

no test coverage detected