Commit 876aad2e authored by Paul Asmuth's avatar Paul Asmuth
Browse files

failed attempt at getting libagg2 to work

parent d738e505
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -54,7 +54,7 @@ add_library(signaltk STATIC
    src/signaltk_cli.cc
    src/signaltk_cmd.cc)

set(SIGNALTK_LDFLAGS signaltk ${CAIRO_LIBRARIES} ${FREETYPE_LIBRARIES} ${HARFBUZZ_LIBRARIES} ${HARFBUZZ_ICU_LIBRARIES} ${PNG_LIBRARIES})
set(SIGNALTK_LDFLAGS signaltk ${CAIRO_LIBRARIES} ${FREETYPE_LIBRARIES} ${HARFBUZZ_LIBRARIES} ${HARFBUZZ_ICU_LIBRARIES} ${PNG_LIBRARIES} agg)

file(GLOB test_files "test/**/test_*.cc")
foreach(test_path ${test_files})
+8 −30
Original line number Diff line number Diff line
@@ -17,34 +17,7 @@ void strokePath(
    const PathData* point_data,
    size_t point_count,
    const StrokeStyle& style) {
  //auto ctx = layer->rasterizer.ctx;

  //if (point_count < 2) {
  //  return;
  //}

  //cairo_set_source_rgba(
  //    ctx,
  //    style.colour.red(),
  //    style.colour.green(),
  //    style.colour.blue(),
  //    style.colour.alpha());

  //cairo_set_line_width(ctx, style.line_width);

  //for (size_t i = 0; i < point_count; ++i) {
  //  const auto& cmd = point_data[i];
  //  switch (cmd.command) {
  //    case PathCommand::MOVE_TO:
  //      cairo_move_to(ctx, cmd[0], cmd[1]);
  //      break;
  //    case PathCommand::LINE_TO:
  //      cairo_line_to(ctx, cmd[0], cmd[1]);
  //      break;
  //  }
  //}

  //cairo_stroke(ctx);
  layer->rasterizer.rasterizePath(point_data, point_count);
}

void strokeLine(
@@ -55,10 +28,15 @@ void strokeLine(
    double y2,
    const StrokeStyle& style) {
  Path p;
  p.moveTo(x1, y1);
  p.lineTo(x2, y2);
  p.moveTo(10, 10);
  p.lineTo(10, 100);
  p.lineTo(100, 100);
  p.lineTo(100, 10);
  p.closePath();
  strokePath(layer, p.data(), p.size(), style);
}

/* rasterize path using Maxim Shemanarev's libagg */

} // namespace signaltk
+77 −0
Original line number Diff line number Diff line
@@ -9,6 +9,11 @@
 */
#include <signaltk/core/rasterize.h>
#include <signaltk/core/image.h>
#include <agg2/agg_basics.h>
#include <agg2/agg_rasterizer_scanline_aa.h>
#include <agg2/agg_path_storage.h>
#include <agg2/agg_scanline_u.h>
#include <agg2/agg_conv_curve.h>

namespace signaltk {

@@ -29,6 +34,78 @@ Rasterizer::~Rasterizer() {
  }
}

Status Rasterizer::rasterizePath(
    const PathData* point_data,
    size_t point_count) {
  if (point_count < 2) {
    return ERROR_INVALID_ARGUMENT;
  }

  agg::rasterizer_scanline_aa<> rasterizer;
  rasterizer.reset();
  //rasterizer.filling_rule(agg::fill_even_odd);
  //rasterizer.gamma(agg::gamma_power(m_gamma.value() * 2.0));

  agg::path_storage agg_path;
  for (size_t i = 0; i < point_count; ++i) {
    const auto& d = point_data[i];

    switch (d.command) {
      case PathCommand::MOVE_TO:
        agg_path.move_to(d.coefficients[0], d.coefficients[1]);
        break;
      case PathCommand::LINE_TO:
        agg_path.line_to(d.coefficients[0], d.coefficients[1]);
        break;
      case PathCommand::QUADRATIC_CURVE_TO:
        agg_path.curve3(
            d.coefficients[0],
            d.coefficients[1],
            d.coefficients[2],
            d.coefficients[3]);
        break;
      case PathCommand::CUBIC_CURVE_TO:
        agg_path.curve4(
            d.coefficients[0],
            d.coefficients[1],
            d.coefficients[2],
            d.coefficients[3],
            d.coefficients[4],
            d.coefficients[5]);
        break;
      case PathCommand::CLOSE:
        agg_path.close_polygon();
        break;
    }
  }

  agg::conv_curve<agg::path_storage> agg_path_polyline(agg_path);
  rasterizer.add_path(agg_path_polyline);

  agg::scanline_u8 scanline;
  scanline.reset(rasterizer.min_x(), rasterizer.max_x());
  while (rasterizer.sweep_scanline(scanline)) {
    for (size_t j = 0; j < scanline.num_spans(); ++j) {
      auto span = scanline.begin() + j;

      for (size_t i = 0; i < std::abs(span->len); ++i) {
        double v = span->covers[i] / 255.0f;
        uint32_t ox = span->x + i;
        uint32_t oy = scanline.y();

        if (ox >= pixmap->getWidth() || oy >= pixmap->getHeight()) {
          continue;
        }

        // FIXME alpha blend instead
        pixmap->setPixel(ox, oy, Colour::fromRGBA(v, v, v, 1));
      }
    }
  }

  return OK;
}

Status Rasterizer::drawTextGlyphs(
    const FontInfo& font_info,
    const GlyphPlacement* glyphs,
+4 −0
Original line number Diff line number Diff line
@@ -37,6 +37,10 @@ public:
  Rasterizer(const Rasterizer&) = delete;
  Rasterizer& operator=(const Rasterizer&) = delete;

  Status rasterizePath(
      const PathData* point_data,
      size_t point_count);

  Status drawTextGlyphs(
      const FontInfo& font_info,
      const GlyphPlacement* glyphs,
+1 −1
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ int main(int argc, char** argv) {
    axis.addTick(0.6);
    axis.addTick(0.8);
    axis.addTick(1.0);
    axis.addLabel(0.0, "asd");
    axis.addLabel(0.0, "fnord");
    axis.addLabel(0.2, "blah");
    axis.addLabel(0.4, "xxx");
    axis.addLabel(0.6, "d");