Кажется, что при декодировании файлов PNG с помощью libpng он не читает последние 16 байтов, поэтому я ищу 16 байтов вперед, чтобы добраться до конца. Могу ли я предположить, что это верно для всех файлов PNG?
#include<sys/stat.h>
#include<unistd.h>
#include<fcntl.h>
#include<stdlib.h>
#include<stdio.h>
#include<png.h>
int fd;
void png_read(png_struct *png,png_byte *data,png_size_t len){
read(fd,data,len);
}
int main(void){
fd=open("foo.png",O_RDONLY);
png_struct *png=png_create_read_struct(PNG_LIBPNG_VER_STRING,0,0,0);
png_info *png_info=png_create_info_struct(png);
png_set_read_fn(png,0,png_read);
struct stat s;
fstat(fd,&s);
printf("File Size: %d\n",s.st_size);
png_read_info(png,png_info);
int x=png_get_image_width(png,png_info);
int y=png_get_image_height(png,png_info);
int c=png_get_channels(png,png_info);
char *buf=malloc(x*y*c);
char **row=malloc(sizeof(*row)*y);
{
int i=0;
while(i<y){
row[i]=buf+x*i*c;
i++;
}
}
png_read_image(png,(png_byte**)row);
printf("Ending File Position: %d\n",lseek(fd,0,SEEK_CUR));
return(0);
}
.
File Size: 20279
Ending File Position: 20263