MCPcopy Create free account
hub / github.com/NazaraEngine/NazaraEngine / LoadArrayFromImage

Method LoadArrayFromImage

src/Nazara/Utility/Image.cpp:896–956  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

894 }
895
896 bool Image::LoadArrayFromImage(const Image& image, const Vector2ui& atlasSize)
897 {
898 #if NAZARA_UTILITY_SAFE
899 if (!image.IsValid())
900 {
901 NazaraError("Image must be valid");
902 return false;
903 }
904
905 if (atlasSize.x == 0)
906 {
907 NazaraError("Atlas width must be over zero");
908 return false;
909 }
910
911 if (atlasSize.y == 0)
912 {
913 NazaraError("Atlas height must be over zero");
914 return false;
915 }
916 #endif
917
918 ImageType type = image.GetType();
919
920 #if NAZARA_UTILITY_SAFE
921 if (type != ImageType_1D && type != ImageType_2D)
922 {
923 NazaraError("Image type not handled (0x" + String::Number(type, 16) + ')');
924 return false;
925 }
926 #endif
927
928 Vector2ui imageSize(image.GetWidth(), image.GetHeight());
929
930 if (imageSize.x % atlasSize.x != 0)
931 {
932 NazaraWarning("Image width is not divisible by atlas width (" + String::Number(imageSize.x) + " mod " + String::Number(atlasSize.x) + " != 0)");
933 }
934
935 if (imageSize.y % atlasSize.y != 0)
936 {
937 NazaraWarning("Image height is not divisible by atlas height (" + String::Number(imageSize.y) + " mod " + String::Number(atlasSize.y) + " != 0)");
938 }
939
940 Vector2ui faceSize = imageSize/atlasSize;
941
942 unsigned int layerCount = atlasSize.x*atlasSize.y;
943
944 // Selon le type de l'image de base, on va créer un array d'images 2D ou 1D
945 if (type == ImageType_2D)
946 Create(ImageType_2D_Array, image.GetFormat(), faceSize.x, faceSize.y, layerCount);
947 else
948 Create(ImageType_1D_Array, image.GetFormat(), faceSize.x, layerCount);
949
950 unsigned int layer = 0;
951 for (unsigned int j = 0; j < atlasSize.y; ++j)
952 for (unsigned int i = 0; i < atlasSize.x; ++i)
953 Copy(image, Rectui(i*faceSize.x, j*faceSize.y, faceSize.x, faceSize.y), Vector3ui(0, 0, layer++));

Callers

nothing calls this directly

Calls 5

IsValidMethod · 0.45
GetTypeMethod · 0.45
GetWidthMethod · 0.45
GetHeightMethod · 0.45
GetFormatMethod · 0.45

Tested by

no test coverage detected