Advertisement
Guest User

Untitled

a guest
Feb 17th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.78 KB | None | 0 0
  1. // MODIFIED CODE FROM BELOW CONTRIBUTOR
  2.  
  3. // (c) Michael Schoeffler 2016, http://www.mschoeffler.de
  4.  
  5.  
  6.  
  7. #include <SD.h> //Load SD library
  8. int chipSelect = 4; //chip select pin for the MicroSD Card Adapter
  9. File file; // file object that is used to read and write data
  10.  
  11. int32_t readNbytesInt(File *p_file, int position, byte nBytes) // FUNCTION WHICH READS A DETERMINED AMMOUNT OF BYTES INTO A SINGLE VARIABLE
  12. {
  13. if (nBytes > 4)
  14. return 0;
  15.  
  16. p_file->seek(position);
  17.  
  18. int32_t weight = 1;
  19. int32_t result = 0;
  20. for (; nBytes; nBytes--)
  21. {
  22. result += weight * p_file->read();
  23. weight <<= 8;
  24. }
  25. return result;
  26. }
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33. void setup() {
  34. Serial.begin(9600); // start serial connection to print out debug messages and data
  35.  
  36. pinMode(chipSelect, OUTPUT); // chip select pin must be set to OUTPUT mode
  37. if (!SD.begin(chipSelect)) { // Initialize SD card
  38. Serial.println("Could not initialize SD card."); // if return value is false, something went wrong.
  39. }
  40.  
  41. if (SD.exists("bitmap.bmp")) { // if "bitmap.bmp" exists, say so
  42. Serial.println("Found The Bitmap File.");
  43.  
  44. }
  45.  
  46. file = SD.open("bitmap.bmp", FILE_READ); // open the file to an object for reading
  47.  
  48. // DETERMINE HOW LARGE THE BITMAP FILE IS
  49. int howmany;
  50. howmany = file.available();
  51. Serial.println(howmany); // print the how large the file is
  52.  
  53.  
  54.  
  55. // DETERMINE STARTING IMAGE ARRAY LOCATION IN THE BITMAP FILE
  56. int32_t dataStartingOffset = readNbytesInt(&file, 0x0A, 4);
  57. Serial.println("The starting location in the fiile is...");
  58. Serial.println(dataStartingOffset);
  59.  
  60.  
  61. // DETERMINE THE IMAGE HEIGHT AND WIDTH
  62. int32_t imgwidth = readNbytesInt(&file, 0x12, 4);
  63. Serial.println("The image width is the following pixels:");
  64. Serial.println(imgwidth);
  65. int32_t imgheight = readNbytesInt(&file, 0x16, 4);
  66. Serial.println(imgheight);
  67.  
  68.  
  69. // MODIFIED CODE. DOES THE COLOR DEPTH LOCATION WORK IN THE BITMAP AND DOES IT GIVE CORRECT INFO ABOUT THE FILE?
  70. int16_t pixelsize = readNbytesInt(&file, 0X1C, 2);
  71. if (pixelsize != 24)
  72. {
  73. Serial.println("This image is most definitely not 24 bpp");
  74. Serial.println(" it is actually a depth of :");
  75. Serial.println(pixelsize);
  76.  
  77. }
  78.  
  79.  
  80. file.seek(dataStartingOffset); //skip bitmap header and go directly to the image data array.
  81.  
  82.  
  83. /* for(int32_t i = 0; i < imgheight; i ++) {
  84. for (int32_t j = 0; j < imgwidth; j ++) {
  85. B = file.read();
  86. Serial.println("height and width location from bottom");
  87. Serial.println(i);
  88. Serial.println(j);
  89. Serial.println("B");
  90. Serial.println(B);
  91. }
  92. Serial.println("height advance");
  93. }
  94.  
  95.  
  96. */
  97. int B;
  98.  
  99. B = file.read();
  100. Serial.println(B, BIN);
  101. B = file.read();
  102. Serial.println(B, BIN);
  103.  
  104.  
  105. B = file.read();
  106. Serial.println(B, BIN);
  107. B = file.read();
  108. Serial.println(B, BIN);
  109.  
  110.  
  111.  
  112. B = file.read();
  113. Serial.println(B, BIN);
  114. B = file.read();
  115. Serial.println(B, BIN);
  116.  
  117.  
  118. B = file.read();
  119. Serial.println(B, BIN);
  120. B = file.read();
  121. Serial.println(B, BIN);
  122.  
  123. B = file.read();
  124. Serial.println(B, BIN);
  125. B = file.read();
  126. Serial.println(B, BIN);
  127.  
  128.  
  129. B = file.read();
  130. Serial.println(B, BIN);
  131. B = file.read();
  132. Serial.println(B, BIN);
  133.  
  134.  
  135.  
  136. B = file.read();
  137. Serial.println(B, BIN);
  138. B = file.read();
  139. Serial.println(B, BIN);
  140.  
  141.  
  142. B = file.read();
  143. Serial.println(B, BIN);
  144. B = file.read();
  145. Serial.println(B, BIN);
  146.  
  147. B = file.read();
  148. Serial.println(B, BIN);
  149. B = file.read();
  150. Serial.println(B, BIN);
  151.  
  152. B = file.read();
  153. Serial.println(B, BIN);
  154. B = file.read();
  155. Serial.println(B, BIN);
  156.  
  157.  
  158. B = file.read();
  159. Serial.println(B, BIN);
  160. B = file.read();
  161. Serial.println(B, BIN);
  162.  
  163.  
  164.  
  165. B = file.read();
  166. Serial.println(B, BIN);
  167. B = file.read();
  168. Serial.println(B, BIN);
  169.  
  170.  
  171. B = file.read();
  172. Serial.println(B, BIN);
  173. B = file.read();
  174. Serial.println(B, BIN);
  175.  
  176. B = file.read();
  177. Serial.println(B, BIN);
  178. B = file.read();
  179. Serial.println(B, BIN);
  180.  
  181.  
  182. B = file.read();
  183. Serial.println(B, BIN);
  184. B = file.read();
  185. Serial.println(B, BIN);
  186.  
  187.  
  188.  
  189. B = file.read();
  190. Serial.println(B, BIN);
  191. B = file.read();
  192. Serial.println(B, BIN);
  193.  
  194.  
  195. B = file.read();
  196. Serial.println(B, BIN);
  197. B = file.read();
  198. Serial.println(B, BIN);
  199.  
  200. B = file.read();
  201. Serial.println(B, BIN);
  202. B = file.read();
  203. Serial.println(B, BIN);
  204.  
  205.  
  206.  
  207. file.close();
  208.  
  209. Serial.println("done write");
  210.  
  211.  
  212. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement