資源簡介
基于VS2012,用c撰寫的解析JPEG圖片頭信息的簡單程序。課程作業

代碼片段和文件信息
/*
*?File?Name:?jpegDe.c
*?Author:?576632108@qq.com?lucio
*?Date:?2014.11.5
*?Description:?analyze?the?head?info?of?jpeg
*/
#include?
#include?
typedef?unsigned?short?WORD;
typedef?unsigned?long?DWORD;
typedef?long?LONG;
int?main(int?argc?char?**argv){
FILE?*fp;
WORD?window;?
WORD?temp;
int?i=0j=0k=0;
int?found_count=0;
int?mark_head=0xFF;
int?mark_part[8]={0xD80xE00xDB0xDD0xC00xC40xDA0xD9};
char?mark_str[8][10]={“SOI““APP0““DQT““DRI““SOF0““DHT““SOS““EOI“};
int?headpart;
int?temp_headtemp_part;
int?done=0;
fp=fopen(“KD.jpg““rb“);
if(fp==0){
printf(“Can?not?open?the?file?to?read.\n“);
return?-1;
}
while(?1?){
fseek(fpiSEEK_SET);
if(fread(&window21fp)!=1){
printf(“Can?not?read?the?info?of?the?info?header.\n“);
fclose(fp);
return?-1;
}
head=window-(window/0x100)*0x100;//靠前的部分是高位
part=window/0x100;//靠后的部分是低位
if(?head==mark_head?){
for?(?j=0;j<8;j++?){
if(?part==mark_part[j]?){
printf(“%s:?%X-%X\n“mark_str[j]headpart);
if(?j==1?){//APP0
//此處不需要fseek,因為讀的過程中指針移動
//Lp
if(fread(&temp21fp)!=1){
printf(“Can?not?read?the?info?of?the?info?header.\n“);
fclose(fp);
return?-1;
}
temp_head=temp-(temp/0x100)*0x100;
temp_part=temp/0x100;
temp=temp_head+temp_part;
printf(“??Lp:?%d\n“temp);
//Identifier
printf(“??Identifier:?“);
for(?k=0;k<3;k++?){
if(fread(&temp21fp)!=1){
printf(“Can?not?read?the?info?of?the?info?header.\n“);
fclose(fp);
return?-1;
}
temp_head=temp-(temp/0x100)*0x100;
temp_part=temp/0x100;
if(?k!=2?) printf(“%02X-%02X-“temp_headtemp_part);
else?printf(“%02X“temp_head);
}
printf(“\n“);
//Version
fseek(fp-1SEEK_CUR);
if(fread(&temp21fp)!=1){
printf(“Can?not?read?the?info?of?the?info?header.\n“);
fclose(fp);
return?-1;
}
temp_head=temp-(temp/0x100)*0x100;
temp_part=temp/0x100;
temp=temp_head+temp_part;
printf(“??Version:?%02X-%02X\n“temp_headtemp_part);
//Units
if(fread(&temp11fp)!=1){
printf(“Can?not?read?the?info?of?the?info?header.\n“);
fclose(fp);
return?-1;
}
printf(“??Units:?%02X\n“temp);
//Xdensity
if(fread(&temp21fp)!=1){
printf(“Can?not?read?the?info?of?the?info?header.\n“);
fclose(fp);
return?-1;
}
temp_head=temp-(temp/0x100)*0x100;
temp_part=temp/0x100;
temp=temp_head+temp_part;
printf(“??Xdensity:?%d\n“temp);
//Ydensity
if(fread(&temp21fp)!=1){
printf(“Can?not?read?the?info?of?the?info?header.\n“);
fclose(fp);
return?-1;
}
temp_head=temp-(temp/0x100)*0x100;
temp_part=temp/0x100;
temp=temp_head+temp_part;
pr
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2014-11-19?11:48??jpegDe\
?????目錄???????????0??2014-11-02?19:07??jpegDe\Debug\
?????文件???????34304??2014-11-05?10:43??jpegDe\Debug\jpegDe.exe
?????文件??????496920??2014-11-05?10:43??jpegDe\Debug\jpegDe.ilk
?????文件??????461824??2014-11-05?10:43??jpegDe\Debug\jpegDe.pdb
?????目錄???????????0??2014-11-03?20:56??jpegDe\jpegDe\
?????文件?????2228224??2014-11-19?11:48??jpegDe\jpegDe.sdf
?????文件?????????885??2014-11-02?19:04??jpegDe\jpegDe.sln
?????文件???????22528??2014-11-19?11:48??jpegDe\jpegDe.v11.suo
?????目錄???????????0??2014-11-05?10:43??jpegDe\jpegDe\Debug\
?????文件?????????534??2014-11-05?10:43??jpegDe\jpegDe\Debug\cl.command.1.tlog
?????文件????????1060??2014-11-05?10:43??jpegDe\jpegDe\Debug\CL.read.1.tlog
?????文件?????????226??2014-11-05?10:43??jpegDe\jpegDe\Debug\CL.write.1.tlog
?????文件??????????48??2014-11-05?10:43??jpegDe\jpegDe\Debug\jpegDe.lastbuildstate
?????文件????????1497??2014-11-05?10:43??jpegDe\jpegDe\Debug\jpegDe.log
?????文件???????13912??2014-11-05?10:43??jpegDe\jpegDe\Debug\jpegDe.obj
?????文件???????????2??2014-11-05?10:43??jpegDe\jpegDe\Debug\li
?????文件???????????2??2014-11-05?10:43??jpegDe\jpegDe\Debug\li
?????文件???????????2??2014-11-05?10:43??jpegDe\jpegDe\Debug\li
?????文件???????????2??2014-11-05?10:43??jpegDe\jpegDe\Debug\li
?????文件?????????978??2014-11-05?10:43??jpegDe\jpegDe\Debug\li
?????文件????????2134??2014-11-05?10:43??jpegDe\jpegDe\Debug\li
?????文件?????????282??2014-11-05?10:43??jpegDe\jpegDe\Debug\li
?????文件???????27648??2014-11-05?10:43??jpegDe\jpegDe\Debug\vc110.idb
?????文件???????77824??2014-11-05?10:43??jpegDe\jpegDe\Debug\vc110.pdb
?????文件????????3587??2014-11-05?11:09??jpegDe\jpegDe\jpegDe.c
?????文件????????4006??2014-11-02?19:06??jpegDe\jpegDe\jpegDe.vcxproj
?????文件?????????942??2014-11-02?19:06??jpegDe\jpegDe\jpegDe.vcxproj.filters
?????文件???????16963??2013-11-09?16:12??jpegDe\jpegDe\KD.jpg
?????文件??????481537??2014-11-03?20:55??jpegDe\jpegDe\tiger.jpg
- 上一篇:Qt5類繼承關系圖
- 下一篇:STM32+GPS程序
評論
共有 條評論