-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpsdclass_loadstreambase.cpp
More file actions
55 lines (49 loc) · 1.1 KB
/
psdclass_loadstreambase.cpp
File metadata and controls
55 lines (49 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#ifndef LOAD_MEMORY
#include "psdclass.h"
void
PSD::clearStream()
{
if (pStream) {
pStream->Destruct();
pStream = 0;
}
mStreamSize = 0;
mBufferPos = 0;
mBufferSize = 0;
}
unsigned char &
PSD::getStreamValue(const tTVInteger &pos)
{
static unsigned char eof = 0;
if (pos >=0 && pos < mStreamSize) {
if (pos >= mBufferPos && pos < mBufferPos + mBufferSize) {
return mBuffer[pos - mBufferPos];
}
mBufferPos = pos;
pStream->Seek((tjs_int64)pos, TJS_BS_SEEK_SET);
mBufferSize = pStream->Read(mBuffer, sizeof mBuffer);
return mBuffer[0];
}
return eof;
}
void
PSD::copyToBuffer(uint8_t *buf, tTVInteger pos, int size)
{
if (pos >=0 && pos < mStreamSize) {
if (size <= 16) {
if (pos >= mBufferPos && pos+size < mBufferPos + mBufferSize) {
memcpy(buf, &mBuffer[pos - mBufferPos], size);
return;
}
mBufferPos = pos;
pStream->Seek((tjs_int64)pos, TJS_BS_SEEK_SET);
mBufferSize = pStream->Read(mBuffer, sizeof mBuffer);
memcpy(buf, mBuffer, size);
return;
}
// 直接読み込む
pStream->Seek((tjs_int64)pos, TJS_BS_SEEK_SET);
pStream->Read(buf, size);
}
}
#endif