| 2436 | |
| 2437 | |
| 2438 | ImageCache::Tile * |
| 2439 | ImageCacheImpl::get_tile (ustring filename, int subimage, int miplevel, |
| 2440 | int x, int y, int z) |
| 2441 | { |
| 2442 | ImageCachePerThreadInfo *thread_info = get_perthread_info (); |
| 2443 | ImageCacheFile *file = find_file (filename, thread_info); |
| 2444 | if (! file || file->broken()) |
| 2445 | return NULL; |
| 2446 | const ImageSpec &spec (file->spec(subimage,miplevel)); |
| 2447 | // Snap x,y,z to the corner of the tile |
| 2448 | int xtile = (x-spec.x) / spec.tile_width; |
| 2449 | int ytile = (y-spec.y) / spec.tile_height; |
| 2450 | int ztile = (z-spec.z) / spec.tile_depth; |
| 2451 | x = spec.x + xtile * spec.tile_width; |
| 2452 | y = spec.y + ytile * spec.tile_height; |
| 2453 | z = spec.z + ztile * spec.tile_depth; |
| 2454 | TileID id (*file, subimage, miplevel, x, y, z); |
| 2455 | if (find_tile(id, thread_info)) { |
| 2456 | ImageCacheTileRef tile(thread_info->tile); |
| 2457 | tile->_incref(); // Fake an extra reference count |
| 2458 | return (ImageCache::Tile *) tile.get(); |
| 2459 | } else { |
| 2460 | return NULL; |
| 2461 | } |
| 2462 | } |
| 2463 | |
| 2464 | |
| 2465 | |