From fe42ba2a305c4f0b2c415be36c83b06216a8a66f Mon Sep 17 00:00:00 2001 From: Benjamin Gilbert Date: Thu, 8 Aug 2013 00:27:48 -0400 Subject: [PATCH] Absorb tilehelper into grid --- CONTRIBUTING.txt | 2 +- Makefile.am | 4 +-- src/openslide-grid.c | 79 +++++++++++++++++++++++++++++++++++++--------- src/openslide-ops-jpeg.c | 1 - src/openslide-ops-ngr.c | 1 - src/openslide-ops-tiff.c | 1 - src/openslide-tilehelper.c | 78 --------------------------------------------- src/openslide-tilehelper.h | 42 ------------------------ src/openslide.c | 1 - 9 files changed, 67 insertions(+), 142 deletions(-) delete mode 100644 src/openslide-tilehelper.c delete mode 100644 src/openslide-tilehelper.h diff --git a/CONTRIBUTING.txt b/CONTRIBUTING.txt index 32873ae5..6131a9bd 100644 --- a/CONTRIBUTING.txt +++ b/CONTRIBUTING.txt @@ -43,7 +43,7 @@ advice. except for the cache (which takes locks) and libtiff (which is sort of a disaster). - * Avoid the midlayer mistake. The tilehelper and cache are there for + * Avoid the midlayer mistake. The grid helpers and cache are there for you. * Have fun! Graphics are a joy. diff --git a/Makefile.am b/Makefile.am index 97d5114e..cbc7b3b5 100644 --- a/Makefile.am +++ b/Makefile.am @@ -16,7 +16,7 @@ src_libopenslide_la_LIBADD = $(GLIB2_LIBS) $(CAIRO_LIBS) $(LIBXML2_LIBS) \ $(OPENJPEG_LIBS) $(LIBTIFF_LIBS) $(ZLIB_LIBS) src_libopenslide_la_SOURCES = src/openslide.c src/openslide-grid.c \ - src/openslide-cache.c src/openslide-tilehelper.c \ + src/openslide-cache.c \ src/openslide-hash.c src/openslide-error.c src/openslide-util.c \ src/openslide-ops-jpeg.c \ src/openslide-vendor-hamamatsu.c \ @@ -42,7 +42,7 @@ src_libopenslide_la_LDFLAGS = -version-info 3:3:3 -no-undefined pkginclude_HEADERS = src/openslide.h src/openslide-features.h -noinst_HEADERS = src/openslide-private.h src/openslide-cache.h src/openslide-tilehelper.h src/openslide-hash.h src/openslide-cairo.h src/openslide-tiffdump.h tools/openslide-tools-common.h +noinst_HEADERS = src/openslide-private.h src/openslide-cache.h src/openslide-hash.h src/openslide-cairo.h src/openslide-tiffdump.h tools/openslide-tools-common.h diff --git a/src/openslide-grid.c b/src/openslide-grid.c index 7ea928c5..54aa2cd8 100644 --- a/src/openslide-grid.c +++ b/src/openslide-grid.c @@ -19,10 +19,11 @@ * */ +#include #include #include +#include #include "openslide-private.h" -#include "openslide-tilehelper.h" struct _openslide_grid_simple { openslide_t *osr; @@ -76,6 +77,54 @@ struct tilemap_read_tile_args { int32_t region_h; }; +static void read_tiles(cairo_t *cr, + struct _openslide_level *level, + int64_t start_tile_x, int64_t start_tile_y, + int64_t end_tile_x, int64_t end_tile_y, + double offset_x, double offset_y, + double advance_x, double advance_y, + openslide_t *osr, + void *arg, + _openslide_tileread_fn read_tile) { + //g_debug("offset: %g %g, advance: %g %g", offset_x, offset_y, advance_x, advance_y); + if (fabs(offset_x) >= advance_x) { + _openslide_set_error(osr, "internal error: fabs(offset_x) >= advance_x"); + return; + } + if (fabs(offset_y) >= advance_y) { + _openslide_set_error(osr, "internal error: fabs(offset_y) >= advance_y"); + return; + } + + // cairo_set_source_rgb(cr, 0, 1, 0); + // cairo_paint(cr); + //g_debug("offset: %d %d", offset_x, offset_y); + + //g_debug("start: %" G_GINT64_FORMAT " %" G_GINT64_FORMAT, start_tile_x, start_tile_y); + //g_debug("end: %" G_GINT64_FORMAT " %" G_GINT64_FORMAT, end_tile_x, end_tile_y); + + cairo_matrix_t matrix; + cairo_get_matrix(cr, &matrix); + + int64_t tile_y = end_tile_y - 1; + + while (tile_y >= start_tile_y) { + double translate_y = ((tile_y - start_tile_y) * advance_y) - offset_y; + int64_t tile_x = end_tile_x - 1; + + while (tile_x >= start_tile_x) { + double translate_x = ((tile_x - start_tile_x) * advance_x) - offset_x; + // g_debug("read_tiles %" G_GINT64_FORMAT " %" G_GINT64_FORMAT, tile_x, tile_y); + cairo_translate(cr, translate_x, translate_y); + read_tile(osr, cr, level, tile_x, tile_y, arg); + cairo_set_matrix(cr, &matrix); + tile_x--; + } + + tile_y--; + } +} + struct _openslide_grid_simple *_openslide_grid_simple_create(openslide_t *osr, int64_t tiles_across, int64_t tiles_down, @@ -117,12 +166,12 @@ void _openslide_grid_simple_paint_region(struct _openslide_grid_simple *grid, end_tile_x = MIN(end_tile_x, grid->tiles_across); end_tile_y = MIN(end_tile_y, grid->tiles_down); - _openslide_read_tiles(cr, level, - start_tile_x, start_tile_y, - end_tile_x, end_tile_y, - offset_x, offset_y, - grid->tile_w, grid->tile_h, - grid->osr, arg, grid->read_tile); + read_tiles(cr, level, + start_tile_x, start_tile_y, + end_tile_x, end_tile_y, + offset_x, offset_y, + grid->tile_w, grid->tile_h, + grid->osr, arg, grid->read_tile); } void _openslide_grid_simple_destroy(struct _openslide_grid_simple *grid) { @@ -293,14 +342,14 @@ void _openslide_grid_tilemap_paint_region(struct _openslide_grid_tilemap *grid, -grid->extra_tiles_left * grid->tile_advance_x, -grid->extra_tiles_top * grid->tile_advance_y); - _openslide_read_tiles(cr, level, - start_tile_x - grid->extra_tiles_left, - start_tile_y - grid->extra_tiles_top, - end_tile_x + grid->extra_tiles_right, - end_tile_y + grid->extra_tiles_bottom, - offset_x, offset_y, - grid->tile_advance_x, grid->tile_advance_y, - grid->osr, &args, grid_tilemap_read_tile); + read_tiles(cr, level, + start_tile_x - grid->extra_tiles_left, + start_tile_y - grid->extra_tiles_top, + end_tile_x + grid->extra_tiles_right, + end_tile_y + grid->extra_tiles_bottom, + offset_x, offset_y, + grid->tile_advance_x, grid->tile_advance_y, + grid->osr, &args, grid_tilemap_read_tile); } void _openslide_grid_tilemap_destroy(struct _openslide_grid_tilemap *grid) { diff --git a/src/openslide-ops-jpeg.c b/src/openslide-ops-jpeg.c index b70edc3c..091ed74d 100644 --- a/src/openslide-ops-jpeg.c +++ b/src/openslide-ops-jpeg.c @@ -44,7 +44,6 @@ #include #include "openslide-cache.h" -#include "openslide-tilehelper.h" struct one_jpeg { char *filename; diff --git a/src/openslide-ops-ngr.c b/src/openslide-ops-ngr.c index 6fcaaff2..8540fd89 100644 --- a/src/openslide-ops-ngr.c +++ b/src/openslide-ops-ngr.c @@ -24,7 +24,6 @@ #include "openslide-private.h" #include "openslide-cache.h" -#include "openslide-tilehelper.h" #include #include diff --git a/src/openslide-ops-tiff.c b/src/openslide-ops-tiff.c index 816a796d..8f218810 100644 --- a/src/openslide-ops-tiff.c +++ b/src/openslide-ops-tiff.c @@ -33,7 +33,6 @@ #include #include "openslide-cache.h" -#include "openslide-tilehelper.h" #include "openslide-hash.h" #define HANDLE_CACHE_MAX 32 diff --git a/src/openslide-tilehelper.c b/src/openslide-tilehelper.c deleted file mode 100644 index af429e43..00000000 --- a/src/openslide-tilehelper.c +++ /dev/null @@ -1,78 +0,0 @@ -/* - * OpenSlide, a library for reading whole slide image files - * - * Copyright (c) 2007-2009 Carnegie Mellon University - * All rights reserved. - * - * OpenSlide is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, version 2.1. - * - * OpenSlide is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with OpenSlide. If not, see - * . - * - */ - -#include - -#include "openslide-private.h" -#include "openslide-tilehelper.h" - -#include -#include -#include -#include - -void _openslide_read_tiles(cairo_t *cr, - struct _openslide_level *level, - int64_t start_tile_x, int64_t start_tile_y, - int64_t end_tile_x, int64_t end_tile_y, - double offset_x, double offset_y, - double advance_x, double advance_y, - openslide_t *osr, - void *arg, - _openslide_tileread_fn read_tile) { - //g_debug("offset: %g %g, advance: %g %g", offset_x, offset_y, advance_x, advance_y); - if (fabs(offset_x) >= advance_x) { - _openslide_set_error(osr, "internal error: fabs(offset_x) >= advance_x"); - return; - } - if (fabs(offset_y) >= advance_y) { - _openslide_set_error(osr, "internal error: fabs(offset_y) >= advance_y"); - return; - } - - // cairo_set_source_rgb(cr, 0, 1, 0); - // cairo_paint(cr); - //g_debug("offset: %d %d", offset_x, offset_y); - - //g_debug("start: %" G_GINT64_FORMAT " %" G_GINT64_FORMAT, start_tile_x, start_tile_y); - //g_debug("end: %" G_GINT64_FORMAT " %" G_GINT64_FORMAT, end_tile_x, end_tile_y); - - cairo_matrix_t matrix; - cairo_get_matrix(cr, &matrix); - - int64_t tile_y = end_tile_y - 1; - - while (tile_y >= start_tile_y) { - double translate_y = ((tile_y - start_tile_y) * advance_y) - offset_y; - int64_t tile_x = end_tile_x - 1; - - while (tile_x >= start_tile_x) { - double translate_x = ((tile_x - start_tile_x) * advance_x) - offset_x; - // g_debug("read_tiles %" G_GINT64_FORMAT " %" G_GINT64_FORMAT, tile_x, tile_y); - cairo_translate(cr, translate_x, translate_y); - read_tile(osr, cr, level, tile_x, tile_y, arg); - cairo_set_matrix(cr, &matrix); - tile_x--; - } - - tile_y--; - } -} diff --git a/src/openslide-tilehelper.h b/src/openslide-tilehelper.h deleted file mode 100644 index d80b6fde..00000000 --- a/src/openslide-tilehelper.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * OpenSlide, a library for reading whole slide image files - * - * Copyright (c) 2007-2009 Carnegie Mellon University - * All rights reserved. - * - * OpenSlide is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, version 2.1. - * - * OpenSlide is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with OpenSlide. If not, see - * . - * - */ - -#ifndef OPENSLIDE_OPENSLIDE_TILEHELPER_H_ -#define OPENSLIDE_OPENSLIDE_TILEHELPER_H_ - -#include - -#include "openslide-private.h" - -#include -#include -#include - -void _openslide_read_tiles(cairo_t *cr, - struct _openslide_level *level, - int64_t start_tile_x, int64_t start_tile_y, - int64_t end_tile_x, int64_t end_tile_y, - double offset_x, double offset_y, - double advance_x, double advance_y, - openslide_t *osr, - void *arg, - _openslide_tileread_fn read_tile); -#endif diff --git a/src/openslide.c b/src/openslide.c index 6e1daac2..4e942889 100644 --- a/src/openslide.c +++ b/src/openslide.c @@ -30,7 +30,6 @@ #include #include "openslide-cache.h" -#include "openslide-tilehelper.h" #include "openslide-cairo.h" const char _openslide_release_info[] = "OpenSlide " PACKAGE_VERSION ", copyright (C) 2007-2013 Carnegie Mellon University and others.\nLicensed under the GNU Lesser General Public License, version 2.1.";