47 #include "allheaders.h" 58 static const l_int32 MAX_JP2K_WIDTH = 100000;
59 static const l_int32 MAX_JP2K_HEIGHT = 100000;
84 PROCNAME(
"readHeaderJp2k");
91 return ERROR_INT(
"filename not defined", procName, 1);
94 return ERROR_INT(
"image file not found", procName, 1);
121 PROCNAME(
"freadHeaderJp2k");
128 return ERROR_INT(
"fp not defined", procName, 1);
131 nread = fread(buf, 1,
sizeof(buf), fp);
132 if (nread !=
sizeof(buf))
133 return ERROR_INT(
"read failure", procName, 1);
174 l_int32 format, val,
w,
h, bps, spp, loc, found, windex;
175 l_uint8 ihdr[4] = {0x69, 0x68, 0x64, 0x72};
177 PROCNAME(
"readHeaderMemJp2k");
184 return ERROR_INT(
"data not defined", procName, 1);
186 return ERROR_INT(
"size < 80", procName, 1);
188 if (format != IFF_JP2)
189 return ERROR_INT(
"not jp2 file", procName, 1);
194 return ERROR_INT(
"image parameters not found", procName, 1);
197 L_INFO(
"Beginning of ihdr is at byte %d\n", procName, loc);
200 windex = loc / 4 + 1;
201 val = *((l_uint32 *)data + windex);
202 h = convertOnLittleEnd32(val);
203 val = *((l_uint32 *)data + windex + 1);
204 w = convertOnLittleEnd32(val);
205 val = *((l_uint16 *)data + 2 * (windex + 2));
206 spp = convertOnLittleEnd16(val);
207 bps = *(data + 4 * (windex + 2) + 2) + 1;
208 if (
w > MAX_JP2K_WIDTH ||
h > MAX_JP2K_HEIGHT)
209 return ERROR_INT(
"unrealistically large sizes", procName, 1);
212 if (pbps) *pbps = bps;
213 if (pspp) *pspp = spp;
240 fgetJp2kResolution(FILE *fp,
246 l_uint16 xnum, ynum, xdenom, ydenom;
248 l_uint8 resc[4] = {0x72, 0x65, 0x73, 0x63};
250 l_float64 xres, yres;
252 PROCNAME(
"fgetJp2kResolution");
254 if (pxres) *pxres = 0;
255 if (pyres) *pyres = 0;
256 if (!pxres || !pyres)
257 return ERROR_INT(
"&xres and &yres not both defined", procName, 1);
259 return ERROR_INT(
"stream not opened", procName, 1);
268 L_WARNING(
"image resolution not found\n", procName);
275 ynum = data[loc + 5] << 8 | data[loc + 4];
276 ynum = convertOnLittleEnd16(ynum);
277 ydenom = data[loc + 7] << 8 | data[loc + 6];
278 ydenom = convertOnLittleEnd16(ydenom);
279 xnum = data[loc + 9] << 8 | data[loc + 8];
280 xnum = convertOnLittleEnd16(xnum);
281 xdenom = data[loc + 11] << 8 | data[loc + 10];
282 xdenom = convertOnLittleEnd16(xdenom);
283 yexp = data[loc + 12];
284 xexp = data[loc + 13];
285 yres = ((l_float64)ynum / (l_float64)ydenom) * pow(10.0, (l_float64)yexp);
286 xres = ((l_float64)xnum / (l_float64)xdenom) * pow(10.0, (l_float64)xexp);
289 yres *= (300.0 / 11811.0);
290 xres *= (300.0 / 11811.0);
291 *pyres = (l_int32)(yres + 0.5);
292 *pxres = (l_int32)(xres + 0.5);
FILE * fopenReadStream(const char *filename)
fopenReadStream()
l_uint8 * l_binaryReadStream(FILE *fp, size_t *pnbytes)
l_binaryReadStream()
l_int32 findFileFormatBuffer(const l_uint8 *buf, l_int32 *pformat)
findFileFormatBuffer()
l_int32 arrayFindSequence(const l_uint8 *data, size_t datalen, const l_uint8 *sequence, size_t seqlen, l_int32 *poffset, l_int32 *pfound)
arrayFindSequence()