+void getPreviewGraphicSource(int graphic, Bitmap **bitmap, int *x, int *y,
+ int tilesize)
+{
+ struct
+ {
+ int width_mult, width_div;
+ int height_mult, height_div;
+ } offset_calc[4] =
+ {
+ { 0, 1, 0, 1 },
+ { 0, 1, 2, 3 },
+ { 1, 2, 2, 3 },
+ { 3, 4, 2, 3 },
+ };
+ int offset_calc_pos = (tilesize < MICRO_TILESIZE || tilesize > TILESIZE ? 3 :
+ 5 - log_2(tilesize));
+ Bitmap *src_bitmap = graphic_info[graphic].bitmap;
+ int width_mult = offset_calc[offset_calc_pos].width_mult;
+ int width_div = offset_calc[offset_calc_pos].width_div;
+ int height_mult = offset_calc[offset_calc_pos].height_mult;
+ int height_div = offset_calc[offset_calc_pos].height_div;
+ int mini_startx = src_bitmap->width * width_mult / width_div;
+ int mini_starty = src_bitmap->height * height_mult / height_div;
+ int src_x = mini_startx + graphic_info[graphic].src_x * tilesize / TILESIZE;
+ int src_y = mini_starty + graphic_info[graphic].src_y * tilesize / TILESIZE;
+
+ *bitmap = src_bitmap;
+ *x = src_x;
+ *y = src_y;
+}
+