Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if ((pData[i] == 0xFF) && (pData[i + 1] == 0xD8) && (pData[i + 2] == 0xFF) && (pData[i + 3] == 0xE0)) {
- i += 4;
- // Check for valid JPEG header (null terminated JFIF)
- if ((pData[i + 2] == 'J') && (pData[i + 3] == 'F') && (pData[i + 4] == 'I') && (pData[i + 5] == 'F')
- && (pData[i + 6] == 0x00)) {
- //Retrieve the block length of the first block since the first block will not contain the size of file
- unsigned short block_length = pData[i] * 256 + pData[i + 1];
- while (i < FileSizeLow) {
- //Increase the file index to get to the next block
- i += block_length;
- if (i >= FileSizeLow) {
- //Check to protect against segmentation faults
- return -1;
- }
- if (pData[i] != 0xFF) {
- return -2;
- }
- if (pData[i + 1] == 0xC0) {
- //0xFFC0 is the "Start of frame" marker which contains the file size
- //The structure of the 0xFFC0 block is quite simple [0xFFC0][ushort length][uchar precision][ushort x][ushort y]
- *pHeight = pData[i + 5] * 256 + pData[i + 6];
- *pWidth = pData[i + 7] * 256 + pData[i + 8];
- return 0;
- }
- else {
- i += 2; //Skip the block marker
- //Go to the next block
- block_length = pData[i] * 256 + pData[i + 1];
- }
- }
- //If this point is reached then no size was found
- return -3;
- }
- else {
- return -4;
- } //Not a valid JFIF string
- }
- else {
- return -5;
- } //Not a valid SOI header
- return -6;
- f = open("filename.jpg", "r")
- s = f.read()
- start = s.find("xffxe0")
- end = s.rfind("xffxd9")
- imagesize = end - start
Add Comment
Please, Sign In to add comment