Guest User

Untitled

a guest
Apr 26th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. if ((pData[i] == 0xFF) && (pData[i + 1] == 0xD8) && (pData[i + 2] == 0xFF) && (pData[i + 3] == 0xE0)) {
  2. i += 4;
  3.  
  4. // Check for valid JPEG header (null terminated JFIF)
  5. if ((pData[i + 2] == 'J') && (pData[i + 3] == 'F') && (pData[i + 4] == 'I') && (pData[i + 5] == 'F')
  6. && (pData[i + 6] == 0x00)) {
  7.  
  8. //Retrieve the block length of the first block since the first block will not contain the size of file
  9. unsigned short block_length = pData[i] * 256 + pData[i + 1];
  10.  
  11. while (i < FileSizeLow) {
  12. //Increase the file index to get to the next block
  13. i += block_length;
  14.  
  15. if (i >= FileSizeLow) {
  16. //Check to protect against segmentation faults
  17. return -1;
  18. }
  19.  
  20. if (pData[i] != 0xFF) {
  21. return -2;
  22. }
  23.  
  24. if (pData[i + 1] == 0xC0) {
  25. //0xFFC0 is the "Start of frame" marker which contains the file size
  26. //The structure of the 0xFFC0 block is quite simple [0xFFC0][ushort length][uchar precision][ushort x][ushort y]
  27. *pHeight = pData[i + 5] * 256 + pData[i + 6];
  28. *pWidth = pData[i + 7] * 256 + pData[i + 8];
  29.  
  30. return 0;
  31. }
  32. else {
  33. i += 2; //Skip the block marker
  34.  
  35. //Go to the next block
  36. block_length = pData[i] * 256 + pData[i + 1];
  37. }
  38. }
  39.  
  40. //If this point is reached then no size was found
  41. return -3;
  42. }
  43. else {
  44. return -4;
  45. } //Not a valid JFIF string
  46. }
  47. else {
  48. return -5;
  49. } //Not a valid SOI header
  50.  
  51. return -6;
  52.  
  53. f = open("filename.jpg", "r")
  54. s = f.read()
  55. start = s.find("xffxe0")
  56. end = s.rfind("xffxd9")
  57. imagesize = end - start
Add Comment
Please, Sign In to add comment