[go: up one dir, main page]

Menu

[r34]: / common / read-png.cpp  Maximize  Restore  History

Download this file

88 lines (71 with data), 2.1 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <png.h>
/*extern "C" int MODEXCHG_mp_M;
extern "C" int MODEXCHG_mp_NBPP;
extern "C" int MODEXCHG_mp_PNGX;
extern "C" int MODEXCHG_mp_PNGY;
extern "C" png_byte MODEXCHG_mp_IN[4096*4096*2];
*/
extern "C" {
int from_png_ (char *path,png_byte IN[2048*2048*2],int *NBPP,int *PNGX, int *PNGY) {
int i, j;
// char sig_buf [SIG_CHECK_SIZE];
png_info *info_ptr;
png_struct *png_ptr;
//png_byte **bitmap;
//png_uint_32 *w,*h;
png_uint_32 width, height;
int bit_depth, color_type, interlace_type,rowbytes;
unsigned char **row_pointers;
char *path_tmp;
path_tmp=strtok(path,"\\");
// path_tmp=strcat(path_tmp,"png");
printf("reading %s:::\n",path);
FILE *fp;
if ((fp = fopen(path, "rb")) == NULL) {
printf("Can't open file %s!!!\n",path_tmp);
*NBPP=-1;
return 0;
}
png_ptr = png_create_read_struct
(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if(png_ptr == NULL) {
printf("Error creating read_struct\n");
fclose(fp);
return 0;
}
info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL) {
fclose(fp);
png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL);
return 0;
}
if (setjmp(png_ptr->jmpbuf)) {
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
fclose(fp);
printf("Error reading file\n");
return 0;
}
png_init_io(png_ptr, fp);
png_read_info(png_ptr, info_ptr);
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
&interlace_type, NULL, NULL);
*NBPP=bit_depth;
*PNGX=int(width);
*PNGY=int(height);
printf("Image size %d %d %d %d %d %d\n",*PNGX, *PNGY, *NBPP,width, height, bit_depth);
// sleep(10);
rowbytes=png_get_rowbytes(png_ptr, info_ptr);
row_pointers = (unsigned char**)malloc(height * sizeof(unsigned char*));
for(i=0;i<(int)height;i++) {
row_pointers[i] = &IN[rowbytes*i];
}
png_read_image(png_ptr, row_pointers);
png_read_end(png_ptr, NULL);
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
fclose(fp);
free(row_pointers);
}
}