traitement.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #include "traitement.h"
  2. SDL_Surface* retournement(SDL_Surface* originale, int nbQuarts)
  3. {
  4. //Création de la seconde surface
  5. nbQuarts%=4;
  6. SDL_Surface* pivot(0);
  7. if (nbQuarts%2)
  8. pivot=SDL_CreateRGBSurface(SDL_HWSURFACE, originale->h, originale->w, originale->format->BitsPerPixel,
  9. originale->format->Rmask, originale->format->Gmask, originale->format->Bmask, originale->format->Amask);
  10. else
  11. pivot=SDL_CreateRGBSurface(SDL_HWSURFACE, originale->w, originale->h, originale->format->BitsPerPixel,
  12. originale->format->Rmask, originale->format->Gmask, originale->format->Bmask, originale->format->Amask);
  13. if (nbQuarts != 0)
  14. {
  15. // Démarrage du retournement
  16. unsigned char* pixelsSources = (unsigned char*) originale->pixels;
  17. unsigned char* pixelsPivot = (unsigned char*) pivot->pixels;
  18. Uint8 bytes(originale->format->BytesPerPixel);
  19. // Balayage
  20. Sint32 xFromPos(0), yFromPos(0);
  21. Sint32 xToPos(0), yToPos(0);
  22. for (xFromPos = 0; xFromPos < originale->w; xFromPos++)
  23. for (yFromPos = 0; yFromPos < originale->h; yFromPos++)
  24. {
  25. if (nbQuarts == 1){
  26. xToPos = originale->h - yFromPos - 1;
  27. yToPos = xFromPos;
  28. }
  29. if (nbQuarts == 2){
  30. xToPos = originale->w - xFromPos - 1;
  31. yToPos = originale->h - yFromPos - 1;
  32. }
  33. if (nbQuarts == 3){
  34. xToPos = yFromPos;
  35. yToPos = originale->w - xFromPos - 1;
  36. }
  37. for (int i(0); i < bytes; i++)
  38. pixelsPivot[yToPos * pivot->w * bytes + xToPos * bytes + i] = pixelsSources[yFromPos * originale->w * bytes + xFromPos * bytes + i];
  39. }
  40. }
  41. else
  42. // Copie sans modif
  43. SDL_BlitSurface(originale, 0, pivot, 0);
  44. return pivot;
  45. }
  46. SDL_Surface* destroyColor(SDL_Surface* originale, bool blue, bool green, bool red)
  47. {
  48. //Création de la seconde surface
  49. SDL_Surface* produit = SDL_CreateRGBSurface(SDL_HWSURFACE, originale->h, originale->w, originale->format->BitsPerPixel,
  50. originale->format->Rmask, originale->format->Gmask, originale->format->Bmask, originale->format->Amask);
  51. if (blue || green || red)
  52. {
  53. // Démarrage du retournement
  54. unsigned char* pixelsSources = (unsigned char*) originale->pixels;
  55. unsigned char* pixelsProduit = (unsigned char*) produit->pixels;
  56. Uint8 bytes(originale->format->BytesPerPixel);
  57. // Balayage
  58. Sint32 xPos(0), yPos(0);
  59. for (xPos = 0; xPos < originale->w; xPos++)
  60. for (yPos = 0; yPos < originale->h; yPos++)
  61. {
  62. if (!blue)
  63. pixelsProduit[yPos * produit->w * bytes + xPos * bytes] = pixelsSources[yPos * originale->w * bytes + xPos * bytes];
  64. if (!green)
  65. pixelsProduit[yPos * produit->w * bytes + xPos * bytes + 1] = pixelsSources[yPos * originale->w * bytes + xPos * bytes + 1];
  66. if (!red)
  67. pixelsProduit[yPos * produit->w * bytes + xPos * bytes + 2] = pixelsSources[yPos * originale->w * bytes + xPos * bytes + 2];
  68. }
  69. }
  70. else
  71. // Copie sans modif
  72. SDL_BlitSurface(originale, 0, produit, 0);
  73. return produit;
  74. }
  75. SDL_Surface* colorMightyObjet(SDL_Surface* source, int id)
  76. {
  77. switch (id)
  78. {
  79. case 0:
  80. return destroyColor(source, true, true, false);// Rouge
  81. break;
  82. case 1:
  83. return destroyColor(source, false, true, true);// Bleu
  84. break;
  85. case 2:
  86. return destroyColor(source, true, false, true);// Vert
  87. break;
  88. case 3:
  89. return destroyColor(source, true, false, false);// Jaune
  90. break;
  91. case 4:
  92. return destroyColor(source, false, true, false);// Rose
  93. break;
  94. case 5:
  95. return destroyColor(source, false, false, true);// Cyan
  96. break;
  97. case 6:
  98. return destroyColor(source, true, true, false);// Orange
  99. break;
  100. default:
  101. return destroyColor(source, false, false, false);// Pas de modif : retourne une copie
  102. break;
  103. }
  104. }