That reminds me...that's where I stopped last...better pick it up again.
I'm getting the exact same results and I'd appreciate if someone could take
a quick peek and tell me where I go wrong. To avoid any sort of mental
barriers I boiled my sample down to 99 lines of code ;)
Kind regards,
Erik Möller
www.timetrap.se
-----Original Message-----
From: freetype-bounces+erik=timetrap...@nongnu.org
[mailto:freetype-bounces+erik=timetrap...@nongnu.org] On Behalf Of Aya
Koshigaya
Sent: den 23 augusti 2009 14:34
To: freetype@nongnu.org
Subject: [ft] How to use Standalone?
Hi,
I am trying to use the Standalone rasterizer, but have some problems
with it..
This is how I am rendering the glyph-outline:
FT_Bitmap bmp;
bmp.buffer = (unsigned char*)bitmap->getBuffer();
bmp.width = bitmap->getWidth();
bmp.rows = bitmap->getHeight();
bmp.pitch = bitmap->getWidth();
bmp.num_grays = 256;
bmp.pixel_mode = FT_PIXEL_MODE_GRAY;
FT_Raster_Params params;
CIMath::zeroMemory(¶ms, sizeof(params));
params.source = &outl;
params.target = &bmp;
params.flags = FT_RASTER_FLAG_AA;
ft_standard_raster.raster_render((FT_Raster)raster, ¶ms);
the bitmap has a size of 512x512 and is only one grayscale channel.
The resulting image looks like this:
http://koshigaya.de/misc/ftstandalone.png
But why..? it's not a fault of my bitmap or the display - I think I
forgot someting in the Standalone Rasterizer..
Anyway, is there somewhere a nice example of how to use the Standalone
Rasterizer?
Aya~
_______________________________________________
Freetype mailing list
Freetype@nongnu.org
http://lists.nongnu.org/mailman/listinfo/freetype
__________ Information from ESET NOD32 Antivirus, version of virus signature
database 4360 (20090823) __________
The message was checked by ESET NOD32 Antivirus.
http://www.eset.com
__________ Information from ESET NOD32 Antivirus, version of virus signature
database 4360 (20090823) __________
The message was checked by ESET NOD32 Antivirus.
http://www.eset.com
#include "ftmisc.h"
#include "ftimage.h"
#include "malloc.h"
#include <fstream>
// Define an acorn shape to test with
static float k_shape[][2] = { {-3, -18}, {0, -12}, {6, -10}, {12, -6}, {12,
-4}, {11, -4},
{10, -5}, {10, 1}, {9, 6}, {7, 10}, {5, 12}, {4,
15},{3, 14},
{1, 13}, {-1, 13}, {-5, 11}, {-8, 8}, {-11, 2},
{-11, -2},
{-14, 0}, {-14, -2}, {-11, -7}, {-9, -9}, {-8, -9},
{-5, -12},
{-5, -14}, {-7, -15}, {-8, -14}, {-9, -15}, {-9,
-17}, {-7, -17},
{-6, -18} };
// Some freetype definitions ripped to get this to work in standalone.
typedef struct FT_MemoryRec_* FT_Memory;
typedef void* (*FT_Alloc_Func)(FT_Memory memory, long size );
typedef void (*FT_Free_Func)(FT_Memory memory, void* block );
typedef void* (*FT_Realloc_Func)(FT_Memory memory,long cur_size, long new_size,
void* block);
struct FT_MemoryRec_
{
void* user;
FT_Alloc_Func alloc;
FT_Free_Func free;
FT_Realloc_Func realloc;
};
// Just use malloc and free
void* MY_Alloc_Func(FT_Memory memory, long size)
{ return malloc(size); }
void MY_Free_Func(FT_Memory memory, void *block)
{ free(block); }
void* MY_Realloc_Func(FT_Memory memory, long cur_size, long new_size, void*
block) { return realloc(block, new_size); }
FT_Memory mem;
extern "C" FT_Raster_Funcs ft_standard_raster;
// Render a shape and dump it out as a raw image
void main()
{
// Set up the memory management to use malloc and free
mem = new FT_MemoryRec_;
mem->alloc = MY_Alloc_Func;
mem->free = MY_Free_Func;
mem->realloc = MY_Realloc_Func;
// Build an outline manually from our acorn shape
FT_Outline_ outline;
outline.n_contours = 1;
outline.n_points = sizeof(k_shape)/(sizeof(float) * 2);
outline.points = new FT_Vector[outline.n_points];
// offset it to fit in the image and scale it up 10 times
for (int i = 0; i < outline.n_points; ++i)
{
FT_Vector v;
v.x = (20 + k_shape[i][0]) * 10 * 64;
v.y = (20 + k_shape[i][1]) * 10 * 64;
outline.points[i] = v;
}
outline.tags = new char[outline.n_points];
for (int i = 0; i < outline.n_points; ++i)
outline.tags[i] = 1;
outline.contours = new short[outline.n_contours];
outline.contours[0] = outline.n_points - 1;
outline.flags = 0;
// Set up a bitmap
FT_Bitmap bmp;
memset(&bmp, 0, sizeof(bmp));
bmp.buffer = new unsigned char[400*400*1];
memset(bmp.buffer, 0xff, 400*400*1);
bmp.width = 400;
bmp.rows = 400;
bmp.pitch = -400*1;
bmp.pixel_mode = FT_PIXEL_MODE_GRAY;
bmp.num_grays = 5;
// Set up the raster params (these seem to be the only two checked).
FT_Raster_Params params;
memset(¶ms, 0, sizeof(params));
params.source = &outline;
params.target = &bmp;
params.flags = FT_RASTER_FLAG_AA;
// Allocate a chunk of mem for the render pool.
const int kRenderPoolSize = 1024 * 1024;
unsigned char *renderPool = new unsigned char[kRenderPoolSize];
// Initialize the rasterer and get it to render into the bitmap.
FT_Raster raster;
ft_standard_raster.raster_new(mem, &raster);
ft_standard_raster.raster_reset(raster, renderPool, kRenderPoolSize);
ft_standard_raster.raster_render(raster, ¶ms);
// Dump out the raw image data.
std::ofstream out("out.raw", std::ios::binary);
out.write((const char *)bmp.buffer, 400*400*1);
}
_______________________________________________
Freetype mailing list
Freetype@nongnu.org
http://lists.nongnu.org/mailman/listinfo/freetype