source: svn/newcon3bcm2_21bu/dst/dlib/src/PNG/pngrio.c

Last change on this file was 76, checked in by megakiss, 10 years ago

1W 대기전력을 만족시키기 위하여 POWEROFF시 튜너를 Standby 상태로 함

  • Property svn:executable set to *
File size: 5.2 KB
Line 
1/*
2 * $Id: //suprahd/releases/suprahd_163/suprahd_ztvapp640_163/drivers/graphics/PNG/lpng102/pngrio.c#1 $
3 * $Revision: #1 $
4 * $DateTime: 2006/02/24 17:51:46 $
5 * $Change: 42566 $
6 * $Author: pryush.sharma $
7 */
8
9
10/* pngrio.c - functions for data input
11 *
12 * libpng 1.0.2 - June 14, 1998
13 * For conditions of distribution and use, see copyright notice in png.h
14 * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
15 * Copyright (c) 1996, 1997 Andreas Dilger
16 * Copyright (c) 1998, Glenn Randers-Pehrson
17 *
18 * This file provides a location for all input.  Users who need
19 * special handling are expected to write a function that has the same
20 * arguments as this and performs a similar function, but that possibly
21 * has a different input method.  Note that you shouldn't change this
22 * function, but rather write a replacement function and then make
23 * libpng use it at run time with png_set_read_fn(...).
24 */
25
26#define PNG_INTERNAL
27#include "png.h"
28
29/* Read the data from whatever input you are using.  The default routine
30   reads from a file pointer.  Note that this routine sometimes gets called
31   with very small lengths, so you should implement some kind of simple
32   buffering if you are using unbuffered reads.  This should never be asked
33   to read more then 64K on a 16 bit machine. */
34void
35png_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
36{
37   png_debug1(4,"reading %d bytes\n", length);
38   if (png_ptr->read_data_fn != NULL)
39      (*(png_ptr->read_data_fn))(png_ptr, data, length);
40   else
41      png_error(png_ptr, "Call to NULL read function");
42}
43
44#if !defined(PNG_NO_STDIO)
45/* This is the function that does the actual reading of data.  If you are
46   not reading from a standard C stream, you should create a replacement
47   read_data function and use it at run time with png_set_read_fn(), rather
48   than changing the library. */
49#ifndef USE_FAR_KEYWORD
50static void
51png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
52{
53   png_size_t check;
54
55   /* fread() returns 0 on error, so it is OK to store this in a png_size_t
56    * instead of an int, which is what fread() actually returns.
57    */
58   check = (png_size_t)fread(data, (png_size_t)1, length,
59      (FILE *)png_ptr->io_ptr);
60
61   if (check != length)
62   {
63      png_error(png_ptr, "Read Error");
64   }
65}
66#else
67/* this is the model-independent version. Since the standard I/O library
68   can't handle far buffers in the medium and small models, we have to copy
69   the data.
70*/
71 
72#define NEAR_BUF_SIZE 1024
73#define MIN(a,b) (a <= b ? a : b)
74 
75static void
76png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
77{
78   int check;
79   png_byte *n_data;
80   FILE *io_ptr;
81
82   /* Check if data really is near. If so, use usual code. */
83   n_data = (png_byte *)CVT_PTR_NOCHECK(data);
84   io_ptr = (FILE *)CVT_PTR(png_ptr->io_ptr);
85   if ((png_bytep)n_data == data)
86   {
87      check = fread(n_data, 1, length, io_ptr);
88   }
89   else
90   {
91      png_byte buf[NEAR_BUF_SIZE];
92      png_size_t read, remaining, err;
93      check = 0;
94      remaining = length;
95      do
96      {
97         read = MIN(NEAR_BUF_SIZE, remaining);
98         err = fread(buf, (png_size_t)1, read, io_ptr);
99         png_memcpy(data, buf, read); /* copy far buffer to near buffer */
100         if(err != read)
101            break;
102         else
103            check += err;
104         data += read;
105         remaining -= read;
106      }
107      while (remaining != 0);
108   }
109   if ((png_uint_32)check != (png_uint_32)length)
110   {
111      png_error(png_ptr, "read Error");
112   }
113}
114#endif
115#endif
116
117/* This function allows the application to supply a new input function
118   for libpng if standard C streams aren't being used.
119
120   This function takes as its arguments:
121   png_ptr      - pointer to a png input data structure
122   io_ptr       - pointer to user supplied structure containing info about
123                  the input functions.  May be NULL.
124   read_data_fn - pointer to a new input function that takes as its
125                  arguments a pointer to a png_struct, a pointer to
126                  a location where input data can be stored, and a 32-bit
127                  unsigned int that is the number of bytes to be read.
128                  To exit and output any fatal error messages the new write
129                  function should call png_error(png_ptr, "Error msg"). */
130void
131png_set_read_fn(png_structp png_ptr, png_voidp io_ptr,
132   png_rw_ptr read_data_fn)
133{
134   png_ptr->io_ptr = io_ptr;
135
136#if !defined(PNG_NO_STDIO)
137   if (read_data_fn != NULL)
138      png_ptr->read_data_fn = read_data_fn;
139   else
140      png_ptr->read_data_fn = png_default_read_data;
141#else
142   png_ptr->read_data_fn = read_data_fn;
143#endif
144
145   /* It is an error to write to a read device */
146   if (png_ptr->write_data_fn != NULL)
147   {
148      png_ptr->write_data_fn = NULL;
149      png_warning(png_ptr,
150         "It's an error to set both read_data_fn and write_data_fn in the ");
151      png_warning(png_ptr,
152         "same structure.  Resetting write_data_fn to NULL.");
153   }
154
155#if defined(PNG_WRITE_FLUSH_SUPPORTED)
156   png_ptr->output_flush_fn = NULL;
157#endif /* PNG_WRITE_FLUSH_SUPPORTED */
158}
159
Note: See TracBrowser for help on using the repository browser.