annotate lib/libpng/pngrio.c @ 2467:43faa2865d57

mistake in previous commit
author zipi
date Sun, 17 Aug 2014 20:58:38 +0100
parents 6e178010fc29
children
rev   line source
2296
Ritor1
parents:
diff changeset
1
Ritor1
parents:
diff changeset
2 /* pngrio.c - functions for data input
Ritor1
parents:
diff changeset
3 *
Ritor1
parents:
diff changeset
4 * Last changed in libpng 1.6.9 [February 6, 2014]
Ritor1
parents:
diff changeset
5 * Copyright (c) 1998-2014 Glenn Randers-Pehrson
Ritor1
parents:
diff changeset
6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
Ritor1
parents:
diff changeset
7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
Ritor1
parents:
diff changeset
8 *
Ritor1
parents:
diff changeset
9 * This code is released under the libpng license.
Ritor1
parents:
diff changeset
10 * For conditions of distribution and use, see the disclaimer
Ritor1
parents:
diff changeset
11 * and license in png.h
Ritor1
parents:
diff changeset
12 *
Ritor1
parents:
diff changeset
13 * This file provides a location for all input. Users who need
Ritor1
parents:
diff changeset
14 * special handling are expected to write a function that has the same
Ritor1
parents:
diff changeset
15 * arguments as this and performs a similar function, but that possibly
Ritor1
parents:
diff changeset
16 * has a different input method. Note that you shouldn't change this
Ritor1
parents:
diff changeset
17 * function, but rather write a replacement function and then make
Ritor1
parents:
diff changeset
18 * libpng use it at run time with png_set_read_fn(...).
Ritor1
parents:
diff changeset
19 */
Ritor1
parents:
diff changeset
20
Ritor1
parents:
diff changeset
21 #include "pngpriv.h"
Ritor1
parents:
diff changeset
22
Ritor1
parents:
diff changeset
23 #ifdef PNG_READ_SUPPORTED
Ritor1
parents:
diff changeset
24
Ritor1
parents:
diff changeset
25 /* Read the data from whatever input you are using. The default routine
Ritor1
parents:
diff changeset
26 * reads from a file pointer. Note that this routine sometimes gets called
Ritor1
parents:
diff changeset
27 * with very small lengths, so you should implement some kind of simple
Ritor1
parents:
diff changeset
28 * buffering if you are using unbuffered reads. This should never be asked
Ritor1
parents:
diff changeset
29 * to read more then 64K on a 16 bit machine.
Ritor1
parents:
diff changeset
30 */
Ritor1
parents:
diff changeset
31 void /* PRIVATE */
Ritor1
parents:
diff changeset
32 png_read_data(png_structrp png_ptr, png_bytep data, png_size_t length)
Ritor1
parents:
diff changeset
33 {
Ritor1
parents:
diff changeset
34 png_debug1(4, "reading %d bytes", (int)length);
Ritor1
parents:
diff changeset
35
Ritor1
parents:
diff changeset
36 if (png_ptr->read_data_fn != NULL)
Ritor1
parents:
diff changeset
37 (*(png_ptr->read_data_fn))(png_ptr, data, length);
Ritor1
parents:
diff changeset
38
Ritor1
parents:
diff changeset
39 else
Ritor1
parents:
diff changeset
40 png_error(png_ptr, "Call to NULL read function");
Ritor1
parents:
diff changeset
41 }
Ritor1
parents:
diff changeset
42
Ritor1
parents:
diff changeset
43 #ifdef PNG_STDIO_SUPPORTED
Ritor1
parents:
diff changeset
44 /* This is the function that does the actual reading of data. If you are
Ritor1
parents:
diff changeset
45 * not reading from a standard C stream, you should create a replacement
Ritor1
parents:
diff changeset
46 * read_data function and use it at run time with png_set_read_fn(), rather
Ritor1
parents:
diff changeset
47 * than changing the library.
Ritor1
parents:
diff changeset
48 */
Ritor1
parents:
diff changeset
49 void PNGCBAPI
Ritor1
parents:
diff changeset
50 png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
Ritor1
parents:
diff changeset
51 {
Ritor1
parents:
diff changeset
52 png_size_t check;
Ritor1
parents:
diff changeset
53
Ritor1
parents:
diff changeset
54 if (png_ptr == NULL)
Ritor1
parents:
diff changeset
55 return;
Ritor1
parents:
diff changeset
56
Ritor1
parents:
diff changeset
57 /* fread() returns 0 on error, so it is OK to store this in a png_size_t
Ritor1
parents:
diff changeset
58 * instead of an int, which is what fread() actually returns.
Ritor1
parents:
diff changeset
59 */
Ritor1
parents:
diff changeset
60 check = fread(data, 1, length, png_voidcast(png_FILE_p, png_ptr->io_ptr));
Ritor1
parents:
diff changeset
61
Ritor1
parents:
diff changeset
62 if (check != length)
Ritor1
parents:
diff changeset
63 png_error(png_ptr, "Read Error");
Ritor1
parents:
diff changeset
64 }
Ritor1
parents:
diff changeset
65 #endif
Ritor1
parents:
diff changeset
66
Ritor1
parents:
diff changeset
67 /* This function allows the application to supply a new input function
Ritor1
parents:
diff changeset
68 * for libpng if standard C streams aren't being used.
Ritor1
parents:
diff changeset
69 *
Ritor1
parents:
diff changeset
70 * This function takes as its arguments:
Ritor1
parents:
diff changeset
71 *
Ritor1
parents:
diff changeset
72 * png_ptr - pointer to a png input data structure
Ritor1
parents:
diff changeset
73 *
Ritor1
parents:
diff changeset
74 * io_ptr - pointer to user supplied structure containing info about
Ritor1
parents:
diff changeset
75 * the input functions. May be NULL.
Ritor1
parents:
diff changeset
76 *
Ritor1
parents:
diff changeset
77 * read_data_fn - pointer to a new input function that takes as its
Ritor1
parents:
diff changeset
78 * arguments a pointer to a png_struct, a pointer to
Ritor1
parents:
diff changeset
79 * a location where input data can be stored, and a 32-bit
Ritor1
parents:
diff changeset
80 * unsigned int that is the number of bytes to be read.
Ritor1
parents:
diff changeset
81 * To exit and output any fatal error messages the new write
Ritor1
parents:
diff changeset
82 * function should call png_error(png_ptr, "Error msg").
Ritor1
parents:
diff changeset
83 * May be NULL, in which case libpng's default function will
Ritor1
parents:
diff changeset
84 * be used.
Ritor1
parents:
diff changeset
85 */
Ritor1
parents:
diff changeset
86 void PNGAPI
Ritor1
parents:
diff changeset
87 png_set_read_fn(png_structrp png_ptr, png_voidp io_ptr,
Ritor1
parents:
diff changeset
88 png_rw_ptr read_data_fn)
Ritor1
parents:
diff changeset
89 {
Ritor1
parents:
diff changeset
90 if (png_ptr == NULL)
Ritor1
parents:
diff changeset
91 return;
Ritor1
parents:
diff changeset
92
Ritor1
parents:
diff changeset
93 png_ptr->io_ptr = io_ptr;
Ritor1
parents:
diff changeset
94
Ritor1
parents:
diff changeset
95 #ifdef PNG_STDIO_SUPPORTED
Ritor1
parents:
diff changeset
96 if (read_data_fn != NULL)
Ritor1
parents:
diff changeset
97 png_ptr->read_data_fn = read_data_fn;
Ritor1
parents:
diff changeset
98
Ritor1
parents:
diff changeset
99 else
Ritor1
parents:
diff changeset
100 png_ptr->read_data_fn = png_default_read_data;
Ritor1
parents:
diff changeset
101 #else
Ritor1
parents:
diff changeset
102 png_ptr->read_data_fn = read_data_fn;
Ritor1
parents:
diff changeset
103 #endif
Ritor1
parents:
diff changeset
104
Ritor1
parents:
diff changeset
105 #ifdef PNG_WRITE_SUPPORTED
Ritor1
parents:
diff changeset
106 /* It is an error to write to a read device */
Ritor1
parents:
diff changeset
107 if (png_ptr->write_data_fn != NULL)
Ritor1
parents:
diff changeset
108 {
Ritor1
parents:
diff changeset
109 png_ptr->write_data_fn = NULL;
Ritor1
parents:
diff changeset
110 png_warning(png_ptr,
Ritor1
parents:
diff changeset
111 "Can't set both read_data_fn and write_data_fn in the"
Ritor1
parents:
diff changeset
112 " same structure");
Ritor1
parents:
diff changeset
113 }
Ritor1
parents:
diff changeset
114 #endif
Ritor1
parents:
diff changeset
115
Ritor1
parents:
diff changeset
116 #ifdef PNG_WRITE_FLUSH_SUPPORTED
Ritor1
parents:
diff changeset
117 png_ptr->output_flush_fn = NULL;
Ritor1
parents:
diff changeset
118 #endif
Ritor1
parents:
diff changeset
119 }
Ritor1
parents:
diff changeset
120 #endif /* PNG_READ_SUPPORTED */