mgh: fix for default HDD DMA mode, that wasn't correctly set
[open-ps2-loader.git] / thirdparty / freetype-2.3.12 / src / raster / ftrend1.c
blob1ed8af612175da4e741ff0e4bd7c1b8304243531
1 /***************************************************************************/
2 /* */
3 /* ftrend1.c */
4 /* */
5 /* The FreeType glyph rasterizer interface (body). */
6 /* */
7 /* Copyright 1996-2001, 2002, 2003, 2005, 2006 by */
8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
9 /* */
10 /* This file is part of the FreeType project, and may only be used, */
11 /* modified, and distributed under the terms of the FreeType project */
12 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */
13 /* this file you indicate that you have read the license and */
14 /* understand and accept it fully. */
15 /* */
16 /***************************************************************************/
19 #include <ft2build.h>
20 #include FT_INTERNAL_OBJECTS_H
21 #include FT_OUTLINE_H
22 #include "ftrend1.h"
23 #include "ftraster.h"
24 #include "rastpic.h"
26 #include "rasterrs.h"
29 /* initialize renderer -- init its raster */
30 static FT_Error
31 ft_raster1_init( FT_Renderer render )
33 FT_Library library = FT_MODULE_LIBRARY( render );
36 render->clazz->raster_class->raster_reset( render->raster,
37 library->raster_pool,
38 library->raster_pool_size );
40 return Raster_Err_Ok;
44 /* set render-specific mode */
45 static FT_Error
46 ft_raster1_set_mode( FT_Renderer render,
47 FT_ULong mode_tag,
48 FT_Pointer data )
50 /* we simply pass it to the raster */
51 return render->clazz->raster_class->raster_set_mode( render->raster,
52 mode_tag,
53 data );
57 /* transform a given glyph image */
58 static FT_Error
59 ft_raster1_transform( FT_Renderer render,
60 FT_GlyphSlot slot,
61 const FT_Matrix* matrix,
62 const FT_Vector* delta )
64 FT_Error error = Raster_Err_Ok;
67 if ( slot->format != render->glyph_format )
69 error = Raster_Err_Invalid_Argument;
70 goto Exit;
73 if ( matrix )
74 FT_Outline_Transform( &slot->outline, matrix );
76 if ( delta )
77 FT_Outline_Translate( &slot->outline, delta->x, delta->y );
79 Exit:
80 return error;
84 /* return the glyph's control box */
85 static void
86 ft_raster1_get_cbox( FT_Renderer render,
87 FT_GlyphSlot slot,
88 FT_BBox* cbox )
90 FT_MEM_ZERO( cbox, sizeof ( *cbox ) );
92 if ( slot->format == render->glyph_format )
93 FT_Outline_Get_CBox( &slot->outline, cbox );
97 /* convert a slot's glyph image into a bitmap */
98 static FT_Error
99 ft_raster1_render( FT_Renderer render,
100 FT_GlyphSlot slot,
101 FT_Render_Mode mode,
102 const FT_Vector* origin )
104 FT_Error error;
105 FT_Outline* outline;
106 FT_BBox cbox;
107 FT_UInt width, height, pitch;
108 FT_Bitmap* bitmap;
109 FT_Memory memory;
111 FT_Raster_Params params;
114 /* check glyph image format */
115 if ( slot->format != render->glyph_format )
117 error = Raster_Err_Invalid_Argument;
118 goto Exit;
121 /* check rendering mode */
122 #ifndef FT_CONFIG_OPTION_PIC
123 if ( mode != FT_RENDER_MODE_MONO )
125 /* raster1 is only capable of producing monochrome bitmaps */
126 if ( render->clazz == &ft_raster1_renderer_class )
127 return Raster_Err_Cannot_Render_Glyph;
129 else
131 /* raster5 is only capable of producing 5-gray-levels bitmaps */
132 if ( render->clazz == &ft_raster5_renderer_class )
133 return Raster_Err_Cannot_Render_Glyph;
135 #else /* FT_CONFIG_OPTION_PIC */
136 /* When PIC is enabled, we cannot get to the class object */
137 /* so instead we check the final character in the class name */
138 /* ("raster5" or "raster1"). Yes this is a hack. */
139 /* The "correct" thing to do is have different render function */
140 /* for each of the classes. */
141 if ( mode != FT_RENDER_MODE_MONO )
143 /* raster1 is only capable of producing monochrome bitmaps */
144 if ( render->clazz->root.module_name[6] == '1' )
145 return Raster_Err_Cannot_Render_Glyph;
147 else
149 /* raster5 is only capable of producing 5-gray-levels bitmaps */
150 if ( render->clazz->root.module_name[6] == '5' )
151 return Raster_Err_Cannot_Render_Glyph;
153 #endif /* FT_CONFIG_OPTION_PIC */
155 outline = &slot->outline;
157 /* translate the outline to the new origin if needed */
158 if ( origin )
159 FT_Outline_Translate( outline, origin->x, origin->y );
161 /* compute the control box, and grid fit it */
162 FT_Outline_Get_CBox( outline, &cbox );
164 cbox.xMin = FT_PIX_FLOOR( cbox.xMin );
165 cbox.yMin = FT_PIX_FLOOR( cbox.yMin );
166 cbox.xMax = FT_PIX_CEIL( cbox.xMax );
167 cbox.yMax = FT_PIX_CEIL( cbox.yMax );
169 width = (FT_UInt)( ( cbox.xMax - cbox.xMin ) >> 6 );
170 height = (FT_UInt)( ( cbox.yMax - cbox.yMin ) >> 6 );
171 bitmap = &slot->bitmap;
172 memory = render->root.memory;
174 /* release old bitmap buffer */
175 if ( slot->internal->flags & FT_GLYPH_OWN_BITMAP )
177 FT_FREE( bitmap->buffer );
178 slot->internal->flags &= ~FT_GLYPH_OWN_BITMAP;
181 /* allocate new one, depends on pixel format */
182 if ( !( mode & FT_RENDER_MODE_MONO ) )
184 /* we pad to 32 bits, only for backwards compatibility with FT 1.x */
185 pitch = FT_PAD_CEIL( width, 4 );
186 bitmap->pixel_mode = FT_PIXEL_MODE_GRAY;
187 bitmap->num_grays = 256;
189 else
191 pitch = ( ( width + 15 ) >> 4 ) << 1;
192 bitmap->pixel_mode = FT_PIXEL_MODE_MONO;
195 bitmap->width = width;
196 bitmap->rows = height;
197 bitmap->pitch = pitch;
199 if ( FT_ALLOC_MULT( bitmap->buffer, pitch, height ) )
200 goto Exit;
202 slot->internal->flags |= FT_GLYPH_OWN_BITMAP;
204 /* translate outline to render it into the bitmap */
205 FT_Outline_Translate( outline, -cbox.xMin, -cbox.yMin );
207 /* set up parameters */
208 params.target = bitmap;
209 params.source = outline;
210 params.flags = 0;
212 if ( bitmap->pixel_mode == FT_PIXEL_MODE_GRAY )
213 params.flags |= FT_RASTER_FLAG_AA;
215 /* render outline into the bitmap */
216 error = render->raster_render( render->raster, &params );
218 FT_Outline_Translate( outline, cbox.xMin, cbox.yMin );
220 if ( error )
221 goto Exit;
223 slot->format = FT_GLYPH_FORMAT_BITMAP;
224 slot->bitmap_left = (FT_Int)( cbox.xMin >> 6 );
225 slot->bitmap_top = (FT_Int)( cbox.yMax >> 6 );
227 Exit:
228 return error;
232 FT_DEFINE_RENDERER(ft_raster1_renderer_class,
234 FT_MODULE_RENDERER,
235 sizeof( FT_RendererRec ),
237 "raster1",
238 0x10000L,
239 0x20000L,
241 0, /* module specific interface */
243 (FT_Module_Constructor)ft_raster1_init,
244 (FT_Module_Destructor) 0,
245 (FT_Module_Requester) 0
248 FT_GLYPH_FORMAT_OUTLINE,
250 (FT_Renderer_RenderFunc) ft_raster1_render,
251 (FT_Renderer_TransformFunc)ft_raster1_transform,
252 (FT_Renderer_GetCBoxFunc) ft_raster1_get_cbox,
253 (FT_Renderer_SetModeFunc) ft_raster1_set_mode,
255 (FT_Raster_Funcs*) &FT_STANDARD_RASTER_GET
259 /* This renderer is _NOT_ part of the default modules; you will need */
260 /* to register it by hand in your application. It should only be */
261 /* used for backwards-compatibility with FT 1.x anyway. */
262 /* */
263 FT_DEFINE_RENDERER(ft_raster5_renderer_class,
266 FT_MODULE_RENDERER,
267 sizeof( FT_RendererRec ),
269 "raster5",
270 0x10000L,
271 0x20000L,
273 0, /* module specific interface */
275 (FT_Module_Constructor)ft_raster1_init,
276 (FT_Module_Destructor) 0,
277 (FT_Module_Requester) 0
280 FT_GLYPH_FORMAT_OUTLINE,
282 (FT_Renderer_RenderFunc) ft_raster1_render,
283 (FT_Renderer_TransformFunc)ft_raster1_transform,
284 (FT_Renderer_GetCBoxFunc) ft_raster1_get_cbox,
285 (FT_Renderer_SetModeFunc) ft_raster1_set_mode,
287 (FT_Raster_Funcs*) &FT_STANDARD_RASTER_GET
291 /* END */