mirror of
https://github.com/leozide/leocad
synced 2025-01-17 18:11:42 +01:00
Rewrote file classes.
This commit is contained in:
parent
f495592d12
commit
7a5bdf36a9
37 changed files with 1568 additions and 1668 deletions
|
@ -225,11 +225,11 @@ void Camera::Initialize()
|
|||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Camera save/load
|
||||
|
||||
bool Camera::FileLoad (File& file)
|
||||
bool Camera::FileLoad(lcFile& file)
|
||||
{
|
||||
unsigned char version, ch;
|
||||
lcuint8 version, ch;
|
||||
|
||||
file.ReadByte (&version, 1);
|
||||
version = file.ReadU8();
|
||||
|
||||
if (version > LC_CAMERA_SAVE_VERSION)
|
||||
return false;
|
||||
|
@ -240,15 +240,15 @@ bool Camera::FileLoad (File& file)
|
|||
|
||||
if (version == 4)
|
||||
{
|
||||
file.Read(m_strName, 80);
|
||||
file.ReadBuffer(m_strName, 80);
|
||||
m_strName[80] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
file.Read(&ch, 1);
|
||||
ch = file.ReadU8();
|
||||
if (ch == 0xFF)
|
||||
return false; // don't read CString
|
||||
file.Read(m_strName, ch);
|
||||
file.ReadBuffer(m_strName, ch);
|
||||
m_strName[ch] = 0;
|
||||
}
|
||||
|
||||
|
@ -257,21 +257,21 @@ bool Camera::FileLoad (File& file)
|
|||
double d[3];
|
||||
float f[3];
|
||||
|
||||
file.ReadDouble (d, 3);
|
||||
file.ReadDoubles(d, 3);
|
||||
f[0] = (float)d[0];
|
||||
f[1] = (float)d[1];
|
||||
f[2] = (float)d[2];
|
||||
ChangeKey (1, false, true, f, LC_CK_EYE);
|
||||
ChangeKey (1, true, true, f, LC_CK_EYE);
|
||||
|
||||
file.ReadDouble (d, 3);
|
||||
file.ReadDoubles(d, 3);
|
||||
f[0] = (float)d[0];
|
||||
f[1] = (float)d[1];
|
||||
f[2] = (float)d[2];
|
||||
ChangeKey (1, false, true, f, LC_CK_TARGET);
|
||||
ChangeKey (1, true, true, f, LC_CK_TARGET);
|
||||
|
||||
file.ReadDouble (d, 3);
|
||||
file.ReadDoubles(d, 3);
|
||||
f[0] = (float)d[0];
|
||||
f[1] = (float)d[1];
|
||||
f[2] = (float)d[2];
|
||||
|
@ -281,21 +281,21 @@ bool Camera::FileLoad (File& file)
|
|||
|
||||
if (version == 3)
|
||||
{
|
||||
file.Read(&ch, 1);
|
||||
ch = file.ReadU8();
|
||||
|
||||
while (ch--)
|
||||
{
|
||||
unsigned char step;
|
||||
lcuint8 step;
|
||||
double eye[3], target[3], up[3];
|
||||
float f[3];
|
||||
|
||||
file.ReadDouble (eye, 3);
|
||||
file.ReadDouble (target, 3);
|
||||
file.ReadDouble (up, 3);
|
||||
file.ReadByte (&step, 1);
|
||||
file.ReadDoubles(eye, 3);
|
||||
file.ReadDoubles(target, 3);
|
||||
file.ReadDoubles(up, 3);
|
||||
file.ReadU8(&step, 1);
|
||||
|
||||
if (up[0] == 0 && up[1] == 0 && up[2] == 0)
|
||||
up[2] = 1;
|
||||
up[2] = 1;
|
||||
|
||||
f[0] = (float)eye[0];
|
||||
f[1] = (float)eye[1];
|
||||
|
@ -315,80 +315,73 @@ bool Camera::FileLoad (File& file)
|
|||
ChangeKey (step, false, true, f, LC_CK_UP);
|
||||
ChangeKey (step, true, true, f, LC_CK_UP);
|
||||
|
||||
int snapshot; // BOOL under Windows
|
||||
int cam;
|
||||
file.ReadLong (&snapshot, 1);
|
||||
file.ReadLong (&cam, 1);
|
||||
// if (cam == -1)
|
||||
// node->pCam = NULL;
|
||||
// else
|
||||
// node->pCam = pDoc->GetCamera(i);
|
||||
lcint32 snapshot = file.ReadS32();
|
||||
lcint32 cam = file.ReadS32();
|
||||
}
|
||||
}
|
||||
|
||||
if (version < 4)
|
||||
{
|
||||
double d;
|
||||
file.ReadDouble (&d, 1); m_fovy = (float)d;
|
||||
file.ReadDouble (&d, 1); m_zFar = (float)d;
|
||||
file.ReadDouble (&d, 1); m_zNear= (float)d;
|
||||
m_fovy = (float)file.ReadDouble();
|
||||
m_zFar = (float)file.ReadDouble();
|
||||
m_zNear= (float)file.ReadDouble();
|
||||
}
|
||||
else
|
||||
{
|
||||
int n;
|
||||
lcint32 n;
|
||||
|
||||
if (version < 6)
|
||||
{
|
||||
unsigned short time;
|
||||
lcuint16 time;
|
||||
float param[4];
|
||||
unsigned char type;
|
||||
lcuint8 type;
|
||||
|
||||
file.ReadLong (&n, 1);
|
||||
n = file.ReadS32();
|
||||
while (n--)
|
||||
{
|
||||
file.ReadShort (&time, 1);
|
||||
file.ReadFloat (param, 3);
|
||||
file.ReadByte (&type, 1);
|
||||
file.ReadU16(&time, 1);
|
||||
file.ReadFloats(param, 3);
|
||||
file.ReadU8(&type, 1);
|
||||
|
||||
ChangeKey (time, false, true, param, type);
|
||||
}
|
||||
|
||||
file.ReadLong (&n, 1);
|
||||
n = file.ReadS32();
|
||||
while (n--)
|
||||
{
|
||||
file.ReadShort (&time, 1);
|
||||
file.ReadFloat (param, 3);
|
||||
file.ReadByte (&type, 1);
|
||||
file.ReadU16(&time, 1);
|
||||
file.ReadFloats(param, 3);
|
||||
file.ReadU8(&type, 1);
|
||||
|
||||
ChangeKey (time, true, true, param, type);
|
||||
}
|
||||
}
|
||||
|
||||
file.ReadFloat (&m_fovy, 1);
|
||||
file.ReadFloat (&m_zFar, 1);
|
||||
file.ReadFloat (&m_zNear, 1);
|
||||
file.ReadFloats(&m_fovy, 1);
|
||||
file.ReadFloats(&m_zFar, 1);
|
||||
file.ReadFloats(&m_zNear, 1);
|
||||
|
||||
if (version < 5)
|
||||
{
|
||||
file.ReadLong (&n, 1);
|
||||
n = file.ReadS32();
|
||||
if (n != 0)
|
||||
m_nState |= LC_CAMERA_HIDDEN;
|
||||
}
|
||||
else
|
||||
{
|
||||
file.ReadByte (&m_nState, 1);
|
||||
file.ReadByte (&m_nType, 1);
|
||||
m_nState = file.ReadU8();
|
||||
m_nType = file.ReadU8();
|
||||
}
|
||||
}
|
||||
|
||||
if ((version > 1) && (version < 4))
|
||||
{
|
||||
unsigned long show;
|
||||
int user;
|
||||
lcuint32 show;
|
||||
lcint32 user;
|
||||
|
||||
file.ReadLong (&show, 1);
|
||||
show = file.ReadU32();
|
||||
// if (version > 2)
|
||||
file.ReadLong (&user, 1);
|
||||
user = file.ReadS32();
|
||||
if (show == 0)
|
||||
m_nState |= LC_CAMERA_HIDDEN;
|
||||
}
|
||||
|
@ -396,24 +389,22 @@ bool Camera::FileLoad (File& file)
|
|||
return true;
|
||||
}
|
||||
|
||||
void Camera::FileSave (File& file) const
|
||||
void Camera::FileSave(lcFile& file) const
|
||||
{
|
||||
unsigned char ch = LC_CAMERA_SAVE_VERSION;
|
||||
|
||||
file.WriteByte (&ch, 1);
|
||||
file.WriteU8(LC_CAMERA_SAVE_VERSION);
|
||||
|
||||
Object::FileSave (file);
|
||||
|
||||
ch = (unsigned char)strlen(m_strName);
|
||||
file.Write (&ch, 1);
|
||||
file.Write (m_strName, ch);
|
||||
lcuint8 ch = (unsigned char)strlen(m_strName);
|
||||
file.WriteU8(ch);
|
||||
file.WriteBuffer(m_strName, ch);
|
||||
|
||||
file.WriteFloat (&m_fovy, 1);
|
||||
file.WriteFloat (&m_zFar, 1);
|
||||
file.WriteFloat (&m_zNear, 1);
|
||||
file.WriteFloat(m_fovy);
|
||||
file.WriteFloat(m_zFar);
|
||||
file.WriteFloat(m_zNear);
|
||||
// version 5
|
||||
file.WriteByte (&m_nState, 1);
|
||||
file.WriteByte (&m_nType, 1);
|
||||
file.WriteU8(m_nState);
|
||||
file.WriteU8(m_nType);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
|
||||
class Camera;
|
||||
class CameraTarget;
|
||||
class File;
|
||||
class TiledRender;
|
||||
|
||||
typedef enum
|
||||
|
@ -144,8 +143,8 @@ public:
|
|||
void SelectTarget (bool bSelecting, bool bFocus, bool bMultiple);
|
||||
|
||||
public:
|
||||
bool FileLoad (File& file);
|
||||
void FileSave (File& file) const;
|
||||
bool FileLoad(lcFile& file);
|
||||
void FileSave(lcFile& file) const;
|
||||
void MinIntersectDist (LC_CLICKLINE* pLine);
|
||||
void Select (bool bSelecting, bool bFocus, bool bMultiple);
|
||||
bool IntersectsVolume(const Vector4* Planes, int NumPlanes)
|
||||
|
|
|
@ -167,13 +167,13 @@ void CurvePoint::UpdatePosition (unsigned short nTime, bool bAnimation)
|
|||
CalculateKeys (nTime, bAnimation);
|
||||
}
|
||||
|
||||
bool CurvePoint::FileLoad (File& file)
|
||||
bool CurvePoint::FileLoad(lcFile& file)
|
||||
{
|
||||
// FIXME
|
||||
return true;
|
||||
}
|
||||
|
||||
void CurvePoint::FileSave (File& file) const
|
||||
void CurvePoint::FileSave(lcFile& file) const
|
||||
{
|
||||
// FIXME
|
||||
}
|
||||
|
@ -303,13 +303,13 @@ void Curve::Initialize ()
|
|||
m_nDisplayList = glGenLists (1);
|
||||
}
|
||||
|
||||
bool Curve::FileLoad (File& file)
|
||||
bool Curve::FileLoad(lcFile& file)
|
||||
{
|
||||
// FIXME
|
||||
return true;
|
||||
}
|
||||
|
||||
void Curve::FileSave (File& file) const
|
||||
void Curve::FileSave(lcFile& file) const
|
||||
{
|
||||
// FIXME
|
||||
}
|
||||
|
|
|
@ -34,8 +34,8 @@ class CurvePoint : public Object
|
|||
virtual ~CurvePoint ();
|
||||
|
||||
// object functions
|
||||
bool FileLoad (File& file);
|
||||
void FileSave (File& file) const;
|
||||
bool FileLoad(lcFile& file);
|
||||
void FileSave(lcFile& file) const;
|
||||
void MinIntersectDist (LC_CLICKLINE* pLine);
|
||||
bool IntersectsVolume(const Vector4* Planes, int NumPlanes)
|
||||
{ return false; }
|
||||
|
@ -97,8 +97,8 @@ class Curve : public Object
|
|||
virtual ~Curve ();
|
||||
|
||||
// object functions
|
||||
bool FileLoad (File& file);
|
||||
void FileSave (File& file) const;
|
||||
bool FileLoad(lcFile& file);
|
||||
void FileSave(lcFile& file) const;
|
||||
void MinIntersectDist (LC_CLICKLINE* pLine);
|
||||
void UpdatePosition (unsigned short nTime, bool bAnimation);
|
||||
void Move (unsigned short nTime, bool bAnimation, bool bAddKey, float dx, float dy, float dz);
|
||||
|
|
|
@ -45,27 +45,27 @@ void Group::UnGroup(Group* pGroup)
|
|||
m_pGroup->UnGroup(pGroup);
|
||||
}
|
||||
|
||||
void Group::FileLoad(File* file)
|
||||
void Group::FileLoad(lcFile* file)
|
||||
{
|
||||
unsigned char version;
|
||||
int i;
|
||||
lcuint8 version;
|
||||
lcint32 i;
|
||||
|
||||
file->Read(&version, 1);
|
||||
file->Read(m_strName, 65);
|
||||
file->Read(m_fCenter, 12);
|
||||
file->ReadLong(&i, 1);
|
||||
file->ReadU8(&version, 1);
|
||||
file->ReadBuffer(m_strName, 65);
|
||||
file->ReadFloats(m_fCenter, 3);
|
||||
file->ReadS32(&i, 1);
|
||||
m_pGroup = (Group*)i;
|
||||
}
|
||||
|
||||
void Group::FileSave(File* file, Group* pGroups)
|
||||
void Group::FileSave(lcFile* file, Group* pGroups)
|
||||
{
|
||||
unsigned char version = 1; // LeoCAD 0.60
|
||||
lcuint8 version = 1; // LeoCAD 0.60
|
||||
lcint32 i = 0;
|
||||
|
||||
file->Write(&version, 1);
|
||||
file->Write(m_strName, 65);
|
||||
file->Write(m_fCenter, 12);
|
||||
file->WriteU8(&version, 1);
|
||||
file->WriteBuffer(m_strName, 65);
|
||||
file->WriteFloats(m_fCenter, 3);
|
||||
|
||||
int i = 0;
|
||||
if (m_pGroup == NULL)
|
||||
i = -1;
|
||||
else
|
||||
|
@ -76,5 +76,6 @@ void Group::FileSave(File* file, Group* pGroups)
|
|||
else
|
||||
i++;
|
||||
}
|
||||
file->WriteLong(&i, 1);
|
||||
|
||||
file->WriteS32(&i, 1);
|
||||
}
|
||||
|
|
|
@ -1,11 +1,5 @@
|
|||
//
|
||||
// group.h
|
||||
////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _GROUP_H
|
||||
#define _GROUP_H
|
||||
|
||||
class File;
|
||||
#ifndef _GROUP_H_
|
||||
#define _GROUP_H_
|
||||
|
||||
class Group
|
||||
{
|
||||
|
@ -21,11 +15,11 @@ public:
|
|||
Group* m_pNext;
|
||||
Group* m_pGroup;
|
||||
|
||||
void FileLoad(File* file);
|
||||
void FileSave(File* file, Group* pGroups);
|
||||
void FileLoad(lcFile* file);
|
||||
void FileSave(lcFile* file, Group* pGroups);
|
||||
|
||||
char m_strName[65];
|
||||
float m_fCenter[3];
|
||||
};
|
||||
|
||||
#endif // _GROUP_H
|
||||
#endif // _GROUP_H_
|
||||
|
|
|
@ -7,79 +7,80 @@
|
|||
|
||||
// ========================================================
|
||||
|
||||
bool Image::LoadBMP (File& file)
|
||||
bool Image::LoadBMP(lcFile& file)
|
||||
{
|
||||
lcint32 bmWidth, bmHeight;
|
||||
lcuint8 bmPlanes, bmBitsPixel, m1, m2;
|
||||
typedef struct {
|
||||
unsigned char rgbBlue;
|
||||
unsigned char rgbGreen;
|
||||
unsigned char rgbRed;
|
||||
unsigned char rgbReserved;
|
||||
} RGBQUAD;
|
||||
lcint16 res1,res2;
|
||||
lcint32 filesize, pixoff;
|
||||
lcint32 bmisize, compression;
|
||||
lcint32 xscale, yscale;
|
||||
lcint32 colors, impcol, rc;
|
||||
lcuint32 sizeimage, m_bytesRead = 0;
|
||||
lcint32 bmWidth, bmHeight;
|
||||
lcuint16 bmPlanes, bmBitsPixel;
|
||||
lcuint8 m1, m2;
|
||||
typedef struct {
|
||||
unsigned char rgbBlue;
|
||||
unsigned char rgbGreen;
|
||||
unsigned char rgbRed;
|
||||
unsigned char rgbReserved;
|
||||
} RGBQUAD;
|
||||
lcint16 res1,res2;
|
||||
lcint32 filesize, pixoff;
|
||||
lcint32 bmisize, compression;
|
||||
lcint32 xscale, yscale;
|
||||
lcint32 colors, impcol, rc;
|
||||
lcuint32 sizeimage, m_bytesRead = 0;
|
||||
|
||||
FreeData ();
|
||||
FreeData ();
|
||||
|
||||
if (file.Read (&m1, 1) != 1)
|
||||
return false;
|
||||
if (file.ReadU8(&m1, 1) != 1)
|
||||
return false;
|
||||
m_bytesRead++;
|
||||
|
||||
if (file.Read (&m2, 1) != 1)
|
||||
return false;
|
||||
if (file.ReadU8(&m2, 1) != 1)
|
||||
return false;
|
||||
m_bytesRead++;
|
||||
|
||||
if ((m1 != 'B') || (m2 != 'M'))
|
||||
return false;
|
||||
|
||||
rc = file.ReadLong ((long*)&(filesize), 1); m_bytesRead+=4;
|
||||
rc = file.ReadS32(&filesize, 1); m_bytesRead+=4;
|
||||
if (rc != 1) { return false; }
|
||||
|
||||
rc = file.ReadShort ((int*)&(res1), 1); m_bytesRead+=2;
|
||||
rc = file.ReadS16(&res1, 1); m_bytesRead+=2;
|
||||
if (rc != 1) { return false; }
|
||||
|
||||
rc = file.ReadShort ((int*)&(res2), 1); m_bytesRead+=2;
|
||||
rc = file.ReadS16(&res2, 1); m_bytesRead+=2;
|
||||
if (rc != 1) { return false; }
|
||||
|
||||
rc = file.ReadLong ((long*)&(pixoff), 1); m_bytesRead+=4;
|
||||
rc = file.ReadS32(&pixoff, 1); m_bytesRead+=4;
|
||||
if (rc != 1) { return false; }
|
||||
|
||||
rc = file.ReadLong ((long*)&(bmisize), 1); m_bytesRead+=4;
|
||||
rc = file.ReadS32(&bmisize, 1); m_bytesRead+=4;
|
||||
if (rc != 1) { return false; }
|
||||
|
||||
rc = file.ReadLong ((long*)&(bmWidth), 1); m_bytesRead+=4;
|
||||
rc = file.ReadS32(&bmWidth, 1); m_bytesRead+=4;
|
||||
if (rc != 1) { return false; }
|
||||
|
||||
rc = file.ReadLong ((long*)&(bmHeight), 1); m_bytesRead+=4;
|
||||
rc = file.ReadS32(&bmHeight, 1); m_bytesRead+=4;
|
||||
if (rc != 1) { return false; }
|
||||
|
||||
rc = file.ReadShort ((int*)&(bmPlanes), 1); m_bytesRead+=2;
|
||||
rc = file.ReadU16(&bmPlanes, 1); m_bytesRead+=2;
|
||||
if (rc != 1) { return false; }
|
||||
|
||||
rc = file.ReadShort ((int*)&(bmBitsPixel), 1); m_bytesRead+=2;
|
||||
rc = file.ReadU16(&bmBitsPixel, 1); m_bytesRead+=2;
|
||||
if (rc != 1) { return false; }
|
||||
|
||||
rc = file.ReadLong ((long*)&(compression), 1); m_bytesRead+=4;
|
||||
rc = file.ReadS32(&compression, 1); m_bytesRead+=4;
|
||||
if (rc != 1) { return false; }
|
||||
|
||||
rc = file.ReadLong ((long*)&(sizeimage), 1); m_bytesRead+=4;
|
||||
rc = file.ReadU32(&sizeimage, 1); m_bytesRead+=4;
|
||||
if (rc != 1) {return false; }
|
||||
|
||||
rc = file.ReadLong ((long*)&(xscale), 1); m_bytesRead+=4;
|
||||
rc = file.ReadS32(&xscale, 1); m_bytesRead+=4;
|
||||
if (rc != 1) { return false; }
|
||||
|
||||
rc = file.ReadLong ((long*)&(yscale), 1); m_bytesRead+=4;
|
||||
rc = file.ReadS32(&yscale, 1); m_bytesRead+=4;
|
||||
if (rc != 1) { return false; }
|
||||
|
||||
rc = file.ReadLong ((long*)&(colors), 1); m_bytesRead+=4;
|
||||
rc = file.ReadS32(&colors, 1); m_bytesRead+=4;
|
||||
if (rc != 1) { return false; }
|
||||
|
||||
rc = file.ReadLong ((long*)&(impcol), 1); m_bytesRead+=4;
|
||||
rc = file.ReadS32(&impcol, 1); m_bytesRead+=4;
|
||||
if (rc != 1) { return false; }
|
||||
|
||||
if (colors == 0)
|
||||
|
@ -98,7 +99,7 @@ bool Image::LoadBMP (File& file)
|
|||
{
|
||||
unsigned char r ,g, b, dummy;
|
||||
|
||||
rc = file.Read (&b, 1);
|
||||
rc = file.ReadU8(&b, 1);
|
||||
m_bytesRead++;
|
||||
if (rc!=1)
|
||||
{
|
||||
|
@ -106,7 +107,7 @@ bool Image::LoadBMP (File& file)
|
|||
return false;
|
||||
}
|
||||
|
||||
rc = file.Read (&g, 1);
|
||||
rc = file.ReadU8(&g, 1);
|
||||
m_bytesRead++;
|
||||
if (rc!=1)
|
||||
{
|
||||
|
@ -114,7 +115,7 @@ bool Image::LoadBMP (File& file)
|
|||
return false;
|
||||
}
|
||||
|
||||
rc = file.Read (&r, 1);
|
||||
rc = file.ReadU8(&r, 1);
|
||||
m_bytesRead++;
|
||||
if (rc != 1)
|
||||
{
|
||||
|
@ -122,7 +123,7 @@ bool Image::LoadBMP (File& file)
|
|||
return false;
|
||||
}
|
||||
|
||||
rc = file.Read (&dummy, 1);
|
||||
rc = file.ReadU8(&dummy, 1);
|
||||
m_bytesRead++;
|
||||
if (rc != 1)
|
||||
{
|
||||
|
@ -144,8 +145,8 @@ bool Image::LoadBMP (File& file)
|
|||
|
||||
while ((long)m_bytesRead < pixoff)
|
||||
{
|
||||
char dummy;
|
||||
file.Read (&dummy, 1);
|
||||
lcuint8 dummy;
|
||||
file.ReadU8(&dummy, 1);
|
||||
m_bytesRead++;
|
||||
}
|
||||
|
||||
|
@ -160,7 +161,7 @@ bool Image::LoadBMP (File& file)
|
|||
{
|
||||
m_nWidth = w;
|
||||
m_nHeight = h;
|
||||
m_bAlpha = false;
|
||||
m_bAlpha = false;
|
||||
unsigned char* outbuf = m_pData;
|
||||
long row = 0;
|
||||
long rowOffset = 0;
|
||||
|
@ -171,16 +172,16 @@ bool Image::LoadBMP (File& file)
|
|||
for (row=bmHeight-1;row>=0;row--)
|
||||
{
|
||||
// which row are we working on?
|
||||
rowOffset = (long unsigned)row*row_size;
|
||||
rowOffset = (long unsigned)row*row_size;
|
||||
|
||||
if (bmBitsPixel == 24)
|
||||
{
|
||||
for (int col=0;col<w;col++)
|
||||
{
|
||||
long offset = col * 3;
|
||||
char pixel[3];
|
||||
lcuint8 pixel[3];
|
||||
|
||||
if (file.Read (pixel, 3) ==3)
|
||||
if (file.ReadU8(pixel, 3) ==3)
|
||||
{
|
||||
// we swap red and blue here
|
||||
*(outbuf + rowOffset + offset + 0) = pixel[2]; // r
|
||||
|
@ -193,10 +194,10 @@ bool Image::LoadBMP (File& file)
|
|||
// read DWORD padding
|
||||
while ((m_bytesRead-pixoff)&3)
|
||||
{
|
||||
char dummy;
|
||||
if (file.Read (&dummy, 1) != 1)
|
||||
lcuint8 dummy;
|
||||
if (file.ReadU8(&dummy, 1) != 1)
|
||||
{
|
||||
FreeData ();
|
||||
FreeData ();
|
||||
return false;
|
||||
}
|
||||
m_bytesRead++;
|
||||
|
@ -217,9 +218,9 @@ bool Image::LoadBMP (File& file)
|
|||
if (bit_count <= 0)
|
||||
{
|
||||
bit_count = 8;
|
||||
if (file.Read (&inbyte, 1) != 1)
|
||||
if (file.ReadU8(&inbyte, 1) != 1)
|
||||
{
|
||||
FreeData ();
|
||||
FreeData ();
|
||||
delete [] colormap;
|
||||
return false;
|
||||
}
|
||||
|
@ -240,10 +241,10 @@ bool Image::LoadBMP (File& file)
|
|||
// read DWORD padding
|
||||
while ((m_bytesRead-pixoff)&3)
|
||||
{
|
||||
char dummy;
|
||||
if (file.Read (&dummy, 1) != 1)
|
||||
lcuint8 dummy;
|
||||
if (file.ReadU8(&dummy, 1) != 1)
|
||||
{
|
||||
FreeData ();
|
||||
FreeData ();
|
||||
if (colormap)
|
||||
delete [] colormap;
|
||||
return false;
|
||||
|
@ -264,12 +265,12 @@ bool Image::LoadBMP (File& file)
|
|||
{
|
||||
while (row < bmHeight)
|
||||
{
|
||||
c = file.GetChar ();
|
||||
c = file.ReadU8();
|
||||
|
||||
if (c)
|
||||
{
|
||||
// encoded mode
|
||||
c1 = file.GetChar ();
|
||||
c1 = file.ReadU8();
|
||||
for (i = 0; i < c; x++, i++)
|
||||
{
|
||||
*pp = colormap[c1].rgbRed; pp++;
|
||||
|
@ -279,8 +280,8 @@ bool Image::LoadBMP (File& file)
|
|||
}
|
||||
else
|
||||
{
|
||||
// c==0x00, escape codes
|
||||
c = file.GetChar ();
|
||||
// c==0x00, escape codes
|
||||
c = file.ReadU8();
|
||||
|
||||
if (c == 0x00) // end of line
|
||||
{
|
||||
|
@ -292,9 +293,9 @@ bool Image::LoadBMP (File& file)
|
|||
break; // end of pic
|
||||
else if (c == 0x02) // delta
|
||||
{
|
||||
c = file.GetChar ();
|
||||
c = file.ReadU8();
|
||||
x += c;
|
||||
c = file.GetChar ();
|
||||
c = file.ReadU8();
|
||||
row += c;
|
||||
pp = outbuf + x*3 + (bmHeight-row-1)*bmWidth*3;
|
||||
}
|
||||
|
@ -302,14 +303,14 @@ bool Image::LoadBMP (File& file)
|
|||
{
|
||||
for (i = 0; i < c; x++, i++)
|
||||
{
|
||||
c1 = file.GetChar ();
|
||||
c1 = file.ReadU8();
|
||||
*pp = colormap[c1].rgbRed; pp++;
|
||||
*pp = colormap[c1].rgbGreen; pp++;
|
||||
*pp = colormap[c1].rgbBlue; pp++;
|
||||
}
|
||||
|
||||
if (c & 1)
|
||||
file.GetChar (); // odd length run: read an extra pad byte
|
||||
file.ReadU8(); // odd length run: read an extra pad byte
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -318,12 +319,12 @@ bool Image::LoadBMP (File& file)
|
|||
{
|
||||
while (row < bmHeight)
|
||||
{
|
||||
c = file.GetChar ();
|
||||
c = file.ReadU8();
|
||||
|
||||
if (c)
|
||||
{
|
||||
// encoded mode
|
||||
c1 = file.GetChar ();
|
||||
c1 = file.ReadU8();
|
||||
for (i = 0; i < c; x++, i++)
|
||||
{
|
||||
*pp = colormap[(i&1) ? (c1 & 0x0f) : ((c1>>4)&0x0f)].rgbRed; pp++;
|
||||
|
@ -333,8 +334,8 @@ bool Image::LoadBMP (File& file)
|
|||
}
|
||||
else
|
||||
{
|
||||
// c==0x00, escape codes
|
||||
c = file.GetChar ();
|
||||
// c==0x00, escape codes
|
||||
c = file.ReadU8();
|
||||
|
||||
if (c == 0x00) // end of line
|
||||
{
|
||||
|
@ -346,9 +347,9 @@ bool Image::LoadBMP (File& file)
|
|||
break; // end of pic
|
||||
else if (c == 0x02) // delta
|
||||
{
|
||||
c = file.GetChar ();
|
||||
c = file.ReadU8();
|
||||
x += c;
|
||||
c = file.GetChar ();
|
||||
c = file.ReadU8();
|
||||
row += c;
|
||||
pp = outbuf + x*3 + (bmHeight-row-1)*bmWidth*3;
|
||||
}
|
||||
|
@ -356,15 +357,15 @@ bool Image::LoadBMP (File& file)
|
|||
{
|
||||
for (i = 0; i < c; x++, i++)
|
||||
{
|
||||
if ((i&1) == 0)
|
||||
c1 = file.GetChar ();
|
||||
if ((i&1) == 0)
|
||||
c1 = file.ReadU8();
|
||||
*pp = colormap[(i&1) ? (c1 & 0x0f) : ((c1>>4)&0x0f)].rgbRed; pp++;
|
||||
*pp = colormap[(i&1) ? (c1 & 0x0f) : ((c1>>4)&0x0f)].rgbGreen; pp++;
|
||||
*pp = colormap[(i&1) ? (c1 & 0x0f) : ((c1>>4)&0x0f)].rgbBlue; pp++;
|
||||
}
|
||||
|
||||
if (((c&3) == 1) || ((c&3) == 2))
|
||||
file.GetChar (); // odd length run: read an extra pad byte
|
||||
file.ReadU8(); // odd length run: read an extra pad byte
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -373,18 +374,18 @@ bool Image::LoadBMP (File& file)
|
|||
|
||||
if (colormap)
|
||||
delete [] colormap;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// ========================================================
|
||||
|
||||
bool Image::SaveBMP (File& file, bool quantize) const
|
||||
bool Image::SaveBMP(lcFile& file, bool quantize) const
|
||||
{
|
||||
unsigned short bits;
|
||||
unsigned long cmap, bfSize;
|
||||
unsigned char pal[3][256], *colormappedbuffer = NULL;
|
||||
lcuint16 bits;
|
||||
lcuint32 cmap, bfSize;
|
||||
lcuint8 pal[3][256], *colormappedbuffer = NULL;
|
||||
|
||||
if (quantize)
|
||||
{
|
||||
|
@ -402,39 +403,39 @@ bool Image::SaveBMP (File& file, bool quantize) const
|
|||
}
|
||||
|
||||
long byteswritten = 0;
|
||||
long pixoff = 54 + cmap*4;
|
||||
short res = 0;
|
||||
char m1 ='B', m2 ='M';
|
||||
file.WriteByte (&m1, 1); byteswritten++; // B
|
||||
file.WriteByte (&m2, 1); byteswritten++; // M
|
||||
file.WriteLong (&bfSize, 1); byteswritten+=4;// bfSize
|
||||
file.WriteShort (&res, 1); byteswritten+=2;// bfReserved1
|
||||
file.WriteShort (&res, 1); byteswritten+=2;// bfReserved2
|
||||
file.WriteLong (&pixoff, 1); byteswritten+=4;// bfOffBits
|
||||
lcuint32 pixoff = 54 + cmap*4;
|
||||
lcuint16 res = 0;
|
||||
lcuint8 m1 ='B', m2 ='M';
|
||||
file.WriteU8(&m1, 1); byteswritten++; // B
|
||||
file.WriteU8(&m2, 1); byteswritten++; // M
|
||||
file.WriteU32(&bfSize, 1); byteswritten+=4;// bfSize
|
||||
file.WriteU16(&res, 1); byteswritten+=2;// bfReserved1
|
||||
file.WriteU16(&res, 1); byteswritten+=2;// bfReserved2
|
||||
file.WriteU32(&pixoff, 1); byteswritten+=4;// bfOffBits
|
||||
|
||||
lcuint32 biSize = 40, compress = 0, size = 0;
|
||||
lcint32 width = m_nWidth, height = m_nHeight, pixels = 0;
|
||||
lcuint32 width = m_nWidth, height = m_nHeight, pixels = 0;
|
||||
lcuint16 planes = 1;
|
||||
file.WriteLong (&biSize, 1); byteswritten+=4;// biSize
|
||||
file.WriteLong (&width, 1); byteswritten+=4;// biWidth
|
||||
file.WriteLong (&height, 1); byteswritten+=4;// biHeight
|
||||
file.WriteShort (&planes, 1); byteswritten+=2;// biPlanes
|
||||
file.WriteShort (&bits, 1); byteswritten+=2;// biBitCount
|
||||
file.WriteLong (&compress, 1); byteswritten+=4;// biCompression
|
||||
file.WriteLong (&size, 1); byteswritten+=4;// biSizeImage
|
||||
file.WriteLong (&pixels, 1); byteswritten+=4;// biXPelsPerMeter
|
||||
file.WriteLong (&pixels, 1); byteswritten+=4;// biYPelsPerMeter
|
||||
file.WriteLong (&cmap, 1); byteswritten+=4;// biClrUsed
|
||||
file.WriteLong (&cmap, 1); byteswritten+=4;// biClrImportant
|
||||
file.WriteU32(&biSize, 1); byteswritten+=4;// biSize
|
||||
file.WriteU32(&width, 1); byteswritten+=4;// biWidth
|
||||
file.WriteU32(&height, 1); byteswritten+=4;// biHeight
|
||||
file.WriteU16(&planes, 1); byteswritten+=2;// biPlanes
|
||||
file.WriteU16(&bits, 1); byteswritten+=2;// biBitCount
|
||||
file.WriteU32(&compress, 1); byteswritten+=4;// biCompression
|
||||
file.WriteU32(&size, 1); byteswritten+=4;// biSizeImage
|
||||
file.WriteU32(&pixels, 1); byteswritten+=4;// biXPelsPerMeter
|
||||
file.WriteU32(&pixels, 1); byteswritten+=4;// biYPelsPerMeter
|
||||
file.WriteU32(&cmap, 1); byteswritten+=4;// biClrUsed
|
||||
file.WriteU32(&cmap, 1); byteswritten+=4;// biClrImportant
|
||||
|
||||
if (quantize)
|
||||
{
|
||||
for (int i = 0; i < 256; i++)
|
||||
{
|
||||
file.PutChar (pal[2][i]);
|
||||
file.PutChar (pal[1][i]);
|
||||
file.PutChar (pal[0][i]);
|
||||
file.PutChar (0); // dummy
|
||||
file.WriteU8(pal[2][i]);
|
||||
file.WriteU8(pal[1][i]);
|
||||
file.WriteU8(pal[0][i]);
|
||||
file.WriteU8(0); // dummy
|
||||
}
|
||||
|
||||
for (int row = 0; row < m_nHeight; row++)
|
||||
|
@ -448,7 +449,7 @@ bool Image::SaveBMP (File& file, bool quantize) const
|
|||
|
||||
pixbuf = (pixbuf << 8) | pval;
|
||||
|
||||
file.PutChar (pixbuf);
|
||||
file.WriteU8(pixbuf);
|
||||
pixbuf = 0;
|
||||
byteswritten++;
|
||||
}
|
||||
|
@ -456,7 +457,7 @@ bool Image::SaveBMP (File& file, bool quantize) const
|
|||
// DWORD align
|
||||
while ((byteswritten - pixoff) & 3)
|
||||
{
|
||||
file.PutChar (0);
|
||||
file.WriteU8(0);
|
||||
byteswritten++;
|
||||
}
|
||||
}
|
||||
|
@ -474,15 +475,15 @@ bool Image::SaveBMP (File& file, bool quantize) const
|
|||
// write a row
|
||||
for (int col = 0; col < row_size; col += 3)
|
||||
{
|
||||
file.PutChar (buf[col+2]);
|
||||
file.PutChar (buf[col+1]);
|
||||
file.PutChar (buf[col]);
|
||||
file.WriteU8(buf[col+2]);
|
||||
file.WriteU8(buf[col+1]);
|
||||
file.WriteU8(buf[col]);
|
||||
}
|
||||
byteswritten += row_size;
|
||||
|
||||
for (unsigned long count = row_size; count < widthDW; count++)
|
||||
{
|
||||
file.PutChar (0); // dummy
|
||||
file.WriteU8(0); // dummy
|
||||
byteswritten++;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ typedef struct
|
|||
lcuint32 pass3_offset; // # of pixel rows in passes 1&2
|
||||
lcuint32 pass4_offset; // # of pixel rows in passes 1,2,3
|
||||
|
||||
File* input_file;
|
||||
lcFile* input_file;
|
||||
bool first_interlace;
|
||||
unsigned char* buffer;//JSAMPARRAY buffer;
|
||||
unsigned int width, height;
|
||||
|
@ -65,9 +65,9 @@ typedef gif_source_struct *gif_source_ptr;
|
|||
|
||||
static int GetDataBlock (gif_source_ptr sinfo, char *buf)
|
||||
{
|
||||
int count = sinfo->input_file->GetChar();
|
||||
int count = sinfo->input_file->ReadU8();
|
||||
if (count > 0)
|
||||
sinfo->input_file->Read(buf, count);
|
||||
sinfo->input_file->ReadBuffer(buf, count);
|
||||
return count;
|
||||
}
|
||||
|
||||
|
@ -193,7 +193,7 @@ static int LZWReadByte (gif_source_ptr sinfo)
|
|||
return sinfo->firstcode; // return first byte of symbol's expansion
|
||||
}
|
||||
|
||||
bool Image::LoadGIF (File& file)
|
||||
bool Image::LoadGIF(lcFile& file)
|
||||
{
|
||||
gif_source_ptr source;
|
||||
source = (gif_source_ptr)malloc (sizeof(gif_source_struct));
|
||||
|
@ -206,13 +206,13 @@ bool Image::LoadGIF (File& file)
|
|||
|
||||
FreeData ();
|
||||
|
||||
source->input_file->Read(hdrbuf, 6);
|
||||
source->input_file->ReadBuffer(hdrbuf, 6);
|
||||
if ((hdrbuf[0] != 'G' || hdrbuf[1] != 'I' || hdrbuf[2] != 'F') ||
|
||||
((hdrbuf[3] != '8' || hdrbuf[4] != '7' || hdrbuf[5] != 'a') &&
|
||||
(hdrbuf[3] != '8' || hdrbuf[4] != '9' || hdrbuf[5] != 'a')))
|
||||
return false;
|
||||
|
||||
source->input_file->Read(hdrbuf, 7);
|
||||
source->input_file->ReadBuffer(hdrbuf, 7);
|
||||
width = LM_to_uint(hdrbuf[0],hdrbuf[1]);
|
||||
height = LM_to_uint(hdrbuf[2],hdrbuf[3]);
|
||||
source->height = height;
|
||||
|
@ -223,14 +223,14 @@ bool Image::LoadGIF (File& file)
|
|||
if (BitSet(hdrbuf[4], COLORMAPFLAG))
|
||||
for (int i = 0; i < colormaplen; i++)
|
||||
{
|
||||
source->colormap[0][i] = source->input_file->GetChar();
|
||||
source->colormap[1][i] = source->input_file->GetChar();
|
||||
source->colormap[2][i] = source->input_file->GetChar();
|
||||
source->colormap[0][i] = source->input_file->ReadU8();
|
||||
source->colormap[1][i] = source->input_file->ReadU8();
|
||||
source->colormap[2][i] = source->input_file->ReadU8();
|
||||
}
|
||||
|
||||
for (;;)
|
||||
{
|
||||
c = source->input_file->GetChar();
|
||||
c = source->input_file->ReadU8();
|
||||
|
||||
// if (c == ';')
|
||||
// ERREXIT(cinfo, JERR_GIF_IMAGENOTFOUND);
|
||||
|
@ -240,7 +240,7 @@ bool Image::LoadGIF (File& file)
|
|||
int extlabel;
|
||||
char buf[256];
|
||||
|
||||
extlabel = source->input_file->GetChar();
|
||||
extlabel = source->input_file->ReadU8();
|
||||
while (GetDataBlock(source, buf) > 0)
|
||||
; // skip
|
||||
continue;
|
||||
|
@ -249,7 +249,7 @@ bool Image::LoadGIF (File& file)
|
|||
if (c != ',')
|
||||
continue;
|
||||
|
||||
source->input_file->Read(hdrbuf, 9);
|
||||
source->input_file->ReadBuffer(hdrbuf, 9);
|
||||
width = LM_to_uint(hdrbuf[4],hdrbuf[5]);
|
||||
height = LM_to_uint(hdrbuf[6],hdrbuf[7]);
|
||||
source->is_interlaced = (hdrbuf[8] & INTERLACE) != 0;
|
||||
|
@ -259,13 +259,13 @@ bool Image::LoadGIF (File& file)
|
|||
colormaplen = 2 << (hdrbuf[8] & 0x07);
|
||||
for (int i = 0; i < colormaplen; i++)
|
||||
{
|
||||
source->colormap[0][i] = source->input_file->GetChar();
|
||||
source->colormap[1][i] = source->input_file->GetChar();
|
||||
source->colormap[2][i] = source->input_file->GetChar();
|
||||
source->colormap[0][i] = source->input_file->ReadU8();
|
||||
source->colormap[1][i] = source->input_file->ReadU8();
|
||||
source->colormap[2][i] = source->input_file->ReadU8();
|
||||
}
|
||||
}
|
||||
|
||||
source->input_code_size = source->input_file->GetChar();
|
||||
source->input_code_size = source->input_file->ReadU8();
|
||||
// if (source->input_code_size < 2 || source->input_code_size >= MAX_LZW_BITS)
|
||||
// ERREXIT1(cinfo, JERR_GIF_CODESIZE, source->input_code_size);
|
||||
|
||||
|
@ -417,17 +417,17 @@ typedef struct
|
|||
hash_entry *hash_value;
|
||||
int bytesinpkt;
|
||||
char packetbuf[256];
|
||||
File* output_file;
|
||||
lcFile* output_file;
|
||||
void* buffer;//JSAMPARRAY buffer;
|
||||
} gif_dest_struct;
|
||||
|
||||
typedef gif_dest_struct* gif_dest_ptr;
|
||||
|
||||
// Emit a 16-bit word, LSB first
|
||||
static void put_word(File& output_file, unsigned int w)
|
||||
static void put_word(lcFile& output_file, unsigned int w)
|
||||
{
|
||||
output_file.PutChar(w & 0xFF);
|
||||
output_file.PutChar((w >> 8) & 0xFF);
|
||||
output_file.WriteU8(w & 0xFF);
|
||||
output_file.WriteU8((w >> 8) & 0xFF);
|
||||
}
|
||||
|
||||
static void flush_packet(gif_dest_ptr dinfo)
|
||||
|
@ -435,7 +435,7 @@ static void flush_packet(gif_dest_ptr dinfo)
|
|||
if (dinfo->bytesinpkt > 0)
|
||||
{
|
||||
dinfo->packetbuf[0] = (char) dinfo->bytesinpkt++;
|
||||
dinfo->output_file->Write(dinfo->packetbuf, dinfo->bytesinpkt);
|
||||
dinfo->output_file->WriteBuffer(dinfo->packetbuf, dinfo->bytesinpkt);
|
||||
dinfo->bytesinpkt = 0;
|
||||
}
|
||||
}
|
||||
|
@ -528,7 +528,7 @@ static void compress_byte (gif_dest_ptr dinfo, int c)
|
|||
dinfo->waiting_code = c;
|
||||
}
|
||||
|
||||
bool Image::SaveGIF (File& file, bool transparent, bool interlaced, unsigned char* background) const
|
||||
bool Image::SaveGIF(lcFile& file, bool transparent, bool interlaced, unsigned char* background) const
|
||||
{
|
||||
int InitCodeSize, FlagByte, i;
|
||||
unsigned char pal[3][256];
|
||||
|
@ -544,27 +544,27 @@ bool Image::SaveGIF (File& file, bool transparent, bool interlaced, unsigned cha
|
|||
|
||||
InitCodeSize = 8;
|
||||
// Write the GIF header.
|
||||
file.PutChar('G');
|
||||
file.PutChar('I');
|
||||
file.PutChar('F');
|
||||
file.PutChar('8');
|
||||
file.PutChar(transparent ? '9' : '7');
|
||||
file.PutChar('a');
|
||||
file.WriteU8('G');
|
||||
file.WriteU8('I');
|
||||
file.WriteU8('F');
|
||||
file.WriteU8('8');
|
||||
file.WriteU8(transparent ? '9' : '7');
|
||||
file.WriteU8('a');
|
||||
// Write the Logical Screen Descriptor
|
||||
put_word(file, (unsigned int)m_nWidth);
|
||||
put_word(file, (unsigned int)m_nHeight);
|
||||
FlagByte = 0x80;
|
||||
FlagByte |= (7) << 4; // color resolution
|
||||
FlagByte |= (7); // size of global color table
|
||||
file.PutChar(FlagByte);
|
||||
file.PutChar(0); // Background color index
|
||||
file.PutChar(0); // Reserved (aspect ratio in GIF89)
|
||||
file.WriteU8(FlagByte);
|
||||
file.WriteU8(0); // Background color index
|
||||
file.WriteU8(0); // Reserved (aspect ratio in GIF89)
|
||||
// Write the Global Color Map
|
||||
for (i = 0; i < 256; i++)
|
||||
{
|
||||
file.PutChar(pal[0][i]);
|
||||
file.PutChar(pal[1][i]);
|
||||
file.PutChar(pal[2][i]);
|
||||
file.WriteU8(pal[0][i]);
|
||||
file.WriteU8(pal[1][i]);
|
||||
file.WriteU8(pal[2][i]);
|
||||
}
|
||||
|
||||
// Write out extension for transparent colour index, if necessary.
|
||||
|
@ -581,28 +581,28 @@ bool Image::SaveGIF (File& file, bool transparent, bool interlaced, unsigned cha
|
|||
break;
|
||||
}
|
||||
|
||||
file.PutChar('!');
|
||||
file.PutChar(0xf9);
|
||||
file.PutChar(4);
|
||||
file.PutChar(1);
|
||||
file.PutChar(0);
|
||||
file.PutChar(0);
|
||||
file.PutChar(index);
|
||||
file.PutChar(0);
|
||||
file.WriteU8('!');
|
||||
file.WriteU8(0xf9);
|
||||
file.WriteU8(4);
|
||||
file.WriteU8(1);
|
||||
file.WriteU8(0);
|
||||
file.WriteU8(0);
|
||||
file.WriteU8(index);
|
||||
file.WriteU8(0);
|
||||
}
|
||||
|
||||
// Write image separator and Image Descriptor
|
||||
file.PutChar(',');
|
||||
file.WriteU8(',');
|
||||
put_word(file, 0);
|
||||
put_word(file, 0);
|
||||
put_word(file, (unsigned int)m_nWidth);
|
||||
put_word(file, (unsigned int)m_nHeight);
|
||||
// flag byte: interlaced
|
||||
if (interlaced)
|
||||
file.PutChar(0x40);
|
||||
file.WriteU8(0x40);
|
||||
else
|
||||
file.PutChar(0x00);
|
||||
file.PutChar(InitCodeSize);// Write Initial Code Size byte
|
||||
file.WriteU8(0x00);
|
||||
file.WriteU8(InitCodeSize);// Write Initial Code Size byte
|
||||
|
||||
// Initialize for LZW compression of image data
|
||||
dinfo->n_bits = dinfo->init_bits = InitCodeSize+1;
|
||||
|
@ -686,8 +686,8 @@ bool Image::SaveGIF (File& file, bool transparent, bool interlaced, unsigned cha
|
|||
}
|
||||
|
||||
flush_packet(dinfo);
|
||||
file.PutChar(0);
|
||||
file.PutChar(';');
|
||||
file.WriteU8(0);
|
||||
file.WriteU8(';');
|
||||
file.Flush();
|
||||
|
||||
free(dinfo->buffer);
|
||||
|
|
|
@ -80,7 +80,7 @@ typedef struct
|
|||
{
|
||||
struct jpeg_source_mgr pub; // public fields
|
||||
|
||||
File * infile; // source stream
|
||||
lcFile * infile; // source stream
|
||||
JOCTET * buffer; // start of buffer
|
||||
boolean start_of_file; // have we gotten any data yet?
|
||||
} my_source_mgr;
|
||||
|
@ -107,7 +107,7 @@ static boolean fill_input_buffer (j_decompress_ptr cinfo)
|
|||
my_src_ptr src = (my_src_ptr) cinfo->src;
|
||||
size_t nbytes;
|
||||
|
||||
nbytes = src->infile->Read (src->buffer, INPUT_BUF_SIZE);
|
||||
nbytes = src->infile->ReadBuffer (src->buffer, INPUT_BUF_SIZE);
|
||||
|
||||
if (nbytes <= 0)
|
||||
{
|
||||
|
@ -160,7 +160,7 @@ static void term_source (j_decompress_ptr cinfo)
|
|||
}
|
||||
|
||||
// Prepare for input from a File object.
|
||||
static void jpeg_file_src (j_decompress_ptr cinfo, File& infile)
|
||||
static void jpeg_file_src (j_decompress_ptr cinfo, lcFile& infile)
|
||||
{
|
||||
my_src_ptr src;
|
||||
|
||||
|
@ -195,7 +195,7 @@ static void jpeg_file_src (j_decompress_ptr cinfo, File& infile)
|
|||
|
||||
// =============================================================================
|
||||
|
||||
bool Image::LoadJPG (File& file)
|
||||
bool Image::LoadJPG(lcFile& file)
|
||||
{
|
||||
struct jpeg_decompress_struct cinfo;
|
||||
struct bt_jpeg_error_mgr jerr;
|
||||
|
@ -259,7 +259,7 @@ typedef struct
|
|||
{
|
||||
struct jpeg_destination_mgr pub; // public fields
|
||||
|
||||
File * outfile; // target stream
|
||||
lcFile * outfile; // target stream
|
||||
JOCTET * buffer; // start of buffer
|
||||
} my_destination_mgr;
|
||||
|
||||
|
@ -292,7 +292,7 @@ static boolean empty_output_buffer (j_compress_ptr cinfo)
|
|||
{
|
||||
my_dest_ptr dest = (my_dest_ptr) cinfo->dest;
|
||||
|
||||
dest->outfile->Write (dest->buffer, OUTPUT_BUF_SIZE);
|
||||
dest->outfile->WriteBuffer (dest->buffer, OUTPUT_BUF_SIZE);
|
||||
// if (dest->outfile.Write (dest->buffer, OUTPUT_BUF_SIZE) != (size_t) OUTPUT_BUF_SIZE)
|
||||
// ERREXIT(cinfo, JERR_FILE_WRITE);
|
||||
|
||||
|
@ -312,7 +312,7 @@ static void term_destination (j_compress_ptr cinfo)
|
|||
// Write any data remaining in the buffer
|
||||
if (datacount > 0)
|
||||
{
|
||||
dest->outfile->Write (dest->buffer, datacount);
|
||||
dest->outfile->WriteBuffer (dest->buffer, datacount);
|
||||
// if (dest->outfile.Write (dest->buffer, datacount) != datacount)
|
||||
// ERREXIT(cinfo, JERR_FILE_WRITE);
|
||||
}
|
||||
|
@ -324,7 +324,7 @@ static void term_destination (j_compress_ptr cinfo)
|
|||
}
|
||||
|
||||
// Prepare for output to a File object.
|
||||
static void jpeg_file_dest (j_compress_ptr cinfo, File& outfile)
|
||||
static void jpeg_file_dest (j_compress_ptr cinfo, lcFile& outfile)
|
||||
{
|
||||
my_dest_ptr dest;
|
||||
|
||||
|
@ -350,7 +350,7 @@ static void jpeg_file_dest (j_compress_ptr cinfo, File& outfile)
|
|||
|
||||
// =============================================================================
|
||||
|
||||
bool Image::SaveJPG (File& file, int quality, bool progressive) const
|
||||
bool Image::SaveJPG(lcFile& file, int quality, bool progressive) const
|
||||
{
|
||||
struct jpeg_compress_struct cinfo;
|
||||
struct bt_jpeg_error_mgr jerr;
|
||||
|
|
|
@ -21,13 +21,13 @@ static void user_read_fn(png_structp png_ptr, png_bytep data, png_size_t length)
|
|||
|
||||
// Read() returns 0 on error, so it is OK to store this in a png_size_t
|
||||
// instead of an int, which is what Read() actually returns.
|
||||
check = (png_size_t)((File*)png_get_io_ptr(png_ptr))->Read(data, length);
|
||||
check = (png_size_t)((lcFile*)png_get_io_ptr(png_ptr))->ReadBuffer(data, length);
|
||||
|
||||
if (check != length)
|
||||
png_error(png_ptr, "Read Error");
|
||||
}
|
||||
|
||||
bool Image::LoadPNG(File& file)
|
||||
bool Image::LoadPNG(lcFile& file)
|
||||
{
|
||||
unsigned char sig[8], red, green, blue;
|
||||
unsigned char *image_data = NULL;
|
||||
|
@ -46,7 +46,7 @@ bool Image::LoadPNG(File& file)
|
|||
|
||||
FreeData();
|
||||
|
||||
file.Read(sig, 8);
|
||||
file.ReadBuffer(sig, 8);
|
||||
if (!png_check_sig(sig, 8))
|
||||
return false; // bad signature
|
||||
|
||||
|
@ -262,7 +262,7 @@ static void user_write_fn(png_structp png_ptr, png_bytep data, png_size_t length
|
|||
{
|
||||
png_uint_32 check;
|
||||
|
||||
check = ((File*)png_get_io_ptr(png_ptr))->Write(data, length);
|
||||
check = ((lcFile*)png_get_io_ptr(png_ptr))->WriteBuffer(data, length);
|
||||
if (check != length)
|
||||
{
|
||||
png_error(png_ptr, "Write Error");
|
||||
|
@ -271,10 +271,10 @@ static void user_write_fn(png_structp png_ptr, png_bytep data, png_size_t length
|
|||
|
||||
static void user_flush_fn(png_structp png_ptr)
|
||||
{
|
||||
((File*)png_get_io_ptr(png_ptr))->Flush();
|
||||
((lcFile*)png_get_io_ptr(png_ptr))->Flush();
|
||||
}
|
||||
|
||||
bool Image::SavePNG(File& file, bool transparent, bool interlaced, unsigned char* background) const
|
||||
bool Image::SavePNG(lcFile& file, bool transparent, bool interlaced, unsigned char* background) const
|
||||
{
|
||||
png_structp png_ptr;
|
||||
png_infop info_ptr;
|
||||
|
|
|
@ -128,12 +128,12 @@ void Image::FromOpenGL (int width, int height)
|
|||
free (buf);
|
||||
}
|
||||
|
||||
bool Image::FileLoad (File& file)
|
||||
bool Image::FileLoad(lcFile& file)
|
||||
{
|
||||
unsigned char buf[8];
|
||||
|
||||
// Read a few bytes
|
||||
if (file.Read (buf, 8) != 8)
|
||||
if (file.ReadBuffer(buf, 8) != 8)
|
||||
return false;
|
||||
file.Seek (-8, SEEK_CUR);
|
||||
|
||||
|
@ -184,9 +184,9 @@ bool Image::FileLoad (File& file)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool Image::FileLoad (const char* filename)
|
||||
bool Image::FileLoad(const char* filename)
|
||||
{
|
||||
FileDisk file;
|
||||
lcDiskFile file;
|
||||
|
||||
if (!file.Open (filename, "rb"))
|
||||
return false;
|
||||
|
@ -194,7 +194,7 @@ bool Image::FileLoad (const char* filename)
|
|||
return FileLoad (file);
|
||||
}
|
||||
|
||||
bool Image::FileSave (File& file, LC_IMAGE_OPTS* opts) const
|
||||
bool Image::FileSave(lcFile& file, LC_IMAGE_OPTS* opts) const
|
||||
{
|
||||
switch (opts->format)
|
||||
{
|
||||
|
@ -223,10 +223,10 @@ bool Image::FileSave (File& file, LC_IMAGE_OPTS* opts) const
|
|||
return false;
|
||||
}
|
||||
|
||||
bool Image::FileSave (const char* filename, LC_IMAGE_OPTS* opts) const
|
||||
bool Image::FileSave(const char* filename, LC_IMAGE_OPTS* opts) const
|
||||
{
|
||||
char name[LC_MAXPATH], ext[5], *p;
|
||||
FileDisk file;
|
||||
lcDiskFile file;
|
||||
bool needext = false;
|
||||
|
||||
strcpy (name, filename);
|
||||
|
@ -291,10 +291,10 @@ bool Image::FileSave (const char* filename, LC_IMAGE_OPTS* opts) const
|
|||
}
|
||||
}
|
||||
|
||||
if (!file.Open (name, "wb"))
|
||||
if (!file.Open(name, "wb"))
|
||||
return false;
|
||||
|
||||
return FileSave (file, opts);
|
||||
return FileSave(file, opts);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,52 +1,50 @@
|
|||
#ifndef _IMAGE_H_
|
||||
#define _IMAGE_H_
|
||||
|
||||
class File;
|
||||
|
||||
#include "typedefs.h"
|
||||
|
||||
class Image
|
||||
{
|
||||
public:
|
||||
Image ();
|
||||
virtual ~Image ();
|
||||
Image();
|
||||
virtual ~Image();
|
||||
|
||||
bool FileSave (File& file, LC_IMAGE_OPTS* opts) const;
|
||||
bool FileSave (const char* filename, LC_IMAGE_OPTS* opts) const;
|
||||
bool FileLoad (File& file);
|
||||
bool FileLoad (const char* filename);
|
||||
bool FileSave(lcFile& file, LC_IMAGE_OPTS* opts) const;
|
||||
bool FileSave(const char* filename, LC_IMAGE_OPTS* opts) const;
|
||||
bool FileLoad(lcFile& file);
|
||||
bool FileLoad(const char* filename);
|
||||
|
||||
void Resize (int width, int height);
|
||||
void ResizePow2 ();
|
||||
void FromOpenGL (int width, int height);
|
||||
void Allocate (int width, int height, bool alpha);
|
||||
void Resize(int width, int height);
|
||||
void ResizePow2();
|
||||
void FromOpenGL(int width, int height);
|
||||
void Allocate(int width, int height, bool alpha);
|
||||
|
||||
int Width () const
|
||||
{ return m_nWidth; }
|
||||
int Height () const
|
||||
{ return m_nHeight; }
|
||||
int Alpha () const
|
||||
{ return m_bAlpha; }
|
||||
unsigned char* GetData () const
|
||||
{ return m_pData; }
|
||||
int Width() const
|
||||
{ return m_nWidth; }
|
||||
int Height() const
|
||||
{ return m_nHeight; }
|
||||
int Alpha() const
|
||||
{ return m_bAlpha; }
|
||||
unsigned char* GetData() const
|
||||
{ return m_pData; }
|
||||
|
||||
protected:
|
||||
void FreeData ();
|
||||
void FreeData();
|
||||
|
||||
bool LoadJPG (File& file);
|
||||
bool LoadBMP (File& file);
|
||||
bool LoadPNG (File& file);
|
||||
bool LoadGIF (File& file);
|
||||
bool LoadJPG(lcFile& file);
|
||||
bool LoadBMP(lcFile& file);
|
||||
bool LoadPNG(lcFile& file);
|
||||
bool LoadGIF(lcFile& file);
|
||||
|
||||
bool SaveJPG (File& file, int quality, bool progressive) const;
|
||||
bool SaveBMP (File& file, bool quantize) const;
|
||||
bool SavePNG (File& file, bool transparent, bool interlaced, unsigned char* background) const;
|
||||
bool SaveGIF (File& file, bool transparent, bool interlaced, unsigned char* background) const;
|
||||
bool SaveJPG(lcFile& file, int quality, bool progressive) const;
|
||||
bool SaveBMP(lcFile& file, bool quantize) const;
|
||||
bool SavePNG(lcFile& file, bool transparent, bool interlaced, unsigned char* background) const;
|
||||
bool SaveGIF(lcFile& file, bool transparent, bool interlaced, unsigned char* background) const;
|
||||
|
||||
int m_nWidth;
|
||||
int m_nHeight;
|
||||
bool m_bAlpha;
|
||||
unsigned char* m_pData;
|
||||
int m_nWidth;
|
||||
int m_nHeight;
|
||||
bool m_bAlpha;
|
||||
unsigned char* m_pData;
|
||||
};
|
||||
|
||||
void SaveVideo(char* filename, Image *images, int count, float fps);
|
||||
|
|
|
@ -136,7 +136,7 @@ LC_KEYBOARD_COMMAND KeyboardShortcuts[KeyboardShortcutsCount];
|
|||
|
||||
bool SaveKeyboardShortcuts(const char* FileName)
|
||||
{
|
||||
FileDisk f;
|
||||
lcDiskFile f;
|
||||
|
||||
if (!f.Open(FileName, "wt"))
|
||||
return false;
|
||||
|
@ -179,7 +179,7 @@ bool SaveKeyboardShortcuts(const char* FileName)
|
|||
|
||||
str += "\n";
|
||||
|
||||
f.Write((const char*)str, str.GetLength());
|
||||
f.WriteBuffer((const char*)str, str.GetLength());
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -187,7 +187,7 @@ bool SaveKeyboardShortcuts(const char* FileName)
|
|||
|
||||
bool LoadKeyboardShortcuts(const char* FileName)
|
||||
{
|
||||
FileDisk f;
|
||||
lcDiskFile f;
|
||||
int i;
|
||||
|
||||
if (!f.Open(FileName, "rt"))
|
||||
|
|
|
@ -1,7 +1,3 @@
|
|||
// File class, can be a memory file or in the disk.
|
||||
// Needed to work with the clipboard and undo/redo easily.
|
||||
// NOTE: Because of endianess issues, all I/O must be done from a File class.
|
||||
|
||||
#include "lc_global.h"
|
||||
#include <stdio.h>
|
||||
#include <memory.h>
|
||||
|
@ -11,560 +7,273 @@
|
|||
#include "str.h"
|
||||
|
||||
// =============================================================================
|
||||
// File construction/destruction
|
||||
// lcFile
|
||||
|
||||
File::File ()
|
||||
lcFile::lcFile()
|
||||
{
|
||||
strcpy(FileName, "");
|
||||
}
|
||||
|
||||
File::~File ()
|
||||
lcFile::~lcFile()
|
||||
{
|
||||
}
|
||||
|
||||
void lcFile::ReadString(String& Value)
|
||||
{
|
||||
lcuint32 Length;
|
||||
ReadU32(&Length, 1);
|
||||
ReadBuffer(Value.GetBuffer(Length + 1), Length);
|
||||
((char*)Value)[Length] = 0;
|
||||
}
|
||||
|
||||
void lcFile::WriteString(const String& Value)
|
||||
{
|
||||
lcuint32 Length = Value.GetLength();
|
||||
WriteU32(Length);
|
||||
WriteBuffer((const char*)Value, Length);
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// Endian-safe functions
|
||||
// lcMemFile
|
||||
|
||||
// reads 1-byte integers
|
||||
unsigned long File::ReadByte (void* pBuf, unsigned long nCount)
|
||||
lcMemFile::lcMemFile()
|
||||
{
|
||||
return Read (pBuf, nCount);
|
||||
mGrowBytes = 1024;
|
||||
mPosition = 0;
|
||||
mBufferSize = 0;
|
||||
mFileSize = 0;
|
||||
mBuffer = NULL;
|
||||
}
|
||||
|
||||
// reads 2-byte integers
|
||||
unsigned long File::ReadShort (void* pBuf, unsigned long nCount)
|
||||
lcMemFile::~lcMemFile()
|
||||
{
|
||||
unsigned long read;
|
||||
|
||||
read = Read (pBuf, nCount*2)/2;
|
||||
|
||||
#ifdef LC_BIG_ENDIAN
|
||||
unsigned long i;
|
||||
lcuint16* val = (lcuint16*)pBuf, x;
|
||||
|
||||
for (i = 0; i < read; i++)
|
||||
{
|
||||
x = *val;
|
||||
*val = ((x>>8) | (x<<8));
|
||||
val++;
|
||||
}
|
||||
#endif
|
||||
|
||||
return read;
|
||||
Close();
|
||||
}
|
||||
|
||||
// reads 4-byte integers
|
||||
unsigned long File::ReadLong (void* pBuf, unsigned long nCount)
|
||||
void lcMemFile::Seek(long Offset, int From)
|
||||
{
|
||||
unsigned long read;
|
||||
|
||||
read = Read (pBuf, nCount*4)/4;
|
||||
|
||||
#ifdef LC_BIG_ENDIAN
|
||||
unsigned long i;
|
||||
lcuint32* val = (lcuint32*)pBuf, x;
|
||||
|
||||
for (i = 0; i < read; i++)
|
||||
{
|
||||
x = *val;
|
||||
*val = ((x>>24) | ((x>>8) & 0xff00) | ((x<<8) & 0xff0000) | (x<<24));
|
||||
val++;
|
||||
}
|
||||
#endif
|
||||
|
||||
return read;
|
||||
if (From == SEEK_SET)
|
||||
mPosition = Offset;
|
||||
else if (From == SEEK_CUR)
|
||||
mPosition += Offset;
|
||||
else if (From == SEEK_END)
|
||||
mPosition = mFileSize + Offset;
|
||||
}
|
||||
|
||||
// reads 4-byte floats
|
||||
unsigned long File::ReadFloat (void* pBuf, unsigned long nCount)
|
||||
long lcMemFile::GetPosition() const
|
||||
{
|
||||
unsigned long read;
|
||||
|
||||
read = Read (pBuf, nCount*4)/4;
|
||||
|
||||
#ifdef LC_BIG_ENDIAN
|
||||
unsigned long i;
|
||||
float* val = (float*)pBuf;
|
||||
union { unsigned char b[4]; float f; } in, out;
|
||||
|
||||
for (i = 0; i < read; i++)
|
||||
{
|
||||
in.f = *val;
|
||||
|
||||
out.b[0] = in.b[3];
|
||||
out.b[1] = in.b[2];
|
||||
out.b[2] = in.b[1];
|
||||
out.b[3] = in.b[0];
|
||||
|
||||
*val = out.f;
|
||||
val++;
|
||||
}
|
||||
#endif
|
||||
|
||||
return read;
|
||||
return mPosition;
|
||||
}
|
||||
|
||||
// reads 8-byte floats
|
||||
unsigned long File::ReadDouble (void* pBuf, unsigned long nCount)
|
||||
void lcMemFile::SetLength(size_t NewLength)
|
||||
{
|
||||
unsigned long read;
|
||||
if (NewLength > mBufferSize)
|
||||
GrowFile(NewLength);
|
||||
|
||||
read = Read (pBuf, nCount*8)/8;
|
||||
if (NewLength < mPosition)
|
||||
mPosition = NewLength;
|
||||
|
||||
#ifdef LC_BIG_ENDIAN
|
||||
unsigned long i;
|
||||
double* val = (double*)pBuf;
|
||||
union { unsigned char b[8]; double d; } in, out;
|
||||
|
||||
for (i = 0; i < read; i++)
|
||||
{
|
||||
in.d = *val;
|
||||
|
||||
out.b[0] = in.b[7];
|
||||
out.b[1] = in.b[6];
|
||||
out.b[2] = in.b[5];
|
||||
out.b[3] = in.b[4];
|
||||
out.b[4] = in.b[3];
|
||||
out.b[5] = in.b[2];
|
||||
out.b[6] = in.b[1];
|
||||
out.b[7] = in.b[0];
|
||||
|
||||
*val = out.d;
|
||||
val++;
|
||||
}
|
||||
#endif
|
||||
|
||||
return read;
|
||||
mFileSize = NewLength;
|
||||
}
|
||||
|
||||
// writes 1-byte integers
|
||||
unsigned long File::WriteByte (const void* pBuf, unsigned long nCount)
|
||||
long lcMemFile::GetLength() const
|
||||
{
|
||||
return Write (pBuf, nCount);
|
||||
return mFileSize;
|
||||
}
|
||||
|
||||
// writes 2-byte integers
|
||||
unsigned long File::WriteShort (const void* pBuf, unsigned long nCount)
|
||||
void lcMemFile::Flush()
|
||||
{
|
||||
#ifdef LC_BIG_ENDIAN
|
||||
unsigned long wrote = 0, i;
|
||||
lcuint16* val = (lcuint16*)pBuf, x;
|
||||
|
||||
for (i = 0; i < nCount; i++)
|
||||
{
|
||||
x = (((*val)>>8) | ((*val)<<8));
|
||||
val++;
|
||||
wrote += Write (&x, 2)/2;
|
||||
}
|
||||
|
||||
return wrote;
|
||||
#else
|
||||
return Write(pBuf, nCount*2)/2;
|
||||
#endif
|
||||
}
|
||||
|
||||
// writes 4-byte integers
|
||||
unsigned long File::WriteLong (const void* pBuf, unsigned long nCount)
|
||||
void lcMemFile::Close()
|
||||
{
|
||||
#ifdef LC_BIG_ENDIAN
|
||||
unsigned long wrote = 0, i;
|
||||
lcuint32* val = (lcuint32*)pBuf, x;
|
||||
if (!mBuffer)
|
||||
return;
|
||||
|
||||
for (i = 0; i < nCount; i++)
|
||||
{
|
||||
x = (((*val)>>24) | (((*val)>>8) & 0xff00) | (((*val)<<8) & 0xff0000) | ((*val)<<24));
|
||||
val++;
|
||||
wrote += Write (&x, 4)/4;
|
||||
}
|
||||
|
||||
return wrote;
|
||||
#else
|
||||
return Write (pBuf, nCount*4)/4;
|
||||
#endif
|
||||
mPosition = 0;
|
||||
mBufferSize = 0;
|
||||
mFileSize = 0;
|
||||
free(mBuffer);
|
||||
mBuffer = NULL;
|
||||
}
|
||||
|
||||
// writes 4-byte floats
|
||||
unsigned long File::WriteFloat (const void* pBuf, unsigned long nCount)
|
||||
size_t lcMemFile::ReadBuffer(void* Buffer, long Bytes)
|
||||
{
|
||||
#ifdef LC_BIG_ENDIAN
|
||||
unsigned long wrote = 0, i;
|
||||
float* val = (float*)pBuf, x;
|
||||
union { unsigned char b[4]; float f; } in, out;
|
||||
if (Bytes == 0 || mPosition > mFileSize)
|
||||
return 0;
|
||||
|
||||
for (i = 0; i < nCount; i++)
|
||||
{
|
||||
in.f = *val;
|
||||
val++;
|
||||
size_t BytesToRead;
|
||||
|
||||
out.b[0] = in.b[3];
|
||||
out.b[1] = in.b[2];
|
||||
out.b[2] = in.b[1];
|
||||
out.b[3] = in.b[0];
|
||||
x = out.f;
|
||||
if (mPosition + Bytes > mFileSize)
|
||||
BytesToRead = mFileSize - mPosition;
|
||||
else
|
||||
BytesToRead = Bytes;
|
||||
|
||||
wrote += Write (&x, 4)/4;
|
||||
}
|
||||
memcpy(Buffer, mBuffer + mPosition, BytesToRead);
|
||||
mPosition += BytesToRead;
|
||||
|
||||
return wrote;
|
||||
#else
|
||||
return Write (pBuf, nCount*4)/4;
|
||||
#endif
|
||||
return BytesToRead;
|
||||
}
|
||||
|
||||
// writes 8-byte floats
|
||||
unsigned long File::WriteDouble (const void* pBuf, unsigned long nCount)
|
||||
size_t lcMemFile::WriteBuffer(const void* Buffer, long Bytes)
|
||||
{
|
||||
#ifdef LC_BIG_ENDIAN
|
||||
unsigned long wrote = 0, i;
|
||||
double* val = (double*)pBuf, x;
|
||||
union { unsigned char b[8]; double d; } in, out;
|
||||
if (Bytes == 0)
|
||||
return 0;
|
||||
|
||||
for (i = 0; i < nCount; i++)
|
||||
{
|
||||
in.d = *val;
|
||||
val++;
|
||||
if (mPosition + Bytes > mBufferSize)
|
||||
GrowFile(mPosition + Bytes);
|
||||
|
||||
out.b[0] = in.b[7];
|
||||
out.b[1] = in.b[6];
|
||||
out.b[2] = in.b[5];
|
||||
out.b[3] = in.b[4];
|
||||
out.b[4] = in.b[3];
|
||||
out.b[5] = in.b[2];
|
||||
out.b[6] = in.b[1];
|
||||
out.b[7] = in.b[0];
|
||||
x = out.d;
|
||||
memcpy(mBuffer + mPosition, Buffer, Bytes);
|
||||
|
||||
wrote += Write (&x, 8)/8;
|
||||
}
|
||||
mPosition += Bytes;
|
||||
|
||||
return wrote;
|
||||
#else
|
||||
return Write (pBuf, nCount*8)/8;
|
||||
#endif
|
||||
if (mPosition > mFileSize)
|
||||
mFileSize = mPosition;
|
||||
|
||||
return Bytes;
|
||||
}
|
||||
|
||||
void File::ReadString(String& Value)
|
||||
void lcMemFile::GrowFile(size_t NewLength)
|
||||
{
|
||||
lcuint32 l;
|
||||
ReadInt(&l);
|
||||
Read(Value.GetBuffer(l+1), l);
|
||||
((char*)Value)[l] = 0;
|
||||
if (NewLength <= mBufferSize)
|
||||
return;
|
||||
|
||||
NewLength = ((NewLength + mGrowBytes - 1) / mGrowBytes) * mGrowBytes;
|
||||
|
||||
if (mBuffer != NULL)
|
||||
mBuffer = (unsigned char*)realloc(mBuffer, NewLength);
|
||||
else
|
||||
mBuffer = (unsigned char*)malloc(NewLength);
|
||||
|
||||
mBufferSize = NewLength;
|
||||
}
|
||||
|
||||
void File::WriteString(const String& Value)
|
||||
char* lcMemFile::ReadLine(char* Buffer, size_t BufferSize)
|
||||
{
|
||||
WriteInt(Value.GetLength());
|
||||
Write((const char*)Value, Value.GetLength());
|
||||
int BytesRead = 0;
|
||||
unsigned char ch;
|
||||
|
||||
if (BufferSize == 0)
|
||||
return NULL;
|
||||
|
||||
if (mPosition >= mFileSize)
|
||||
return NULL;
|
||||
|
||||
while ((--BufferSize))
|
||||
{
|
||||
if (mPosition == mFileSize)
|
||||
break;
|
||||
|
||||
ch = mBuffer[mPosition];
|
||||
mPosition++;
|
||||
Buffer[BytesRead++] = ch;
|
||||
|
||||
if (ch == '\n')
|
||||
break;
|
||||
}
|
||||
|
||||
Buffer[BytesRead] = 0;
|
||||
return Buffer;
|
||||
}
|
||||
|
||||
void lcMemFile::CopyFrom(lcFile& Source)
|
||||
{
|
||||
size_t Length = Source.GetLength();
|
||||
|
||||
SetLength(Length);
|
||||
Seek(0, SEEK_SET);
|
||||
|
||||
Source.Seek(0, SEEK_SET);
|
||||
Source.ReadBuffer(mBuffer, Length);
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// lcDiskFile
|
||||
|
||||
FileMem::FileMem()
|
||||
lcDiskFile::lcDiskFile()
|
||||
{
|
||||
m_nGrowBytes = 1024;
|
||||
m_nPosition = 0;
|
||||
m_nBufferSize = 0;
|
||||
m_nFileSize = 0;
|
||||
m_pBuffer = NULL;
|
||||
m_bAutoDelete = true;
|
||||
mFile = NULL;
|
||||
}
|
||||
|
||||
FileDisk::FileDisk()
|
||||
lcDiskFile::~lcDiskFile()
|
||||
{
|
||||
m_hFile = NULL;
|
||||
m_bCloseOnDelete = false;
|
||||
Close();
|
||||
}
|
||||
|
||||
FileMem::~FileMem()
|
||||
long lcDiskFile::GetPosition() const
|
||||
{
|
||||
if (m_pBuffer)
|
||||
Close();
|
||||
|
||||
m_nGrowBytes = 0;
|
||||
m_nPosition = 0;
|
||||
m_nBufferSize = 0;
|
||||
m_nFileSize = 0;
|
||||
return ftell(mFile);
|
||||
}
|
||||
|
||||
FileDisk::~FileDisk()
|
||||
void lcDiskFile::Seek(long Offset, int From)
|
||||
{
|
||||
if (m_hFile != NULL && m_bCloseOnDelete)
|
||||
Close();
|
||||
fseek(mFile, Offset, From);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// File operations
|
||||
|
||||
char* FileMem::ReadLine(char* pBuf, unsigned long nMax)
|
||||
void lcDiskFile::SetLength(size_t NewLength)
|
||||
{
|
||||
int nRead = 0;
|
||||
unsigned char ch;
|
||||
|
||||
if (nMax <= 0)
|
||||
return NULL;
|
||||
if (m_nPosition >= m_nFileSize)
|
||||
return NULL;
|
||||
|
||||
while ((--nMax))
|
||||
{
|
||||
if (m_nPosition == m_nFileSize)
|
||||
break;
|
||||
|
||||
ch = m_pBuffer[m_nPosition];
|
||||
m_nPosition++;
|
||||
pBuf[nRead++] = ch;
|
||||
|
||||
if (ch == '\n')
|
||||
break;
|
||||
}
|
||||
|
||||
pBuf[nRead] = '\0';
|
||||
return pBuf;
|
||||
fseek(mFile, NewLength, SEEK_SET);
|
||||
}
|
||||
|
||||
char* FileDisk::ReadLine(char* pBuf, unsigned long nMax)
|
||||
long lcDiskFile::GetLength() const
|
||||
{
|
||||
return fgets(pBuf, nMax, m_hFile);
|
||||
long Length, Current;
|
||||
|
||||
Current = ftell(mFile);
|
||||
fseek(mFile, 0, SEEK_END);
|
||||
Length = ftell(mFile);
|
||||
fseek(mFile, Current, SEEK_SET);
|
||||
|
||||
return Length;
|
||||
}
|
||||
|
||||
unsigned long FileMem::Read(void* pBuf, unsigned long nCount)
|
||||
void lcDiskFile::Flush()
|
||||
{
|
||||
if (nCount == 0)
|
||||
return 0;
|
||||
if (mFile == NULL)
|
||||
return;
|
||||
|
||||
if (m_nPosition > m_nFileSize)
|
||||
return 0;
|
||||
|
||||
unsigned long nRead;
|
||||
if (m_nPosition + nCount > m_nFileSize)
|
||||
nRead = (unsigned long)(m_nFileSize - m_nPosition);
|
||||
else
|
||||
nRead = nCount;
|
||||
|
||||
memcpy((unsigned char*)pBuf, (unsigned char*)m_pBuffer + m_nPosition, nRead);
|
||||
m_nPosition += nRead;
|
||||
|
||||
return nRead;
|
||||
fflush(mFile);
|
||||
}
|
||||
|
||||
unsigned long FileDisk::Read(void* pBuf, unsigned long nCount)
|
||||
void lcDiskFile::Close()
|
||||
{
|
||||
return fread(pBuf, 1, nCount, m_hFile);
|
||||
if (mFile == NULL)
|
||||
return;
|
||||
|
||||
fclose(mFile);
|
||||
mFile = NULL;
|
||||
}
|
||||
|
||||
int FileMem::GetChar()
|
||||
size_t lcDiskFile::ReadBuffer(void* pBuf, long Bytes)
|
||||
{
|
||||
if (m_nPosition > m_nFileSize)
|
||||
return EOF;
|
||||
|
||||
unsigned char* ret = (unsigned char*)m_pBuffer + m_nPosition;
|
||||
m_nPosition++;
|
||||
|
||||
return *ret;
|
||||
return fread(pBuf, 1, Bytes, mFile);
|
||||
}
|
||||
|
||||
int FileDisk::GetChar()
|
||||
size_t lcDiskFile::WriteBuffer(const void* pBuf, long Bytes)
|
||||
{
|
||||
return fgetc(m_hFile);
|
||||
return fwrite(pBuf, 1, Bytes, mFile);
|
||||
}
|
||||
|
||||
unsigned long FileMem::Write(const void* pBuf, unsigned long nCount)
|
||||
bool lcDiskFile::Open(const char* FileName, const char* Mode)
|
||||
{
|
||||
if (nCount == 0)
|
||||
return 0;
|
||||
|
||||
if (m_nPosition + nCount > m_nBufferSize)
|
||||
GrowFile(m_nPosition + nCount);
|
||||
|
||||
memcpy((unsigned char*)m_pBuffer + m_nPosition, (unsigned char*)pBuf, nCount);
|
||||
|
||||
m_nPosition += nCount;
|
||||
|
||||
if (m_nPosition > m_nFileSize)
|
||||
m_nFileSize = m_nPosition;
|
||||
|
||||
return nCount;
|
||||
}
|
||||
|
||||
unsigned long FileDisk::Write(const void* pBuf, unsigned long nCount)
|
||||
{
|
||||
return fwrite(pBuf, 1, nCount, m_hFile);
|
||||
}
|
||||
|
||||
int FileMem::PutChar(int c)
|
||||
{
|
||||
if (m_nPosition + 1 > m_nBufferSize)
|
||||
GrowFile(m_nPosition + 1);
|
||||
|
||||
unsigned char* bt = (unsigned char*)m_pBuffer + m_nPosition;
|
||||
*bt = c;
|
||||
|
||||
m_nPosition++;
|
||||
|
||||
if (m_nPosition > m_nFileSize)
|
||||
m_nFileSize = m_nPosition;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int FileDisk::PutChar(int c)
|
||||
{
|
||||
return fputc(c, m_hFile);
|
||||
}
|
||||
|
||||
bool FileDisk::Open(const char *filename, const char *mode)
|
||||
{
|
||||
if (*filename == 0)
|
||||
if (*FileName == 0)
|
||||
return false;
|
||||
|
||||
strcpy(FileName, filename);
|
||||
Close();
|
||||
|
||||
m_hFile = fopen(filename, mode);
|
||||
m_bCloseOnDelete = true;
|
||||
mFile = fopen(FileName, Mode);
|
||||
|
||||
return (m_hFile != NULL);
|
||||
return (mFile != NULL);
|
||||
}
|
||||
|
||||
void FileMem::Close()
|
||||
char* lcDiskFile::ReadLine(char* Buffer, size_t BufferSize)
|
||||
{
|
||||
m_nGrowBytes = 0;
|
||||
m_nPosition = 0;
|
||||
m_nBufferSize = 0;
|
||||
m_nFileSize = 0;
|
||||
if (m_pBuffer && m_bAutoDelete)
|
||||
free(m_pBuffer);
|
||||
m_pBuffer = NULL;
|
||||
strcpy(FileName, "");
|
||||
return fgets(Buffer, BufferSize, mFile);
|
||||
}
|
||||
|
||||
void FileDisk::Close()
|
||||
void lcDiskFile::CopyFrom(lcMemFile& Source)
|
||||
{
|
||||
if (m_hFile != NULL)
|
||||
fclose(m_hFile);
|
||||
size_t Length = Source.GetLength();
|
||||
|
||||
m_hFile = NULL;
|
||||
m_bCloseOnDelete = false;
|
||||
strcpy(FileName, "");
|
||||
}
|
||||
|
||||
unsigned long FileMem::Seek(long lOff, int nFrom)
|
||||
{
|
||||
unsigned long lNewPos = m_nPosition;
|
||||
|
||||
if (nFrom == SEEK_SET)
|
||||
lNewPos = lOff;
|
||||
else if (nFrom == SEEK_CUR)
|
||||
lNewPos += lOff;
|
||||
else if (nFrom == SEEK_END)
|
||||
lNewPos = m_nFileSize + lOff;
|
||||
else
|
||||
return (unsigned long)-1;
|
||||
|
||||
m_nPosition = lNewPos;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned long FileDisk::Seek(long lOff, int nFrom)
|
||||
{
|
||||
fseek (m_hFile, lOff, nFrom);
|
||||
|
||||
return ftell(m_hFile);
|
||||
}
|
||||
|
||||
unsigned long FileMem::GetPosition() const
|
||||
{
|
||||
return m_nPosition;
|
||||
}
|
||||
|
||||
unsigned long FileDisk::GetPosition() const
|
||||
{
|
||||
return ftell(m_hFile);
|
||||
}
|
||||
|
||||
void FileMem::GrowFile(unsigned long nNewLen)
|
||||
{
|
||||
if (nNewLen > m_nBufferSize)
|
||||
{
|
||||
// grow the buffer
|
||||
unsigned long nNewBufferSize = m_nBufferSize;
|
||||
|
||||
// determine new buffer size
|
||||
while (nNewBufferSize < nNewLen)
|
||||
nNewBufferSize += m_nGrowBytes;
|
||||
|
||||
// allocate new buffer
|
||||
unsigned char* lpNew;
|
||||
if (m_pBuffer == NULL)
|
||||
lpNew = (unsigned char*)malloc(nNewBufferSize);
|
||||
else
|
||||
lpNew = (unsigned char*)realloc(m_pBuffer, nNewBufferSize);
|
||||
|
||||
m_pBuffer = lpNew;
|
||||
m_nBufferSize = nNewBufferSize;
|
||||
}
|
||||
}
|
||||
|
||||
void FileMem::Flush()
|
||||
{
|
||||
// Nothing to be done
|
||||
}
|
||||
|
||||
void FileDisk::Flush()
|
||||
{
|
||||
if (m_hFile == NULL)
|
||||
return;
|
||||
|
||||
fflush(m_hFile);
|
||||
}
|
||||
|
||||
void FileMem::Abort()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
void FileDisk::Abort()
|
||||
{
|
||||
if (m_hFile != NULL)
|
||||
{
|
||||
// close but ignore errors
|
||||
if (m_bCloseOnDelete)
|
||||
fclose(m_hFile);
|
||||
m_hFile = NULL;
|
||||
m_bCloseOnDelete = false;
|
||||
}
|
||||
}
|
||||
|
||||
void FileMem::SetLength(unsigned long nNewLen)
|
||||
{
|
||||
if (nNewLen > m_nBufferSize)
|
||||
GrowFile(nNewLen);
|
||||
|
||||
if (nNewLen < m_nPosition)
|
||||
m_nPosition = nNewLen;
|
||||
|
||||
m_nFileSize = nNewLen;
|
||||
}
|
||||
|
||||
void FileDisk::SetLength(unsigned long nNewLen)
|
||||
{
|
||||
fseek(m_hFile, nNewLen, SEEK_SET);
|
||||
}
|
||||
|
||||
unsigned long FileMem::GetLength() const
|
||||
{
|
||||
return m_nFileSize;
|
||||
}
|
||||
|
||||
unsigned long FileDisk::GetLength() const
|
||||
{
|
||||
unsigned long nLen, nCur;
|
||||
|
||||
// Seek is a non const operation
|
||||
nCur = ftell(m_hFile);
|
||||
fseek(m_hFile, 0, SEEK_END);
|
||||
nLen = ftell(m_hFile);
|
||||
fseek(m_hFile, nCur, SEEK_SET);
|
||||
|
||||
return nLen;
|
||||
Seek(0, SEEK_SET);
|
||||
WriteBuffer(Source.mBuffer, Length);
|
||||
}
|
||||
|
|
505
common/lc_file.h
505
common/lc_file.h
|
@ -6,136 +6,427 @@
|
|||
|
||||
class String;
|
||||
|
||||
class File
|
||||
class lcFile
|
||||
{
|
||||
public:
|
||||
// Constructors
|
||||
File();
|
||||
virtual ~File();
|
||||
lcFile();
|
||||
virtual ~lcFile();
|
||||
|
||||
// Implementation
|
||||
public:
|
||||
virtual unsigned long GetPosition() const = 0;
|
||||
virtual unsigned long Seek(long lOff, int nFrom) = 0;
|
||||
virtual void SetLength(unsigned long nNewLen) = 0;
|
||||
virtual unsigned long GetLength() const = 0;
|
||||
virtual long GetPosition() const = 0;
|
||||
virtual void Seek(long Offset, int From) = 0;
|
||||
virtual void SetLength(size_t NewLength) = 0;
|
||||
virtual long GetLength() const = 0;
|
||||
|
||||
virtual char* ReadLine(char* pBuf, unsigned long nMax)=0;
|
||||
virtual unsigned long Read(void* pBuf, unsigned long nCount)=0;
|
||||
virtual unsigned long Write(const void* pBuf, unsigned long nCount)=0;
|
||||
virtual int GetChar()=0;
|
||||
virtual int PutChar(int c)=0;
|
||||
virtual void Flush() = 0;
|
||||
virtual void Close() = 0;
|
||||
|
||||
unsigned long ReadByte(void* pBuf, unsigned long nCount);
|
||||
unsigned long ReadShort(void* pBuf, unsigned long nCount);
|
||||
unsigned long ReadLong(void* pBuf, unsigned long nCount);
|
||||
unsigned long ReadFloat(void* pBuf, unsigned long nCount);
|
||||
unsigned long ReadDouble(void* pBuf, unsigned long nCount);
|
||||
unsigned long WriteByte(const void* pBuf, unsigned long nCount);
|
||||
unsigned long WriteShort(const void* pBuf, unsigned long nCount);
|
||||
unsigned long WriteLong(const void* pBuf, unsigned long nCount);
|
||||
unsigned long WriteFloat(const void* pBuf, unsigned long nCount);
|
||||
unsigned long WriteDouble(const void* pBuf, unsigned long nCount);
|
||||
virtual char* ReadLine(char* Buffer, size_t BufferSize) = 0;
|
||||
void WriteLine(const char* Buffer)
|
||||
{
|
||||
WriteBuffer(Buffer, strlen(Buffer));
|
||||
}
|
||||
|
||||
void ReadString(String& Value);
|
||||
void ReadInt(lcint32* Value)
|
||||
{ ReadLong(Value, 1); }
|
||||
void ReadInt(lcuint32* Value)
|
||||
{ ReadLong(Value, 1); }
|
||||
|
||||
void WriteString(const String& Value);
|
||||
void WriteInt(lcint32 Value)
|
||||
{ WriteLong(&Value, 1); }
|
||||
void WriteInt(lcuint32 Value)
|
||||
{ WriteLong(&Value, 1); }
|
||||
|
||||
void WriteLine(const char* pBuf)
|
||||
{ WriteByte(pBuf, strlen(pBuf)); }
|
||||
virtual size_t ReadBuffer(void* Buffer, long Bytes) = 0;
|
||||
virtual size_t WriteBuffer(const void* Buffer, long Bytes) = 0;
|
||||
|
||||
virtual void Abort()=0;
|
||||
virtual void Flush()=0;
|
||||
virtual void Close()=0;
|
||||
|
||||
const char* GetFileName() const
|
||||
{ return FileName; }
|
||||
|
||||
void SetFileName(const char* Name)
|
||||
{ strncpy(FileName, Name, LC_MAXPATH); }
|
||||
|
||||
protected:
|
||||
char FileName[LC_MAXPATH];
|
||||
};
|
||||
|
||||
class FileMem : public File
|
||||
{
|
||||
public:
|
||||
// Constructors
|
||||
FileMem();
|
||||
~FileMem();
|
||||
|
||||
// Implementation
|
||||
public:
|
||||
unsigned long GetPosition() const;
|
||||
unsigned long Seek(long lOff, int nFrom);
|
||||
void SetLength(unsigned long nNewLen);
|
||||
unsigned long GetLength() const;
|
||||
|
||||
char* ReadLine(char* pBuf, unsigned long nMax);
|
||||
unsigned long Read(void* pBuf, unsigned long nCount);
|
||||
unsigned long Write(const void* pBuf, unsigned long nCount);
|
||||
int GetChar();
|
||||
int PutChar(int c);
|
||||
|
||||
void Abort();
|
||||
void Flush();
|
||||
void Close();
|
||||
bool Open(const char *filename, const char *mode);
|
||||
|
||||
void* GetBuffer() const
|
||||
lcuint8 ReadU8()
|
||||
{
|
||||
return m_pBuffer;
|
||||
lcuint8 Value;
|
||||
Read8(&Value, 1);
|
||||
return Value;
|
||||
}
|
||||
|
||||
size_t ReadU8(lcuint8* Buffer, size_t Count)
|
||||
{
|
||||
return Read8(Buffer, Count);
|
||||
}
|
||||
|
||||
lcint8 ReadS8()
|
||||
{
|
||||
lcint8 Value;
|
||||
Read8(&Value, 1);
|
||||
return Value;
|
||||
}
|
||||
|
||||
size_t ReadS8(lcint8* Buffer, size_t Count)
|
||||
{
|
||||
return Read8(Buffer, Count);
|
||||
}
|
||||
|
||||
lcuint16 ReadU16()
|
||||
{
|
||||
lcuint16 Value;
|
||||
Read16(&Value, 1);
|
||||
return Value;
|
||||
}
|
||||
|
||||
size_t ReadU16(lcuint16* Buffer, size_t Count)
|
||||
{
|
||||
return Read16(Buffer, Count);
|
||||
}
|
||||
|
||||
lcint16 ReadS16()
|
||||
{
|
||||
lcint16 Value;
|
||||
Read16(&Value, 1);
|
||||
return Value;
|
||||
}
|
||||
|
||||
size_t ReadS16(lcint16* Buffer, size_t Count)
|
||||
{
|
||||
return Read16(Buffer, Count);
|
||||
}
|
||||
|
||||
lcuint32 ReadU32()
|
||||
{
|
||||
lcuint32 Value;
|
||||
Read32(&Value, 1);
|
||||
return Value;
|
||||
}
|
||||
|
||||
size_t ReadU32(lcuint32* Buffer, size_t Count)
|
||||
{
|
||||
return Read32(Buffer, Count);
|
||||
}
|
||||
|
||||
lcint32 ReadS32()
|
||||
{
|
||||
lcint32 Value;
|
||||
Read32(&Value, 1);
|
||||
return Value;
|
||||
}
|
||||
|
||||
size_t ReadS32(lcint32* Buffer, size_t Count)
|
||||
{
|
||||
return Read32(Buffer, Count);
|
||||
}
|
||||
|
||||
float ReadFloat()
|
||||
{
|
||||
float Value;
|
||||
Read32(&Value, 1);
|
||||
return Value;
|
||||
}
|
||||
|
||||
size_t ReadFloats(float* Buffer, size_t Count)
|
||||
{
|
||||
return Read32(Buffer, Count);
|
||||
}
|
||||
|
||||
double ReadDouble()
|
||||
{
|
||||
double Value;
|
||||
Read64(&Value, 1);
|
||||
return Value;
|
||||
}
|
||||
|
||||
size_t ReadDoubles(double* Buffer, size_t Count)
|
||||
{
|
||||
return Read64(Buffer, Count);
|
||||
}
|
||||
|
||||
void WriteU8(const lcuint8& Value)
|
||||
{
|
||||
Write8(&Value, 1);
|
||||
}
|
||||
|
||||
size_t WriteU8(const lcuint8* Buffer, size_t Count)
|
||||
{
|
||||
return Write8(Buffer, Count);
|
||||
}
|
||||
|
||||
void WriteS8(const lcint8& Value)
|
||||
{
|
||||
Write8(&Value, 1);
|
||||
}
|
||||
|
||||
size_t WriteS8(const lcint8* Buffer, size_t Count)
|
||||
{
|
||||
return Write8(Buffer, Count);
|
||||
}
|
||||
|
||||
void WriteU16(const lcuint16& Value)
|
||||
{
|
||||
Write16(&Value, 1);
|
||||
}
|
||||
|
||||
size_t WriteU16(const lcuint16* Buffer, size_t Count)
|
||||
{
|
||||
return Write16(Buffer, Count);
|
||||
}
|
||||
|
||||
void WriteS16(const lcint16& Value)
|
||||
{
|
||||
Write16(&Value, 1);
|
||||
}
|
||||
|
||||
size_t WriteS16(const lcint16* Buffer, size_t Count)
|
||||
{
|
||||
return Write16(Buffer, Count);
|
||||
}
|
||||
|
||||
void WriteU32(const lcuint32& Value)
|
||||
{
|
||||
Write32(&Value, 1);
|
||||
}
|
||||
|
||||
size_t WriteU32(const lcuint32* Buffer, size_t Count)
|
||||
{
|
||||
return Write32(Buffer, Count);
|
||||
}
|
||||
|
||||
void WriteS32(const lcint32& Value)
|
||||
{
|
||||
Write32(&Value, 1);
|
||||
}
|
||||
|
||||
size_t WriteS32(const lcint32* Buffer, size_t Count)
|
||||
{
|
||||
return Write32(Buffer, Count);
|
||||
}
|
||||
|
||||
void WriteFloat(const float& Value)
|
||||
{
|
||||
Write32(&Value, 1);
|
||||
}
|
||||
|
||||
size_t WriteFloats(const float* Buffer, size_t Count)
|
||||
{
|
||||
return Write32(Buffer, Count);
|
||||
}
|
||||
|
||||
void WriteDouble(const double& Value)
|
||||
{
|
||||
Write64(&Value, 1);
|
||||
}
|
||||
|
||||
size_t WriteDoubles(const double* Buffer, size_t Count)
|
||||
{
|
||||
return Write64(Buffer, Count);
|
||||
}
|
||||
|
||||
protected:
|
||||
// MemFile specific:
|
||||
unsigned long m_nGrowBytes;
|
||||
unsigned long m_nPosition;
|
||||
unsigned long m_nBufferSize;
|
||||
unsigned long m_nFileSize;
|
||||
unsigned char* m_pBuffer;
|
||||
bool m_bAutoDelete;
|
||||
void GrowFile(unsigned long nNewLen);
|
||||
size_t Read8(void* Buffer, size_t Count)
|
||||
{
|
||||
return ReadBuffer(Buffer, Count);
|
||||
}
|
||||
|
||||
size_t Read16(void* Buffer, size_t Count)
|
||||
{
|
||||
size_t NumRead;
|
||||
|
||||
NumRead = ReadBuffer(Buffer, Count * 2) / 2;
|
||||
|
||||
#ifdef LC_BIG_ENDIAN
|
||||
lcuint8 Temp[2];
|
||||
lcuint8* Bytes = (lcuint8*)Buffer;
|
||||
|
||||
for (size_t Idx = 0; Idx < NumRead; Idx++)
|
||||
{
|
||||
Temp[0] = Bytes[0];
|
||||
Temp[1] = Bytes[1];
|
||||
|
||||
*Bytes++ = Temp[1];
|
||||
*Bytes++ = Temp[0];
|
||||
}
|
||||
#endif
|
||||
|
||||
return NumRead;
|
||||
}
|
||||
|
||||
size_t Read32(void* Buffer, size_t Count)
|
||||
{
|
||||
size_t NumRead;
|
||||
|
||||
NumRead = ReadBuffer(Buffer, Count * 4) / 4;
|
||||
|
||||
#ifdef LC_BIG_ENDIAN
|
||||
lcuint8 Temp[4];
|
||||
lcuint8* Bytes = (lcuint8*)Buffer;
|
||||
|
||||
for (size_t Idx = 0; Idx < NumRead; Idx++)
|
||||
{
|
||||
Temp[0] = Bytes[0];
|
||||
Temp[1] = Bytes[1];
|
||||
Temp[2] = Bytes[2];
|
||||
Temp[3] = Bytes[3];
|
||||
|
||||
*Bytes++ = Temp[3];
|
||||
*Bytes++ = Temp[2];
|
||||
*Bytes++ = Temp[1];
|
||||
*Bytes++ = Temp[0];
|
||||
}
|
||||
#endif
|
||||
|
||||
return NumRead;
|
||||
}
|
||||
|
||||
size_t Read64(void* Buffer, size_t Count)
|
||||
{
|
||||
size_t NumRead;
|
||||
|
||||
NumRead = ReadBuffer(Buffer, Count * 8) / 8;
|
||||
|
||||
#ifdef LC_BIG_ENDIAN
|
||||
lcuint8 Temp[8];
|
||||
lcuint8* Bytes = (lcuint8*)Buffer;
|
||||
|
||||
for (size_t Idx = 0; Idx < NumRead; Idx++)
|
||||
{
|
||||
Temp[0] = Bytes[0];
|
||||
Temp[1] = Bytes[1];
|
||||
Temp[2] = Bytes[2];
|
||||
Temp[3] = Bytes[3];
|
||||
Temp[4] = Bytes[4];
|
||||
Temp[5] = Bytes[5];
|
||||
Temp[6] = Bytes[6];
|
||||
Temp[7] = Bytes[7];
|
||||
|
||||
*Bytes++ = Temp[7];
|
||||
*Bytes++ = Temp[6];
|
||||
*Bytes++ = Temp[5];
|
||||
*Bytes++ = Temp[4];
|
||||
*Bytes++ = Temp[3];
|
||||
*Bytes++ = Temp[2];
|
||||
*Bytes++ = Temp[1];
|
||||
*Bytes++ = Temp[0];
|
||||
}
|
||||
#endif
|
||||
|
||||
return NumRead;
|
||||
}
|
||||
|
||||
size_t Write8(const void* Buffer, size_t Count)
|
||||
{
|
||||
return WriteBuffer(Buffer, Count);
|
||||
}
|
||||
|
||||
size_t Write16(const void* Buffer, size_t Count)
|
||||
{
|
||||
#ifdef LC_BIG_ENDIAN
|
||||
size_t BytesWritten = 0;
|
||||
lcuint8 Temp[2];
|
||||
lcuint8* Bytes = (lcuint8*)Buffer;
|
||||
|
||||
for (size_t Idx = 0; Idx < NumRead; Idx++)
|
||||
{
|
||||
Temp[1] = *Buffer++;
|
||||
Temp[0] = *Buffer++;
|
||||
|
||||
BytesWritten += WriteBuffer(&Temp, 2);
|
||||
}
|
||||
|
||||
return BytesWritten / 2;
|
||||
#else
|
||||
return WriteBuffer(Buffer, Count * 2) / 2;
|
||||
#endif
|
||||
}
|
||||
|
||||
size_t Write32(const void* Buffer, size_t Count)
|
||||
{
|
||||
#ifdef LC_BIG_ENDIAN
|
||||
size_t BytesWritten = 0;
|
||||
lcuint8 Temp[4];
|
||||
lcuint8* Bytes = (lcuint8*)Buffer;
|
||||
|
||||
for (size_t Idx = 0; Idx < NumRead; Idx++)
|
||||
{
|
||||
Temp[3] = *Buffer++;
|
||||
Temp[2] = *Buffer++;
|
||||
Temp[1] = *Buffer++;
|
||||
Temp[0] = *Buffer++;
|
||||
|
||||
BytesWritten += WriteBuffer(&Temp, 4);
|
||||
}
|
||||
|
||||
return BytesWritten / 4;
|
||||
#else
|
||||
return WriteBuffer(Buffer, Count * 4);
|
||||
#endif
|
||||
}
|
||||
|
||||
size_t Write64(const void* Buffer, size_t Count)
|
||||
{
|
||||
#ifdef LC_BIG_ENDIAN
|
||||
size_t BytesWritten = 0;
|
||||
lcuint8 Temp[8];
|
||||
lcuint8* Bytes = (lcuint8*)Buffer;
|
||||
|
||||
for (size_t Idx = 0; Idx < NumRead; Idx++)
|
||||
{
|
||||
Temp[7] = *Buffer++;
|
||||
Temp[6] = *Buffer++;
|
||||
Temp[5] = *Buffer++;
|
||||
Temp[4] = *Buffer++;
|
||||
Temp[3] = *Buffer++;
|
||||
Temp[2] = *Buffer++;
|
||||
Temp[1] = *Buffer++;
|
||||
Temp[0] = *Buffer++;
|
||||
|
||||
BytesWritten += WriteBuffer(&Temp, 8);
|
||||
}
|
||||
|
||||
return BytesWritten / 8;
|
||||
#else
|
||||
return WriteBuffer(Buffer, Count * 8);
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
class FileDisk : public File
|
||||
class lcMemFile : public lcFile
|
||||
{
|
||||
public:
|
||||
// Constructors
|
||||
FileDisk();
|
||||
~FileDisk();
|
||||
lcMemFile();
|
||||
virtual ~lcMemFile();
|
||||
|
||||
// Implementation
|
||||
public:
|
||||
unsigned long GetPosition() const;
|
||||
unsigned long Seek(long lOff, int nFrom);
|
||||
void SetLength(unsigned long nNewLen);
|
||||
unsigned long GetLength() const;
|
||||
long GetPosition() const;
|
||||
void Seek(long Offset, int From);
|
||||
void SetLength(size_t NewLength);
|
||||
long GetLength() const;
|
||||
|
||||
char* ReadLine(char* pBuf, unsigned long nMax);
|
||||
unsigned long Read(void* pBuf, unsigned long nCount);
|
||||
unsigned long Write(const void* pBuf, unsigned long nCount);
|
||||
int GetChar();
|
||||
int PutChar(int c);
|
||||
|
||||
void Abort();
|
||||
void Flush();
|
||||
void Close();
|
||||
bool Open(const char *filename, const char *mode);
|
||||
|
||||
protected:
|
||||
// DiscFile specific:
|
||||
FILE* m_hFile;
|
||||
bool m_bCloseOnDelete;
|
||||
char* ReadLine(char* Buffer, size_t BufferSize);
|
||||
size_t ReadBuffer(void* Buffer, long Bytes);
|
||||
size_t WriteBuffer(const void* Buffer, long Bytes);
|
||||
|
||||
void CopyFrom(lcFile& Source);
|
||||
void GrowFile(size_t NewLength);
|
||||
|
||||
size_t mGrowBytes;
|
||||
size_t mPosition;
|
||||
size_t mBufferSize;
|
||||
size_t mFileSize;
|
||||
unsigned char* mBuffer;
|
||||
};
|
||||
|
||||
class lcDiskFile : public lcFile
|
||||
{
|
||||
public:
|
||||
lcDiskFile();
|
||||
virtual ~lcDiskFile();
|
||||
|
||||
long GetPosition() const;
|
||||
void Seek(long Offset, int From);
|
||||
void SetLength(size_t NewLength);
|
||||
long GetLength() const;
|
||||
|
||||
void Flush();
|
||||
void Close();
|
||||
|
||||
char* ReadLine(char* Buffer, size_t BufferSize);
|
||||
size_t ReadBuffer(void* Buffer, long Bytes);
|
||||
size_t WriteBuffer(const void* Buffer, long Bytes);
|
||||
|
||||
void CopyFrom(lcMemFile& Source);
|
||||
|
||||
bool Open(const char* FileName, const char* Mode);
|
||||
|
||||
FILE* mFile;
|
||||
};
|
||||
|
||||
#endif // _FILE_H_
|
||||
|
|
|
@ -14,4 +14,9 @@
|
|||
#include "stdafx.h"
|
||||
#endif
|
||||
|
||||
// Forward declarations.
|
||||
class lcFile;
|
||||
class lcMemFile;
|
||||
class lcDiskFile;
|
||||
|
||||
#endif // _LC_GLOBAL_H_
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -4,8 +4,6 @@
|
|||
#include "str.h"
|
||||
#include "array.h"
|
||||
|
||||
class File;
|
||||
class FileDisk;
|
||||
class Texture;
|
||||
class PieceInfo;
|
||||
|
||||
|
@ -88,7 +86,7 @@ public:
|
|||
bool LoadUpdate(const char* update);
|
||||
bool DeleteTextures(char** Names, int NumTextures);
|
||||
bool ImportTexture(const char* Name);
|
||||
bool ImportLDrawPiece(const char* Filename, File* NewIdxFile, File* NewBinFile, File* OldIdxFile, File* OldBinFile);
|
||||
bool ImportLDrawPiece(const char* Filename, lcFile* NewIdxFile, lcFile* NewBinFile, lcFile* OldIdxFile, lcFile* OldBinFile);
|
||||
|
||||
// Set when pieces are added/removed from the library.
|
||||
bool m_Modified;
|
||||
|
@ -109,8 +107,8 @@ protected:
|
|||
bool m_CategoriesModified;
|
||||
char m_CategoriesFile[LC_MAXPATH];
|
||||
|
||||
bool ValidatePiecesFile(FileDisk& IdxFile, FileDisk& BinFile) const;
|
||||
bool ValidateTexturesFile(File& IdxFile, File& BinFile) const;
|
||||
bool ValidatePiecesFile(lcFile& IdxFile, lcFile& BinFile) const;
|
||||
bool ValidateTexturesFile(lcFile& IdxFile, lcFile& BinFile) const;
|
||||
|
||||
// File headers
|
||||
static const char PiecesBinHeader[32];
|
||||
|
@ -173,7 +171,7 @@ struct LC_LDRAW_PIECE
|
|||
};
|
||||
|
||||
bool ReadLDrawPiece(const char* filename, LC_LDRAW_PIECE* piece);
|
||||
bool SaveLDrawPiece(LC_LDRAW_PIECE* piece, File* NewIdxFile, File* NewBinFile, File* OldIdxFile, File* OldBinFile);
|
||||
bool SaveLDrawPiece(LC_LDRAW_PIECE* piece, lcFile* NewIdxFile, lcFile* NewBinFile, lcFile* OldIdxFile, lcFile* OldBinFile);
|
||||
void FreeLDrawPiece(LC_LDRAW_PIECE* piece);
|
||||
|
||||
#endif // _LIBRARY_H_
|
||||
|
|
|
@ -792,15 +792,15 @@ MinifigWizard::MinifigWizard (GLWindow *share)
|
|||
strcpy(Filename, lcGetPiecesLibrary()->GetLibraryPath());
|
||||
strcat(Filename, "mlcad.ini");
|
||||
|
||||
FileDisk DiskSettings;
|
||||
lcDiskFile DiskSettings;
|
||||
if (DiskSettings.Open(Filename, "rt"))
|
||||
{
|
||||
ParseSettings(DiskSettings);
|
||||
}
|
||||
else
|
||||
{
|
||||
FileMem MemSettings;
|
||||
MemSettings.Write(DefaultSettings, strlen(DefaultSettings)+1);
|
||||
lcMemFile MemSettings;
|
||||
MemSettings.WriteBuffer(DefaultSettings, strlen(DefaultSettings)+1);
|
||||
ParseSettings(MemSettings);
|
||||
}
|
||||
|
||||
|
@ -933,7 +933,7 @@ MinifigWizard::~MinifigWizard ()
|
|||
m_Info[i]->DeRef();
|
||||
}
|
||||
|
||||
void MinifigWizard::ParseSettings(File& Settings)
|
||||
void MinifigWizard::ParseSettings(lcFile& Settings)
|
||||
{
|
||||
const char* SectionNames[LC_MFW_NUMITEMS] =
|
||||
{
|
||||
|
|
|
@ -54,7 +54,7 @@ public:
|
|||
bool LoadMinifig (const char* name);
|
||||
void DeleteMinifig (const char* name);
|
||||
|
||||
void ParseSettings(class File& Settings);
|
||||
void ParseSettings(lcFile& Settings);
|
||||
|
||||
ObjArray<lcMinifigPieceInfo> mSettings[LC_MFW_NUMITEMS];
|
||||
|
||||
|
|
|
@ -79,11 +79,10 @@ Object::~Object ()
|
|||
RemoveKeys ();
|
||||
}
|
||||
|
||||
bool Object::FileLoad (File& file)
|
||||
bool Object::FileLoad(lcFile& file)
|
||||
{
|
||||
lcuint8 version;
|
||||
lcuint8 version = file.ReadU8();
|
||||
|
||||
file.ReadByte (&version, 1);
|
||||
if (version > LC_KEY_SAVE_VERSION)
|
||||
return false;
|
||||
|
||||
|
@ -92,22 +91,22 @@ bool Object::FileLoad (File& file)
|
|||
lcuint8 type;
|
||||
lcuint32 n;
|
||||
|
||||
file.ReadLong (&n, 1);
|
||||
file.ReadU32(&n, 1);
|
||||
while (n--)
|
||||
{
|
||||
file.ReadShort (&time, 1);
|
||||
file.ReadFloat (param, 4);
|
||||
file.ReadByte (&type, 1);
|
||||
file.ReadU16(&time, 1);
|
||||
file.ReadFloats(param, 4);
|
||||
file.ReadU8(&type, 1);
|
||||
|
||||
ChangeKey (time, false, true, param, type);
|
||||
}
|
||||
|
||||
file.ReadLong (&n, 1);
|
||||
file.ReadU32(&n, 1);
|
||||
while (n--)
|
||||
{
|
||||
file.ReadShort (&time, 1);
|
||||
file.ReadFloat (param, 4);
|
||||
file.ReadByte (&type, 1);
|
||||
file.ReadU16(&time, 1);
|
||||
file.ReadFloats(param, 4);
|
||||
file.ReadU8(&type, 1);
|
||||
|
||||
ChangeKey (time, true, true, param, type);
|
||||
}
|
||||
|
@ -115,34 +114,33 @@ bool Object::FileLoad (File& file)
|
|||
return true;
|
||||
}
|
||||
|
||||
void Object::FileSave (File& file) const
|
||||
void Object::FileSave(lcFile& file) const
|
||||
{
|
||||
lcuint8 version = LC_KEY_SAVE_VERSION;
|
||||
LC_OBJECT_KEY *node;
|
||||
lcuint32 n;
|
||||
|
||||
file.WriteByte (&version, 1);
|
||||
file.WriteU8(LC_KEY_SAVE_VERSION);
|
||||
|
||||
for (n = 0, node = m_pInstructionKeys; node; node = node->next)
|
||||
n++;
|
||||
file.WriteLong (&n, 1);
|
||||
file.WriteU32(n);
|
||||
|
||||
for (node = m_pInstructionKeys; node; node = node->next)
|
||||
{
|
||||
file.WriteShort (&node->time, 1);
|
||||
file.WriteFloat (node->param, 4);
|
||||
file.WriteByte (&node->type, 1);
|
||||
file.WriteU16(node->time);
|
||||
file.WriteFloats(node->param, 4);
|
||||
file.WriteU8(node->type);
|
||||
}
|
||||
|
||||
for (n = 0, node = m_pAnimationKeys; node; node = node->next)
|
||||
n++;
|
||||
file.WriteLong (&n, 1);
|
||||
file.WriteU32(n);
|
||||
|
||||
for (node = m_pAnimationKeys; node; node = node->next)
|
||||
{
|
||||
file.WriteShort (&node->time, 1);
|
||||
file.WriteFloat (node->param, 4);
|
||||
file.WriteByte (&node->type, 1);
|
||||
file.WriteU16(node->time);
|
||||
file.WriteFloats(node->param, 4);
|
||||
file.WriteU8(node->type);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#ifndef _OBJECT_H_
|
||||
#define _OBJECT_H_
|
||||
|
||||
class File;
|
||||
class Matrix;
|
||||
class Object;
|
||||
/*
|
||||
|
@ -158,8 +157,8 @@ public:
|
|||
// Str m_strName;
|
||||
// unsigned char m_nState;
|
||||
|
||||
virtual bool FileLoad (File& file);
|
||||
virtual void FileSave (File& file) const;
|
||||
virtual bool FileLoad(lcFile& file);
|
||||
virtual void FileSave(lcFile& file) const;
|
||||
|
||||
|
||||
// Key handling stuff
|
||||
|
|
137
common/piece.cpp
137
common/piece.cpp
|
@ -149,11 +149,11 @@ void Piece::SetPieceInfo(PieceInfo* pPieceInfo)
|
|||
}
|
||||
}
|
||||
|
||||
bool Piece::FileLoad (File& file, char* name)
|
||||
bool Piece::FileLoad(lcFile& file, char* name)
|
||||
{
|
||||
unsigned char version, ch;
|
||||
lcuint8 version, ch;
|
||||
|
||||
file.ReadByte (&version, 1);
|
||||
version = file.ReadU8();
|
||||
|
||||
if (version > LC_PIECE_SAVE_VERSION)
|
||||
return false;
|
||||
|
@ -166,28 +166,28 @@ bool Piece::FileLoad (File& file, char* name)
|
|||
{
|
||||
lcuint16 time;
|
||||
float param[4];
|
||||
unsigned char type;
|
||||
lcuint8 type;
|
||||
|
||||
if (version > 5)
|
||||
{
|
||||
lcuint32 keys;
|
||||
|
||||
file.ReadLong (&keys, 1);
|
||||
file.ReadU32(&keys, 1);
|
||||
while (keys--)
|
||||
{
|
||||
file.ReadFloat (param, 4);
|
||||
file.ReadShort (&time, 1);
|
||||
file.ReadByte (&type, 1);
|
||||
file.ReadFloats(param, 4);
|
||||
file.ReadU16(&time, 1);
|
||||
file.ReadU8(&type, 1);
|
||||
|
||||
ChangeKey (time, false, true, param, type);
|
||||
}
|
||||
|
||||
file.ReadLong (&keys, 1);
|
||||
file.ReadU32(&keys, 1);
|
||||
while (keys--)
|
||||
{
|
||||
file.ReadFloat (param, 4);
|
||||
file.ReadShort (&time, 1);
|
||||
file.ReadByte (&type, 1);
|
||||
file.ReadFloats(param, 4);
|
||||
file.ReadU16(&time, 1);
|
||||
file.ReadU8(&type, 1);
|
||||
|
||||
ChangeKey (time, true, true, param, type);
|
||||
}
|
||||
|
@ -196,7 +196,7 @@ bool Piece::FileLoad (File& file, char* name)
|
|||
{
|
||||
if (version > 2)
|
||||
{
|
||||
file.Read (&ch, 1);
|
||||
file.ReadU8(&ch, 1);
|
||||
|
||||
while (ch--)
|
||||
{
|
||||
|
@ -204,19 +204,19 @@ bool Piece::FileLoad (File& file, char* name)
|
|||
if (version > 3)
|
||||
{
|
||||
float m[16];
|
||||
file.ReadFloat (m, 16);
|
||||
file.ReadFloats(m, 16);
|
||||
mat.FromFloat (m);
|
||||
}
|
||||
else
|
||||
{
|
||||
float move[3], rotate[3];
|
||||
file.ReadFloat (move, 3);
|
||||
file.ReadFloat (rotate, 3);
|
||||
file.ReadFloats(move, 3);
|
||||
file.ReadFloats(rotate, 3);
|
||||
mat.CreateOld (move[0], move[1], move[2], rotate[0], rotate[1], rotate[2]);
|
||||
}
|
||||
|
||||
unsigned char b;
|
||||
file.ReadByte(&b, 1);
|
||||
lcuint8 b;
|
||||
file.ReadU8(&b, 1);
|
||||
time = b;
|
||||
|
||||
mat.GetTranslation(¶m[0], ¶m[1], ¶m[2]);
|
||||
|
@ -228,16 +228,16 @@ bool Piece::FileLoad (File& file, char* name)
|
|||
ChangeKey (time, false, true, param, LC_PK_ROTATION);
|
||||
ChangeKey (time, true, true, param, LC_PK_ROTATION);
|
||||
|
||||
int bl;
|
||||
file.ReadLong (&bl, 1);
|
||||
lcint32 bl;
|
||||
file.ReadS32(&bl, 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Matrix mat;
|
||||
float move[3], rotate[3];
|
||||
file.ReadFloat (move, 3);
|
||||
file.ReadFloat (rotate, 3);
|
||||
file.ReadFloats(move, 3);
|
||||
file.ReadFloats(rotate, 3);
|
||||
mat.CreateOld (move[0], move[1], move[2], rotate[0], rotate[1], rotate[2]);
|
||||
|
||||
mat.GetTranslation(¶m[0], ¶m[1], ¶m[2]);
|
||||
|
@ -256,11 +256,11 @@ bool Piece::FileLoad (File& file, char* name)
|
|||
if (version < 10)
|
||||
{
|
||||
memset(name, 0, LC_PIECE_NAME_LEN);
|
||||
file.Read(name, 9);
|
||||
file.ReadBuffer(name, 9);
|
||||
}
|
||||
else
|
||||
file.Read(name, LC_PIECE_NAME_LEN);
|
||||
file.ReadByte(&m_nColor, 1);
|
||||
file.ReadBuffer(name, LC_PIECE_NAME_LEN);
|
||||
file.ReadU8(&m_nColor, 1);
|
||||
|
||||
if (version < 5)
|
||||
{
|
||||
|
@ -268,37 +268,37 @@ bool Piece::FileLoad (File& file, char* name)
|
|||
m_nColor = conv[m_nColor];
|
||||
}
|
||||
|
||||
file.ReadByte(&m_nStepShow, 1);
|
||||
file.ReadU8(&m_nStepShow, 1);
|
||||
if (version > 1)
|
||||
file.ReadByte(&m_nStepHide, 1);
|
||||
file.ReadU8(&m_nStepHide, 1);
|
||||
else
|
||||
m_nStepHide = 255;
|
||||
|
||||
if (version > 5)
|
||||
{
|
||||
file.ReadShort(&m_nFrameShow, 1);
|
||||
file.ReadShort(&m_nFrameHide, 1);
|
||||
file.ReadU16(&m_nFrameShow, 1);
|
||||
file.ReadU16(&m_nFrameHide, 1);
|
||||
|
||||
if (version > 7)
|
||||
{
|
||||
file.ReadByte(&m_nState, 1);
|
||||
file.ReadU8(&m_nState, 1);
|
||||
Select (false, false, false);
|
||||
file.ReadByte(&ch, 1);
|
||||
file.Read(m_strName, ch);
|
||||
file.ReadU8(&ch, 1);
|
||||
file.ReadBuffer(m_strName, ch);
|
||||
}
|
||||
else
|
||||
{
|
||||
int hide;
|
||||
file.ReadLong(&hide, 1);
|
||||
lcint32 hide;
|
||||
file.ReadS32(&hide, 1);
|
||||
if (hide != 0)
|
||||
m_nState |= LC_PIECE_HIDDEN;
|
||||
file.Read(m_strName, 81);
|
||||
file.ReadBuffer(m_strName, 81);
|
||||
}
|
||||
|
||||
// 7 (0.64)
|
||||
int i = -1;
|
||||
lcint32 i = -1;
|
||||
if (version > 6)
|
||||
file.ReadLong(&i, 1);
|
||||
file.ReadS32(&i, 1);
|
||||
m_pGroup = (Group*)i;
|
||||
}
|
||||
else
|
||||
|
@ -306,13 +306,13 @@ bool Piece::FileLoad (File& file, char* name)
|
|||
m_nFrameShow = 1;
|
||||
m_nFrameHide = 65535;
|
||||
|
||||
file.ReadByte(&ch, 1);
|
||||
file.ReadU8(&ch, 1);
|
||||
if (ch == 0)
|
||||
m_pGroup = (Group*)-1;
|
||||
else
|
||||
m_pGroup = (Group*)(lcuint32)ch;
|
||||
|
||||
file.ReadByte(&ch, 1);
|
||||
file.ReadU8(&ch, 1);
|
||||
if (ch & 0x01)
|
||||
m_nState |= LC_PIECE_HIDDEN;
|
||||
}
|
||||
|
@ -320,41 +320,42 @@ bool Piece::FileLoad (File& file, char* name)
|
|||
return true;
|
||||
}
|
||||
|
||||
void Piece::FileSave (File& file, Group* pGroups)
|
||||
void Piece::FileSave(lcFile& file, Group* pGroups)
|
||||
{
|
||||
unsigned char ch = LC_PIECE_SAVE_VERSION;
|
||||
file.WriteU8(LC_PIECE_SAVE_VERSION);
|
||||
|
||||
file.WriteByte (&ch, 1);
|
||||
Object::FileSave (file);
|
||||
|
||||
Object::FileSave (file);
|
||||
file.WriteBuffer(m_pPieceInfo->m_strName, LC_PIECE_NAME_LEN);
|
||||
file.WriteU8(m_nColor);
|
||||
file.WriteU8(m_nStepShow);
|
||||
file.WriteU8(m_nStepHide);
|
||||
file.WriteU16(m_nFrameShow);
|
||||
file.WriteU16(m_nFrameHide);
|
||||
|
||||
file.Write(m_pPieceInfo->m_strName, LC_PIECE_NAME_LEN);
|
||||
file.WriteByte(&m_nColor, 1);
|
||||
file.WriteByte(&m_nStepShow, 1);
|
||||
file.WriteByte(&m_nStepHide, 1);
|
||||
file.WriteShort(&m_nFrameShow, 1);
|
||||
file.WriteShort(&m_nFrameHide, 1);
|
||||
// version 8
|
||||
file.WriteU8(m_nState);
|
||||
|
||||
// version 8
|
||||
file.WriteByte(&m_nState, 1);
|
||||
ch = strlen(m_strName);
|
||||
file.WriteByte(&ch, 1);
|
||||
file.Write(m_strName, ch);
|
||||
lcuint8 Length = strlen(m_strName);
|
||||
file.WriteU8(Length);
|
||||
file.WriteBuffer(m_strName, Length);
|
||||
|
||||
// version 7
|
||||
int i;
|
||||
if (m_pGroup != NULL)
|
||||
{
|
||||
for (i = 0; pGroups; pGroups = pGroups->m_pNext)
|
||||
{
|
||||
if (m_pGroup == pGroups)
|
||||
break;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
else
|
||||
i = -1;
|
||||
file.WriteLong(&i, 1);
|
||||
// version 7
|
||||
lcint32 i;
|
||||
|
||||
if (m_pGroup != NULL)
|
||||
{
|
||||
for (i = 0; pGroups; pGroups = pGroups->m_pNext)
|
||||
{
|
||||
if (m_pGroup == pGroups)
|
||||
break;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
else
|
||||
i = -1;
|
||||
|
||||
file.WriteS32(i);
|
||||
}
|
||||
|
||||
void Piece::Initialize(float x, float y, float z, unsigned char nStep, unsigned short nFrame, unsigned char nColor)
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#ifndef _PIECE_H_
|
||||
#define _PIECE_H_
|
||||
|
||||
class File;
|
||||
class Piece;
|
||||
class Group;
|
||||
class PieceInfo;
|
||||
|
@ -61,8 +60,8 @@ public:
|
|||
void RemoveConnections(CONNECTION_TYPE* pConnections);
|
||||
void CompareBoundingBox(float box[6]);
|
||||
void SetPieceInfo(PieceInfo* pPieceInfo);
|
||||
bool FileLoad(File& file, char* name);
|
||||
void FileSave(File& file, Group* pGroups);
|
||||
bool FileLoad(lcFile& file, char* name);
|
||||
void FileSave(lcFile& file, Group* pGroups);
|
||||
|
||||
void CalculateConnections(CONNECTION_TYPE* pConnections, unsigned short nTime, bool bAnimation, bool bForceRebuild, bool bFixOthers);
|
||||
void UpdatePosition(unsigned short nTime, bool bAnimation);
|
||||
|
|
|
@ -189,7 +189,7 @@ PieceInfo::~PieceInfo ()
|
|||
/////////////////////////////////////////////////////////////////////////////
|
||||
// File I/O
|
||||
|
||||
void PieceInfo::LoadIndex (File& file)
|
||||
void PieceInfo::LoadIndex(lcFile& file)
|
||||
{
|
||||
static bool init = false;
|
||||
short sh[6];
|
||||
|
@ -218,14 +218,14 @@ void PieceInfo::LoadIndex (File& file)
|
|||
m_pTextures = NULL;
|
||||
m_nBoxList = 0;
|
||||
|
||||
file.Read (m_strName, LC_PIECE_NAME_LEN);
|
||||
file.Read (m_strDescription, 64);
|
||||
file.ReadBuffer(m_strName, LC_PIECE_NAME_LEN);
|
||||
file.ReadBuffer(m_strDescription, 64);
|
||||
m_strDescription[64] = '\0';
|
||||
file.ReadShort (sh, 6);
|
||||
file.ReadByte (&m_nFlags, 1);
|
||||
lcuint32 Groups; file.ReadLong (&Groups, 1);
|
||||
file.ReadLong (&m_nOffset, 1);
|
||||
file.ReadLong (&m_nSize, 1);
|
||||
file.ReadS16(sh, 6);
|
||||
file.ReadU8(&m_nFlags, 1);
|
||||
lcuint32 Groups; file.ReadU32(&Groups, 1);
|
||||
file.ReadU32(&m_nOffset, 1);
|
||||
file.ReadU32(&m_nSize, 1);
|
||||
|
||||
if (m_nFlags & LC_PIECE_SMALL)
|
||||
scale = 10000;
|
||||
|
@ -454,7 +454,7 @@ void PieceInfo::LoadInformation()
|
|||
return;
|
||||
}
|
||||
|
||||
FileDisk bin;
|
||||
lcDiskFile bin;
|
||||
char filename[LC_MAXPATH];
|
||||
CONNECTIONINFO* pConnection;
|
||||
DRAWGROUP* pGroup;
|
||||
|
@ -477,8 +477,7 @@ void PieceInfo::LoadInformation()
|
|||
|
||||
buf = malloc(m_nSize);
|
||||
bin.Seek(m_nOffset, SEEK_SET);
|
||||
bin.Read(buf, m_nSize);
|
||||
bin.Close();
|
||||
bin.ReadBuffer(buf, m_nSize);
|
||||
|
||||
shift = 1.0f/(1<<14);
|
||||
scale = 0.01f;
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
|
||||
#define LC_PIECE_NAME_LEN 256
|
||||
|
||||
class File;
|
||||
class Texture;
|
||||
|
||||
struct CONNECTIONINFO
|
||||
|
@ -92,7 +91,7 @@ class PieceInfo
|
|||
CreateBoxDisplayList();
|
||||
return m_nBoxList;
|
||||
};
|
||||
void LoadIndex(File& file);
|
||||
void LoadIndex(lcFile& file);
|
||||
void CreatePlaceholder(const char* Name);
|
||||
void AddRef();
|
||||
void DeRef();
|
||||
|
@ -102,8 +101,8 @@ public:
|
|||
char m_strName[LC_PIECE_NAME_LEN];
|
||||
char m_strDescription[65];
|
||||
float m_fDimensions[6];
|
||||
unsigned long m_nOffset;
|
||||
unsigned long m_nSize;
|
||||
lcuint32 m_nOffset;
|
||||
lcuint32 m_nSize;
|
||||
|
||||
// Nobody should change these
|
||||
unsigned char m_nFlags;
|
||||
|
|
|
@ -354,17 +354,17 @@ void Project::LoadDefaults(bool cameras)
|
|||
// Standard file menu commands
|
||||
|
||||
// Read a .lcd file
|
||||
bool Project::FileLoad(File* file, bool bUndo, bool bMerge)
|
||||
bool Project::FileLoad(lcFile* file, bool bUndo, bool bMerge)
|
||||
{
|
||||
int i, count;
|
||||
lcint32 i, count;
|
||||
char id[32];
|
||||
unsigned long rgb;
|
||||
lcuint32 rgb;
|
||||
float fv = 0.4f;
|
||||
unsigned char ch, action = m_nCurAction;
|
||||
unsigned short sh;
|
||||
lcuint8 ch, action = m_nCurAction;
|
||||
lcuint16 sh;
|
||||
|
||||
file->Seek(0, SEEK_SET);
|
||||
file->Read(id, 32);
|
||||
file->ReadBuffer(id, 32);
|
||||
sscanf(&id[7], "%f", &fv);
|
||||
|
||||
// Fix the ugly floating point reading on computers with different decimal points.
|
||||
|
@ -379,9 +379,9 @@ bool Project::FileLoad(File* file, bool bUndo, bool bMerge)
|
|||
}
|
||||
|
||||
if (fv > 0.4f)
|
||||
file->ReadFloat (&fv, 1);
|
||||
file->ReadFloats(&fv, 1);
|
||||
|
||||
file->ReadLong (&rgb, 1);
|
||||
file->ReadU32(&rgb, 1);
|
||||
if (!bMerge)
|
||||
{
|
||||
m_fBackground[0] = (float)((unsigned char) (rgb))/255;
|
||||
|
@ -408,8 +408,8 @@ bool Project::FileLoad(File* file, bool bUndo, bool bMerge)
|
|||
}
|
||||
|
||||
double eye[3], target[3];
|
||||
file->ReadDouble (&eye, 3);
|
||||
file->ReadDouble (&target, 3);
|
||||
file->ReadDoubles(eye, 3);
|
||||
file->ReadDoubles(target, 3);
|
||||
float tmp[3] = { (float)eye[0], (float)eye[1], (float)eye[2] };
|
||||
pCam->ChangeKey(1, false, false, tmp, LC_CK_EYE);
|
||||
pCam->ChangeKey(1, true, false, tmp, LC_CK_EYE);
|
||||
|
@ -435,20 +435,20 @@ bool Project::FileLoad(File* file, bool bUndo, bool bMerge)
|
|||
file->Seek(32, SEEK_CUR);
|
||||
else
|
||||
{
|
||||
file->ReadLong (&i, 1); m_nAngleSnap = i;
|
||||
file->ReadLong (&m_nSnap, 1);
|
||||
file->ReadFloat (&m_fLineWidth, 1);
|
||||
file->ReadLong (&m_nDetail, 1);
|
||||
file->ReadLong (&i, 1); //m_nCurGroup = i;
|
||||
file->ReadLong (&i, 1); m_nCurColor = i;
|
||||
file->ReadLong (&i, 1); action = i;
|
||||
file->ReadLong (&i, 1); m_nCurStep = i;
|
||||
file->ReadS32(&i, 1); m_nAngleSnap = i;
|
||||
file->ReadU32(&m_nSnap, 1);
|
||||
file->ReadFloats(&m_fLineWidth, 1);
|
||||
file->ReadU32(&m_nDetail, 1);
|
||||
file->ReadS32(&i, 1); //m_nCurGroup = i;
|
||||
file->ReadS32(&i, 1); m_nCurColor = i;
|
||||
file->ReadS32(&i, 1); action = i;
|
||||
file->ReadS32(&i, 1); m_nCurStep = i;
|
||||
}
|
||||
|
||||
if (fv > 0.8f)
|
||||
file->ReadLong (&m_nScene, 1);
|
||||
file->ReadU32(&m_nScene, 1);
|
||||
|
||||
file->ReadLong (&count, 1);
|
||||
file->ReadS32(&count, 1);
|
||||
SystemStartProgressBar(0, count, 1, "Loading project...");
|
||||
|
||||
while (count--)
|
||||
|
@ -485,14 +485,14 @@ bool Project::FileLoad(File* file, bool bUndo, bool bMerge)
|
|||
{
|
||||
char name[LC_PIECE_NAME_LEN];
|
||||
float pos[3], rot[3], param[4];
|
||||
unsigned char color, step, group;
|
||||
lcuint8 color, step, group;
|
||||
|
||||
file->ReadFloat (pos, 3);
|
||||
file->ReadFloat (rot, 3);
|
||||
file->ReadByte (&color, 1);
|
||||
file->Read(name, sizeof(name));
|
||||
file->ReadByte (&step, 1);
|
||||
file->ReadByte (&group, 1);
|
||||
file->ReadFloats(pos, 3);
|
||||
file->ReadFloats(rot, 3);
|
||||
file->ReadU8(&color, 1);
|
||||
file->ReadBuffer(name, sizeof(name));
|
||||
file->ReadU8(&step, 1);
|
||||
file->ReadU8(&group, 1);
|
||||
|
||||
const unsigned char conv[20] = { 0,2,4,9,7,6,22,8,10,11,14,16,18,9,21,20,22,8,10,11 };
|
||||
color = conv[color];
|
||||
|
@ -522,49 +522,49 @@ bool Project::FileLoad(File* file, bool bUndo, bool bMerge)
|
|||
{
|
||||
if (fv >= 0.4f)
|
||||
{
|
||||
file->Read(&ch, 1);
|
||||
if (ch == 0xFF) file->ReadShort (&sh, 1); else sh = ch;
|
||||
file->ReadBuffer(&ch, 1);
|
||||
if (ch == 0xFF) file->ReadU16(&sh, 1); else sh = ch;
|
||||
if (sh > 100)
|
||||
file->Seek(sh, SEEK_CUR);
|
||||
else
|
||||
file->Read(m_strAuthor, sh);
|
||||
file->ReadBuffer(m_strAuthor, sh);
|
||||
|
||||
file->Read(&ch, 1);
|
||||
if (ch == 0xFF) file->ReadShort (&sh, 1); else sh = ch;
|
||||
file->ReadBuffer(&ch, 1);
|
||||
if (ch == 0xFF) file->ReadU16(&sh, 1); else sh = ch;
|
||||
if (sh > 100)
|
||||
file->Seek(sh, SEEK_CUR);
|
||||
else
|
||||
file->Read(m_strDescription, sh);
|
||||
file->ReadBuffer(m_strDescription, sh);
|
||||
|
||||
file->Read(&ch, 1);
|
||||
if (ch == 0xFF && fv < 1.3f) file->ReadShort (&sh, 1); else sh = ch;
|
||||
file->ReadBuffer(&ch, 1);
|
||||
if (ch == 0xFF && fv < 1.3f) file->ReadU16(&sh, 1); else sh = ch;
|
||||
if (sh > 255)
|
||||
file->Seek(sh, SEEK_CUR);
|
||||
else
|
||||
file->Read(m_strComments, sh);
|
||||
file->ReadBuffer(m_strComments, sh);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (fv >= 0.4f)
|
||||
{
|
||||
file->Read (&ch, 1);
|
||||
if (ch == 0xFF) file->ReadShort (&sh, 1); else sh = ch;
|
||||
file->ReadBuffer(&ch, 1);
|
||||
if (ch == 0xFF) file->ReadU16(&sh, 1); else sh = ch;
|
||||
file->Seek (sh, SEEK_CUR);
|
||||
|
||||
file->Read (&ch, 1);
|
||||
if (ch == 0xFF) file->ReadShort (&sh, 1); else sh = ch;
|
||||
file->ReadBuffer(&ch, 1);
|
||||
if (ch == 0xFF) file->ReadU16(&sh, 1); else sh = ch;
|
||||
file->Seek (sh, SEEK_CUR);
|
||||
|
||||
file->Read (&ch, 1);
|
||||
if (ch == 0xFF && fv < 1.3f) file->ReadShort (&sh, 1); else sh = ch;
|
||||
file->ReadBuffer(&ch, 1);
|
||||
if (ch == 0xFF && fv < 1.3f) file->ReadU16(&sh, 1); else sh = ch;
|
||||
file->Seek (sh, SEEK_CUR);
|
||||
}
|
||||
}
|
||||
|
||||
if (fv >= 0.5f)
|
||||
{
|
||||
file->ReadLong (&count, 1);
|
||||
file->ReadS32(&count, 1);
|
||||
|
||||
Group* pGroup;
|
||||
Group* pLastGroup = NULL;
|
||||
|
@ -588,8 +588,8 @@ bool Project::FileLoad(File* file, bool bUndo, bool bMerge)
|
|||
{
|
||||
if (fv < 1.0f)
|
||||
{
|
||||
file->Read(pGroup->m_strName, 65);
|
||||
file->Read(&ch, 1);
|
||||
file->ReadBuffer(pGroup->m_strName, 65);
|
||||
file->ReadBuffer(&ch, 1);
|
||||
pGroup->m_fCenter[0] = 0;
|
||||
pGroup->m_fCenter[1] = 0;
|
||||
pGroup->m_fCenter[2] = 0;
|
||||
|
@ -650,17 +650,17 @@ bool Project::FileLoad(File* file, bool bUndo, bool bMerge)
|
|||
{
|
||||
if (fv < 1.0f)
|
||||
{
|
||||
int ViewportMode;
|
||||
file->ReadLong(&ViewportMode, 1);
|
||||
lcuint32 ViewportMode;
|
||||
file->ReadU32(&ViewportMode, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
lcuint8 ViewportMode, ActiveViewport;
|
||||
file->ReadByte(&ViewportMode, 1);
|
||||
file->ReadByte(&ActiveViewport, 1);
|
||||
file->ReadU8(&ViewportMode, 1);
|
||||
file->ReadU8(&ActiveViewport, 1);
|
||||
}
|
||||
|
||||
file->ReadLong (&count, 1);
|
||||
file->ReadS32(&count, 1);
|
||||
Camera* pCam = NULL;
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
|
@ -688,7 +688,7 @@ bool Project::FileLoad(File* file, bool bUndo, bool bMerge)
|
|||
{
|
||||
for (count = 0; count < 4; count++)
|
||||
{
|
||||
file->ReadLong (&i, 1);
|
||||
file->ReadS32(&i, 1);
|
||||
|
||||
Camera* pCam = m_pCameras;
|
||||
while (i--)
|
||||
|
@ -696,69 +696,69 @@ bool Project::FileLoad(File* file, bool bUndo, bool bMerge)
|
|||
// m_pViewCameras[count] = pCam;
|
||||
}
|
||||
|
||||
file->ReadLong (&rgb, 1);
|
||||
file->ReadU32(&rgb, 1);
|
||||
m_fFogColor[0] = (float)((unsigned char) (rgb))/255;
|
||||
m_fFogColor[1] = (float)((unsigned char) (((unsigned short) (rgb)) >> 8))/255;
|
||||
m_fFogColor[2] = (float)((unsigned char) ((rgb) >> 16))/255;
|
||||
|
||||
if (fv < 1.0f)
|
||||
{
|
||||
file->ReadLong (&rgb, 1);
|
||||
file->ReadU32(&rgb, 1);
|
||||
m_fFogDensity = (float)rgb/100;
|
||||
}
|
||||
else
|
||||
file->ReadFloat (&m_fFogDensity, 1);
|
||||
file->ReadFloats(&m_fFogDensity, 1);
|
||||
|
||||
if (fv < 1.3f)
|
||||
{
|
||||
file->ReadByte (&ch, 1);
|
||||
file->ReadU8(&ch, 1);
|
||||
if (ch == 0xFF)
|
||||
file->ReadShort (&sh, 1);
|
||||
file->ReadU16(&sh, 1);
|
||||
sh = ch;
|
||||
}
|
||||
else
|
||||
file->ReadShort (&sh, 1);
|
||||
file->ReadU16(&sh, 1);
|
||||
|
||||
if (sh < LC_MAXPATH)
|
||||
file->Read (m_strBackground, sh);
|
||||
file->ReadBuffer(m_strBackground, sh);
|
||||
else
|
||||
file->Seek (sh, SEEK_CUR);
|
||||
}
|
||||
|
||||
if (fv >= 0.8f)
|
||||
{
|
||||
file->Read(&ch, 1);
|
||||
file->Read(m_strHeader, ch);
|
||||
file->Read(&ch, 1);
|
||||
file->Read(m_strFooter, ch);
|
||||
file->ReadBuffer(&ch, 1);
|
||||
file->ReadBuffer(m_strHeader, ch);
|
||||
file->ReadBuffer(&ch, 1);
|
||||
file->ReadBuffer(m_strFooter, ch);
|
||||
}
|
||||
|
||||
if (fv > 0.9f)
|
||||
{
|
||||
file->ReadLong (&rgb, 1);
|
||||
file->ReadU32(&rgb, 1);
|
||||
m_fAmbient[0] = (float)((unsigned char) (rgb))/255;
|
||||
m_fAmbient[1] = (float)((unsigned char) (((unsigned short) (rgb)) >> 8))/255;
|
||||
m_fAmbient[2] = (float)((unsigned char) ((rgb) >> 16))/255;
|
||||
|
||||
if (fv < 1.3f)
|
||||
{
|
||||
file->ReadLong (&i, 1); m_bAnimation = (i != 0);
|
||||
file->ReadLong (&i, 1); m_bAddKeys = (i != 0);
|
||||
file->ReadByte (&m_nFPS, 1);
|
||||
file->ReadLong (&i, 1); m_nCurFrame = i;
|
||||
file->ReadShort (&m_nTotalFrames, 1);
|
||||
file->ReadLong (&i, 1); m_nGridSize = i;
|
||||
file->ReadLong (&i, 1); //m_nMoveSnap = i;
|
||||
file->ReadS32(&i, 1); m_bAnimation = (i != 0);
|
||||
file->ReadS32(&i, 1); m_bAddKeys = (i != 0);
|
||||
file->ReadU8(&m_nFPS, 1);
|
||||
file->ReadS32(&i, 1); m_nCurFrame = i;
|
||||
file->ReadU16(&m_nTotalFrames, 1);
|
||||
file->ReadS32(&i, 1); m_nGridSize = i;
|
||||
file->ReadS32(&i, 1); //m_nMoveSnap = i;
|
||||
}
|
||||
else
|
||||
{
|
||||
file->ReadByte (&ch, 1); m_bAnimation = (ch != 0);
|
||||
file->ReadByte (&ch, 1); m_bAddKeys = (ch != 0);
|
||||
file->ReadByte (&m_nFPS, 1);
|
||||
file->ReadShort (&m_nCurFrame, 1);
|
||||
file->ReadShort (&m_nTotalFrames, 1);
|
||||
file->ReadShort (&m_nGridSize, 1);
|
||||
file->ReadShort (&sh, 1);
|
||||
file->ReadU8(&ch, 1); m_bAnimation = (ch != 0);
|
||||
file->ReadU8(&ch, 1); m_bAddKeys = (ch != 0);
|
||||
file->ReadU8(&m_nFPS, 1);
|
||||
file->ReadU16(&m_nCurFrame, 1);
|
||||
file->ReadU16(&m_nTotalFrames, 1);
|
||||
file->ReadU16(&m_nGridSize, 1);
|
||||
file->ReadU16(&sh, 1);
|
||||
if (fv >= 1.4f)
|
||||
m_nMoveSnap = sh;
|
||||
}
|
||||
|
@ -766,11 +766,11 @@ bool Project::FileLoad(File* file, bool bUndo, bool bMerge)
|
|||
|
||||
if (fv > 1.0f)
|
||||
{
|
||||
file->ReadLong (&rgb, 1);
|
||||
file->ReadU32(&rgb, 1);
|
||||
m_fGradient1[0] = (float)((unsigned char) (rgb))/255;
|
||||
m_fGradient1[1] = (float)((unsigned char) (((unsigned short) (rgb)) >> 8))/255;
|
||||
m_fGradient1[2] = (float)((unsigned char) ((rgb) >> 16))/255;
|
||||
file->ReadLong (&rgb, 1);
|
||||
file->ReadU32(&rgb, 1);
|
||||
m_fGradient2[0] = (float)((unsigned char) (rgb))/255;
|
||||
m_fGradient2[1] = (float)((unsigned char) (((unsigned short) (rgb)) >> 8))/255;
|
||||
m_fGradient2[2] = (float)((unsigned char) ((rgb) >> 16))/255;
|
||||
|
@ -779,9 +779,9 @@ bool Project::FileLoad(File* file, bool bUndo, bool bMerge)
|
|||
m_pTerrain->FileLoad (file);
|
||||
else
|
||||
{
|
||||
file->Seek (4, SEEK_CUR);
|
||||
file->Read (&ch, 1);
|
||||
file->Seek (ch, SEEK_CUR);
|
||||
file->Seek(4, SEEK_CUR);
|
||||
file->ReadBuffer(&ch, 1);
|
||||
file->Seek(ch, SEEK_CUR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -822,66 +822,66 @@ bool Project::FileLoad(File* file, bool bUndo, bool bMerge)
|
|||
return true;
|
||||
}
|
||||
|
||||
void Project::FileSave(File* file, bool bUndo)
|
||||
void Project::FileSave(lcFile* file, bool bUndo)
|
||||
{
|
||||
float ver_flt = 1.4f; // LeoCAD 0.75 - (and this should have been an integer).
|
||||
unsigned long rgb;
|
||||
unsigned char ch;
|
||||
unsigned short sh;
|
||||
lcuint32 rgb;
|
||||
lcuint8 ch;
|
||||
lcuint16 sh;
|
||||
int i, j;
|
||||
|
||||
file->Seek (0, SEEK_SET);
|
||||
file->Write (LC_STR_VERSION, 32);
|
||||
file->WriteFloat (&ver_flt, 1);
|
||||
file->Seek(0, SEEK_SET);
|
||||
file->WriteBuffer(LC_STR_VERSION, 32);
|
||||
file->WriteFloats(&ver_flt, 1);
|
||||
|
||||
rgb = FLOATRGB(m_fBackground);
|
||||
file->WriteLong (&rgb, 1);
|
||||
file->WriteU32(&rgb, 1);
|
||||
|
||||
i = m_nAngleSnap; file->WriteLong (&i, 1);
|
||||
file->WriteLong (&m_nSnap, 1);
|
||||
file->WriteFloat (&m_fLineWidth, 1);
|
||||
file->WriteLong (&m_nDetail, 1);
|
||||
i = m_nAngleSnap; file->WriteS32(&i, 1);
|
||||
file->WriteU32(&m_nSnap, 1);
|
||||
file->WriteFloats(&m_fLineWidth, 1);
|
||||
file->WriteU32(&m_nDetail, 1);
|
||||
//i = m_nCurGroup;
|
||||
file->WriteLong (&i, 1);
|
||||
i = m_nCurColor; file->WriteLong (&i, 1);
|
||||
i = m_nCurAction; file->WriteLong (&i, 1);
|
||||
i = m_nCurStep; file->WriteLong (&i, 1);
|
||||
file->WriteLong (&m_nScene, 1);
|
||||
file->WriteS32(&i, 1);
|
||||
i = m_nCurColor; file->WriteS32(&i, 1);
|
||||
i = m_nCurAction; file->WriteS32(&i, 1);
|
||||
i = m_nCurStep; file->WriteS32(&i, 1);
|
||||
file->WriteU32(&m_nScene, 1);
|
||||
|
||||
Piece* pPiece;
|
||||
for (i = 0, pPiece = m_pPieces; pPiece; pPiece = pPiece->m_pNext)
|
||||
i++;
|
||||
file->WriteLong (&i, 1);
|
||||
file->WriteS32(&i, 1);
|
||||
|
||||
for (pPiece = m_pPieces; pPiece; pPiece = pPiece->m_pNext)
|
||||
pPiece->FileSave (*file, m_pGroups);
|
||||
|
||||
ch = strlen(m_strAuthor);
|
||||
file->Write(&ch, 1);
|
||||
file->Write(m_strAuthor, ch);
|
||||
file->WriteBuffer(&ch, 1);
|
||||
file->WriteBuffer(m_strAuthor, ch);
|
||||
ch = strlen(m_strDescription);
|
||||
file->Write(&ch, 1);
|
||||
file->Write(m_strDescription, ch);
|
||||
file->WriteBuffer(&ch, 1);
|
||||
file->WriteBuffer(m_strDescription, ch);
|
||||
ch = strlen(m_strComments);
|
||||
file->Write(&ch, 1);
|
||||
file->Write(m_strComments, ch);
|
||||
file->WriteBuffer(&ch, 1);
|
||||
file->WriteBuffer(m_strComments, ch);
|
||||
|
||||
Group* pGroup;
|
||||
for (i = 0, pGroup = m_pGroups; pGroup; pGroup = pGroup->m_pNext)
|
||||
i++;
|
||||
file->WriteLong (&i, 1);
|
||||
file->WriteS32(&i, 1);
|
||||
|
||||
for (pGroup = m_pGroups; pGroup; pGroup = pGroup->m_pNext)
|
||||
pGroup->FileSave(file, m_pGroups);
|
||||
|
||||
lcuint8 ViewportMode = 0, ActiveViewport = 0;
|
||||
file->WriteByte(&ViewportMode, 1);
|
||||
file->WriteByte(&ActiveViewport, 1);
|
||||
file->WriteU8(&ViewportMode, 1);
|
||||
file->WriteU8(&ActiveViewport, 1);
|
||||
|
||||
Camera* pCamera;
|
||||
for (i = 0, pCamera = m_pCameras; pCamera; pCamera = pCamera->m_pNext)
|
||||
i++;
|
||||
file->WriteLong (&i, 1);
|
||||
file->WriteS32(&i, 1);
|
||||
|
||||
for (i = 0, pCamera = m_pCameras; pCamera; pCamera = pCamera->m_pNext)
|
||||
pCamera->FileSave(*file);
|
||||
|
@ -895,51 +895,51 @@ void Project::FileSave(File* file, bool bUndo)
|
|||
// else
|
||||
// i++;
|
||||
|
||||
file->WriteLong (&i, 1);
|
||||
file->WriteS32(&i, 1);
|
||||
}
|
||||
|
||||
rgb = FLOATRGB(m_fFogColor);
|
||||
file->WriteLong (&rgb, 1);
|
||||
file->WriteFloat (&m_fFogDensity, 1);
|
||||
file->WriteU32(&rgb, 1);
|
||||
file->WriteFloats(&m_fFogDensity, 1);
|
||||
sh = strlen(m_strBackground);
|
||||
file->WriteShort (&sh, 1);
|
||||
file->Write(m_strBackground, sh);
|
||||
file->WriteU16(&sh, 1);
|
||||
file->WriteBuffer(m_strBackground, sh);
|
||||
ch = strlen(m_strHeader);
|
||||
file->Write(&ch, 1);
|
||||
file->Write(m_strHeader, ch);
|
||||
file->WriteBuffer(&ch, 1);
|
||||
file->WriteBuffer(m_strHeader, ch);
|
||||
ch = strlen(m_strFooter);
|
||||
file->Write(&ch, 1);
|
||||
file->Write(m_strFooter, ch);
|
||||
file->WriteBuffer(&ch, 1);
|
||||
file->WriteBuffer(m_strFooter, ch);
|
||||
// 0.60 (1.0)
|
||||
rgb = FLOATRGB(m_fAmbient);
|
||||
file->WriteLong (&rgb, 1);
|
||||
file->WriteU32(&rgb, 1);
|
||||
ch = m_bAnimation;
|
||||
file->Write(&ch, 1);
|
||||
file->WriteBuffer(&ch, 1);
|
||||
ch = m_bAddKeys;
|
||||
file->WriteByte (&ch, 1);
|
||||
file->WriteByte (&m_nFPS, 1);
|
||||
file->WriteShort (&m_nCurFrame, 1);
|
||||
file->WriteShort (&m_nTotalFrames, 1);
|
||||
file->WriteShort (&m_nGridSize, 1);
|
||||
file->WriteShort (&m_nMoveSnap, 1);
|
||||
file->WriteU8(&ch, 1);
|
||||
file->WriteU8 (&m_nFPS, 1);
|
||||
file->WriteU16(&m_nCurFrame, 1);
|
||||
file->WriteU16(&m_nTotalFrames, 1);
|
||||
file->WriteU16(&m_nGridSize, 1);
|
||||
file->WriteU16(&m_nMoveSnap, 1);
|
||||
// 0.62 (1.1)
|
||||
rgb = FLOATRGB(m_fGradient1);
|
||||
file->WriteLong (&rgb, 1);
|
||||
file->WriteU32(&rgb, 1);
|
||||
rgb = FLOATRGB(m_fGradient2);
|
||||
file->WriteLong (&rgb, 1);
|
||||
file->WriteU32(&rgb, 1);
|
||||
// 0.64 (1.2)
|
||||
m_pTerrain->FileSave(file);
|
||||
|
||||
if (!bUndo)
|
||||
{
|
||||
unsigned long pos = 0;
|
||||
lcuint32 pos = 0;
|
||||
|
||||
i = Sys_ProfileLoadInt ("Default", "Save Preview", 0);
|
||||
if (i != 0)
|
||||
{
|
||||
pos = file->GetPosition();
|
||||
|
||||
Image* image = new Image[1];
|
||||
Image* image = new Image[1];
|
||||
LC_IMAGE_OPTS opts;
|
||||
opts.interlaced = false;
|
||||
opts.transparent = false;
|
||||
|
@ -951,60 +951,60 @@ void Project::FileSave(File* file, bool bUndo)
|
|||
delete []image;
|
||||
}
|
||||
|
||||
file->WriteLong (&pos, 1);
|
||||
file->WriteU32(&pos, 1);
|
||||
m_nSaveTimer = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void Project::FileReadMPD(File& MPD, PtrArray<File>& FileArray) const
|
||||
void Project::FileReadMPD(lcFile& MPD, PtrArray<LC_FILEENTRY>& FileArray) const
|
||||
{
|
||||
FileMem* CurFile = NULL;
|
||||
LC_FILEENTRY* CurFile = NULL;
|
||||
char Buf[1024];
|
||||
|
||||
while (MPD.ReadLine(Buf, 1024))
|
||||
{
|
||||
String Line(Buf);
|
||||
{
|
||||
String Line(Buf);
|
||||
|
||||
Line.TrimLeft();
|
||||
Line.TrimLeft();
|
||||
|
||||
if (Line[0] != '0')
|
||||
{
|
||||
// Copy current line.
|
||||
if (CurFile != NULL)
|
||||
CurFile->Write(Buf, strlen(Buf));
|
||||
if (Line[0] != '0')
|
||||
{
|
||||
// Copy current line.
|
||||
if (CurFile != NULL)
|
||||
CurFile->File.WriteBuffer(Buf, strlen(Buf));
|
||||
|
||||
continue;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
Line.TrimRight();
|
||||
Line = Line.Right(Line.GetLength() - 1);
|
||||
Line.TrimLeft();
|
||||
Line.TrimRight();
|
||||
Line = Line.Right(Line.GetLength() - 1);
|
||||
Line.TrimLeft();
|
||||
|
||||
// Find where a subfile starts.
|
||||
if (Line.CompareNoCase("FILE", 4) == 0)
|
||||
{
|
||||
Line = Line.Right(Line.GetLength() - 4);
|
||||
Line.TrimLeft();
|
||||
// Find where a subfile starts.
|
||||
if (Line.CompareNoCase("FILE", 4) == 0)
|
||||
{
|
||||
Line = Line.Right(Line.GetLength() - 4);
|
||||
Line.TrimLeft();
|
||||
|
||||
// Create a new file.
|
||||
CurFile = new FileMem();
|
||||
CurFile->SetFileName(Line);
|
||||
FileArray.Add(CurFile);
|
||||
}
|
||||
else if (Line.CompareNoCase("ENDFILE", 7) == 0)
|
||||
{
|
||||
// File ends here.
|
||||
CurFile = NULL;
|
||||
}
|
||||
else if (CurFile != NULL)
|
||||
{
|
||||
// Copy current line.
|
||||
CurFile->Write(Buf, strlen(Buf));
|
||||
}
|
||||
}
|
||||
// Create a new file.
|
||||
CurFile = new LC_FILEENTRY();
|
||||
strncpy(CurFile->FileName, Line, sizeof(CurFile->FileName));
|
||||
FileArray.Add(CurFile);
|
||||
}
|
||||
else if (Line.CompareNoCase("ENDFILE", 7) == 0)
|
||||
{
|
||||
// File ends here.
|
||||
CurFile = NULL;
|
||||
}
|
||||
else if (CurFile != NULL)
|
||||
{
|
||||
// Copy current line.
|
||||
CurFile->File.WriteBuffer(Buf, strlen(Buf));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Project::FileReadLDraw(File* file, Matrix* prevmat, int* nOk, int DefColor, int* nStep, PtrArray<File>& FileArray)
|
||||
void Project::FileReadLDraw(lcFile* file, Matrix* prevmat, int* nOk, int DefColor, int* nStep, PtrArray<LC_FILEENTRY>& FileArray)
|
||||
{
|
||||
char buf[1024];
|
||||
|
||||
|
@ -1079,9 +1079,9 @@ void Project::FileReadLDraw(File* file, Matrix* prevmat, int* nOk, int DefColor,
|
|||
{
|
||||
for (int i = 0; i < FileArray.GetSize(); i++)
|
||||
{
|
||||
if (stricmp(FileArray[i]->GetFileName(), pn) == 0)
|
||||
if (stricmp(FileArray[i]->FileName, pn) == 0)
|
||||
{
|
||||
FileReadLDraw(FileArray[i], &tmpmat, nOk, cl, nStep, FileArray);
|
||||
FileReadLDraw(&FileArray[i]->File, &tmpmat, nOk, cl, nStep, FileArray);
|
||||
read = false;
|
||||
break;
|
||||
}
|
||||
|
@ -1091,7 +1091,7 @@ void Project::FileReadLDraw(File* file, Matrix* prevmat, int* nOk, int DefColor,
|
|||
// Try to read the file from disk.
|
||||
if (read)
|
||||
{
|
||||
FileDisk tf;
|
||||
lcDiskFile tf;
|
||||
|
||||
if (tf.Open(pn, "rt"))
|
||||
{
|
||||
|
@ -1152,7 +1152,7 @@ bool Project::DoFileSave()
|
|||
// if 'bReplace' is FALSE will not change path name (SaveCopyAs)
|
||||
bool Project::DoSave(char* lpszPathName, bool bReplace)
|
||||
{
|
||||
FileDisk file;
|
||||
lcDiskFile file;
|
||||
char newName[LC_MAXPATH];
|
||||
memset(newName, 0, sizeof(newName));
|
||||
if (lpszPathName)
|
||||
|
@ -1238,7 +1238,7 @@ bool Project::DoSave(char* lpszPathName, bool bReplace)
|
|||
strcat(buf, "\r\n");
|
||||
}
|
||||
strcat(buf, "\r\n");
|
||||
file.Write(buf, strlen(buf));
|
||||
file.WriteBuffer(buf, strlen(buf));
|
||||
|
||||
const char* OldLocale = setlocale(LC_NUMERIC, "C");
|
||||
|
||||
|
@ -1255,14 +1255,14 @@ bool Project::DoSave(char* lpszPathName, bool bReplace)
|
|||
mat.ToLDraw(f);
|
||||
sprintf (buf, " 1 %d %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %s.DAT\r\n",
|
||||
col[pPiece->GetColor()], f[0], f[1], f[2], f[3], f[4], f[5], f[6], f[7], f[8], f[9], f[10], f[11], pPiece->GetPieceInfo()->m_strName);
|
||||
file.Write(buf, strlen(buf));
|
||||
file.WriteBuffer(buf, strlen(buf));
|
||||
}
|
||||
}
|
||||
|
||||
if (i != steps)
|
||||
file.Write("0 STEP\r\n", 8);
|
||||
file.WriteBuffer("0 STEP\r\n", 8);
|
||||
}
|
||||
file.Write("0\r\n", 3);
|
||||
file.WriteBuffer("0\r\n", 3);
|
||||
|
||||
setlocale(LC_NUMERIC, OldLocale);
|
||||
}
|
||||
|
@ -1384,7 +1384,7 @@ bool Project::OpenProject(const char* FileName)
|
|||
|
||||
bool Project::OnOpenDocument (const char* lpszPathName)
|
||||
{
|
||||
FileDisk file;
|
||||
lcDiskFile file;
|
||||
bool bSuccess = false;
|
||||
|
||||
if (!file.Open(lpszPathName, "rb"))
|
||||
|
@ -1421,7 +1421,7 @@ bool Project::OnOpenDocument (const char* lpszPathName)
|
|||
|
||||
if (file.GetLength() != 0)
|
||||
{
|
||||
PtrArray<File> FileArray;
|
||||
PtrArray<LC_FILEENTRY> FileArray;
|
||||
|
||||
// Unpack the MPD file.
|
||||
if (mpdfile)
|
||||
|
@ -1443,7 +1443,7 @@ bool Project::OnOpenDocument (const char* lpszPathName)
|
|||
Matrix mat;
|
||||
|
||||
if (mpdfile)
|
||||
FileReadLDraw(FileArray[0], &mat, &ok, m_nCurColor, &step, FileArray);
|
||||
FileReadLDraw(&FileArray[0]->File, &mat, &ok, m_nCurColor, &step, FileArray);
|
||||
else
|
||||
FileReadLDraw(&file, &mat, &ok, m_nCurColor, &step, FileArray);
|
||||
|
||||
|
@ -2782,7 +2782,7 @@ void Project::RenderInitialize()
|
|||
if (!m_pScreenFont->IsLoaded())
|
||||
{
|
||||
char filename[LC_MAXPATH];
|
||||
FileDisk file;
|
||||
lcDiskFile file;
|
||||
|
||||
strcpy(filename, lcGetPiecesLibrary()->GetLibraryPath());
|
||||
strcat(filename, "sysfont.txf");
|
||||
|
@ -3433,7 +3433,7 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
|
|||
|
||||
if (SystemDoDialog(LC_DLG_FILE_MERGE_PROJECT, filename))
|
||||
{
|
||||
FileDisk file;
|
||||
lcDiskFile file;
|
||||
if (file.Open(filename, "rb"))
|
||||
{
|
||||
// CWaitCursor wait;
|
||||
|
@ -3832,7 +3832,7 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
|
|||
if (!SystemDoDialog(LC_DLG_POVRAY, &opts))
|
||||
break;
|
||||
|
||||
FileDisk POVFile;
|
||||
lcDiskFile POVFile;
|
||||
char Line[1024];
|
||||
|
||||
if (!POVFile.Open(opts.outpath, "wt"))
|
||||
|
@ -3870,7 +3870,7 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
|
|||
// Parse LGEO tables.
|
||||
if (opts.libpath[0])
|
||||
{
|
||||
FileDisk TableFile, ColorFile;
|
||||
lcDiskFile TableFile, ColorFile;
|
||||
char Filename[LC_MAXPATH];
|
||||
|
||||
int Length = strlen(opts.libpath);
|
||||
|
@ -4380,7 +4380,7 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
|
|||
|
||||
case LC_FILE_LIBRARY:
|
||||
{
|
||||
FileMem file;
|
||||
lcMemFile file;
|
||||
FileSave(&file, true);
|
||||
|
||||
if (SystemDoDialog(LC_DLG_LIBRARY, NULL))
|
||||
|
@ -4465,7 +4465,7 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
|
|||
{
|
||||
if (m_pClipboard[m_nCurClipboard] != NULL)
|
||||
delete m_pClipboard[m_nCurClipboard];
|
||||
m_pClipboard[m_nCurClipboard] = new FileMem;
|
||||
m_pClipboard[m_nCurClipboard] = new lcMemFile;
|
||||
|
||||
int i = 0;
|
||||
Piece* pPiece;
|
||||
|
@ -4476,7 +4476,7 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
|
|||
for (pPiece = m_pPieces; pPiece; pPiece = pPiece->m_pNext)
|
||||
if (pPiece->IsSelected())
|
||||
i++;
|
||||
m_pClipboard[m_nCurClipboard]->Write(&i, sizeof(i));
|
||||
m_pClipboard[m_nCurClipboard]->WriteBuffer(&i, sizeof(i));
|
||||
|
||||
for (pPiece = m_pPieces; pPiece; pPiece = pPiece->m_pNext)
|
||||
if (pPiece->IsSelected())
|
||||
|
@ -4484,7 +4484,7 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
|
|||
|
||||
for (i = 0, pGroup = m_pGroups; pGroup; pGroup = pGroup->m_pNext)
|
||||
i++;
|
||||
m_pClipboard[m_nCurClipboard]->Write(&i, sizeof(i));
|
||||
m_pClipboard[m_nCurClipboard]->WriteBuffer(&i, sizeof(i));
|
||||
|
||||
for (pGroup = m_pGroups; pGroup; pGroup = pGroup->m_pNext)
|
||||
pGroup->FileSave(m_pClipboard[m_nCurClipboard], m_pGroups);
|
||||
|
@ -4492,7 +4492,7 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
|
|||
for (i = 0, pCamera = m_pCameras; pCamera; pCamera = pCamera->m_pNext)
|
||||
if (pCamera->IsSelected())
|
||||
i++;
|
||||
m_pClipboard[m_nCurClipboard]->Write(&i, sizeof(i));
|
||||
m_pClipboard[m_nCurClipboard]->WriteBuffer(&i, sizeof(i));
|
||||
|
||||
for (pCamera = m_pCameras; pCamera; pCamera = pCamera->m_pNext)
|
||||
if (pCamera->IsSelected())
|
||||
|
@ -4524,13 +4524,13 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
|
|||
{
|
||||
int i, j;
|
||||
Piece* pPasted = NULL;
|
||||
File* file = m_pClipboard[m_nCurClipboard];
|
||||
lcFile* file = m_pClipboard[m_nCurClipboard];
|
||||
if (file == NULL)
|
||||
break;
|
||||
file->Seek(0, SEEK_SET);
|
||||
SelectAndFocusNone(false);
|
||||
|
||||
file->Read(&i, sizeof(i));
|
||||
file->ReadBuffer(&i, sizeof(i));
|
||||
while (i--)
|
||||
{
|
||||
char name[LC_PIECE_NAME_LEN];
|
||||
|
@ -4547,7 +4547,7 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
|
|||
delete pPiece;
|
||||
}
|
||||
|
||||
file->Read(&i, sizeof(i));
|
||||
file->ReadBuffer(&i, sizeof(i));
|
||||
Piece* pPiece;
|
||||
Group** groups = (Group**)malloc(i*sizeof(Group**));
|
||||
for (j = 0; j < i; j++)
|
||||
|
@ -4619,7 +4619,7 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
|
|||
Camera* pCamera = m_pCameras;
|
||||
while (pCamera->m_pNext)
|
||||
pCamera = pCamera->m_pNext;
|
||||
file->Read(&i, sizeof(i));
|
||||
file->ReadBuffer(&i, sizeof(i));
|
||||
|
||||
while (i--)
|
||||
{
|
||||
|
@ -6680,7 +6680,7 @@ void Project::StartTracking(int mode)
|
|||
if (m_pTrackFile != NULL)
|
||||
m_pTrackFile->SetLength (0);
|
||||
else
|
||||
m_pTrackFile = new FileMem;
|
||||
m_pTrackFile = new lcMemFile;
|
||||
|
||||
FileSave(m_pTrackFile, true);
|
||||
}
|
||||
|
|
|
@ -47,12 +47,18 @@ class TexFont;
|
|||
|
||||
struct LC_UNDOINFO
|
||||
{
|
||||
FileMem file;
|
||||
lcMemFile file;
|
||||
char strText[21];
|
||||
LC_UNDOINFO* pNext;
|
||||
LC_UNDOINFO() { pNext = NULL; };
|
||||
};
|
||||
|
||||
struct LC_FILEENTRY
|
||||
{
|
||||
lcMemFile File;
|
||||
char FileName[LC_MAXPATH];
|
||||
};
|
||||
|
||||
class Project
|
||||
{
|
||||
public:
|
||||
|
@ -165,7 +171,7 @@ protected:
|
|||
Light* m_pLights;
|
||||
Group* m_pGroups;
|
||||
Terrain* m_pTerrain;
|
||||
File* m_pClipboard[10];
|
||||
lcFile* m_pClipboard[10];
|
||||
unsigned char m_nCurClipboard;
|
||||
|
||||
CONNECTION_TYPE m_pConnections[LC_CONNECTIONS];
|
||||
|
@ -203,7 +209,7 @@ protected:
|
|||
void CreateHTMLPieceList(FILE* f, int nStep, bool bImages, const char* ext);
|
||||
|
||||
bool m_bStopRender;
|
||||
File* m_pTrackFile;
|
||||
lcFile* m_pTrackFile;
|
||||
bool m_bTrackCancel;
|
||||
int m_nTracking;
|
||||
int m_nDownX;
|
||||
|
@ -256,15 +262,15 @@ protected:
|
|||
bool m_bAddKeys;
|
||||
unsigned char m_nFPS;
|
||||
unsigned char m_nCurStep;
|
||||
unsigned short m_nCurFrame;
|
||||
unsigned short m_nTotalFrames;
|
||||
lcuint16 m_nCurFrame;
|
||||
lcuint16 m_nTotalFrames;
|
||||
|
||||
unsigned long m_nScene;
|
||||
unsigned long m_nDetail;
|
||||
unsigned long m_nSnap;
|
||||
unsigned short m_nMoveSnap;
|
||||
unsigned short m_nAngleSnap;
|
||||
unsigned short m_nGridSize;
|
||||
lcuint32 m_nScene;
|
||||
lcuint32 m_nDetail;
|
||||
lcuint32 m_nSnap;
|
||||
lcuint16 m_nMoveSnap;
|
||||
lcuint16 m_nAngleSnap;
|
||||
lcuint16 m_nGridSize;
|
||||
float m_fLineWidth;
|
||||
float m_fFogDensity;
|
||||
float m_fFogColor[4];
|
||||
|
@ -286,10 +292,10 @@ protected:
|
|||
// File load/save implementation.
|
||||
bool DoSave(char* PathName, bool bReplace);
|
||||
bool DoFileSave();
|
||||
bool FileLoad(File* file, bool bUndo, bool bMerge);
|
||||
void FileSave(File* file, bool bUndo);
|
||||
void FileReadLDraw(File* file, Matrix* prevmat, int* nOk, int DefColor, int* nStep, PtrArray<File>& FileArray);
|
||||
void FileReadMPD(File& MPD, PtrArray<File>& FileArray) const;
|
||||
bool FileLoad(lcFile* file, bool bUndo, bool bMerge);
|
||||
void FileSave(lcFile* file, bool bUndo);
|
||||
void FileReadLDraw(lcFile* file, Matrix* prevmat, int* nOk, int DefColor, int* nStep, PtrArray<LC_FILEENTRY>& FileArray);
|
||||
void FileReadMPD(lcFile& MPD, PtrArray<LC_FILEENTRY>& FileArray) const;
|
||||
|
||||
public:
|
||||
// File helpers
|
||||
|
|
|
@ -82,7 +82,6 @@ bool Sys_KeyDown (int key);
|
|||
|
||||
|
||||
|
||||
class File;
|
||||
class Camera;
|
||||
class PieceInfo;
|
||||
|
||||
|
@ -116,8 +115,8 @@ void SystemPieceComboAdd(char* name);
|
|||
void SystemCaptureMouse();
|
||||
void SystemReleaseMouse();
|
||||
|
||||
void SystemExportClipboard(File* clip);
|
||||
File* SystemImportClipboard();
|
||||
void SystemExportClipboard(lcFile* clip);
|
||||
lcFile* SystemImportClipboard();
|
||||
|
||||
void SystemPumpMessages();
|
||||
long SystemGetTicks();
|
||||
|
|
|
@ -261,59 +261,59 @@ Terrain::~Terrain()
|
|||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Terrain functions
|
||||
|
||||
void Terrain::FileLoad(File* file)
|
||||
void Terrain::FileLoad(lcFile* file)
|
||||
{
|
||||
unsigned char ch;
|
||||
unsigned short sh;
|
||||
int i, j;
|
||||
lcuint8 ch;
|
||||
lcuint16 sh;
|
||||
lcint32 i, j;
|
||||
|
||||
file->ReadByte (&ch, 1);
|
||||
file->ReadLong (&i, 1);
|
||||
file->ReadLong (&j, 1);
|
||||
file->ReadFloat (&m_uSize, 1);
|
||||
file->ReadFloat (&m_vSize, 1);
|
||||
file->ReadLong (&m_nOptions, 1);
|
||||
file->ReadFloat (&m_fColor, 3);
|
||||
file->ReadU8(&ch, 1);
|
||||
file->ReadS32(&i, 1);
|
||||
file->ReadS32(&j, 1);
|
||||
file->ReadFloats(&m_uSize, 1);
|
||||
file->ReadFloats(&m_vSize, 1);
|
||||
file->ReadU32(&m_nOptions, 1);
|
||||
file->ReadFloats(m_fColor, 3);
|
||||
|
||||
if (ch == 1)
|
||||
{
|
||||
file->Read(&ch, 1);
|
||||
sh = ch;
|
||||
}
|
||||
else
|
||||
file->ReadShort (&sh, 1);
|
||||
if (ch == 1)
|
||||
{
|
||||
file->ReadU8(&ch, 1);
|
||||
sh = ch;
|
||||
}
|
||||
else
|
||||
file->ReadU16(&sh, 1);
|
||||
|
||||
if (sh > LC_MAXPATH)
|
||||
file->Seek (sh, SEEK_CUR);
|
||||
else
|
||||
file->Read (&m_strTexture, sh);
|
||||
if (sh > LC_MAXPATH)
|
||||
file->Seek (sh, SEEK_CUR);
|
||||
else
|
||||
file->ReadBuffer(&m_strTexture, sh);
|
||||
|
||||
SetPatchCount(i, j);
|
||||
for (i = 0; i < GetCountU(); i++)
|
||||
for (j = 0; j < GetCountV(); j++)
|
||||
file->ReadFloat (&m_pControl[i][j*3+2], 1);
|
||||
SetPatchCount(i, j);
|
||||
for (i = 0; i < GetCountU(); i++)
|
||||
for (j = 0; j < GetCountV(); j++)
|
||||
file->ReadFloats(&m_pControl[i][j*3+2], 1);
|
||||
}
|
||||
|
||||
void Terrain::FileSave(File* file)
|
||||
void Terrain::FileSave(lcFile* file)
|
||||
{
|
||||
unsigned char version = 2; // LeoCAD 0.70
|
||||
unsigned short sh;
|
||||
lcuint8 version = 2; // LeoCAD 0.70
|
||||
lcuint16 sh;
|
||||
|
||||
file->WriteByte (&version, 1);
|
||||
file->WriteLong (&m_uPatches, 1);
|
||||
file->WriteLong (&m_vPatches, 1);
|
||||
file->WriteFloat (&m_uSize, 1);
|
||||
file->WriteFloat (&m_vSize, 1);
|
||||
file->WriteLong (&m_nOptions, 1);
|
||||
file->WriteFloat (&m_fColor, 3);
|
||||
file->WriteU8(&version, 1);
|
||||
file->WriteS32(&m_uPatches, 1);
|
||||
file->WriteS32(&m_vPatches, 1);
|
||||
file->WriteFloats(&m_uSize, 1);
|
||||
file->WriteFloats(&m_vSize, 1);
|
||||
file->WriteU32(&m_nOptions, 1);
|
||||
file->WriteFloats(m_fColor, 3);
|
||||
|
||||
sh = strlen (m_strTexture);
|
||||
file->WriteShort (&sh, 1);
|
||||
file->Write (m_strTexture, sh);
|
||||
file->WriteU16(&sh, 1);
|
||||
file->WriteBuffer(m_strTexture, sh);
|
||||
|
||||
for (int i = 0; i < GetCountU(); i++)
|
||||
for (int j = 0; j < GetCountV(); j++)
|
||||
file->WriteFloat (&m_pControl[i][j*3+2], 1);
|
||||
file->WriteFloats(&m_pControl[i][j*3+2], 1);
|
||||
}
|
||||
|
||||
void Terrain::FreeMemory()
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
#ifndef _TERRAIN_H_
|
||||
#define _TERRAIN_H_
|
||||
|
||||
class File;
|
||||
class Camera;
|
||||
class Texture;
|
||||
|
||||
|
@ -46,8 +45,8 @@ public:
|
|||
void LoadDefaults(bool bLinear);
|
||||
void SetSize(float uSize, float vSize);
|
||||
void GetSize(float *uSize, float *vSize);
|
||||
void FileLoad(File* file);
|
||||
void FileSave(File* file);
|
||||
void FileLoad(lcFile* file);
|
||||
void FileSave(lcFile* file);
|
||||
void Tesselate();
|
||||
void SetControlPoints();
|
||||
void GenerateRandom();
|
||||
|
@ -61,7 +60,7 @@ public:
|
|||
float** GetControlPoints()
|
||||
{ return m_pControl; }
|
||||
|
||||
unsigned long m_nOptions;
|
||||
lcuint32 m_nOptions;
|
||||
char m_strTexture[LC_MAXPATH];
|
||||
float m_fColor[3];
|
||||
|
||||
|
|
|
@ -30,9 +30,9 @@ TexFont::~TexFont ()
|
|||
m_pTexture->DeRef ();
|
||||
}
|
||||
|
||||
bool TexFont::FileLoad (File& file)
|
||||
bool TexFont::FileLoad(lcFile& file)
|
||||
{
|
||||
unsigned char version;
|
||||
lcuint8 version;
|
||||
char buf[64];
|
||||
|
||||
if (m_bLoaded)
|
||||
|
@ -41,14 +41,14 @@ bool TexFont::FileLoad (File& file)
|
|||
return false;
|
||||
}
|
||||
|
||||
file.Read (buf, 32);
|
||||
file.ReadBuffer(buf, 32);
|
||||
if (strncmp (buf, LC_TEXFONT_FILE_HEADER, 32) != 0)
|
||||
{
|
||||
console.PrintError ("Texture font file header mismatch.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
file.ReadByte (&version, 1);
|
||||
file.ReadU8(&version, 1);
|
||||
if (version > LC_TEXFONT_FILE_VERSION)
|
||||
{
|
||||
console.PrintError ("Wrong version of texture font file.\n");
|
||||
|
@ -56,7 +56,7 @@ bool TexFont::FileLoad (File& file)
|
|||
}
|
||||
|
||||
memset (buf, 0, 32);
|
||||
file.Read (buf, 8);
|
||||
file.ReadBuffer(buf, 8);
|
||||
|
||||
m_pTexture = lcGetPiecesLibrary()->FindTexture (buf);
|
||||
if (m_pTexture == NULL)
|
||||
|
@ -66,22 +66,22 @@ bool TexFont::FileLoad (File& file)
|
|||
}
|
||||
m_pTexture->AddRef (false);
|
||||
|
||||
file.ReadByte (&m_nFontHeight, 1);
|
||||
file.ReadU8(&m_nFontHeight, 1);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
unsigned char glyph;
|
||||
|
||||
file.ReadByte (&glyph, 1);
|
||||
file.ReadU8(&glyph, 1);
|
||||
|
||||
if (glyph == 0)
|
||||
break;
|
||||
|
||||
file.ReadByte (&m_Glyphs[glyph].width, 1);
|
||||
file.ReadFloat (&m_Glyphs[glyph].left, 1);
|
||||
file.ReadFloat (&m_Glyphs[glyph].right, 1);
|
||||
file.ReadFloat (&m_Glyphs[glyph].top, 1);
|
||||
file.ReadFloat (&m_Glyphs[glyph].bottom, 1);
|
||||
file.ReadU8(&m_Glyphs[glyph].width, 1);
|
||||
file.ReadFloats(&m_Glyphs[glyph].left, 1);
|
||||
file.ReadFloats(&m_Glyphs[glyph].right, 1);
|
||||
file.ReadFloats(&m_Glyphs[glyph].top, 1);
|
||||
file.ReadFloats(&m_Glyphs[glyph].bottom, 1);
|
||||
|
||||
m_Glyphs[glyph].left /= m_pTexture->m_nWidth;
|
||||
m_Glyphs[glyph].right /= m_pTexture->m_nWidth;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#ifndef _TEXFONT_H_
|
||||
#define _TEXFONT_H_
|
||||
|
||||
class File;
|
||||
class Texture;
|
||||
|
||||
#include "texture.h"
|
||||
|
@ -17,7 +16,7 @@ public:
|
|||
void MakeCurrent ()
|
||||
{ if (m_bLoaded) m_pTexture->MakeCurrent (); }
|
||||
|
||||
bool FileLoad(File& file);
|
||||
bool FileLoad(lcFile& file);
|
||||
void PrintText(float left, float top, float z, const char* text) const;
|
||||
void PrintText(float Left, float Top, float ScaleX, float ScaleY, const char* Text) const;
|
||||
void PrintCharScaled(float scale, int ch) const;
|
||||
|
|
|
@ -87,18 +87,18 @@ void Texture::DeRef()
|
|||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Load methods
|
||||
|
||||
void Texture::LoadIndex(File* idx)
|
||||
void Texture::LoadIndex(lcFile* idx)
|
||||
{
|
||||
unsigned char bt;
|
||||
lcuint8 bt;
|
||||
|
||||
// TODO: don't change ref. if reloading
|
||||
m_nRef = 0;
|
||||
m_nID = 0;
|
||||
|
||||
idx->Read(m_strName, 8);
|
||||
idx->ReadShort(&m_nWidth, 1);
|
||||
idx->ReadShort(&m_nHeight, 1);
|
||||
idx->ReadByte(&bt, 1);
|
||||
idx->ReadBuffer(m_strName, 8);
|
||||
idx->ReadU16(&m_nWidth, 1);
|
||||
idx->ReadU16(&m_nHeight, 1);
|
||||
idx->ReadU8(&bt, 1);
|
||||
|
||||
switch (bt)
|
||||
{
|
||||
|
@ -116,7 +116,7 @@ void Texture::LoadIndex(File* idx)
|
|||
break;
|
||||
}
|
||||
|
||||
idx->ReadLong(&m_nOffset, 1);
|
||||
idx->ReadU32(&m_nOffset, 1);
|
||||
}
|
||||
|
||||
void Texture::Unload()
|
||||
|
@ -130,7 +130,7 @@ void Texture::Unload()
|
|||
void Texture::Load(bool bFilter)
|
||||
{
|
||||
char filename[LC_MAXPATH];
|
||||
FileDisk bin;
|
||||
lcDiskFile bin;
|
||||
void* bits;
|
||||
|
||||
strcpy(filename, lcGetPiecesLibrary()->GetLibraryPath());
|
||||
|
@ -144,8 +144,7 @@ void Texture::Load(bool bFilter)
|
|||
bits = malloc (m_nFileSize);
|
||||
|
||||
bin.Seek (m_nOffset, SEEK_SET);
|
||||
bin.Read (bits, m_nFileSize);
|
||||
bin.Close ();
|
||||
bin.ReadBuffer(bits, m_nFileSize);
|
||||
|
||||
FinishLoadImage (bFilter, bits);
|
||||
|
||||
|
|
|
@ -1,11 +1,5 @@
|
|||
//
|
||||
// texture.h
|
||||
////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _TEXTURE_H
|
||||
#define _TEXTURE_H
|
||||
|
||||
class File;
|
||||
#ifndef _TEXTURE_H_
|
||||
#define _TEXTURE_H_
|
||||
|
||||
#include "opengl.h"
|
||||
|
||||
|
@ -29,7 +23,7 @@ class Texture
|
|||
bool LoadFromFile(char* strFilename, bool bFilter);
|
||||
void Unload();
|
||||
|
||||
void LoadIndex(File* idx);
|
||||
void LoadIndex(lcFile* idx);
|
||||
void AddRef(bool bFilter);
|
||||
void DeRef();
|
||||
|
||||
|
@ -49,4 +43,4 @@ protected:
|
|||
};
|
||||
|
||||
|
||||
#endif // _TEXTURE_H
|
||||
#endif // _TEXTURE_H_
|
||||
|
|
|
@ -138,7 +138,7 @@ bool CLibraryDlg::ImportPieces(const ObjArray<String>& FileList)
|
|||
{
|
||||
char file1[LC_MAXPATH], file2[LC_MAXPATH];
|
||||
PiecesLibrary* Library = lcGetPiecesLibrary();
|
||||
FileDisk DiskIdx, DiskBin;
|
||||
lcDiskFile DiskIdx, DiskBin;
|
||||
|
||||
strcpy(file1, Library->GetLibraryPath());
|
||||
strcat(file1, "pieces.idx");
|
||||
|
@ -148,23 +148,17 @@ bool CLibraryDlg::ImportPieces(const ObjArray<String>& FileList)
|
|||
if ((!DiskIdx.Open(file1, "rb")) || (!DiskBin.Open(file2, "rb")))
|
||||
return false;
|
||||
|
||||
FileMem IdxFile1, IdxFile2, BinFile1, BinFile2;
|
||||
long Length;
|
||||
lcMemFile IdxFile1, IdxFile2, BinFile1, BinFile2;
|
||||
|
||||
Length = DiskIdx.GetLength();
|
||||
IdxFile1.SetLength(Length);
|
||||
DiskIdx.Read(IdxFile1.GetBuffer(), Length);
|
||||
IdxFile1.CopyFrom(DiskIdx);
|
||||
DiskIdx.Close();
|
||||
|
||||
Length = DiskBin.GetLength();
|
||||
BinFile1.SetLength(Length);
|
||||
DiskBin.Read(BinFile1.GetBuffer(), Length);
|
||||
BinFile1.CopyFrom(DiskBin);
|
||||
DiskBin.Close();
|
||||
|
||||
FileMem* NewIdx = &IdxFile1;
|
||||
FileMem* NewBin = &BinFile1;
|
||||
FileMem* OldIdx = &IdxFile2;
|
||||
FileMem* OldBin = &BinFile2;
|
||||
lcMemFile* NewIdx = &IdxFile1;
|
||||
lcMemFile* NewBin = &BinFile1;
|
||||
lcMemFile* OldIdx = &IdxFile2;
|
||||
lcMemFile* OldBin = &BinFile2;
|
||||
|
||||
CProgressDlg Dlg("Importing pieces");
|
||||
Dlg.Create(this);
|
||||
|
@ -184,7 +178,7 @@ bool CLibraryDlg::ImportPieces(const ObjArray<String>& FileList)
|
|||
Dlg.SetStatus(Name);
|
||||
Dlg.StepIt();
|
||||
|
||||
FileMem* TmpFile;
|
||||
lcMemFile* TmpFile;
|
||||
|
||||
TmpFile = NewBin;
|
||||
NewBin = OldBin;
|
||||
|
@ -223,11 +217,8 @@ bool CLibraryDlg::ImportPieces(const ObjArray<String>& FileList)
|
|||
strcat(file2, "pieces.idx");
|
||||
rename(file2, file1);
|
||||
|
||||
DiskBin.Seek(0, SEEK_SET);
|
||||
DiskBin.Write(NewBin->GetBuffer(), NewBin->GetLength());
|
||||
|
||||
DiskIdx.Seek(0, SEEK_SET);
|
||||
DiskIdx.Write(NewIdx->GetBuffer(), NewIdx->GetLength());
|
||||
DiskBin.CopyFrom(*NewBin);
|
||||
DiskIdx.CopyFrom(*NewIdx);
|
||||
|
||||
UpdateList();
|
||||
|
||||
|
|
|
@ -150,20 +150,20 @@ UINT APIENTRY OFNOpenHookProc(HWND hdlg, UINT uiMsg, WPARAM wParam, LPARAM lPara
|
|||
|
||||
float fv;
|
||||
char id[32];
|
||||
FileDisk file;
|
||||
lcDiskFile file;
|
||||
file.Open(filename, "rb");
|
||||
file.Read(id, 32);
|
||||
file.ReadBuffer(id, 32);
|
||||
sscanf(strchr(id, ' '), "%f", &fv);
|
||||
|
||||
if (fv > 0.4f)
|
||||
{
|
||||
file.Read(&fv, 4);
|
||||
file.ReadFloats(&fv, 1);
|
||||
|
||||
if (fv > 0.7f)
|
||||
{
|
||||
unsigned long dwPosition;
|
||||
lcuint32 dwPosition;
|
||||
file.Seek(-4, SEEK_END);
|
||||
file.Read(&dwPosition, 4);
|
||||
file.ReadU32(&dwPosition, 1);
|
||||
file.Seek(dwPosition, SEEK_SET);
|
||||
|
||||
if (dwPosition != 0)
|
||||
|
@ -171,10 +171,10 @@ UINT APIENTRY OFNOpenHookProc(HWND hdlg, UINT uiMsg, WPARAM wParam, LPARAM lPara
|
|||
if (fv < 1.0f)
|
||||
{
|
||||
BITMAPFILEHEADER bmfHeader;
|
||||
file.Read((LPSTR)&bmfHeader, sizeof(bmfHeader));
|
||||
file.ReadBuffer((LPSTR)&bmfHeader, sizeof(bmfHeader));
|
||||
DWORD nPackedDIBLen = sizeof(BITMAPINFOHEADER) + 36000;
|
||||
HGLOBAL hDIB = ::GlobalAlloc(GMEM_FIXED, nPackedDIBLen);
|
||||
file.Read((LPSTR)hDIB, nPackedDIBLen);
|
||||
file.ReadBuffer((LPSTR)hDIB, nPackedDIBLen);
|
||||
BITMAPINFOHEADER &bmiHeader = *(LPBITMAPINFOHEADER)hDIB;
|
||||
BITMAPINFO &bmInfo = *(LPBITMAPINFO)hDIB;
|
||||
int nColors = bmiHeader.biClrUsed ? bmiHeader.biClrUsed : 1 << bmiHeader.biBitCount;
|
||||
|
@ -192,32 +192,31 @@ UINT APIENTRY OFNOpenHookProc(HWND hdlg, UINT uiMsg, WPARAM wParam, LPARAM lPara
|
|||
else
|
||||
{
|
||||
Image image;
|
||||
|
||||
if (image.FileLoad (file))
|
||||
{
|
||||
HWND hwndDesktop = GetDesktopWindow();
|
||||
HDC hdcDesktop = GetDC(hwndDesktop);
|
||||
HDC hdcMem = CreateCompatibleDC(hdcDesktop);
|
||||
hbm = CreateCompatibleBitmap(hdcDesktop, 120, 100);
|
||||
HBITMAP hbmOld = (HBITMAP)SelectObject(hdcMem, hbm);
|
||||
|
||||
for (int y = 0; y < 100; y++)
|
||||
for (int x = 0; x < 120; x++)
|
||||
{
|
||||
unsigned char* b = image.GetData () + (y*120+x)*3;
|
||||
SetPixelV(hdcMem, x, y, RGB(b[0], b[1], b[2]));
|
||||
}
|
||||
if (image.FileLoad (file))
|
||||
{
|
||||
HWND hwndDesktop = GetDesktopWindow();
|
||||
HDC hdcDesktop = GetDC(hwndDesktop);
|
||||
HDC hdcMem = CreateCompatibleDC(hdcDesktop);
|
||||
hbm = CreateCompatibleBitmap(hdcDesktop, 120, 100);
|
||||
HBITMAP hbmOld = (HBITMAP)SelectObject(hdcMem, hbm);
|
||||
|
||||
// Clean up
|
||||
SelectObject(hdcMem, hbmOld);
|
||||
DeleteDC(hdcMem);
|
||||
ReleaseDC(hwndDesktop, hdcDesktop);
|
||||
}
|
||||
for (int y = 0; y < 100; y++)
|
||||
for (int x = 0; x < 120; x++)
|
||||
{
|
||||
unsigned char* b = image.GetData () + (y*120+x)*3;
|
||||
SetPixelV(hdcMem, x, y, RGB(b[0], b[1], b[2]));
|
||||
}
|
||||
|
||||
// Clean up
|
||||
SelectObject(hdcMem, hbmOld);
|
||||
DeleteDC(hdcMem);
|
||||
ReleaseDC(hwndDesktop, hdcDesktop);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
file.Close();
|
||||
|
||||
if (!hbm)
|
||||
hbm = CreateColorBitmap (120, 100, GetSysColor(COLOR_BTNFACE));
|
||||
|
@ -1471,7 +1470,7 @@ void SystemReleaseMouse()
|
|||
ReleaseCapture();
|
||||
}
|
||||
|
||||
void SystemExportClipboard(File* clip)
|
||||
void SystemExportClipboard(lcFile* clip)
|
||||
{
|
||||
if (clip == NULL)
|
||||
return;
|
||||
|
@ -1479,7 +1478,7 @@ void SystemExportClipboard(File* clip)
|
|||
HGLOBAL hData = GlobalAlloc(GMEM_DDESHARE|GMEM_MOVEABLE, clip->GetLength());
|
||||
void* lpBuffer = GlobalLock(hData);
|
||||
clip->Seek(0, SEEK_SET);
|
||||
clip->Read(lpBuffer, clip->GetLength());
|
||||
clip->ReadBuffer(lpBuffer, clip->GetLength());
|
||||
GlobalUnlock(hData);
|
||||
|
||||
if (OpenClipboard(NULL))
|
||||
|
@ -1491,9 +1490,9 @@ void SystemExportClipboard(File* clip)
|
|||
// AfxMessageBox(IDS_CANNOT_OPEN_CLIPBOARD);
|
||||
}
|
||||
|
||||
File* SystemImportClipboard()
|
||||
lcFile* SystemImportClipboard()
|
||||
{
|
||||
File* clip = NULL;
|
||||
lcFile* clip = NULL;
|
||||
|
||||
if (ClipboardFormat != 0)
|
||||
if (OpenClipboard(NULL))
|
||||
|
@ -1501,11 +1500,11 @@ File* SystemImportClipboard()
|
|||
HANDLE hData = ::GetClipboardData(ClipboardFormat);
|
||||
if (hData != NULL)
|
||||
{
|
||||
clip = new FileMem();
|
||||
clip = new lcMemFile();
|
||||
|
||||
BYTE* lpBuffer = (BYTE*)::GlobalLock(hData);
|
||||
long nBufferSize = ::GlobalSize(hData);
|
||||
clip->Write(lpBuffer, nBufferSize);
|
||||
clip->WriteBuffer(lpBuffer, nBufferSize);
|
||||
GlobalUnlock(hData);
|
||||
}
|
||||
// else
|
||||
|
|
Loading…
Reference in a new issue