tile.c
author Tero Marttila <terom@fixme.fi>
Wed, 27 Aug 2008 21:30:32 +0300
changeset 41 540737bf6bac
parent 27 1e79b4cc8f1b
permissions -rw-r--r--
sending requests, and partial support for receiving -- incomplete, not tested
27
1e79b4cc8f1b support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     1
1e79b4cc8f1b support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     2
#include "tile.h"
1e79b4cc8f1b support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     3
#include "render_struct.h"
1e79b4cc8f1b support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     4
1e79b4cc8f1b support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     5
#define MIN(a, b) ((a) < (b) ? (a) : (b))
1e79b4cc8f1b support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     6
#define MAX(a, b) ((a) > (b) ? (a) : (b))
1e79b4cc8f1b support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     7
1e79b4cc8f1b support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     8
int render_set_tile (struct render *render_info, u_int32_t view_w, u_int32_t view_h, u_int32_t x, u_int32_t y, u_int16_t zoom) {
1e79b4cc8f1b support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     9
    // figure out how many tiles will fit onto the view area
1e79b4cc8f1b support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    10
    u_int16_t tiles = MIN(
1e79b4cc8f1b support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    11
        MAX(view_w / TILE_WIDTH, 1),
1e79b4cc8f1b support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    12
        MAX(view_h / TILE_HEIGHT, 1)
1e79b4cc8f1b support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    13
    ) + 1;
1e79b4cc8f1b support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    14
    
1e79b4cc8f1b support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    15
    // have it be square
1e79b4cc8f1b support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    16
    view_w = tiles * TILE_WIDTH;
1e79b4cc8f1b support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    17
    view_h = tiles * TILE_HEIGHT;
1e79b4cc8f1b support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    18
    
1e79b4cc8f1b support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    19
    // the image width is fixed
1e79b4cc8f1b support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    20
    render_info->img_w = TILE_WIDTH;
1e79b4cc8f1b support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    21
    render_info->img_h = TILE_HEIGHT;
1e79b4cc8f1b support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    22
    
1e79b4cc8f1b support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    23
    // calcuate how wide each pixel is
1e79b4cc8f1b support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    24
    double width_scale = REGION_W/(view_w << zoom);
1e79b4cc8f1b support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    25
    double height_scale = REGION_H/(view_h << zoom);
1e79b4cc8f1b support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    26
    
1e79b4cc8f1b support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    27
    // calcuate the region
1e79b4cc8f1b support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    28
    render_info->x1 = REGION_X1 + x * width_scale;
1e79b4cc8f1b support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    29
    render_info->y1 = REGION_Y1 + y * height_scale;
1e79b4cc8f1b support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    30
    render_info->x2 = render_info->x1 + TILE_WIDTH * width_scale;
1e79b4cc8f1b support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    31
    render_info->y2 = render_info->y1 + TILE_HEIGHT * height_scale;
1e79b4cc8f1b support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    32
    
1e79b4cc8f1b support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    33
    // ok
1e79b4cc8f1b support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    34
    return 0;
1e79b4cc8f1b support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    35
}