Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(185)

Side by Side Diff: third_party/libpng/pngrio.c

Issue 1118002: libpng: update to 1.2.43 (Closed)
Patch Set: Created 10 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 1
2 /* pngrio.c - functions for data input 2 /* pngrio.c - functions for data input
3 * 3 *
4 * Last changed in libpng 1.2.37 [June 4, 2009] 4 * Last changed in libpng 1.2.43 [February 25, 2010]
5 * For conditions of distribution and use, see copyright notice in png.h 5 * Copyright (c) 1998-2010 Glenn Randers-Pehrson
6 * Copyright (c) 1998-2009 Glenn Randers-Pehrson
7 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) 6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
8 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) 7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
9 * 8 *
9 * This code is released under the libpng license.
10 * For conditions of distribution and use, see the disclaimer
11 * and license in png.h
12 *
10 * This file provides a location for all input. Users who need 13 * This file provides a location for all input. Users who need
11 * special handling are expected to write a function that has the same 14 * special handling are expected to write a function that has the same
12 * arguments as this and performs a similar function, but that possibly 15 * arguments as this and performs a similar function, but that possibly
13 * has a different input method. Note that you shouldn't change this 16 * has a different input method. Note that you shouldn't change this
14 * function, but rather write a replacement function and then make 17 * function, but rather write a replacement function and then make
15 * libpng use it at run time with png_set_read_fn(...). 18 * libpng use it at run time with png_set_read_fn(...).
16 */ 19 */
17 20
18 #define PNG_INTERNAL 21 #define PNG_INTERNAL
22 #define PNG_NO_PEDANTIC_WARNINGS
19 #include "png.h" 23 #include "png.h"
20 #if defined(PNG_READ_SUPPORTED) 24 #ifdef PNG_READ_SUPPORTED
21 25
22 /* Read the data from whatever input you are using. The default routine 26 /* Read the data from whatever input you are using. The default routine
23 * reads from a file pointer. Note that this routine sometimes gets called 27 * reads from a file pointer. Note that this routine sometimes gets called
24 * with very small lengths, so you should implement some kind of simple 28 * with very small lengths, so you should implement some kind of simple
25 * buffering if you are using unbuffered reads. This should never be asked 29 * buffering if you are using unbuffered reads. This should never be asked
26 * to read more then 64K on a 16 bit machine. 30 * to read more then 64K on a 16 bit machine.
27 */ 31 */
28 void /* PRIVATE */ 32 void /* PRIVATE */
29 png_read_data(png_structp png_ptr, png_bytep data, png_size_t length) 33 png_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
30 { 34 {
31 png_debug1(4, "reading %d bytes", (int)length); 35 png_debug1(4, "reading %d bytes", (int)length);
36
32 if (png_ptr->read_data_fn != NULL) 37 if (png_ptr->read_data_fn != NULL)
33 (*(png_ptr->read_data_fn))(png_ptr, data, length); 38 (*(png_ptr->read_data_fn))(png_ptr, data, length);
34 else 39 else
35 png_error(png_ptr, "Call to NULL read function"); 40 png_error(png_ptr, "Call to NULL read function");
36 } 41 }
37 42
38 #if !defined(PNG_NO_STDIO) 43 #ifdef PNG_STDIO_SUPPORTED
39 /* This is the function that does the actual reading of data. If you are 44 /* This is the function that does the actual reading of data. If you are
40 * not reading from a standard C stream, you should create a replacement 45 * not reading from a standard C stream, you should create a replacement
41 * read_data function and use it at run time with png_set_read_fn(), rather 46 * read_data function and use it at run time with png_set_read_fn(), rather
42 * than changing the library. 47 * than changing the library.
43 */ 48 */
44 #ifndef USE_FAR_KEYWORD 49 #ifndef USE_FAR_KEYWORD
45 void PNGAPI 50 void PNGAPI
46 png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length) 51 png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
47 { 52 {
48 png_size_t check; 53 png_size_t check;
49 54
50 if (png_ptr == NULL) 55 if (png_ptr == NULL)
51 return; 56 return;
52 /* fread() returns 0 on error, so it is OK to store this in a png_size_t 57 /* fread() returns 0 on error, so it is OK to store this in a png_size_t
53 * instead of an int, which is what fread() actually returns. 58 * instead of an int, which is what fread() actually returns.
54 */ 59 */
55 #if defined(_WIN32_WCE) 60 #ifdef _WIN32_WCE
56 if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) ) 61 if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
57 check = 0; 62 check = 0;
58 #else 63 #else
59 check = (png_size_t)fread(data, (png_size_t)1, length, 64 check = (png_size_t)fread(data, (png_size_t)1, length,
60 (png_FILE_p)png_ptr->io_ptr); 65 (png_FILE_p)png_ptr->io_ptr);
61 #endif 66 #endif
62 67
63 if (check != length) 68 if (check != length)
64 png_error(png_ptr, "Read Error"); 69 png_error(png_ptr, "Read Error");
65 } 70 }
(...skipping 13 matching lines...) Expand all
79 png_byte *n_data; 84 png_byte *n_data;
80 png_FILE_p io_ptr; 85 png_FILE_p io_ptr;
81 86
82 if (png_ptr == NULL) 87 if (png_ptr == NULL)
83 return; 88 return;
84 /* Check if data really is near. If so, use usual code. */ 89 /* Check if data really is near. If so, use usual code. */
85 n_data = (png_byte *)CVT_PTR_NOCHECK(data); 90 n_data = (png_byte *)CVT_PTR_NOCHECK(data);
86 io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr); 91 io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
87 if ((png_bytep)n_data == data) 92 if ((png_bytep)n_data == data)
88 { 93 {
89 #if defined(_WIN32_WCE) 94 #ifdef _WIN32_WCE
90 if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) ) 95 if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check,
96 NULL) )
91 check = 0; 97 check = 0;
92 #else 98 #else
93 check = fread(n_data, 1, length, io_ptr); 99 check = fread(n_data, 1, length, io_ptr);
94 #endif 100 #endif
95 } 101 }
96 else 102 else
97 { 103 {
98 png_byte buf[NEAR_BUF_SIZE]; 104 png_byte buf[NEAR_BUF_SIZE];
99 png_size_t read, remaining, err; 105 png_size_t read, remaining, err;
100 check = 0; 106 check = 0;
101 remaining = length; 107 remaining = length;
102 do 108 do
103 { 109 {
104 read = MIN(NEAR_BUF_SIZE, remaining); 110 read = MIN(NEAR_BUF_SIZE, remaining);
105 #if defined(_WIN32_WCE) 111 #ifdef _WIN32_WCE
106 if ( !ReadFile((HANDLE)(io_ptr), buf, read, &err, NULL) ) 112 if ( !ReadFile((HANDLE)(io_ptr), buf, read, &err, NULL) )
107 err = 0; 113 err = 0;
108 #else 114 #else
109 err = fread(buf, (png_size_t)1, read, io_ptr); 115 err = fread(buf, (png_size_t)1, read, io_ptr);
110 #endif 116 #endif
111 png_memcpy(data, buf, read); /* copy far buffer to near buffer */ 117 png_memcpy(data, buf, read); /* copy far buffer to near buffer */
112 if (err != read) 118 if (err != read)
113 break; 119 break;
114 else 120 else
115 check += err; 121 check += err;
(...skipping 25 matching lines...) Expand all
141 * be used. 147 * be used.
142 */ 148 */
143 void PNGAPI 149 void PNGAPI
144 png_set_read_fn(png_structp png_ptr, png_voidp io_ptr, 150 png_set_read_fn(png_structp png_ptr, png_voidp io_ptr,
145 png_rw_ptr read_data_fn) 151 png_rw_ptr read_data_fn)
146 { 152 {
147 if (png_ptr == NULL) 153 if (png_ptr == NULL)
148 return; 154 return;
149 png_ptr->io_ptr = io_ptr; 155 png_ptr->io_ptr = io_ptr;
150 156
151 #if !defined(PNG_NO_STDIO) 157 #ifdef PNG_STDIO_SUPPORTED
152 if (read_data_fn != NULL) 158 if (read_data_fn != NULL)
153 png_ptr->read_data_fn = read_data_fn; 159 png_ptr->read_data_fn = read_data_fn;
154 else 160 else
155 png_ptr->read_data_fn = png_default_read_data; 161 png_ptr->read_data_fn = png_default_read_data;
156 #else 162 #else
157 png_ptr->read_data_fn = read_data_fn; 163 png_ptr->read_data_fn = read_data_fn;
158 #endif 164 #endif
159 165
160 /* It is an error to write to a read device */ 166 /* It is an error to write to a read device */
161 if (png_ptr->write_data_fn != NULL) 167 if (png_ptr->write_data_fn != NULL)
162 { 168 {
163 png_ptr->write_data_fn = NULL; 169 png_ptr->write_data_fn = NULL;
164 png_warning(png_ptr, 170 png_warning(png_ptr,
165 "It's an error to set both read_data_fn and write_data_fn in the "); 171 "It's an error to set both read_data_fn and write_data_fn in the ");
166 png_warning(png_ptr, 172 png_warning(png_ptr,
167 "same structure. Resetting write_data_fn to NULL."); 173 "same structure. Resetting write_data_fn to NULL.");
168 } 174 }
169 175
170 #if defined(PNG_WRITE_FLUSH_SUPPORTED) 176 #ifdef PNG_WRITE_FLUSH_SUPPORTED
171 png_ptr->output_flush_fn = NULL; 177 png_ptr->output_flush_fn = NULL;
172 #endif 178 #endif
173 } 179 }
174 #endif /* PNG_READ_SUPPORTED */ 180 #endif /* PNG_READ_SUPPORTED */
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698