intuition.library: implement EasyReqest and BuildEasyRequest that are x64/arm compatible
[AROS.git] / test / hidds / graphics / convertpixels.c
blob602f2c03d39181b3bd8f3a27611651f62cfd36ed
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define __OOP_NOATTRBASES__
8 #include <hidd/graphics.h>
9 #include <proto/graphics.h>
10 #include <proto/oop.h>
12 #include <stdio.h>
14 #undef ConvertPixels
16 static OOP_AttrBase HiddBitMapAttrBase;
18 #if AROS_BIG_ENDIAN
19 #define SRC_PIXFMT vHidd_StdPixFmt_ARGB32
20 #define DST_PIXFMT vHidd_StdPixFmt_RGB15
21 #else
22 #define SRC_PIXFMT vHidd_StdPixFmt_BGRA32
23 #define DST_PIXFMT vHidd_StdPixFmt_RGB15_LE
24 #endif
26 static ULONG argb[8] =
28 0x00112233,
29 0x00FFFFFF,
30 0xFF888888,
31 0x00FF0000,
32 0x0000FF00,
33 0x000000FF,
34 0x00FFFF00,
35 0x8899AABB,
37 static UWORD rgb15[8];
38 static ULONG argb_inv[8];
40 static void ConvertPixels(APTR srcPixels, ULONG srcMod, HIDDT_StdPixFmt srcPixFmt,
41 APTR dstPixels, ULONG dstMod, HIDDT_StdPixFmt dstPixFmt,
42 ULONG width, ULONG height, OOP_Object *bm)
44 OOP_Object *gfxhidd = NULL;
45 OOP_Object *srcpf, *dstpf;
46 APTR src = srcPixels;
47 APTR dst = dstPixels;
49 OOP_GetAttr(bm, aHidd_BitMap_GfxHidd, (IPTR *)&gfxhidd);
51 if (!gfxhidd) {
52 printf("ConvertPixels(): Failed to obtain graphics driver\n");
53 return;
56 srcpf = HIDD_Gfx_GetPixFmt(gfxhidd, srcPixFmt);
57 dstpf = HIDD_Gfx_GetPixFmt(gfxhidd, dstPixFmt);
59 if (!srcpf || !dstpf)
61 printf("ConvertPixels(): Bad source (%ld) or dest (%ld) pixfmt!\n", srcPixFmt, dstPixFmt);
62 return;
65 HIDD_BM_ConvertPixels(bm, &src, (HIDDT_PixelFormat *)srcpf, srcMod,
66 &dst, (HIDDT_PixelFormat *)dstpf, dstMod,
67 width, height, NULL);
70 int main(void)
72 struct BitMap *bitmap;
74 HiddBitMapAttrBase = OOP_ObtainAttrBase(IID_Hidd_BitMap);
75 if (!HiddBitMapAttrBase) {
76 printf("Failed to obtain IID_Hidd_BitMap\n");
77 return RETURN_FAIL;
80 bitmap = AllocBitMap(1, 1, 16, 0, NULL);
81 if (!bitmap) {
82 printf("Failed to allocate a placeholder bitmap!\n");
83 OOP_ReleaseAttrBase(IID_Hidd_BitMap);
84 return RETURN_FAIL;
87 ConvertPixels(argb, 0, SRC_PIXFMT, rgb15, 0, DST_PIXFMT, 8, 1, HIDD_BM_OBJ(bitmap));
88 ConvertPixels(rgb15, 0, DST_PIXFMT, argb_inv, 0, SRC_PIXFMT, 8, 1, HIDD_BM_OBJ(bitmap));
91 int i;
93 for(i = 0; i < 8; i++)
95 printf("ARGB32 %08x = RGB15 %04x (%02x %02x %02x) (%3d%% %3d%% %3d%%) [%08x]\n",
96 (unsigned int)argb[i], rgb15[i],
97 (rgb15[i] & 0x7C00) >> 10,
98 (rgb15[i] & 0x03E0) >> 5,
99 (rgb15[i] & 0x001F),
100 ((rgb15[i] & 0x7C00) >> 10) * 100 / 31,
101 ((rgb15[i] & 0x03E0) >> 5) * 100 / 31,
102 (rgb15[i] & 0x001F) * 100 / 31,
103 (unsigned int)argb_inv[i]
108 OOP_ReleaseAttrBase(IID_Hidd_BitMap);
109 return 0;