Advertisement
Guest User

erstmal

a guest
Nov 25th, 2014
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. Index: imaging.c
  2. ===================================================================
  3. --- imaging.c (revision 172)
  4. +++ imaging.c (working copy)
  5. @@ -17,6 +17,7 @@
  6. /* Include the interface definition */
  7. #include "imaging.h"
  8.  
  9. +#define ARRAY_SIZE (sizeof(ARRAY_BASE_TYPE) * MAX_ARRAY_SIZE)
  10.  
  11. /** Maximum number of pixel in img.pixels */
  12. #define MAX_PIXEL_COUNT ((MAX_ARRAY_SIZE*ARRAY_ELEMENT_SIZE) / BITS_PER_COLOR)
  13. @@ -25,7 +26,7 @@
  14. #define CHANNELMASK ((1 << COLORDEPTH) - 1)
  15.  
  16. /** A Mask where every Bit belonging to a color is set */
  17. -#define COLORMASK ((1 << BITS_PER_COLOR) - 1)
  18. +#define COLORMASK ((Color) ((1 << BITS_PER_COLOR) - 1))
  19.  
  20. /* as given by Hanno */
  21. #define MAX_INTENSITY 255
  22. @@ -155,9 +156,15 @@
  23. assert(x < imaging_getWidth(img));
  24. assert(y < imaging_getHeight(img));
  25. {
  26. + Color tempColor = 0;
  27. div_t divRes = div(getColorOffsetInBit(imaging_getWidth(img),x,y),
  28. BYTE_SIZE);
  29. - Color tempColor = * (Color *) ((unsigned char *)img.pixels + divRes.quot);
  30. + int offset = sizeof(Color) + divRes.quot - ARRAY_SIZE;
  31. + if (offset >= 0) {
  32. + divRes.quot -= offset;
  33. + divRes.rem += offset * 8;
  34. + }
  35. + tempColor = * (Color *) ((unsigned char *)img.pixels + divRes.quot);
  36.  
  37. return (tempColor >> divRes.rem) & COLORMASK;
  38. }
  39. @@ -177,12 +184,16 @@
  40. assert(img != NULL);
  41. assert(x < imaging_getWidth(*img));
  42. assert(y < imaging_getHeight(*img));
  43. -
  44. {
  45. + Color * pos = NULL;
  46. div_t divRes = div(getColorOffsetInBit(imaging_getWidth(*img),x,y),
  47. BYTE_SIZE);
  48. - Color * pos = (Color *) ((unsigned char *)img->pixels + divRes.quot);
  49. -
  50. + int offset = sizeof(Color) + divRes.quot - ARRAY_SIZE;
  51. + if (offset >= 0) {
  52. + divRes.quot -= offset;
  53. + divRes.rem += offset * 8;
  54. + }
  55. + pos = (Color *) ((unsigned char *)img->pixels + divRes.quot);
  56. *pos &= ~(COLORMASK << divRes.rem);
  57. *pos |= color << divRes.rem;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement