Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/image.c
| Show First 20 Lines • Show All 992 Lines • ▼ Show 20 Lines | |||||
| if (image) { | if (image) { | ||||
| *r_aspy = image->aspy / image->aspx; | *r_aspy = image->aspy / image->aspx; | ||||
| } | } | ||||
| else { | else { | ||||
| *r_aspy = 1.0f; | *r_aspy = 1.0f; | ||||
| } | } | ||||
| } | } | ||||
| int BKE_image_find_nearest_tile(Image *image, const float co[2]) | |||||
| { | |||||
| /* Distance to the closest UDIM tile */ | |||||
| float closest_distance = FLT_MAX; | |||||
| int nearest_tile_number; | |||||
campbellbarton: Initialize this to `-1`, then if anything goes wrong it's clear that no tile could be found. | |||||
| LISTBASE_FOREACH (ImageTile *, tile, &image->tiles) { | |||||
| int tile_index = tile->tile_number - 1001; | |||||
| /* Coordinates of the current tile */ | |||||
| float tile_index_co[2] = {tile_index % 10, tile_index / 10}; | |||||
| /* Distance between co[2] and UDIM tile */ | |||||
| float dist_sq = len_squared_v2v2(tile_index_co, co); | |||||
| if (floor(co[0]) == tile_index_co[0] && floor(co[1]) == tile_index_co[1]) { | |||||
| return tile->tile_number; | |||||
| } | |||||
| else if (dist_sq < closest_distance) { | |||||
| closest_distance = dist_sq; | |||||
| nearest_tile_number = tile->tile_number; | |||||
| } | |||||
| } | |||||
| return nearest_tile_number; | |||||
| } | |||||
| unsigned char *BKE_image_get_pixels_for_frame(struct Image *image, int frame, int tile) | unsigned char *BKE_image_get_pixels_for_frame(struct Image *image, int frame, int tile) | ||||
| { | { | ||||
| ImageUser iuser; | ImageUser iuser; | ||||
| BKE_imageuser_default(&iuser); | BKE_imageuser_default(&iuser); | ||||
| void *lock; | void *lock; | ||||
| ImBuf *ibuf; | ImBuf *ibuf; | ||||
| unsigned char *pixels = NULL; | unsigned char *pixels = NULL; | ||||
| ▲ Show 20 Lines • Show All 416 Lines • Show Last 20 Lines | |||||
Initialize this to -1, then if anything goes wrong it's clear that no tile could be found.
While unlikely, a NAN value in co could cause no tiles to match.