Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <stdio.h>
- #include <stdlib.h>
- int detect(unsigned char* img, int width);
- int main (int argc, char** argv)
- {
- char *buff;
- if(argc != 2 )
- {
- printf("The number of arguments is not correct. \n ");
- return 1;
- }
- struct stat st;
- stat(argv[1], &st);
- buff = (char *) malloc(st.st_size);
- if (buff == NULL)
- {
- printf("Cannot allocate memory\n");
- return 1;
- }
- int handle = open(argv[1], O_RDONLY, 0);
- if (handle == -1) {
- printf("Cannot access file.\n");
- free(buff);
- return 1;
- }
- int n = read(handle, buff, st.st_size);
- int width = *(int *) (buff + 18);
- int height = *(int *) (buff + 22);
- short bpp = *(short *) (buff + 28);
- int dupa;
- printf("width = %d, height = %d bpp = %d\n", width , height, bpp );
- if (bpp == 24 && width = 320 && height = 2400)
- {
- dupa = detect(buff + 54, width);
- printf("Done.\n");
- }
- else
- printf("This bmp is not 24 bit depth. \n");
- printf("width = %d, height = %d dupa = %d\n", width , height, dupa );
- free(buff);
- close(handle);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement