5 |
/* FreeType utility functions for converting 1bpp, 2bpp, 4bpp, and 8bpp */ |
/* FreeType utility functions for converting 1bpp, 2bpp, 4bpp, and 8bpp */ |
6 |
/* bitmaps into 8bpp format (body). */ |
/* bitmaps into 8bpp format (body). */ |
7 |
/* */ |
/* */ |
8 |
/* Copyright 2004 by */ |
/* Copyright 2004, 2005 by */ |
9 |
/* David Turner, Robert Wilhelm, and Werner Lemberg. */ |
/* David Turner, Robert Wilhelm, and Werner Lemberg. */ |
10 |
/* */ |
/* */ |
11 |
/* This file is part of the FreeType project, and may only be used, */ |
/* This file is part of the FreeType project, and may only be used, */ |
18 |
|
|
19 |
|
|
20 |
#include <ft2build.h> |
#include <ft2build.h> |
21 |
#include FT_FREETYPE_H |
#include FT_BITMAP_H |
|
#include FT_IMAGE_H |
|
22 |
#include FT_INTERNAL_OBJECTS_H |
#include FT_INTERNAL_OBJECTS_H |
23 |
|
|
24 |
|
|
35 |
} |
} |
36 |
|
|
37 |
|
|
38 |
|
/* documentation is in ftbitmap.h */ |
39 |
|
|
40 |
|
FT_EXPORT_DEF( FT_Error ) |
41 |
|
FT_Bitmap_Copy( FT_Library library, |
42 |
|
const FT_Bitmap *source, |
43 |
|
FT_Bitmap *target) |
44 |
|
{ |
45 |
|
FT_Memory memory = library->memory; |
46 |
|
FT_Error error = FT_Err_Ok; |
47 |
|
FT_Int pitch = source->pitch; |
48 |
|
FT_ULong size; |
49 |
|
|
50 |
|
|
51 |
|
if ( source == target ) |
52 |
|
return FT_Err_Ok; |
53 |
|
|
54 |
|
if ( source->buffer == NULL ) |
55 |
|
{ |
56 |
|
*target = *source; |
57 |
|
|
58 |
|
return FT_Err_Ok; |
59 |
|
} |
60 |
|
|
61 |
|
if ( pitch < 0 ) |
62 |
|
pitch = -pitch; |
63 |
|
size = (FT_ULong)( pitch * source->rows ); |
64 |
|
|
65 |
|
if ( target->buffer ) |
66 |
|
{ |
67 |
|
FT_Int target_pitch = target->pitch; |
68 |
|
FT_ULong target_size; |
69 |
|
|
70 |
|
|
71 |
|
if ( target_pitch < 0 ) |
72 |
|
target_pitch = -target_pitch; |
73 |
|
target_size = (FT_ULong)( target_pitch * target->rows ); |
74 |
|
|
75 |
|
if ( target_size != size ) |
76 |
|
FT_QREALLOC( target->buffer, target_size, size ); |
77 |
|
} |
78 |
|
else |
79 |
|
FT_QALLOC( target->buffer, size ); |
80 |
|
|
81 |
|
if ( !error ) |
82 |
|
{ |
83 |
|
unsigned char *p; |
84 |
|
|
85 |
|
|
86 |
|
p = target->buffer; |
87 |
|
*target = *source; |
88 |
|
target->buffer = p; |
89 |
|
|
90 |
|
FT_MEM_COPY( target->buffer, source->buffer, size ); |
91 |
|
} |
92 |
|
|
93 |
|
return error; |
94 |
|
} |
95 |
|
|
96 |
|
|
97 |
/* documentation is in ftbitmap.h */ |
/* documentation is in ftbitmap.h */ |
98 |
|
|
99 |
FT_EXPORT_DEF( FT_Error ) |
FT_EXPORT_DEF( FT_Error ) |