source: trunk/src/testing/app/bitplay/libimage/rdwr.c @ 4

Revision 4, 3.8 KB checked in by ajaworski, 13 years ago (diff)

Added modified SAGE sources

  • Property svn:executable set to *
RevLine 
[4]1/******************************************************************************
2 * SAGE - Scalable Adaptive Graphics Environment
3 *
4 * Copyright (C) 2004 Electronic Visualization Laboratory,
5 * University of Illinois at Chicago
6 *
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 *  * Redistributions of source code must retain the above copyright
13 *    notice, this list of conditions and the following disclaimer.
14 *  * Redistributions in binary form must reproduce the above
15 *    copyright notice, this list of conditions and the following disclaimer
16 *    in the documentation and/or other materials provided with the distribution.
17 *  * Neither the name of the University of Illinois at Chicago nor
18 *    the names of its contributors may be used to endorse or promote
19 *    products derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 *
33 * Direct questions, comments etc about SAGE to http://www.evl.uic.edu/cavern/forum/
34 *
35 *****************************************************************************/
36
37/*
38 *      img_seek, img_write, img_read, img_optseek -
39 *
40 *                              Paul Haeberli - 1984
41 *
42 */
43#include        <stdio.h>
44#include        <errno.h>
45#include        <unistd.h>
46#include        "image.h"
47
48int img_seek( IMAGE *image, int y, int z )
49{
50    if(img_badrow(image,y,z)) {
51        i_errhdlr("imglib: row number out of range\n");
52        return EOF;
53    }
54    image->x = 0;
55    image->y = y;
56    image->z = z;
57    if(ISVERBATIM(image->type)) {
58        switch(image->dim) {
59            case 1:
60                return img_optseek(image, 512L);
61            case 2:
62                return img_optseek(image,512L+(y*image->xsize)*BPP(image->type));
63            case 3:
64                return img_optseek(image,
65                    512L+(y*image->xsize+z*image->xsize*image->ysize)*
66                                                        BPP(image->type));
67            default:
68                i_errhdlr("img_seek: wierd dim\n");
69                break;
70        }
71    } else if(ISRLE(image->type)) {
72        switch(image->dim) {
73            case 1:
74                return img_optseek(image, image->rowstart[0]);
75            case 2:
76                return img_optseek(image, image->rowstart[y]);
77            case 3:
78                return img_optseek(image, image->rowstart[y+z*image->ysize]);
79            default:
80                i_errhdlr("img_seek: wierd dim\n");
81                break;
82        }
83    } else
84        i_errhdlr("img_seek: wierd image type\n");
85    return EOF;
86}
87
88int img_badrow( IMAGE *image, int y, int z )
89{
90    if(y>=image->ysize || z>=image->zsize)
91        return 1;
92    else
93        return 0;
94}
95
96int img_write( IMAGE *image, char *buffer, long count )
97{
98    long retval;
99
100    retval =  write(image->file,buffer,count);
101    if(retval == count)
102        image->offset += count;
103    else
104        image->offset = -1;
105    return retval;
106}
107
108int img_read( IMAGE *image, char *buffer, long count)
109{
110    long retval;
111
112    retval =  read(image->file,buffer,count);
113    if(retval == count)
114        image->offset += count;
115    else
116        image->offset = -1;
117    return retval;
118}
119
120unsigned long img_optseek( IMAGE *image, unsigned long offset )
121{
122    if(image->offset != offset) {
123       image->offset = offset;
124       return lseek(image->file,offset,0);
125   }
126   return offset;
127}
128
Note: See TracBrowser for help on using the repository browser.