IT 취미생활.  
Front Page
Tag | Location | Media | Guestbook | Admin   
 
rgb565 <--> rgb888 code
출처 : http://www.davechapman.f2s.com/rockbox/rgb.c

코드를 그대로 가져 왔습니다.
------------------------------------------------------

#include <stdio.h>

#define swap16(x) (((x) >> 8) || ((x) << 8))

#define _RGBPACK(r, g, b) ( ((((r) * 31 + 127) / 255) << 11) \
                          |((((g) * 63 + 127) / 255) << 5) \
                          | (((b) * 31 + 127) / 255))


#define _RGB_UNPACK_RED(x)   (((x) >> 8) & 0xf8) | ((x) >> 13);
#define _RGB_UNPACK_GREEN(x) (((x) >> 3) & 0xfc) | (((x) >> 9) & 0x03);
#define _RGB_UNPACK_BLUE(x)  (((x) << 3) & 0xf8) | (((x) >> 2) & 0x07);

#if 1   /* RGB565 */
#define RGBPACK(r,g,b) _RGBPACK(r,g,b)

#define RGB_UNPACK_RED(x)   _RGB_UNPACK_RED(x)
#define RGB_UNPACK_GREEN(x) _RGB_UNPACK_GREEN(x)
#define RGB_UNPACK_BLUE(x)  _RGB_UNPACK_BLUE(x)

#else   /* RGB565 Byte-swapped */

#define RGBPACK(r,g,b) swap16(_RGBPACK(r,g,b))

#define RGB_UNPACK_RED(x)   _RGB_UNPACK_RED(swap16(x))
#define RGB_UNPACK_GREEN(x) _RGB_UNPACK_GREEN(swap16(x))
#define RGB_UNPACK_BLUE(x)  _RGB_UNPACK_BLUE(swap16(x))

#endif

int main (int argc, char* argv[])
{
    int c;
    int r,g,b;

    unsigned short rgb565a;
    unsigned short rgb565b;
    unsigned int rgb888;

    for (c=0;c<256;c++) {
        /* Create RGB565 */
        rgb565a=RGBPACK(c,c,c);

        /* Unpack RGB565 to RGB888 and then re-pack to RGB565 */
        r = RGB_UNPACK_RED(rgb565a);
        g = RGB_UNPACK_GREEN(rgb565a);
        b = RGB_UNPACK_BLUE(rgb565a);

        /* Convert back to RGB565 */
        rgb565b = RGBPACK(r,g,b);

        printf("%3d -> 0x%04x -> (%3d, %3d, %3d) -> 0x%04x  %s\n",
               c,rgb565a,r,g,b,rgb565b,((rgb565a == rgb565b) ? "OK" : "BAD"));
    }
}


BLOG main image
취미생활
 Notice
 Category
분류 전체보기 (191)
매일매일갱생 (83)
서버개발 (1)
임베디드개발 (12)
Programming (80)
Personal Projects (6)
유용한 프로그램 (0)
 TAGS
C++ C debugging Wince5.0 english email Error Case project Windows Mobile6.0 서태지 MP3 영어 이메일 티스토리 초대장 음식 VC++ 알고리즘 미라지폰 warning M480 Debug Algorithm 1seg It spam mail 개발자 isdbt 군대 Brazil 출장 Java DVB DirectShow Linux Dshow 퇴사 ISDB-T 티스토리초대 벨소리 변경 English DVB-T
 Calendar
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
 Recent Entries
 Recent Comments
 Recent Trackbacks
 Archive
 Link Site
zextor
괴짜 프로그래머의 일상사~@@
Gag & Peace, and more..
Kazakhstan Almaty.......
Min-A
Sadgarret
Steve Yoon's log
가슴 뛰는 삶을 살아라
오스틴 파워
GUI sin
melanie parker_Lady
제레미의 TV 2.0 이야기..
 Visitor Statistics
Total :
Today :
Yesterday :
rss