MCPcopy Create free account
hub / github.com/ImageEngine/cortex / imagePrimitive

Method imagePrimitive

src/IECoreGL/LuminanceTexture.cpp:159–214  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

157}
158
159IECoreImage::ImagePrimitivePtr LuminanceTexture::imagePrimitive() const
160{
161 ScopedBinding binding( *this );
162
163 GLint width = 0;
164 GLint height = 0;
165 glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width );
166 glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height );
167
168 GLint aSize = 0;
169 glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_ALPHA_SIZE, &aSize );
170
171 unsigned int numChannels = aSize ? 2 : 1;
172
173 vector<float> data( width * height * numChannels );
174
175 glGetTexImage( GL_TEXTURE_2D, 0, numChannels==2 ? GL_LUMINANCE_ALPHA : GL_LUMINANCE, GL_FLOAT, &data[0] );
176
177 FloatVectorDataPtr yd = new FloatVectorData();
178 vector<float> &y = yd->writable(); y.resize( width * height );
179
180 FloatVectorDataPtr ad = nullptr;
181 vector<float> *a = nullptr;
182 if( aSize )
183 {
184 ad = new FloatVectorData();
185 a = &ad->writable(); a->resize( width * height );
186 }
187
188 unsigned int i = 0;
189 for( int yy=height-1; yy>=0; yy-- )
190 {
191 float *ry = &y[yy*width];
192 float *ra = a ? &(*a)[yy*width] : nullptr;
193 for( int x=0; x<width; x++ )
194 {
195 ry[x] = data[i++];
196 if( ra )
197 {
198 ra[x] = data[i++];
199 }
200 }
201 }
202
203 Box2i imageExtents( V2i( 0, 0 ), V2i( width-1, height-1 ) );
204 IECoreImage::ImagePrimitivePtr image = new IECoreImage::ImagePrimitive( imageExtents, imageExtents );
205 image->channels["Y"] = yd;
206 if( a )
207 {
208 image->channels["A"] = ad;
209 }
210
211 IECoreGL::Exception::throwIfError();
212
213 return image;
214}
215

Callers 1

testMethod · 0.95

Calls 2

writableMethod · 0.45
resizeMethod · 0.45

Tested by 1

testMethod · 0.76