CnUnix

[알림판목록 I] [알림판목록 II] [글목록][이 전][다 음]
[ CnUnix ] in KIDS
글 쓴 이(By): Gunee (해오라비)
날 짜 (Date): 2005년 5월 18일 수요일 오후 10시 22분 13초
제 목(Title): 질문...


아래는 헤더 파일에 있는 소스입니다.

error C2526: 'Spaghetti::Color::FromRGBA' : C linkage function cannot return C++ class 'Spaghetti::Color" 

라는 에러메세지가 나오는데, 혹시 에러가 왜 발생하는지,
어떻게 해결할 수 있을 지 조언 좀 해주시면 감사하겠습니다.
참, VC++ 6.0, VS.NET 2003에서 컴팔했습니다.

제발, 머리 나쁜 중생에게 밝은 희망을 주세요...
아구 눈 뻑뻑해...




namespace Spaghetti {

class Color {

public:
enum {
MAX = 0xff
};

public:
U8 r, g, b, a;

public:
Color() {
r = g = b = a = 0;
}

Color(U32 rgba) { 
r = (rgba >> 24) & 0xff;
g = (rgba >> 16) & 0xff;
b = (rgba >>  8) & 0xff;
a = rgba & 0xff;
}

Color(U8 R, U8 G, U8 B, U8 A) {
r = R;
g = G;
b = B;
a = A;
}

Color(const Color& other) {
r = other.r;
g = other.g;
b = other.b;
a = other.a;
}

Color& operator=(const Color& other) {
r = other.r;
g = other.g;
b = other.b;
a = other.a;
return *this;
}

bool operator==(const Color& other) const {
return ConvertToRGBA() == other.ConvertToRGBA();
}

inline U8 A() const {
return a;
}

inline U8 R() const {
return r;
}

inline U8 G() const {
return g;
}

inline U8 B() const {
return b;
}

inline Color Mask(bool maskR, bool maskG, bool maskB, bool maskA) const {
return Color(maskR ? r : 0, maskG ? g : 0, maskB ? b : 0, maskA ? a : 0);
}

inline U16 ConvertTo565() const {
return (b & 0xF8) >> 3 | (g & 0xFC) << 3 | (r & 0xF8) << 8;
}

inline U32 ConvertToRGBA() const {
return r << 24 | g << 16 | b << 8 | a;
}

inline U16 ConvertTo5551() const {
return (b & 0xF8) >> 2 | (g & 0xF8) << 3 | (r & 0xF8) << 8 | (a & 0x80) >> 7;
}

inline U16 ConvertTo4444() const {
return (r & 0xf0) << 8 |
(g & 0xf0) << 4 |
(b & 0xf0) |
a >> 4;
}

static inline Color FromRGBA(U32 rgba) {
U8 r = (rgba & 0xFF000000) >> 24;
U8 g = (rgba & 0x00FF0000) >> 16;
U8 b = (rgba & 0x0000FF00) >>  8;
U8 a = (rgba & 0x000000FF);

return Color(r, g, b, a);
}

static inline Color From4444(U16 u4444) {
U8 r = (u4444 & 0xF000u) >> 8;
U8 g = (u4444 & 0x0F00u) >> 4;
U8 b = (u4444 & 0x00F0u);
U8 a = (u4444 & 0x000Fu) << 4;

r |= r >> 4;
g |= g >> 4;
b |= b >> 4;
a |= a >> 4;

return Color(r, g, b, a);
}

static inline Color From565(U16 u565) {
U8 b = (u565 & 0x001Fu) << 3;
U8 g = (u565 & 0x07E0u) >> 3;
U8 r = (u565 & 0xF800u) >> 8;

r |= r >> 5;
g |= g >> 6;
b |= b >> 5;

return Color(r, g, b, 0xFF);
}

static inline Color From565A(U16 u565, U8 alpha) {
U8 b = (u565 & 0x001Fu) << 3;
U8 g = (u565 & 0x07E0u) >> 3;
U8 r = (u565 & 0xF800u) >> 8;

r |= r >> 5;
g |= g >> 6;
b |= b >> 5;

return Color(r, g, b, alpha);
}

static inline Color From5551(U16 u5551) {
U8 b = (u5551 & 0x003Eu) << 2;
U8 g = (u5551 & 0x07C0u) >> 3;
U8 r = (u5551 & 0xF800u) >> 8;
U8 a = (u5551 & 0x0001u) << 7;

r |= r >> 5;
g |= g >> 5;
b |= b >> 5;
if (a) a |= 0x7f;

return Color(r, g, b, a);
}

static inline Color FromLuminanceAlpha(U16 la) {
U8 l = (la & 0xff);
U8 a = (la & 0xff00) >> 8;

return Color(l, l, l, a);
}

Color operator+(const Color& other) const {
return Color(clamp(r + other.r), clamp(g + other.g), 
clamp(b + other.b), clamp(a + other.a));
}

Color operator*(const Color& factor) const {
return Color(mul(r, factor.r), mul(g, factor.g), mul(b, factor.b), mul(a, factor.a));
}

static inline Color Blend(const Color& src, const Color& dst, U32 alpha) {
U32 oneMinusAlpha = 0x100 - alpha;

return Color((src.R() * alpha + dst.R() * oneMinusAlpha) >> 8,
(src.G() * alpha + dst.G() * oneMinusAlpha) >> 8,
(src.B() * alpha + dst.B() * oneMinusAlpha) >> 8,
src.A());
}

static inline Color BlendAlpha(const Color& src, const Color& dst, U32 alpha) {
U32 oneMinusAlpha = 0x100 - alpha;

return Color((src.R() * alpha + dst.R() * oneMinusAlpha) >> 8,
(src.G() * alpha + dst.G() * oneMinusAlpha) >> 8,
(src.B() * alpha + dst.B() * oneMinusAlpha) >> 8,
(src.A() * alpha + dst.A() * oneMinusAlpha) >> 8);
}

static inline Color Average(const Color & a, const Color & b) {
return Color((a.R() + b.R()) / 2,
 (a.G() + b.G()) / 2,
 (a.B() + b.B()) / 2,
 (a.A() + b.A()) / 2);
}

static inline Color Average(const Color & a, const Color & b,
const Color & c, const Color & d) {
return Color((a.R() + b.R() + c.R() + d.R()) / 4,
 (a.G() + b.G() + c.G() + d.G()) / 4,
 (a.B() + b.B() + c.B() + d.B()) / 4,
 (a.A() + b.A() + c.A() + d.A()) / 4);
}

private:
static inline U8 clamp(U16 value) {
return (value > MAX) ? (U8) MAX : (U8) value;
}

static inline U8 mul(U8 color, U8 factor) {
U16 prod = color * factor;

return (prod + (prod >> 7)) >> 8;
}
};

}


                         Fear can hold you prisoner,
                      
                                 Hope will set you free !!!
[알림판목록 I] [알림판목록 II] [글 목록][이 전][다 음]
키 즈 는 열 린 사 람 들 의 모 임 입 니 다.