Hi guys,

 

I’m trying to use your rasterizer standalone to render out an outline but I
keep getting squashed results back and I can’t seem to get my head around
why.

By visual inspection it seems to be 1/8 the width it should be, see the
attached image (it’s only 11k so hope you let it slip).

 

I’m attaching my small test source. It’s not very pretty but then again it’s
only 100 lines so it should be pretty easy to sift through.

 

I’d really appreciate any help you can give… oh and support for the direct
rendering flag is at the top of my list to Santa this year ;)

 

Kind regards,

 

Erik Möller,

Timetrap

 <http://www.timetrap.se> http://www.timetrap.se

 

<<attachment: out.jpg>>

#include "ftmisc.h"
#include "ftimage.h"
#include "malloc.h"
#include <fstream>

//
// Define an acorn shape to test with
//
struct Vec2
{
  Vec2(float a, float b) : x(a), y(b) { }

  float x, y;
};

static Vec2 k_shape[] = { Vec2(-3, -18), Vec2(0, -12), Vec2(6, -10), Vec2(12, 
-6), Vec2(12, -4), Vec2(11, -4),
                          Vec2(10, -5), Vec2(10, 1), Vec2(9, 6), Vec2(7, 10), 
Vec2(5, 12), Vec2(4, 15),Vec2(3, 14),
                          Vec2(1, 13), Vec2(-1, 13), Vec2(-5, 11), Vec2(-8, 8), 
Vec2(-11, 2), Vec2(-11, -2),
                          Vec2(-14, 0), Vec2(-14, -2), Vec2(-11, -7), Vec2(-9, 
-9), Vec2(-8, -9), Vec2(-5, -12),
                          Vec2(-5, -14), Vec2(-7, -15), Vec2(-8, -14), Vec2(-9, 
-15), Vec2(-9, -17), Vec2(-7, -17),
                          Vec2(-6, -18) };

//
// Some freetype definitions ripped to get this to work. Maybe there's some way 
to
// include these instead?
//
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;
};

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
  FT_Outline_ outline;
  outline.n_contours = 1;
  outline.n_points = sizeof(k_shape)/sizeof(Vec2);
  outline.points = new FT_Vector[outline.n_points];
  for (int i = 0; i < sizeof(k_shape)/sizeof(Vec2); ++i)
  {
    FT_Vector v;
    v.x = (20 + k_shape[i].x) * 10 * 64;  // offset it to fit in the image and 
scale it up 10 times
    v.y = (20 + k_shape[i].y) * 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;
  bmp.buffer = new unsigned char[400*400];
  memset(bmp.buffer, 0, 400*400);
  bmp.width = 400;
  bmp.rows = 400;
  bmp.pitch = -400;
  bmp.pixel_mode = FT_PIXEL_MODE_GRAY;

  // Set up the raster params (these seem to be the only two checked).
  FT_Raster_Params params;
  memset(&params, 0, sizeof(params));
  params.source     = &outline;
  params.target     = &bmp;

  // 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, &params);

  // Dump out the raw image data.
  std::ofstream out("out.raw", std::ios::binary);
  out.write((const char *)bmp.buffer, 400*400);
}
_______________________________________________
Freetype mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/freetype

Reply via email to