123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- #include "traitement.h"
- SDL_Surface* retournement(SDL_Surface* originale, int nbQuarts)
- {
- //Création de la seconde surface
- nbQuarts%=4;
- SDL_Surface* pivot(0);
- if (nbQuarts%2)
- pivot=SDL_CreateRGBSurface(SDL_HWSURFACE, originale->h, originale->w, originale->format->BitsPerPixel,
- originale->format->Rmask, originale->format->Gmask, originale->format->Bmask, originale->format->Amask);
- else
- pivot=SDL_CreateRGBSurface(SDL_HWSURFACE, originale->w, originale->h, originale->format->BitsPerPixel,
- originale->format->Rmask, originale->format->Gmask, originale->format->Bmask, originale->format->Amask);
- if (nbQuarts != 0)
- {
- // Démarrage du retournement
- unsigned char* pixelsSources = (unsigned char*) originale->pixels;
- unsigned char* pixelsPivot = (unsigned char*) pivot->pixels;
- Uint8 bytes(originale->format->BytesPerPixel);
- // Balayage
- Sint32 xFromPos(0), yFromPos(0);
- Sint32 xToPos(0), yToPos(0);
- for (xFromPos = 0; xFromPos < originale->w; xFromPos++)
- for (yFromPos = 0; yFromPos < originale->h; yFromPos++)
- {
- if (nbQuarts == 1){
- xToPos = originale->h - yFromPos - 1;
- yToPos = xFromPos;
- }
- if (nbQuarts == 2){
- xToPos = originale->w - xFromPos - 1;
- yToPos = originale->h - yFromPos - 1;
- }
- if (nbQuarts == 3){
- xToPos = yFromPos;
- yToPos = originale->w - xFromPos - 1;
- }
- for (int i(0); i < bytes; i++)
- pixelsPivot[yToPos * pivot->w * bytes + xToPos * bytes + i] = pixelsSources[yFromPos * originale->w * bytes + xFromPos * bytes + i];
- }
- }
- else
- // Copie sans modif
- SDL_BlitSurface(originale, 0, pivot, 0);
- return pivot;
- }
- SDL_Surface* destroyColor(SDL_Surface* originale, bool blue, bool green, bool red)
- {
- //Création de la seconde surface
- SDL_Surface* produit = SDL_CreateRGBSurface(SDL_HWSURFACE, originale->h, originale->w, originale->format->BitsPerPixel,
- originale->format->Rmask, originale->format->Gmask, originale->format->Bmask, originale->format->Amask);
- if (blue || green || red)
- {
- // Démarrage du retournement
- unsigned char* pixelsSources = (unsigned char*) originale->pixels;
- unsigned char* pixelsProduit = (unsigned char*) produit->pixels;
- Uint8 bytes(originale->format->BytesPerPixel);
- // Balayage
- Sint32 xPos(0), yPos(0);
- for (xPos = 0; xPos < originale->w; xPos++)
- for (yPos = 0; yPos < originale->h; yPos++)
- {
- if (!blue)
- pixelsProduit[yPos * produit->w * bytes + xPos * bytes] = pixelsSources[yPos * originale->w * bytes + xPos * bytes];
- if (!green)
- pixelsProduit[yPos * produit->w * bytes + xPos * bytes + 1] = pixelsSources[yPos * originale->w * bytes + xPos * bytes + 1];
- if (!red)
- pixelsProduit[yPos * produit->w * bytes + xPos * bytes + 2] = pixelsSources[yPos * originale->w * bytes + xPos * bytes + 2];
- }
- }
- else
- // Copie sans modif
- SDL_BlitSurface(originale, 0, produit, 0);
- return produit;
- }
- SDL_Surface* colorMightyObjet(SDL_Surface* source, int id)
- {
- switch (id)
- {
- case 0:
- return destroyColor(source, true, true, false);// Rouge
- break;
- case 1:
- return destroyColor(source, false, true, true);// Bleu
- break;
- case 2:
- return destroyColor(source, true, false, true);// Vert
- break;
- case 3:
- return destroyColor(source, true, false, false);// Jaune
- break;
- case 4:
- return destroyColor(source, false, true, false);// Rose
- break;
- case 5:
- return destroyColor(source, false, false, true);// Cyan
- break;
- case 6:
- return destroyColor(source, true, true, false);// Orange
- break;
- default:
- return destroyColor(source, false, false, false);// Pas de modif : retourne une copie
- break;
- }
- }
|