|
Blender V2.27
|
00001 00025 #include <Stream.h> 00026 00027 #include <stdio.h> // printf 00028 #include <string.h> // memcpy 00029 00030 unsigned int Stream::seek(unsigned int p) 00031 { 00032 if (p > size) { 00033 printf("DDS: trying to seek beyond end of stream (corrupt file?)"); 00034 } 00035 else { 00036 pos = p; 00037 } 00038 00039 return pos; 00040 } 00041 00042 unsigned int mem_read(Stream & mem, unsigned long long & i) 00043 { 00044 if (mem.pos + 8 > mem.size) { 00045 printf("DDS: trying to read beyond end of stream (corrupt file?)"); 00046 return(0); 00047 }; 00048 memcpy(&i, mem.mem + mem.pos, 8); // @@ todo: make sure little endian 00049 mem.pos += 8; 00050 return(8); 00051 } 00052 00053 unsigned int mem_read(Stream & mem, unsigned int & i) 00054 { 00055 if (mem.pos + 4 > mem.size) { 00056 printf("DDS: trying to read beyond end of stream (corrupt file?)"); 00057 return(0); 00058 }; 00059 memcpy(&i, mem.mem + mem.pos, 4); // @@ todo: make sure little endian 00060 mem.pos += 4; 00061 return(4); 00062 } 00063 00064 unsigned int mem_read(Stream & mem, unsigned short & i) 00065 { 00066 if (mem.pos + 2 > mem.size) { 00067 printf("DDS: trying to read beyond end of stream (corrupt file?)"); 00068 return(0); 00069 }; 00070 memcpy(&i, mem.mem + mem.pos, 2); // @@ todo: make sure little endian 00071 mem.pos += 2; 00072 return(2); 00073 } 00074 00075 unsigned int mem_read(Stream & mem, unsigned char & i) 00076 { 00077 if (mem.pos + 1 > mem.size) { 00078 printf("DDS: trying to read beyond end of stream (corrupt file?)"); 00079 return(0); 00080 }; 00081 i = (mem.mem + mem.pos)[0]; 00082 mem.pos += 1; 00083 return(1); 00084 } 00085 00086 unsigned int mem_read(Stream & mem, unsigned char *i, unsigned int cnt) 00087 { 00088 if (mem.pos + cnt > mem.size) { 00089 printf("DDS: trying to read beyond end of stream (corrupt file?)"); 00090 return(0); 00091 }; 00092 memcpy(i, mem.mem + mem.pos, cnt); 00093 mem.pos += cnt; 00094 return(cnt); 00095 } 00096
1.7.3