CodePudding user response:
Refer to the open source software Image MagickCodePudding user response:
This post to explain very detailedhttp://blog.csdn.net/ryfdizuo/article/details/41250775
CodePudding user response:
Each jpeg files, documents and files is different, have differences, such as some have exif information, some not, there are additional to other information in it, so you must be standardized in accordance with the tag and to offset,CodePudding user response:
Words, don't know the search JPEG file format?https://en.wikipedia.org/wiki/JPEG_File_Interchange_Format
CodePudding user response:
# include & lt; Stdio. H>
#include
# define WIN32_LEAN_AND_MEAN
#include
#include
#include
//0 xffd8: SOI
//0 xffe0: APP0
//0 xffe1: APP1
//0 xffe2: APP2
//0 xffe3: APP3
//0 xffe4: APP4
//0 xffe5: APP5
//0 xffe6: APP6
//0 xffe7: APP7
//0 xffe8: APP8
//0 xffe9: APP9
//0 XFFDB: DQT
//0 xffc0: SOF0
//0 xffc4: DHT
//0 xffda: SOS
//0 xffd9: EOI
Int main (int arg c, char * argv [])
{
HANDLE hFile=CreateFile (TEXT (" image. JPG "), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
If (hFile! INVALID_HANDLE_VALUE)={
LARGE_INTEGER lli={0};
If (GetFileSizeEx (hFile, & amp; Lli)) {
HANDLE hMapping=CreateFileMapping (PAGE_READONLY hFile, NULL, 0, 0, NULL);
If (hMapping!=NULL) {
BYTE * lpFileBuffer=(BYTE *) MapViewOfFile (hMapping FILE_MAP_READ, 0, 0, 0).
If (lpFileBuffer!=NULL) {
BYTE * lpStartBuffer=lpFileBuffer;
BYTE * lpEndBuffer=lpFileBuffer + (size_t) lli. QuadPart;
While (lpStartBuffer & lt; LpEndBuffer) {
BYTE b1=lpStartBuffer [0];
BYTE b2=lpStartBuffer [1].
BYTE b3=lpStartBuffer [2];
BYTE b4=lpStartBuffer [3].
WORD wMark=MAKEWORD (b2, b1);
WORD wSize=MAKEWORD (b4, b3);
Size_t uOffset=lpStartBuffer - lpFileBuffer;
LpStartBuffer +=sizeof (wSize);
If ((wMark!=0 xffd8) & amp; & (wMark! {
=0 xffd9))LpStartBuffer +=wSize;
}
The switch (wMark) {
Case 0 xffd8:
Printf (" SOI=& gt; The from % u \ n ", uOffset);
break;
Case 0 xffe0:
Printf (" APP0=& gt; The from % u, u size % \ n ", uOffset, wSize);
break;
Case 0 xffe1:
Printf (" APP1=& gt; The from % u, u size % \ n ", uOffset, wSize);
break;
Case 0 xffe2:
Printf (" APP2=& gt; The from % u, u size % \ n ", uOffset, wSize);
break;
Case 0 xffe3:
Printf (" APP3=& gt; The from % u, u size % \ n ", uOffset, wSize);
break;
Case 0 xffe4:
Printf (" APP4=& gt; The from % u, u size % \ n ", uOffset, wSize);
break;
Case 0 xffe5:
Printf (" APP5=& gt; The from % u, u size % \ n ", uOffset, wSize);
break;
Case 0 xffe6:
Printf (" APP6=& gt; The from % u, u size % \ n ", uOffset, wSize);
break;
Case 0 xffe7:
Printf (" APP7=& gt; The from % u, u size % \ n ", uOffset, wSize);
break;
Case 0 xffe8:
Printf (" APP8=& gt; The from % u, u size % \ n ", uOffset, wSize);
break;
Case 0 xffe9:
Printf (" APP9=& gt; The from % u, u size % \ n ", uOffset, wSize);
break;
Case 0 XFFDB:
Printf (" DQT=& gt; The from % u, u size % \ n ", uOffset, wSize);
break;
Case 0 xffc0:
Printf (" SOF0=& gt; The from % u, u size % \ n ", uOffset, wSize);
break;
Case 0 xffc4:
Printf (" DHT=& gt; The from % u, u size % \ n ", uOffset, wSize);
break;
Case 0 xffda:
Printf (" SOS=& gt; The from % u, u size % \ n ", uOffset, wSize);
break;
Case 0 xffd9:
Printf (" EOI=& gt; The from % u \ n ", uOffset);
break;
Default:
break;
}
}
}
UnmapViewOfFile (lpFileBuffer);
}
The CloseHandle (hMapping);
}
The CloseHandle (hFile);
}
return 0;
}
CodePudding user response:
JPGFFD8 start
Between each block begin with FFXX, then is big end save 2 bytes (unsigned short) indicates the size of the block, the block size including storage block size of the 2 bytes,
FFD9 end
Don't need to care about redundant file header details, his casual analysis analysis, find the block, is very simple,