0

Hi guys, i really need help here. I must write a program in c that reads a file .RAW that it contains photos in sequential order, every photo has a head-board of 4 bytes. (0xff 0xd8 oxff 0xe0 or 0xe1) and that way I can identify the beginning of the photo and the size.
dont know if i must read the file in binary form or not, and i do not understand whath this storing in the dynamic vector

The files in this folder will have to be separated and with the extension .JPG which it will allow his visualization. In turn, these will have to have a name that goes from 0.jpg up to [Number of photos in the file].jpg.
It will have guard in a dynamic vector the size of each one of the photos. It is to say that
The size of the vector will be exactly the quantity of the existing photos in the file to
To recover.

This is what I did till now

#include <stdio.h>
#include <stdlib.h>


void load(FILE *archivo, unsigned char *vector, int n);
void findHeader (unsigned char *vector, int n);

int main()
{
  
  unsigned char *character;
  int cont=0;
  int nBytes;
  char c;

FILE* file = fopen("fotos.RAW", "r");
      if(archivo != NULL)
      {
            fseek(archivo, 0, SEEK_END); o
            nBytes = ftell(file); // size in bytes
            rewind(file);
            printf("The size of file is: %d Kbytes\n", nBytes/1024 ) ;
          
            while( ( c = fgetc( archivo ) ) != EOF )
                   cont++;     
      }
      else
	  {
         printf("error!\n");
      }
      rewind(file);
      cargar(file, character, cont);
      
     findHeader(character, cont);
      
      
      fclose(file);
 


getch();
return 0;

}


void load(FILE *archivo,unsigned char *vector, int n)
{
    int i;
    char c;
    vector = (unsigned char*) malloc (sizeof(unsigned char)*n+1);
    
    if (vector == NULL)
       printf("wrong operation\n");
    else
        {
            
            while( ( c = fgetc( file ) ) != EOF )
            {
                    
                   for (i=0; i <= n; i++)
                   {
                       vector[i] = c;
                       printf("0x%x", vector[i]); // to control what is saving in the array
                       getch();    
                   }       
            }     
        }
}

void findHeader (unsigned char *vector, int n)
{
    int band=0;;
   int i;
   for(i=0; i <=n; i++)
   {
            if ((vector[i] == 0xff ) && (vector[i+1] == 0xd8) && (vector[i+2] == 0xff) && (vector[i+3] == 0xe0))
               band++;
            else
            {
               if ((vector[i] == 0xff) && (vector[i+1] == 0xd8) && (vector[i+2] == 0xff) && (vector[i+3] == 0xe1)) 
                  band++;
            }
   }          
    printf("Band show up %d times\n", band); //to control how many pics are
     
}
2
Contributors
1
Reply
6
Views
7 Years
Discussion Span
Last Post by Adak
0

You'll certainly want to open the files in binary mode.

First thing I'd do is write a function that will open and copy a solo and regular JPG file, and make sure it can be then viewed OK.

Then, I'd see about getting the smallest *.RAW file I could, with only two small JPG's in the file, and see if you're able to separate out the two JPG files. Then use your function above, to copy them out to their own files.

And again, check that they are OK, when viewed.

The file naming is simple - no problem there.

#include <stdio.h>

int main() {
  int i;
  char filename[] = {"file0.jpg"};
  char n = '0';

  for(i = 0; i < 3; i++) {
    filename[4] = n++;
    printf("\n New filename is: %s", filename);
  }

  n = getchar();
  return 0;
}

Let us know how you're doing, OK? And Welcome to the forum! ;)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.