Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/image.c
| Show First 20 Lines • Show All 5,517 Lines • ▼ Show 20 Lines | void BKE_image_get_aspect(Image *image, float *r_aspx, float *r_aspy) | ||||
| 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; | ||||
| } | } | ||||
| } | } | ||||
| /** | |||||
| * Return the tile_number for the closest UDIM tile. | |||||
| */ | |||||
| int BKE_image_find_nearest_tile(const Image *image, const float co[2]) | |||||
| { | |||||
campbellbarton: Initialize this to `-1`, then if anything goes wrong it's clear that no tile could be found. | |||||
| const float co_floor[2] = {floorf(co[0]), floorf(co[1])}; | |||||
| /* Distance to the closest UDIM tile. */ | |||||
| float dist_best_sq = FLT_MAX; | |||||
| int tile_number_best = -1; | |||||
| LISTBASE_FOREACH (const ImageTile *, tile, &image->tiles) { | |||||
| const int tile_index = tile->tile_number - 1001; | |||||
| /* Coordinates of the current tile. */ | |||||
| const float tile_index_co[2] = {tile_index % 10, tile_index / 10}; | |||||
| if (equals_v2v2(co_floor, tile_index_co)) { | |||||
| return tile->tile_number; | |||||
| } | |||||
| /* Distance between co[2] and UDIM tile. */ | |||||
| const float dist_sq = len_squared_v2v2(tile_index_co, co); | |||||
| if (dist_sq < dist_best_sq) { | |||||
| dist_best_sq = dist_sq; | |||||
| tile_number_best = tile->tile_number; | |||||
| } | |||||
| } | |||||
| return tile_number_best; | |||||
| } | |||||
| 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.