📄 elrgb8.cpp
字号:
#include <fstream.h>
#include "elemdbm.h"
#include "elements.h"
// class information
const char* mgcRGB8::description = "X";
const int mgcRGB8::size = sizeof(unsigned int);
const int mgcRGB8::type = mgcRGB8::Register();
// error handling
int mgcRGB8::verbose = 0;
unsigned mgcRGB8::error = 0;
const unsigned mgcRGB8::registration_failed = 0x00000001;
const char* mgcRGB8::message[1] = {
"registration failed"
};
//===========================================================================
int mgcRGB8::
Register ()
{
static int first_time = 1;
if ( first_time == 0 )
return mgcRGB8::type;
first_time = 0;
mgcElementDBM::ElementRecord er;
er.addrtype = &mgcRGB8::type;
er.description = mgcRGB8::description;
er.memory_size = mgcRGB8::size;
er.packed_size = mgcRGB8::size;
er.input = mgcRGB8::Input;
er.output = mgcRGB8::Output;
er.reverse = mgcElementDBM::Reverse4;
er.pack = 0;
er.unpack = 0;
er.convert_to = 0;
if ( mgcRGB8::type != mgcElementDBM::AddType(er) ) {
Report(registration_failed);
return -1;
}
mgcElementDBM::AddConvert
(mgcRGB8::type,mgcUshort::type,mgcRGB8::ToUshort);
mgcElementDBM::AddConvert
(mgcRGB8::type,mgcUint::type,mgcRGB8::ToUint);
mgcElementDBM::AddConvert
(mgcRGB8::type,mgcUlong::type,mgcRGB8::ToUlong);
mgcElementDBM::AddConvert
(mgcRGB8::type,mgcRGB8::type,mgcRGB8::ToUint);
return mgcRGB8::type;
}
//---------------------------------------------------------------------------
mgcRGB8& mgcRGB8::
operator= (const mgcElement& element)
{
mgcElementDBM::EFconvert convert =
mgcElementDBM::record[element.type].convert_to[type];
if ( convert )
convert(1,element.data,data);
return *this;
}
//---------------------------------------------------------------------------
#define CONVERSION(ToType,type) \
void mgcRGB8:: \
ToType (int quantity, void* src, void* trg) \
{ \
register unsigned int* psrc = (unsigned int*)src; \
register type* ptrg = (type*)trg; \
for (register long i = 0; i < quantity; i++, psrc++, ptrg++) \
*ptrg = (type)(*psrc); \
}
CONVERSION(ToUshort,unsigned short);
CONVERSION(ToUint,unsigned int);
CONVERSION(ToUlong,unsigned long);
//---------------------------------------------------------------------------
int mgcRGB8::
Number (unsigned single_error)
{
int result;
for (result = -1; single_error; single_error >>= 1)
result++;
return result;
}
//---------------------------------------------------------------------------
void mgcRGB8::
Report (unsigned single_error)
{
if ( mgcElement::verbose || mgcRGB8::verbose )
cout << "mgcRGB8: " << message[Number(single_error)] << endl;
else
ofstream("elint.err",ios::out|ios::app)
<< "mgcRGB8: " << message[Number(single_error)] << endl;
error |= single_error;
}
//---------------------------------------------------------------------------
void mgcRGB8::
Report (ostream& ostr)
{
for (unsigned single_error = 1; single_error; single_error <<= 1)
if ( error & single_error )
ostr << "mgcRGB8: " << message[Number(single_error)] << endl;
error = 0;
}
//===========================================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -