! * \brief pixacompFastConvertToPdfData() * * \param[in] pixac containing images all at the same resolution * \param[in] res input resolution of all images * \param[in] title [optional] pdf title * \param[out] pdata output pdf data (of all images * \param[out] pnbytes size of output pdf data * \return 0 if OK, 1 on error * * * Notes: * (1) This generates the
| 2113 | * </pre> |
| 2114 | */ |
| 2115 | l_int32 |
| 2116 | pixacompFastConvertToPdfData(PIXAC *pixac, |
| 2117 | const char *title, |
| 2118 | l_uint8 **pdata, |
| 2119 | size_t *pnbytes) |
| 2120 | { |
| 2121 | l_uint8 *imdata; |
| 2122 | l_int32 i, n, ret, comptype; |
| 2123 | size_t imbytes; |
| 2124 | L_BYTEA *ba; |
| 2125 | PIXC *pixc; |
| 2126 | L_PTRA *pa_data; |
| 2127 | |
| 2128 | PROCNAME("pixacompFastConvertToPdfData"); |
| 2129 | |
| 2130 | if (!pdata) |
| 2131 | return ERROR_INT("&data not defined", procName, 1); |
| 2132 | *pdata = NULL; |
| 2133 | if (!pnbytes) |
| 2134 | return ERROR_INT("&nbytes not defined", procName, 1); |
| 2135 | *pnbytes = 0; |
| 2136 | if (!pixac) |
| 2137 | return ERROR_INT("pixac not defined", procName, 1); |
| 2138 | |
| 2139 | /* Generate all the encoded pdf strings */ |
| 2140 | n = pixacompGetCount(pixac); |
| 2141 | pa_data = ptraCreate(n); |
| 2142 | for (i = 0; i < n; i++) { |
| 2143 | if ((pixc = pixacompGetPixcomp(pixac, i, L_NOCOPY)) == NULL) { |
| 2144 | L_ERROR("pixc[%d] not retrieved\n", procName, i); |
| 2145 | continue; |
| 2146 | } |
| 2147 | pixcompGetParameters(pixc, NULL, NULL, &comptype, NULL); |
| 2148 | if (comptype != IFF_JFIF_JPEG) { |
| 2149 | L_ERROR("pixc[%d] not jpeg compressed\n", procName, i); |
| 2150 | continue; |
| 2151 | } |
| 2152 | ret = pixcompFastConvertToPdfData(pixc, title, &imdata, &imbytes); |
| 2153 | if (ret) { |
| 2154 | L_ERROR("pdf encoding failed for pixc[%d]\n", procName, i); |
| 2155 | continue; |
| 2156 | } |
| 2157 | ba = l_byteaInitFromMem(imdata, imbytes); |
| 2158 | LEPT_FREE(imdata); |
| 2159 | ptraAdd(pa_data, ba); |
| 2160 | } |
| 2161 | ptraGetActualCount(pa_data, &n); |
| 2162 | if (n == 0) { |
| 2163 | L_ERROR("no pdf files made\n", procName); |
| 2164 | ptraDestroy(&pa_data, FALSE, FALSE); |
| 2165 | return 1; |
| 2166 | } |
| 2167 | |
| 2168 | /* Concatenate them */ |
| 2169 | ret = ptraConcatenatePdfToData(pa_data, NULL, pdata, pnbytes); |
| 2170 | |
| 2171 | /* Clean up */ |
| 2172 | ptraGetActualCount(pa_data, &n); /* recalculate in case it changes */ |
nothing calls this directly
no test coverage detected