grub2: bring back build of aros-side grub2 tools
[AROS.git] / rom / graphics / fontsupport.c
blob051dbe55fd111349c639b7c31afda0990d99e0bb
1 /*
2 Copyright © 1995-2010, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Misc font help funcs
6 Lang: english
7 */
9 #include <proto/exec.h>
10 #include <proto/oop.h>
11 #include <proto/graphics.h>
13 #include <exec/memory.h>
14 #include <graphics/text.h>
16 #include "graphics_intern.h"
17 #include "gfxfuncsupport.h"
18 #include "fontsupport.h"
20 /****************************************************************************************/
22 ULONG CalcHashIndex(IPTR n, UWORD hashsize)
24 UBYTE Index = (n & 0xff)
25 + ((n >> 8) & 0xff)
26 + ((n >> 16) & 0xff)
27 + ((n >> 24) & 0xff)
28 #if __WORDSIZE == 64
29 + ((n >> 32) & 0xff)
30 + ((n >> 40) & 0xff)
31 + ((n >> 48) & 0xff)
32 + ((n >> 56) & 0xff)
33 #endif
36 Index &= (hashsize - 1);
38 return Index;
40 /****************************************************************************************/
42 /* Functions for solving the TextFontExtension problem using hashes */
44 #define GFBI(x) ((struct GfxBase_intern *)x)
46 /****************************************************************************************/
48 struct tfe_hashnode *tfe_hashlookup(struct TextFont *tf, struct GfxBase *GfxBase)
51 ULONG idx = CalcHashIndex((IPTR)tf, TFE_HASHTABSIZE);
52 struct tfe_hashnode *n = NULL;
55 ObtainSemaphoreShared( &GFBI(GfxBase)->tfe_hashtab_sema );
57 for ( n = GFBI(GfxBase)->tfe_hashtab[idx]; n; n = n->next)
59 if (n->back == tf)
61 break;
65 ReleaseSemaphore( &GFBI(GfxBase)->tfe_hashtab_sema );
67 return n;
70 /****************************************************************************************/
72 struct tfe_hashnode *tfe_hashnode_create(struct GfxBase *GfxBase)
74 struct tfe_hashnode *n;
76 n = AllocMem( sizeof (struct tfe_hashnode), MEMF_ANY|MEMF_CLEAR);
78 return n;
81 /****************************************************************************************/
83 void tfe_hashadd(struct tfe_hashnode *hn
84 , struct TextFont *tf
85 , struct TextFontExtension *etf
86 , struct GfxBase *GfxBase)
89 ULONG idx = CalcHashIndex((IPTR)tf, TFE_HASHTABSIZE);
91 hn->back = tf;
92 hn->ext = etf;
94 ObtainSemaphore( &GFBI(GfxBase)->tfe_hashtab_sema );
96 hn->next = GFBI(GfxBase)->tfe_hashtab[idx];
97 GFBI(GfxBase)->tfe_hashtab[idx] = hn;
99 ReleaseSemaphore( &GFBI(GfxBase)->tfe_hashtab_sema );
101 return;
104 /****************************************************************************************/
106 void tfe_hashdelete(struct TextFont *tf, struct GfxBase *GfxBase)
108 ULONG idx = CalcHashIndex((IPTR)tf, TFE_HASHTABSIZE);
109 struct tfe_hashnode *n, *last = NULL;
111 ObtainSemaphore( &GFBI(GfxBase)->tfe_hashtab_sema );
113 for (n = GFBI(GfxBase)->tfe_hashtab[idx]; n; n = n->next)
115 if (n->back == tf)
117 if (last)
118 last->next = n->next;
119 else
120 GFBI(GfxBase)->tfe_hashtab[idx] = n->next;
122 FreeMem(n, sizeof (struct tfe_hashnode));
123 break;
125 last = n;
128 ReleaseSemaphore( &GFBI(GfxBase)->tfe_hashtab_sema );
130 return;
134 /****************************************************************************************/
136 UBYTE *colorfontbm_to_chunkybuffer(struct TextFont *font, struct GfxBase *GfxBase)
138 ULONG width, height;
139 UBYTE *chunky;
141 width = font->tf_Modulo * 8;
142 height = font->tf_YSize;
144 chunky = AllocVec(width * height, MEMF_CLEAR);
145 if (chunky)
147 struct BitMap bm;
148 struct RastPort rp;
149 UBYTE d, shift = 1, plane = 0;
151 InitBitMap(&bm, CTF(font)->ctf_Depth, width, height);
153 for(d = 0; d < CTF(font)->ctf_Depth; d++, shift <<= 1)
155 if (CTF(font)->ctf_PlanePick & shift)
157 bm.Planes[d] = (PLANEPTR)(CTF(font)->ctf_CharData[plane++]);
159 else
161 bm.Planes[d] = (CTF(font)->ctf_PlaneOnOff & shift) ? (PLANEPTR)-1 : NULL;
165 InitRastPort(&rp);
166 rp.BitMap = &bm;
168 ReadPixelArray8(&rp, 0, 0, width - 1, height - 1, chunky, NULL);
171 return chunky;
174 /****************************************************************************************/