暫無描述

Filter.cpp 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include "ImageScrambler.h"
  2. #include <qdebug.h>
  3. // Given an image and two rectangles defined by the x,y locations of their
  4. // upperleft pixels and their height, width, swaps the pixels in those rectangles.
  5. // For example, for an image I with height and width of 100. The following invocation
  6. // swaps the top and bottom halves of the image:
  7. // cropSwap(I, 0, 0, 0, 50, 100, 50)
  8. void ImageScrambler::cropSwap(QImage &img, int x0, int y0, int x1, int y1, int width, int height ) {
  9. QRgb p;
  10. // For each of the pixels of the square with starting coord (x0,y0)
  11. // Por cada pixel del cuadrado con coordenada inicial (x0,y0)
  12. for (int dx = 0; dx < width; dx++) {
  13. for (int dy = 0; dy < height; dy++) {
  14. // extract the pixel
  15. // extrae el pixel
  16. p = img.pixel(x0 + dx , y0 + dy);
  17. // swap the pixel with the square starting coord (x1,y1)
  18. // intercabia el pixel con el cuadrado con coodenada inicial (x1,y1)
  19. img.setPixel(x0 + dx , y0 + dy, img.pixel(x1 + dx , y1 + dy));
  20. img.setPixel(x1 + dx , y1 + dy, p);
  21. }
  22. }
  23. }
  24. // This is the function you will code. Given the image, the level of recursion,
  25. // the x, y, width and height of the topleft corner of the rectangle that you'd
  26. // like to scramble, this function scrambles that part of the image.
  27. // For example, for an image of height and width 100, to scramble the whole image
  28. // two levels, you would invoke:
  29. // ScrambleFilter(I, 2, 0, 0, 100, 100);
  30. QImage ImageScrambler::ScrambleFilter(QImage image, int level, int sx, int sy, int width, int height){
  31. return image;
  32. }