! * \brief boxaaReadStream() * * \param[in] fp file stream * \return boxaa, or NULL on error */
| 1892 | * \return boxaa, or NULL on error |
| 1893 | */ |
| 1894 | BOXAA * |
| 1895 | boxaaReadStream(FILE *fp) |
| 1896 | { |
| 1897 | l_int32 n, i, x, y, w, h, version; |
| 1898 | l_int32 ignore; |
| 1899 | BOXA *boxa; |
| 1900 | BOXAA *baa; |
| 1901 | |
| 1902 | PROCNAME("boxaaReadStream"); |
| 1903 | |
| 1904 | if (!fp) |
| 1905 | return (BOXAA *)ERROR_PTR("stream not defined", procName, NULL); |
| 1906 | |
| 1907 | if (fscanf(fp, "\nBoxaa Version %d\n", &version) != 1) |
| 1908 | return (BOXAA *)ERROR_PTR("not a boxaa file", procName, NULL); |
| 1909 | if (version != BOXAA_VERSION_NUMBER) |
| 1910 | return (BOXAA *)ERROR_PTR("invalid boxa version", procName, NULL); |
| 1911 | if (fscanf(fp, "Number of boxa = %d\n", &n) != 1) |
| 1912 | return (BOXAA *)ERROR_PTR("not a boxaa file", procName, NULL); |
| 1913 | |
| 1914 | if ((baa = boxaaCreate(n)) == NULL) |
| 1915 | return (BOXAA *)ERROR_PTR("boxaa not made", procName, NULL); |
| 1916 | for (i = 0; i < n; i++) { |
| 1917 | if (fscanf(fp, "\nBoxa[%d] extent: x = %d, y = %d, w = %d, h = %d", |
| 1918 | &ignore, &x, &y, &w, &h) != 5) { |
| 1919 | boxaaDestroy(&baa); |
| 1920 | return (BOXAA *)ERROR_PTR("boxa descr not valid", procName, NULL); |
| 1921 | } |
| 1922 | if ((boxa = boxaReadStream(fp)) == NULL) { |
| 1923 | boxaaDestroy(&baa); |
| 1924 | return (BOXAA *)ERROR_PTR("boxa not made", procName, NULL); |
| 1925 | } |
| 1926 | boxaaAddBoxa(baa, boxa, L_INSERT); |
| 1927 | } |
| 1928 | return baa; |
| 1929 | } |
| 1930 | |
| 1931 | |
| 1932 | /*! |
no test coverage detected