AfterBurner/src/image.cpp

57 lines
1.3 KiB
C++

#include "afterburner.h"
#include <gint/display.h>
#include <gint/image.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
//---
// Dynamic images
//---
DynamicImage::DynamicImage(bopti_image_t const *source, float alpha,
prof_t *prof_ctx, int anchor_x, int anchor_y):
m_anchor_x {anchor_x}, m_anchor_y {anchor_y}, m_source {source},
m_alpha {alpha}, m_prof {prof_ctx}
{
for(int i = 0; i < 16; i++) {
m_images[i] = NULL;
m_ax[i] = -1;
m_ay[i] = -1;
}
}
bopti_image_t *DynamicImage::getAtScale(num scale, int *ax, int *ay)
{
if(m_prof)
prof_enter(*m_prof);
/* Round to the closest multiple of 0.125 */
int i = (int)(8 * scale + num(0.5));
if(i < 0) i = 0;
if(i > 15) i = 15;
if(!m_images[i]) {
int ax_i=m_anchor_x, ay_i=m_anchor_y;
struct image_linear_map map;
image_rotate_around_scale(m_source, m_alpha, scale.v, false, &ax_i,
&ay_i, &map);
m_images[i] = image_linear_alloc(m_source, &map);
m_ax[i] = ax_i;
m_ay[i] = ay_i;
}
if(m_prof)
prof_leave(*m_prof);
*ax = m_ax[i];
*ay = m_ay[i];
return m_images[i];
}
DynamicImage::~DynamicImage()
{
for(int i = 0; i < 16; i++)
image_free(m_images[i]);
}