| OLD | NEW |
| 1 /* | 1 /* |
| 2 * example.c | 2 * example.c |
| 3 * | 3 * |
| 4 * This file illustrates how to use the IJG code as a subroutine library | 4 * This file illustrates how to use the IJG code as a subroutine library |
| 5 * to read or write JPEG image files. You should look at this code in | 5 * to read or write JPEG image files. You should look at this code in |
| 6 * conjunction with the documentation file libjpeg.doc. | 6 * conjunction with the documentation file libjpeg.txt. |
| 7 * | 7 * |
| 8 * This code will not do anything useful as-is, but it may be helpful as a | 8 * This code will not do anything useful as-is, but it may be helpful as a |
| 9 * skeleton for constructing routines that call the JPEG library. | 9 * skeleton for constructing routines that call the JPEG library. |
| 10 * | 10 * |
| 11 * We present these routines in the same coding style used in the JPEG code | 11 * We present these routines in the same coding style used in the JPEG code |
| 12 * (ANSI function definitions, etc); but you are of course free to code your | 12 * (ANSI function definitions, etc); but you are of course free to code your |
| 13 * routines in a different style if you prefer. | 13 * routines in a different style if you prefer. |
| 14 */ | 14 */ |
| 15 | 15 |
| 16 #include <stdio.h> | 16 #include <stdio.h> |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 * then jpeg_write_scanlines will write all the lines passed (or else exit | 189 * then jpeg_write_scanlines will write all the lines passed (or else exit |
| 190 * with a fatal error). Partial writes can only occur if you use a data | 190 * with a fatal error). Partial writes can only occur if you use a data |
| 191 * destination module that can demand suspension of the compressor. | 191 * destination module that can demand suspension of the compressor. |
| 192 * (If you don't know what that's for, you don't need it.) | 192 * (If you don't know what that's for, you don't need it.) |
| 193 * | 193 * |
| 194 * If the compressor requires full-image buffers (for entropy-coding | 194 * If the compressor requires full-image buffers (for entropy-coding |
| 195 * optimization or a multi-scan JPEG file), it will create temporary | 195 * optimization or a multi-scan JPEG file), it will create temporary |
| 196 * files for anything that doesn't fit within the maximum-memory setting. | 196 * files for anything that doesn't fit within the maximum-memory setting. |
| 197 * (Note that temp files are NOT needed if you use the default parameters.) | 197 * (Note that temp files are NOT needed if you use the default parameters.) |
| 198 * On some systems you may need to set up a signal handler to ensure that | 198 * On some systems you may need to set up a signal handler to ensure that |
| 199 * temporary files are deleted if the program is interrupted. See libjpeg.doc. | 199 * temporary files are deleted if the program is interrupted. See libjpeg.txt. |
| 200 * | 200 * |
| 201 * Scanlines MUST be supplied in top-to-bottom order if you want your JPEG | 201 * Scanlines MUST be supplied in top-to-bottom order if you want your JPEG |
| 202 * files to be compatible with everyone else's. If you cannot readily read | 202 * files to be compatible with everyone else's. If you cannot readily read |
| 203 * your data in that order, you'll need an intermediate array to hold the | 203 * your data in that order, you'll need an intermediate array to hold the |
| 204 * image. See rdtarga.c or rdbmp.c for examples of handling bottom-to-top | 204 * image. See rdtarga.c or rdbmp.c for examples of handling bottom-to-top |
| 205 * source data using the JPEG code's internal virtual-array mechanisms. | 205 * source data using the JPEG code's internal virtual-array mechanisms. |
| 206 */ | 206 */ |
| 207 | 207 |
| 208 | 208 |
| 209 | 209 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 /* Step 2: specify data source (eg, a file) */ | 328 /* Step 2: specify data source (eg, a file) */ |
| 329 | 329 |
| 330 jpeg_stdio_src(&cinfo, infile); | 330 jpeg_stdio_src(&cinfo, infile); |
| 331 | 331 |
| 332 /* Step 3: read file parameters with jpeg_read_header() */ | 332 /* Step 3: read file parameters with jpeg_read_header() */ |
| 333 | 333 |
| 334 (void) jpeg_read_header(&cinfo, TRUE); | 334 (void) jpeg_read_header(&cinfo, TRUE); |
| 335 /* We can ignore the return value from jpeg_read_header since | 335 /* We can ignore the return value from jpeg_read_header since |
| 336 * (a) suspension is not possible with the stdio data source, and | 336 * (a) suspension is not possible with the stdio data source, and |
| 337 * (b) we passed TRUE to reject a tables-only JPEG file as an error. | 337 * (b) we passed TRUE to reject a tables-only JPEG file as an error. |
| 338 * See libjpeg.doc for more info. | 338 * See libjpeg.txt for more info. |
| 339 */ | 339 */ |
| 340 | 340 |
| 341 /* Step 4: set parameters for decompression */ | 341 /* Step 4: set parameters for decompression */ |
| 342 | 342 |
| 343 /* In this example, we don't need to change any of the defaults set by | 343 /* In this example, we don't need to change any of the defaults set by |
| 344 * jpeg_read_header(), so we do nothing here. | 344 * jpeg_read_header(), so we do nothing here. |
| 345 */ | 345 */ |
| 346 | 346 |
| 347 /* Step 5: Start decompressor */ | 347 /* Step 5: Start decompressor */ |
| 348 | 348 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 return 1; | 406 return 1; |
| 407 } | 407 } |
| 408 | 408 |
| 409 | 409 |
| 410 /* | 410 /* |
| 411 * SOME FINE POINTS: | 411 * SOME FINE POINTS: |
| 412 * | 412 * |
| 413 * In the above code, we ignored the return value of jpeg_read_scanlines, | 413 * In the above code, we ignored the return value of jpeg_read_scanlines, |
| 414 * which is the number of scanlines actually read. We could get away with | 414 * which is the number of scanlines actually read. We could get away with |
| 415 * this because we asked for only one line at a time and we weren't using | 415 * this because we asked for only one line at a time and we weren't using |
| 416 * a suspending data source. See libjpeg.doc for more info. | 416 * a suspending data source. See libjpeg.txt for more info. |
| 417 * | 417 * |
| 418 * We cheated a bit by calling alloc_sarray() after jpeg_start_decompress(); | 418 * We cheated a bit by calling alloc_sarray() after jpeg_start_decompress(); |
| 419 * we should have done it beforehand to ensure that the space would be | 419 * we should have done it beforehand to ensure that the space would be |
| 420 * counted against the JPEG max_memory setting. In some systems the above | 420 * counted against the JPEG max_memory setting. In some systems the above |
| 421 * code would risk an out-of-memory error. However, in general we don't | 421 * code would risk an out-of-memory error. However, in general we don't |
| 422 * know the output image dimensions before jpeg_start_decompress(), unless we | 422 * know the output image dimensions before jpeg_start_decompress(), unless we |
| 423 * call jpeg_calc_output_dimensions(). See libjpeg.doc for more about this. | 423 * call jpeg_calc_output_dimensions(). See libjpeg.txt for more about this. |
| 424 * | 424 * |
| 425 * Scanlines are returned in the same order as they appear in the JPEG file, | 425 * Scanlines are returned in the same order as they appear in the JPEG file, |
| 426 * which is standardly top-to-bottom. If you must emit data bottom-to-top, | 426 * which is standardly top-to-bottom. If you must emit data bottom-to-top, |
| 427 * you can use one of the virtual arrays provided by the JPEG memory manager | 427 * you can use one of the virtual arrays provided by the JPEG memory manager |
| 428 * to invert the data. See wrbmp.c for an example. | 428 * to invert the data. See wrbmp.c for an example. |
| 429 * | 429 * |
| 430 * As with compression, some operating modes may require temporary files. | 430 * As with compression, some operating modes may require temporary files. |
| 431 * On some systems you may need to set up a signal handler to ensure that | 431 * On some systems you may need to set up a signal handler to ensure that |
| 432 * temporary files are deleted if the program is interrupted. See libjpeg.doc. | 432 * temporary files are deleted if the program is interrupted. See libjpeg.txt. |
| 433 */ | 433 */ |
| OLD | NEW |