MCPcopy Create free account
hub / github.com/cinder/Cinder / ImageSourceFileStbImage

Method ImageSourceFileStbImage

src/cinder/ImageSourceFileStbImage.cpp:60–125  ·  view source on GitHub ↗

////////////////////////////////////////////////////////////////////////// ImageSourceFileStbImage

Source from the content-addressed store, hash-verified

58///////////////////////////////////////////////////////////////////////////////
59// ImageSourceFileStbImage
60ImageSourceFileStbImage::ImageSourceFileStbImage( DataSourceRef dataSourceRef, ImageSource::Options /*options*/ )
61 : mData8u( nullptr ), mData32f( nullptr ), mRowBytes( 0 )
62{
63 int width = 0, height = 0, components = 0;
64
65 if( dataSourceRef->isFilePath() ) {
66 if( stbi_is_hdr( dataSourceRef->getFilePath().string().c_str() ) ) {
67 mData32f = stbi_loadf( dataSourceRef->getFilePath().string().c_str(), &width, &height, &components, 0 /*any # of components*/ );
68 if( ! mData32f )
69 throw ImageIoException( stbi_failure_reason() );
70
71 mRowBytes = width * components * sizeof( float );
72 }
73 else {
74 mData8u = stbi_load( dataSourceRef->getFilePath().string().c_str(), &width, &height, &components, 0 /*any # of components*/ );
75 if( ! mData8u )
76 throw ImageIoException( stbi_failure_reason() );
77
78 mRowBytes = width * components;
79 }
80 }
81 else { // we'll use a dataref from the buffer
82 BufferRef buffer = dataSourceRef->getBuffer();
83 if( stbi_is_hdr_from_memory( (unsigned char*)buffer->getData(), (int)buffer->getSize() ) ) {
84 mData32f = stbi_loadf_from_memory( (unsigned char*)buffer->getData(), (int)buffer->getSize(), &width, &height, &components, 0 /*any # of components*/ );
85 if( ! mData32f )
86 throw ImageIoException( stbi_failure_reason() );
87
88 mRowBytes = width * components * sizeof(float);
89 }
90 else {
91 mData8u = stbi_load_from_memory( (unsigned char*)buffer->getData(), (int)buffer->getSize(), &width, &height, &components, 0 /*any # of components*/ );
92 if( ! mData8u )
93 throw ImageIoException( stbi_failure_reason() );
94
95 mRowBytes = width * components;
96 }
97 }
98
99 if( mData8u )
100 setDataType( ImageIo::UINT8 );
101 else if( mData32f )
102 setDataType( ImageIo::FLOAT32 );
103 setSize( width, height );
104
105 switch( components ) {
106 case 1:
107 setColorModel( ImageIo::CM_GRAY );
108 setChannelOrder( ImageIo::ChannelOrder::Y );
109 break;
110 case 2:
111 setColorModel( ImageIo::CM_GRAY );
112 setChannelOrder( ImageIo::ChannelOrder::YA );
113 break;
114 case 3:
115 setColorModel( ImageIo::CM_RGB );
116 setChannelOrder( ImageIo::ChannelOrder::RGB );
117 break;

Callers

nothing calls this directly

Calls 15

stbi_is_hdrFunction · 0.85
stbi_loadfFunction · 0.85
stbi_failure_reasonFunction · 0.85
stbi_loadFunction · 0.85
stbi_is_hdr_from_memoryFunction · 0.85
stbi_loadf_from_memoryFunction · 0.85
stbi_load_from_memoryFunction · 0.85
setColorModelFunction · 0.85
setChannelOrderFunction · 0.85
isFilePathMethod · 0.80
getBufferMethod · 0.80
setDataTypeFunction · 0.50

Tested by

no test coverage detected