diff options
| author | Leo Chan <leochanj@live.unc.edu> | 2020-10-22 01:53:21 -0400 |
|---|---|---|
| committer | Joshua Bakita <jbakita@cs.unc.edu> | 2020-10-22 01:56:35 -0400 |
| commit | d17b33131c14864bd1eae275f49a3f148e21cf29 (patch) | |
| tree | 0d8f77922e8d193cb0f6edab83018f057aad64a0 /SD-VBS/common/c/readImage.c | |
| parent | 601ed25a4c5b66cb75315832c15613a727db2c26 (diff) | |
Squashed commit of the sb-vbs branch.
Includes the SD-VBS benchmarks modified to:
- Use libextra to loop as realtime jobs
- Preallocate memory before starting their main computation
- Accept input via stdin instead of via argc
Does not include the SD-VBS matlab code.
Fixes libextra execution in LITMUS^RT.
Diffstat (limited to 'SD-VBS/common/c/readImage.c')
| -rw-r--r-- | SD-VBS/common/c/readImage.c | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/SD-VBS/common/c/readImage.c b/SD-VBS/common/c/readImage.c new file mode 100644 index 0000000..a4dd990 --- /dev/null +++ b/SD-VBS/common/c/readImage.c | |||
| @@ -0,0 +1,112 @@ | |||
| 1 | /******************************** | ||
| 2 | Author: Sravanthi Kota Venkata | ||
| 3 | ********************************/ | ||
| 4 | |||
| 5 | #include <stdio.h> | ||
| 6 | #include <stdlib.h> | ||
| 7 | #include "sdvbs_common.h" | ||
| 8 | |||
| 9 | I2D* readImage(const char* pathName) | ||
| 10 | { | ||
| 11 | // Reading BMP image | ||
| 12 | char signature[2]; | ||
| 13 | int file_size; | ||
| 14 | short int reserved1; | ||
| 15 | short int reserved2; | ||
| 16 | int loc_of_bitmap; | ||
| 17 | |||
| 18 | int size_of_infoheader; | ||
| 19 | int width; | ||
| 20 | int height; | ||
| 21 | short int number_of_planes; | ||
| 22 | short int bits_per_pixel; | ||
| 23 | |||
| 24 | int compression_method; | ||
| 25 | int bytes_of_bitmap; | ||
| 26 | int hori_reso; | ||
| 27 | int vert_reso; | ||
| 28 | int no_of_colors; | ||
| 29 | int no_of_imp_colors; | ||
| 30 | |||
| 31 | int nI,nJ; | ||
| 32 | int pixSize; | ||
| 33 | |||
| 34 | unsigned char tempb,tempg,tempr,tempjunk[12]; | ||
| 35 | int ta; | ||
| 36 | I2D* srcImage; | ||
| 37 | |||
| 38 | FILE *input; | ||
| 39 | input = fopen(pathName,"rb"); | ||
| 40 | if(input == NULL) | ||
| 41 | { | ||
| 42 | perror("File pointer error"); | ||
| 43 | return NULL; | ||
| 44 | } | ||
| 45 | else | ||
| 46 | { | ||
| 47 | //start of header information | ||
| 48 | fread(&signature,sizeof(signature),1,input); | ||
| 49 | fread(&file_size,sizeof(file_size),1,input); | ||
| 50 | fread(&reserved1,sizeof(reserved1),1,input); | ||
| 51 | fread(&reserved2,sizeof(reserved2),1,input); | ||
| 52 | fread(&loc_of_bitmap,sizeof(loc_of_bitmap),1,input); | ||
| 53 | |||
| 54 | fread(&size_of_infoheader,sizeof(size_of_infoheader),1,input); | ||
| 55 | fread(&width,sizeof(width),1,input); // Reads the width of the image | ||
| 56 | fread(&height,sizeof(height),1,input); // Reads the height of the image | ||
| 57 | fread(&number_of_planes,sizeof(number_of_planes),1,input); | ||
| 58 | fread(&bits_per_pixel,sizeof(bits_per_pixel),1,input); | ||
| 59 | fread(&compression_method,sizeof(compression_method),1,input); | ||
| 60 | fread(&bytes_of_bitmap,sizeof(bytes_of_bitmap),1,input); | ||
| 61 | |||
| 62 | fread(&hori_reso,sizeof(hori_reso),1,input); | ||
| 63 | fread(&vert_reso,sizeof(vert_reso),1,input); | ||
| 64 | fread(&no_of_colors,sizeof(no_of_colors),1,input); | ||
| 65 | fread(&no_of_imp_colors,sizeof(no_of_imp_colors),1,input); | ||
| 66 | //end of header information | ||
| 67 | |||
| 68 | srcImage = iMallocHandle(height, width); | ||
| 69 | |||
| 70 | // Conditions to check whether the BMP is interleaved and handling few exceptions | ||
| 71 | if(srcImage->height <= 0 || srcImage->width <= 0 || signature[0] != 'B' || signature[1] != 'M' || ( bits_per_pixel !=24 && bits_per_pixel !=8 ) ) | ||
| 72 | { | ||
| 73 | printf("ERROR in BMP read: The input file is not in standard BMP format"); | ||
| 74 | return NULL; | ||
| 75 | } | ||
| 76 | fseek(input,loc_of_bitmap,SEEK_SET); | ||
| 77 | |||
| 78 | if (bits_per_pixel == 8) | ||
| 79 | { | ||
| 80 | for(nI = (height - 1); nI >= 0 ; nI--) | ||
| 81 | { | ||
| 82 | for(nJ = 0;nJ < width; nJ++) | ||
| 83 | { | ||
| 84 | fread(&tempg,sizeof(unsigned char),1,input); | ||
| 85 | subsref(srcImage,nI,nJ) = (int)tempg; | ||
| 86 | } | ||
| 87 | } | ||
| 88 | } | ||
| 89 | else if (bits_per_pixel == 24) | ||
| 90 | { | ||
| 91 | for(nI = (height - 1); nI >= 0 ; nI--) | ||
| 92 | { | ||
| 93 | for(nJ = 0;nJ < width; nJ++) | ||
| 94 | { | ||
| 95 | fread(&tempb,sizeof(unsigned char),1,input); | ||
| 96 | fread(&tempg,sizeof(unsigned char),1,input); | ||
| 97 | fread(&tempr,sizeof(unsigned char),1,input); | ||
| 98 | ta = (3*tempr + 6*tempg + tempb)/10; | ||
| 99 | ta = tempg; | ||
| 100 | subsref(srcImage,nI,nJ) = (int)ta; | ||
| 101 | } | ||
| 102 | } | ||
| 103 | } | ||
| 104 | else | ||
| 105 | { | ||
| 106 | return NULL; | ||
| 107 | } | ||
| 108 | |||
| 109 | fclose(input); | ||
| 110 | return srcImage; | ||
| 111 | } | ||
| 112 | } | ||
