MCPcopy Create free account
hub / github.com/OSSystems/EasySplash / get_image_handle_at

Method get_image_handle_at

src/animation.cpp:156–209  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

154
155
156display::image_handle animation::get_image_handle_at(animation_position const &p_animation_position)
157{
158 // Check if the position is beyond the list of parts
159 if (p_animation_position.m_part_nr >= m_parts.size())
160 {
161 LOG_MSG(warning, "animation position (" << p_animation_position << ") has invalid part nr");
162 return display::invalid_image_handle;
163 }
164
165 animation::part const &part = m_parts[p_animation_position.m_part_nr];
166
167 // Check if the position is beyond the list of frames inside the part
168 if (p_animation_position.m_frame_nr_in_part >= part.m_frames.size())
169 {
170 LOG_MSG(warning, "animation position (" << p_animation_position << ") has invalid frame nr");
171 return display::invalid_image_handle;
172 }
173
174 display::image_handle * cached_handle = m_image_handle_cache.get_entry(p_animation_position);
175 if (cached_handle == nullptr)
176 {
177 LOG_MSG(trace, "no frame at position " << p_animation_position << " in LRU cache - loading");
178
179 // Get the zip archive entry for the current position
180 zip_archive::entry const &p_entry = *(part.m_frames[p_animation_position.m_frame_nr_in_part]);
181
182 image frame = load_png(m_zip_archive.uncompress_data(p_entry));
183 if (!is_valid(frame))
184 {
185 LOG_MSG(error, "could not load PNG \"" << p_entry.m_filename << "\"");
186 return display::invalid_image_handle;
187 }
188
189 // Create a display image_handle for each frame
190 display::image_handle handle = m_display.load_image(std::move(frame));
191 if (handle != display::invalid_image_handle)
192 {
193 LOG_MSG(trace, "loaded frame \"" << p_entry.m_filename << "\"");
194
195 cached_handle = &(m_image_handle_cache.add_entry(p_animation_position, std::move(handle)));
196 }
197 else
198 {
199 LOG_MSG(error, "could not load frame \"" << p_entry.m_filename << "\" into display");
200 return display::invalid_image_handle;
201 }
202 }
203 else
204 {
205 LOG_MSG(trace, "retrieved frame at position " << p_animation_position << " from LRU cache");
206 }
207
208 return *cached_handle;
209}
210
211
212

Callers 1

runMethod · 0.80

Calls 5

load_pngFunction · 0.85
get_entryMethod · 0.80
uncompress_dataMethod · 0.80
is_validFunction · 0.70
load_imageMethod · 0.45

Tested by

no test coverage detected