! * \brief readHeaderWebP() * * \param[in] filename * \param[out] pw width * \param[out] ph height * \param[out] pspp spp (3 or 4) * \return 0 if OK, 1 on error */
| 163 | * \return 0 if OK, 1 on error |
| 164 | */ |
| 165 | l_int32 |
| 166 | readHeaderWebP(const char *filename, |
| 167 | l_int32 *pw, |
| 168 | l_int32 *ph, |
| 169 | l_int32 *pspp) |
| 170 | { |
| 171 | l_uint8 data[100]; /* expect size info within the first 50 bytes or so */ |
| 172 | l_int32 nbytes, bytesread; |
| 173 | size_t filesize; |
| 174 | FILE *fp; |
| 175 | |
| 176 | PROCNAME("readHeaderWebP"); |
| 177 | |
| 178 | if (!pw || !ph || !pspp) |
| 179 | return ERROR_INT("input ptr(s) not defined", procName, 1); |
| 180 | *pw = *ph = *pspp = 0; |
| 181 | if (!filename) |
| 182 | return ERROR_INT("filename not defined", procName, 1); |
| 183 | |
| 184 | /* Read no more than 100 bytes from the file */ |
| 185 | if ((filesize = nbytesInFile(filename)) == 0) |
| 186 | return ERROR_INT("no file size found", procName, 1); |
| 187 | if (filesize < 100) |
| 188 | L_WARNING("very small webp file\n", procName); |
| 189 | nbytes = L_MIN(filesize, 100); |
| 190 | if ((fp = fopenReadStream(filename)) == NULL) |
| 191 | return ERROR_INT("image file not found", procName, 1); |
| 192 | bytesread = fread((char *)data, 1, nbytes, fp); |
| 193 | fclose(fp); |
| 194 | if (bytesread != nbytes) |
| 195 | return ERROR_INT("failed to read requested data", procName, 1); |
| 196 | |
| 197 | return readHeaderMemWebP(data, nbytes, pw, ph, pspp); |
| 198 | } |
| 199 | |
| 200 | |
| 201 | /*! |
no test coverage detected