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