[Date Prev][Date Next][Thread Prev][Thread Next] - [Date Index][Thread Index][Author Index]

Re: D-block utility



So once you decode a D-block, like the one from orbit 329, you get what 
appears to be a file that is 144k in length. The file actually contains 
14 JPEG  images stored back-to-back.

It took me a while to figure this out, my JPEG viewer would only show 
the first file. However, I started to wonder where the other images were 
since the archive I downloaded for orbit 329, had 14 images (not 
counting the despun versions).  I used a hex editor to view the decode 
d-block and found multiple JFIF headers in the file.

The routine below will take a decoded d-block file  and split out the 
individual image and name them as show below:

D00329_PH.raw  <------ decoded d-block
D00329_PH0.jpg <------ one of the 14 images stored in the source file
D00329_PH1.jpg
D00329_PH10.jpg
D00329_PH11.jpg
D00329_PH12.jpg
D00329_PH13.jpg
D00329_PH2.jpg
D00329_PH3.jpg
D00329_PH4.jpg
D00329_PH5.jpg
D00329_PH6.jpg
D00329_PH7.jpg
D00329_PH8.jpg
D00329_PH9.jpg





void getJFIF(char path[],char fname[],char source[])
{

     // "source" is the complete path to the decoded D-block file
     // "path" is just that, the path to the file
     // "fname" is he file name with out the ".raw"

     FILE *fp1,*fp2;
     unsigned char	c,header[10],temp[255];
     unsigned short	i=0;
    unsigned long 		x,s=0,index[100],indexCount=0;

     //JFIF header pattern
     header[0]=0xFF;
     header[1]=0xD8;
     header[2]=0xFF;
     header[3]=0xE0;
     header[4]=0x00;
     header[5]=0x10;
     header[6]=0x4A;
     header[7]=0x46;
     header[8]=0x49;
     header[9]=0x46;

     sprintf(temp,"%s/%s",path,fname);
     fp1=fopen(source,"rb");
     //printf("getJFIF %s\n",source);

      while ( fread(&c,1,sizeof(unsigned char) ,fp1) )
             {
                if( c == header[i]) // serach for JFIF header
                     {
                         ++i;
                         // printf("indexCount=%ld i=%d c=%X 
\n%s\n",indexCount,i,c,path);
                     }
                 else
                    {
                         i=0;
                     }

                 if(i>9) // record start of JFIF images
                 {
                     index[indexCount]=ftell(fp1) -10;
                     //printf("indexCount=%ld start=%ld\n",indexCount, 
index[indexCount]);

                     ++indexCount;
                     i=0;
                 }

             }

     index[indexCount]=ftell(fp1); //store end of file.
     fclose(fp1);
     x=0; // point to curent image
     s=0; //current postion in source file

     // split out images
       fp1=fopen(source,"rb");
        for(x=0;x<indexCount;x++)
         {
             sprintf(temp,"%s/%s%ld.jpg",path,fname,x);
             fp2=fopen(temp,"wb");
             fseek(fp1,index[x],SEEK_SET);   // goto start of next image

            while( s < index[x+ 1])
                 {
                      fread(&c,1,sizeof(unsigned char) ,fp1);
                     fputc(c,fp2);
                       s=ftell(fp1);
                 }
              fclose(fp2);

         }
       fclose(fp1);
}




Gilbert Mackall
N3RZN

----
Via the amsat-bb mailing list at AMSAT.ORG courtesy of AMSAT-NA.
To unsubscribe, send "unsubscribe amsat-bb" to Majordomo@amsat.org



AMSAT Top AMSAT Home