Blender V2.61 - r43446
|
00001 00004 /* 00005 * Cineon image file format library routines. 00006 * 00007 * Copyright 2006 Joseph Eagar (joeedh@gmail.com) 00008 * 00009 * This program is free software; you can redistribute it and/or modify it 00010 * under the terms of the GNU General Public License as published by the Free 00011 * Software Foundation; either version 2 of the License, or (at your option) 00012 * any later version. 00013 * 00014 * This program is distributed in the hope that it will be useful, but 00015 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 00016 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00017 * for more details. 00018 * 00019 * You should have received a copy of the GNU General Public License 00020 * along with this program; if not, write to the Free Software 00021 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00022 * 00023 */ 00024 #include <stdio.h> 00025 #include <stdlib.h> 00026 #include <string.h> 00027 00028 #include "logImageCore.h" 00029 00030 #include "logmemfile.h" /* own include */ 00031 00032 int logimage_fseek(void* logfile, intptr_t offsett, int origin) 00033 { 00034 struct _Log_Image_File_t_ *file = (struct _Log_Image_File_t_*) logfile; 00035 intptr_t offset = offsett; 00036 00037 if (file->file) fseek(file->file, offset, origin); 00038 else { /*we're seeking in memory*/ 00039 if (origin==SEEK_SET) { 00040 if (offset > file->membuffersize) return 1; 00041 file->memcursor = file->membuffer + offset; 00042 } else if (origin==SEEK_END) { 00043 if (offset > file->membuffersize) return 1; 00044 file->memcursor = (file->membuffer + file->membuffersize) - offset; 00045 } else if (origin==SEEK_CUR) { 00046 uintptr_t pos = (uintptr_t)file->membuffer - (uintptr_t)file->memcursor; 00047 if (pos + offset > file->membuffersize) return 1; 00048 if (pos < 0) return 1; 00049 file->memcursor += offset; 00050 } 00051 } 00052 return 0; 00053 } 00054 00055 int logimage_fwrite(void *buffer, unsigned int size, unsigned int count, void *logfile) 00056 { 00057 struct _Log_Image_File_t_ *file = (struct _Log_Image_File_t_*) logfile; 00058 if (file->file) return fwrite(buffer, size, count, file->file); 00059 else { /*we're writing to memory*/ 00060 /*do nothing as this isn't supported yet*/ 00061 return count; 00062 } 00063 } 00064 00065 int logimage_fread(void *buffer, unsigned int size, unsigned int count, void *logfile) 00066 { 00067 struct _Log_Image_File_t_ *file = (struct _Log_Image_File_t_*) logfile; 00068 if (file->file) return fread(buffer, size, count, file->file); 00069 else { /*we're reading from memory*/ 00070 int i; 00071 /*we convert ot uchar just on the off chance some platform can't handle 00072 pointer arithmetic with type (void*). */ 00073 unsigned char *buf = (unsigned char *) buffer; 00074 00075 for (i=0; i<count; i++) { 00076 memcpy(buf, file->memcursor, size); 00077 file->memcursor += size; 00078 buf += size; 00079 } 00080 return count; 00081 } 00082 }