orton_runner/lib/my_csfml/my_vram_zoom.c

46 lines
1.0 KiB
C

/*
** EPITECH PROJECT, 2018
** task01
** File description:
** I do task
*/
#include <stdlib.h>
#include "../../include/lib/s_sfml.h"
#include "../../include/lib/my_graphics.h"
void copy_vram(sfml_t *sfml, uint32_t *src)
{
int i;
int end;
i = -1;
end = sfml->height * sfml->width;
while (++i < end)
sfml->vram[i] = src[i];
}
void my_vram_zoom(sfml_t *sfml, double zoom_width, double zoom_height)
{
uint32_t *new_vram;
int copy_x;
int copy_y;
int i = -1;
int j;
zoom_width = (zoom_width < 0) ? 0 : zoom_width;
zoom_height = (zoom_height < 0) ? 0 : zoom_height;
new_vram = (uint32_t*)malloc(sizeof(uint32_t) *
sfml->width * sfml->height);
while (++i < sfml->width){
j = -1;
copy_x = i / zoom_width + 0.5;
while (++j < sfml->height){
copy_y = j / zoom_height + 0.5;
new_vram[i + j * sfml->width] =
sfml->vram[copy_x + copy_y * sfml->width];
}
}
copy_vram(sfml, new_vram);
free(new_vram);
}