LICENSE.Author: Add license file to permit per-author *additional* permissions
[AROS.git] / test / convertpixels.c
blob73a4de826a56a9b385dd40f36420f472f84e29f8
1 #define __OOP_NOATTRBASES__
3 #include <hidd/graphics.h>
4 #include <proto/graphics.h>
5 #include <proto/oop.h>
7 #include <stdio.h>
9 #undef ConvertPixels
11 static OOP_AttrBase HiddBitMapAttrBase;
13 #if AROS_BIG_ENDIAN
14 #define SRC_PIXFMT vHidd_StdPixFmt_ARGB32
15 #define DST_PIXFMT vHidd_StdPixFmt_RGB15
16 #else
17 #define SRC_PIXFMT vHidd_StdPixFmt_BGRA32
18 #define DST_PIXFMT vHidd_StdPixFmt_RGB15_LE
19 #endif
21 static ULONG argb[8] =
23 0x00112233,
24 0x00FFFFFF,
25 0xFF888888,
26 0x00FF0000,
27 0x0000FF00,
28 0x000000FF,
29 0x00FFFF00,
30 0x8899AABB,
32 static UWORD rgb15[8];
33 static ULONG argb_inv[8];
35 static void ConvertPixels(APTR srcPixels, ULONG srcMod, HIDDT_StdPixFmt srcPixFmt,
36 APTR dstPixels, ULONG dstMod, HIDDT_StdPixFmt dstPixFmt,
37 ULONG width, ULONG height, OOP_Object *bm)
39 OOP_Object *gfxhidd = NULL;
40 OOP_Object *srcpf, *dstpf;
41 APTR src = srcPixels;
42 APTR dst = dstPixels;
44 OOP_GetAttr(bm, aHidd_BitMap_GfxHidd, (IPTR *)&gfxhidd);
46 if (!gfxhidd) {
47 printf("ConvertPixels(): Failed to obtain graphics driver\n");
48 return;
51 srcpf = HIDD_Gfx_GetPixFmt(gfxhidd, srcPixFmt);
52 dstpf = HIDD_Gfx_GetPixFmt(gfxhidd, dstPixFmt);
54 if (!srcpf || !dstpf)
56 printf("ConvertPixels(): Bad source (%ld) or dest (%ld) pixfmt!\n", srcPixFmt, dstPixFmt);
57 return;
60 HIDD_BM_ConvertPixels(bm, &src, (HIDDT_PixelFormat *)srcpf, srcMod,
61 &dst, (HIDDT_PixelFormat *)dstpf, dstMod,
62 width, height, NULL);
65 int main(void)
67 struct BitMap *bitmap;
69 HiddBitMapAttrBase = OOP_ObtainAttrBase(IID_Hidd_BitMap);
70 if (!HiddBitMapAttrBase) {
71 printf("Failed to obtain IID_Hidd_BitMap\n");
72 return RETURN_FAIL;
75 bitmap = AllocBitMap(1, 1, 16, 0, NULL);
76 if (!bitmap) {
77 printf("Failed to allocate a placeholder bitmap!\n");
78 OOP_ReleaseAttrBase(IID_Hidd_BitMap);
79 return RETURN_FAIL;
82 ConvertPixels(argb, 0, SRC_PIXFMT, rgb15, 0, DST_PIXFMT, 8, 1, (OOP_Object *)bitmap->Planes[0]);
83 ConvertPixels(rgb15, 0, DST_PIXFMT, argb_inv, 0, SRC_PIXFMT, 8, 1, (OOP_Object *)bitmap->Planes[0]);
86 int i;
88 for(i = 0; i < 8; i++)
90 printf("ARGB32 %08x = RGB15 %04x (%02x %02x %02x) (%3d%% %3d%% %3d%%) [%08x]\n",
91 (unsigned int)argb[i], rgb15[i],
92 (rgb15[i] & 0x7C00) >> 10,
93 (rgb15[i] & 0x03E0) >> 5,
94 (rgb15[i] & 0x001F),
95 ((rgb15[i] & 0x7C00) >> 10) * 100 / 31,
96 ((rgb15[i] & 0x03E0) >> 5) * 100 / 31,
97 (rgb15[i] & 0x001F) * 100 / 31,
98 (unsigned int)argb_inv[i]
103 OOP_ReleaseAttrBase(IID_Hidd_BitMap);
104 return 0;