1ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov/***************************************************************************/
2ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov/*                                                                         */
3ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov/*  ftmisc.h                                                               */
4ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov/*                                                                         */
5ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov/*    Miscellaneous macros for stand-alone rasterizer (specification       */
6ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov/*    only).                                                               */
7ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov/*                                                                         */
8ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov/*  Copyright 2005, 2009, 2010 by                                          */
9ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
10ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov/*                                                                         */
11ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov/*  This file is part of the FreeType project, and may only be used        */
12ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov/*  modified and distributed under the terms of the FreeType project       */
13ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
14ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov/*  this file you indicate that you have read the license and              */
15ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov/*  understand and accept it fully.                                        */
16ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov/*                                                                         */
17ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov/***************************************************************************/
18ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
19ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
20ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  /***************************************************/
21ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  /*                                                 */
22ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  /* This file is *not* portable!  You have to adapt */
23ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  /* its definitions to your platform.               */
24ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  /*                                                 */
25ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  /***************************************************/
26ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
27ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#ifndef __FTMISC_H__
28ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define __FTMISC_H__
29ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
30ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
31ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  /* memset */
32ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#include "../../include/freetype/config/ftstdlib.h"
33ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
34ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FT_BEGIN_HEADER
35ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FT_END_HEADER
36ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
37ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FT_LOCAL_DEF( x )   static x
38ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
39ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
40ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  /* from include/freetype2/fttypes.h */
41ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
42ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  typedef unsigned char  FT_Byte;
43ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  typedef signed int     FT_Int;
44ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  typedef unsigned int   FT_UInt;
45ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  typedef signed long    FT_Long;
46ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  typedef unsigned long  FT_ULong;
47ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  typedef signed long    FT_F26Dot6;
48ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  typedef int            FT_Error;
49ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
50ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FT_MAKE_TAG( _x1, _x2, _x3, _x4 ) \
51ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov          ( ( (FT_ULong)_x1 << 24 ) |     \
52ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            ( (FT_ULong)_x2 << 16 ) |     \
53ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            ( (FT_ULong)_x3 <<  8 ) |     \
54ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov              (FT_ULong)_x4         )
55ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
56ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
57ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  /* from include/freetype2/ftsystem.h */
58ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
59ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  typedef struct FT_MemoryRec_*  FT_Memory;
60ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
61ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  typedef void* (*FT_Alloc_Func)( FT_Memory  memory,
62ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                                  long       size );
63ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
64ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  typedef void (*FT_Free_Func)( FT_Memory  memory,
65ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                                void*      block );
66ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
67ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  typedef void* (*FT_Realloc_Func)( FT_Memory  memory,
68ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                                    long       cur_size,
69ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                                    long       new_size,
70ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                                    void*      block );
71ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
72ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  typedef struct FT_MemoryRec_
73ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  {
74ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void*            user;
75ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
76ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FT_Alloc_Func    alloc;
77ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FT_Free_Func     free;
78ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FT_Realloc_Func  realloc;
79ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
80ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  } FT_MemoryRec;
81ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
82ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
83ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  /* from src/ftcalc.c */
84ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
85ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#if ( defined _WIN32 || defined _WIN64 )
86ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
87ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  typedef __int64  FT_Int64;
88ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
89ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#else
90ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
91ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#include "inttypes.h"
92ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
93ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  typedef int64_t  FT_Int64;
94ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
95ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#endif
96ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
97ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
98ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  static FT_Long
99ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  FT_MulDiv( FT_Long  a,
100ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov             FT_Long  b,
101ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov             FT_Long  c )
102ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  {
103ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FT_Int   s;
104ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FT_Long  d;
105ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
106ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
107ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    s = 1;
108ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if ( a < 0 ) { a = -a; s = -1; }
109ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if ( b < 0 ) { b = -b; s = -s; }
110ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if ( c < 0 ) { c = -c; s = -s; }
111ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
112ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    d = (FT_Long)( c > 0 ? ( (FT_Int64)a * b + ( c >> 1 ) ) / c
113ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                         : 0x7FFFFFFFL );
114ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
115ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    return ( s > 0 ) ? d : -d;
116ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  }
117ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
118ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
119ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  static FT_Long
120ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  FT_MulDiv_No_Round( FT_Long  a,
121ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                      FT_Long  b,
122ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                      FT_Long  c )
123ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  {
124ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FT_Int   s;
125ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FT_Long  d;
126ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
127ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
128ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    s = 1;
129ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if ( a < 0 ) { a = -a; s = -1; }
130ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if ( b < 0 ) { b = -b; s = -s; }
131ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if ( c < 0 ) { c = -c; s = -s; }
132ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
133ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    d = (FT_Long)( c > 0 ? (FT_Int64)a * b / c
134ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                         : 0x7FFFFFFFL );
135ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
136ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    return ( s > 0 ) ? d : -d;
137ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov  }
138ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
139ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#endif /* __FTMISC_H__ */
140ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
141ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
142ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov/* END */
143