Advertisement
Guest User

Untitled

a guest
Jan 21st, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. #include <sys/stat.h>
  2. #include <fcntl.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5.  
  6. int detect(unsigned char* img, int width);
  7.  
  8. int main (int argc, char** argv)
  9. {
  10. char *buff;
  11.  
  12. if(argc != 2 )
  13. {
  14. printf("The number of arguments is not correct. \n ");
  15. return 1;
  16. }
  17.  
  18. struct stat st;
  19. stat(argv[1], &st);
  20.  
  21. buff = (char *) malloc(st.st_size);
  22. if (buff == NULL)
  23. {
  24. printf("Cannot allocate memory\n");
  25. return 1;
  26. }
  27.  
  28. int handle = open(argv[1], O_RDONLY, 0);
  29. if (handle == -1) {
  30. printf("Cannot access file.\n");
  31. free(buff);
  32. return 1;
  33. }
  34.  
  35.  
  36. int n = read(handle, buff, st.st_size);
  37.  
  38. int width = *(int *) (buff + 18);
  39. int height = *(int *) (buff + 22);
  40. short bpp = *(short *) (buff + 28);
  41. int dupa;
  42. printf("width = %d, height = %d bpp = %d\n", width , height, bpp );
  43. if (bpp == 24 && width = 320 && height = 2400)
  44. {
  45. dupa = detect(buff + 54, width);
  46.  
  47. printf("Done.\n");
  48. }
  49. else
  50. printf("This bmp is not 24 bit depth. \n");
  51.  
  52.  
  53. printf("width = %d, height = %d dupa = %d\n", width , height, dupa );
  54. free(buff);
  55.  
  56. close(handle);
  57.  
  58.  
  59.  
  60. return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement