MCPcopy Create free account
hub / github.com/cpvrlab/ImagePlay / loadMemory

Method loadMemory

IPL/src/IPLFileIO.cpp:145–225  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

143
144
145bool IPLFileIO::loadMemory(void* mem, IPLImage*& image)
146{
147 FIMEMORY* hmem = (FIMEMORY*) mem;
148 FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;
149 FreeImage_SeekMemory(hmem, 0L, SEEK_SET);
150 fif = FreeImage_GetFileTypeFromMemory(hmem, 0);
151
152 if(fif == FIF_UNKNOWN)
153 {
154 // always close the memory stream
155 FreeImage_CloseMemory(hmem);
156 return false;
157 }
158
159 FIBITMAP *dib = FreeImage_LoadFromMemory(fif, hmem);
160 int width = FreeImage_GetWidth(dib);
161 int height = FreeImage_GetHeight(dib);
162
163 // all files need to be flipped
164 FreeImage_FlipVertical(dib);
165
166 if(FreeImage_GetBPP(dib) == 8)
167 {
168 // grayscale images
169
170 // convert to 32 bit
171 FIBITMAP *dib2 = FreeImage_ConvertToGreyscale(dib);
172
173 // clear old image
174 delete image;
175 // create new instance with the right dimensions
176 image = new IPLImage(IPL_IMAGE_GRAYSCALE, width, height);
177
178 for(int y = 0; y < height; y++)
179 {
180 for(int x = 0; x < width; x++)
181 {
182 BYTE value;
183 FreeImage_GetPixelIndex(dib2, x, y, &value);
184 image->plane(0)->p(x, y) = (value * FACTOR_TO_FLOAT);
185 }
186 }
187
188 FreeImage_Unload(dib2);
189 }
190 else
191 {
192 // color images
193
194 // convert to 32 bit
195 FIBITMAP *dib2 = FreeImage_ConvertTo32Bits(dib);
196
197 // clear old image
198 delete image;
199 // create new instance with the right dimensions
200 image = new IPLImage(IPL_IMAGE_COLOR, width, height);
201
202 for(int y = 0; y < height; y++)

Callers

nothing calls this directly

Calls 1

planeMethod · 0.80

Tested by

no test coverage detected