http://www.mediafire.com/file/u3gb1fx0fxn4rn1/data.rar/file
Many thanks to everyone for the attention ..
I picked up some pieces of my other work and created this code.
but have a two problem I'm not got weight right from where is the error. If anyone can help me...
First: I am not able to put the information of the other images in the header of the file.
2nd: Something is modified the contents of the other images only the first one stays with the original size
[code]
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned int u32;
u32 LE32(u32 b) {
u32 t = 0x12345678;
if (*((unsigned char*)(&t)) == 0x78) {
return b;
} else {
return ((b & 0xff000000) >> 24) |
((b & 0x00ff0000) >> 8 ) |
((b & 0x0000ff00) << 8 ) |
((b & 0x000000ff) << 24);
}
}
unsigned char dat_header[] = {
0x7f, 'D', 'A', 'T', 0x00, 0x00, 0x00, 0x00,
};
void usage();
void create_dat(FILE * dest, const unsigned char * source, u32 size, int three_argc);
int main(int argc, char** argv)
{
u32 fd_size, start = 0, end = 0xffffffff, size = 0xffffffff;
unsigned char * buffer;
FILE * source, * dest;
char * f_source = 0, * f_dest = 0;
f_source = argv[1];
f_dest = argv[2];
int quantity_of_items = atoi(argv[3]); //quantity of items
if (!f_source || !f_dest) {
usage();
printf("Not enough arguments.\n");
return 1;
}
if (!(source = fopen(f_source, "rb"))) {
printf("Error opening %s for reading.\n", f_source);
return 1;
}
fseek(source, 0, SEEK_END);
fd_size = ftell(source);
fseek(source, start, SEEK_SET);
if (fd_size < end)
end = fd_size;
if (end < (size - start))
size = end - start;
buffer = malloc(size);
if (buffer == NULL) {
printf("Failed to allocate memory.\n");
return 1;
}
if (fread(buffer, 1, size, source) != size) {
printf("Failed to read file.\n");
return 1;
}
fclose(source);
if (access(f_dest, F_OK) != 0)
{
if (!(dest = fopen(f_dest, "wb+"))) {
printf("Failed to open/create %s.\n", f_dest);
return 1;
}
}else{
if (!(dest = fopen(f_dest, "a+"))) {
printf("Failed to open/create %s.\n", f_dest);
return 1;
}
}
create_dat(dest, buffer, size, quantity_of_items);
fclose(dest);
free(buffer);
return 0;
}
void create_dat(FILE * dest, const unsigned char * source, u32 size, int three_argc)
{
u32 data_size[4];
int i;
if(three_argc > 0){ //three argument = 1
for (i = 0; i < sizeof(dat_header); i++) {
dat_header[4] = three_argc; //quantity of items
fputc(dat_header[i], dest);
}
}
data_size[0] = LE32(size);
data_size[1] = 0;
data_size[2] = 0;
data_size[3] = 0;
fwrite(data_size, 4, 4, dest);
fwrite(source, 1, size, dest);
}
void usage() {
printf("Usage: create_dat.exe infile outfile.dat\n--------------------------\n");
}
[\code]
I add the images through a .bat file, like this:
create_dat.exe file1.png myfile.dat 5
create_dat.exe file2.png myfile.dat
create_dat.exe file3.png myfile.dat
create_dat.exe file4.png myfile.dat
create_dat.exe file5.png myfile.dat
only the first file has argv [3];