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