MCPcopy Create free account
hub / github.com/ZDoom/Raze / GetCachedBitmap

Method GetCachedBitmap

source/common/textures/image.cpp:193–272  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

191//==========================================================================
192
193FBitmap FImageSource::GetCachedBitmap(const PalEntry *remap, int conversion, int *ptrans, int frame)
194{
195 FBitmap ret;
196
197 int trans = -1;
198 auto imageID = ImageID;
199
200 if (NumOfFrames == 1 && frame == 1)
201 {
202 frame = 0;
203 }
204
205 if (remap != nullptr)
206 {
207 // Remapped images are never run through the cache because they would complicate matters too much for very little gain.
208 // Translated images are normally sprites which normally just consist of a single image and use no composition.
209 // Additionally, since translation requires the base palette, the really time consuming stuff will never be subjected to it.
210 ret.Create(Width, Height);
211 trans = CopyTranslatedPixels(&ret, remap, frame);
212 }
213 else
214 {
215 if (conversion == luminance) conversion = normal; // luminance has no meaning for true color.
216 // Do we have this image in the cache?
217 unsigned index = conversion != normal? UINT_MAX : precacheDataRgba.FindEx([=](PrecacheDataRgba &entry) { return entry.ImageID == imageID && entry.Frame == frame; });
218 if (index < precacheDataRgba.Size())
219 {
220 auto cache = &precacheDataRgba[index];
221
222 trans = cache->TransInfo;
223 if (cache->RefCount > 1)
224 {
225 //Printf("returning reference to %s, refcount = %d\n", name.GetChars(), cache->RefCount);
226 ret.Copy(cache->Pixels, false);
227 cache->RefCount--;
228 }
229 else if (cache->Pixels.GetPixels())
230 {
231 //Printf("returning contents of %s, refcount = %d\n", name.GetChars(), cache->RefCount);
232 ret = std::move(cache->Pixels);
233 precacheDataRgba.Delete(index);
234 }
235 else
236 {
237 // This should never happen if the function is implemented correctly
238 //Printf("something bad happened for %s, refcount = %d\n", name.GetChars(), cache->RefCount);
239 ret.Create(Width, Height);
240 trans = CopyPixels(&ret, normal, frame);
241 }
242 }
243 else
244 {
245 // The image wasn't cached. Now there's two possibilities:
246 auto info = precacheInfo.CheckKey(ImageID);
247 if (!info || info->first <= 1 || conversion != normal)
248 {
249 // This is either the only copy needed or some access outside the caching block. In these cases create a new one and directly return it.
250 //Printf("returning fresh copy of %s\n", name.GetChars());

Callers 6

FStrifeStartScreenMethod · 0.80
FGenericStartScreenMethod · 0.80
FHexenStartScreenMethod · 0.80
GetBgraBitmapMethod · 0.80
CopyPixelsMethod · 0.80
RecordLuminosityFunction · 0.80

Calls 9

moveFunction · 0.85
FindExMethod · 0.80
ReserveMethod · 0.80
CreateMethod · 0.45
SizeMethod · 0.45
CopyMethod · 0.45
GetPixelsMethod · 0.45
DeleteMethod · 0.45
CheckKeyMethod · 0.45

Tested by

no test coverage detected