Advertisement
reversyn

Untitled

Mar 24th, 2014
425
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.42 KB | None | 0 0
  1. /**
  2.  * Common header files and definitions for bmpedit.
  3.  */
  4.  
  5. #if defined(__GNUC__)
  6.     #define unlikely_if(cond) if (__builtin_expect((cond), 0))
  7.     #define likely_if(cond) if (__builtin_expect((cond), !0))
  8. #else
  9.     #define unlikely_if if
  10.     #define likely_if if
  11. #endif
  12.  
  13.  
  14. /* This pragma removes the requirement for aligned structs. It allows mapping of
  15.  * the struct directly onto the file's contents in memory.
  16.  */
  17. #pragma pack(push, 1)
  18.  
  19. /**
  20.  * Structs for the 24-bit pixel type, as well as the bmp header.
  21.  *
  22.  * The pixel struct is in reverse order because we read them directly from
  23.  * mmap'd memory, which reverses the endianness.
  24.  */
  25. typedef struct {
  26.     uint8_t blue;
  27.     uint8_t green;
  28.     uint8_t red;
  29. } pixel;
  30.  
  31. typedef struct {
  32.     uint32_t size;
  33.     uint32_t width;
  34.     uint32_t height;
  35.     uint16_t colorplanes;
  36.     uint16_t bpp;
  37.     uint32_t compression;
  38.     uint32_t arraysize;
  39.     uint32_t h_res;
  40.     uint32_t v_res;
  41.     uint32_t colors;
  42.     uint32_t important_colors;
  43. } dib_header;
  44.  
  45. typedef struct {
  46.     uint16_t magic;
  47.     uint32_t size;
  48.     uint16_t reserved1;
  49.     uint16_t reserved2;
  50.     uint32_t data_offset;
  51.     dib_header dib;
  52. } bmp_header;
  53.  
  54. typedef struct {
  55.     int x;
  56.     int y;
  57. } gradients;
  58. #pragma pack(pop)
  59.  
  60. inline static int get_gradient(gradients *gs, int rowsize, int xpos, int ypos);
  61. inline static int bounded(int bound, int pos);
  62. inline static pixel* lookup(pixel *data, int width, int height, int padding, int x, int y);
  63. inline static int gen_padding(bmp_header *header);
  64. inline static void convert_grayscale(pixel *p);
  65. inline static int get_direction(gradients *gs, int rowsize, int xpos, int ypos);
  66.  
  67. gradients* sobel_operator(pixel *data, int rowsize, int rows, int padding);
  68.  
  69. void threshold_shade(bmp_header *header, pixel *data, int, double threshold, double);
  70. void gaussian_blur(bmp_header *header, pixel *data, int radius, double, double);
  71. void linear_blur(bmp_header *header, pixel *data, int lblur_times, double, double);
  72. void monochrome_shade(bmp_header *header, pixel *data, int, double, double);
  73. void sobel_detect(bmp_header *header, pixel *data, int radius, double threshold, double);
  74. void canny_detect(bmp_header *header, pixel *data, int radius, double upper, double lower);
  75.  
  76.  
  77. void canny_follow(pixel *data, gradients *gs, int width, int height, int padding, int x, int y, double lower);
  78.  
  79. static void usage(void);
  80. int main(int argc, char *argv[]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement