diff --git a/src/raudio.c b/src/raudio.c index 555dfe50..afb076af 100644 --- a/src/raudio.c +++ b/src/raudio.c @@ -752,7 +752,7 @@ Wave LoadWave(const char *fileName) // Loading wave from memory data if (fileData != NULL) wave = LoadWaveFromMemory(GetFileExtension(fileName), fileData, dataSize); - RL_FREE(fileData); + UnloadFileData(fileData); return wave; } @@ -870,11 +870,15 @@ Wave LoadWaveFromMemory(const char *fileType, const unsigned char *fileData, int // Checks if wave data is ready bool IsWaveReady(Wave wave) { - return ((wave.data != NULL) && // Validate wave data available - (wave.frameCount > 0) && // Validate frame count - (wave.sampleRate > 0) && // Validate sample rate is supported - (wave.sampleSize > 0) && // Validate sample size is supported - (wave.channels > 0)); // Validate number of channels supported + bool result = false; + + if ((wave.data != NULL) && // Validate wave data available + (wave.frameCount > 0) && // Validate frame count + (wave.sampleRate > 0) && // Validate sample rate is supported + (wave.sampleSize > 0) && // Validate sample size is supported + (wave.channels > 0)) result = true; // Validate number of channels supported + + return result; } // Load sound from file @@ -967,11 +971,15 @@ Sound LoadSoundAlias(Sound source) // Checks if a sound is ready bool IsSoundReady(Sound sound) { - return ((sound.frameCount > 0) && // Validate frame count - (sound.stream.buffer != NULL) && // Validate stream buffer - (sound.stream.sampleRate > 0) && // Validate sample rate is supported - (sound.stream.sampleSize > 0) && // Validate sample size is supported - (sound.stream.channels > 0)); // Validate number of channels supported + bool result = false; + + if ((sound.frameCount > 0) && // Validate frame count + (sound.stream.buffer != NULL) && // Validate stream buffer + (sound.stream.sampleRate > 0) && // Validate sample rate is supported + (sound.stream.sampleSize > 0) && // Validate sample size is supported + (sound.stream.channels > 0)) result = true; // Validate number of channels supported + + return result; } // Unload wave data @@ -1163,7 +1171,11 @@ void StopSound(Sound sound) // Check if a sound is playing bool IsSoundPlaying(Sound sound) { - return IsAudioBufferPlaying(sound.stream.buffer); + bool result = false; + + if (IsAudioBufferPlaying(sound.stream.buffer)) result = true; + + return result; } // Set volume for a sound diff --git a/src/rcore.c b/src/rcore.c index 9705495e..b4aaed68 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -1419,7 +1419,9 @@ void SetShaderValueTexture(Shader shader, int locIndex, Texture2D texture) // Get a ray trace from screen position (i.e mouse) Ray GetScreenToWorldRay(Vector2 position, Camera camera) { - return GetScreenToWorldRayEx(position, camera, GetScreenWidth(), GetScreenHeight()); + Ray ray = GetScreenToWorldRayEx(position, camera, GetScreenWidth(), GetScreenHeight()); + + return ray; } // Get a ray trace from the screen position (i.e mouse) within a specific section of the screen @@ -1480,7 +1482,9 @@ Ray GetScreenToWorldRayEx(Vector2 position, Camera camera, int width, int height // Get transform matrix for camera Matrix GetCameraMatrix(Camera camera) { - return MatrixLookAt(camera.position, camera.target, camera.up); + Matrix mat = MatrixLookAt(camera.position, camera.target, camera.up); + + return mat; } // Get camera 2d transform matrix @@ -1661,7 +1665,7 @@ float GetFrameTime(void) // Ref: http://www.geisswerks.com/ryan/FAQS/timing.html --> All about timing on Win32! void WaitTime(double seconds) { - if (seconds < 0) return; + if (seconds < 0) return; // Security check #if defined(SUPPORT_BUSY_WAIT_LOOP) || defined(SUPPORT_PARTIALBUSY_WAIT_LOOP) double destinationTime = GetTime() + seconds; @@ -1754,7 +1758,7 @@ int *LoadRandomSequence(unsigned int count, int min, int max) #if defined(SUPPORT_RPRAND_GENERATOR) values = rprand_load_sequence(count, min, max); #else - if (count > ((unsigned int)abs(max - min) + 1)) return values; + if (count > ((unsigned int)abs(max - min) + 1)) return values; // Security check values = (int *)RL_CALLOC(count, sizeof(int)); @@ -1946,7 +1950,9 @@ const char *GetFileExtension(const char *fileName) static const char *strprbrk(const char *s, const char *charset) { const char *latestMatch = NULL; + for (; s = strpbrk(s, charset), s != NULL; latestMatch = s++) { } + return latestMatch; } @@ -1954,9 +1960,10 @@ static const char *strprbrk(const char *s, const char *charset) const char *GetFileName(const char *filePath) { const char *fileName = NULL; + if (filePath != NULL) fileName = strprbrk(filePath, "\\/"); - - if (!fileName) return filePath; + + if (fileName != NULL) return filePath; return fileName + 1; } @@ -2235,8 +2242,11 @@ bool IsPathFile(const char *path) // Check if a file has been dropped into window bool IsFileDropped(void) { - if (CORE.Window.dropFileCount > 0) return true; - else return false; + bool result = false; + + if (CORE.Window.dropFileCount > 0) result = true; + + return result; } // Load dropped filepaths @@ -2270,15 +2280,16 @@ void UnloadDroppedFiles(FilePathList files) long GetFileModTime(const char *fileName) { struct stat result = { 0 }; + long modTime = 0; if (stat(fileName, &result) == 0) { time_t mod = result.st_mtime; - return (long)mod; + modTime = (long)mod; } - return 0; + return modTime; } //---------------------------------------------------------------------------------- @@ -2347,7 +2358,7 @@ char *EncodeDataBase64(const unsigned char *data, int dataSize, int *outputSize) char *encodedData = (char *)RL_MALLOC(*outputSize); - if (encodedData == NULL) return NULL; + if (encodedData == NULL) return NULL; // Security check for (int i = 0, j = 0; i < dataSize;) { @@ -2949,13 +2960,15 @@ bool IsMouseButtonUp(int button) // Get mouse position X int GetMouseX(void) { - return (int)((CORE.Input.Mouse.currentPosition.x + CORE.Input.Mouse.offset.x)*CORE.Input.Mouse.scale.x); + int mouseX = (int)((CORE.Input.Mouse.currentPosition.x + CORE.Input.Mouse.offset.x)*CORE.Input.Mouse.scale.x); + return mouseX; } // Get mouse position Y int GetMouseY(void) { - return (int)((CORE.Input.Mouse.currentPosition.y + CORE.Input.Mouse.offset.y)*CORE.Input.Mouse.scale.y); + int mouseY = (int)((CORE.Input.Mouse.currentPosition.y + CORE.Input.Mouse.offset.y)*CORE.Input.Mouse.scale.y); + return mouseY; } // Get mouse position XY @@ -3022,13 +3035,15 @@ Vector2 GetMouseWheelMoveV(void) // Get touch position X for touch point 0 (relative to screen size) int GetTouchX(void) { - return (int)CORE.Input.Touch.position[0].x; + int touchX = (int)CORE.Input.Touch.position[0].x; + return touchX; } // Get touch position Y for touch point 0 (relative to screen size) int GetTouchY(void) { - return (int)CORE.Input.Touch.position[0].y; + int touchY = (int)CORE.Input.Touch.position[0].y; + return touchY; } // Get touch position XY for a touch point index (relative to screen size) diff --git a/src/rmodels.c b/src/rmodels.c index 969920c0..4bbceaf2 100644 --- a/src/rmodels.c +++ b/src/rmodels.c @@ -228,7 +228,7 @@ void DrawTriangle3D(Vector3 v1, Vector3 v2, Vector3 v3, Color color) // Draw a triangle strip defined by points void DrawTriangleStrip3D(Vector3 *points, int pointCount, Color color) { - if (pointCount < 3) return; + if (pointCount < 3) return; // Security check rlBegin(RL_TRIANGLES); rlColor4ub(color.r, color.g, color.b, color.a); @@ -559,7 +559,7 @@ void DrawCylinderEx(Vector3 startPos, Vector3 endPos, float startRadius, float e if (sides < 3) sides = 3; Vector3 direction = { endPos.x - startPos.x, endPos.y - startPos.y, endPos.z - startPos.z }; - if ((direction.x == 0) && (direction.y == 0) && (direction.z == 0)) return; + if ((direction.x == 0) && (direction.y == 0) && (direction.z == 0)) return; // Security check // Construct a basis of the base and the top face: Vector3 b1 = Vector3Normalize(Vector3Perpendicular(direction)); @@ -649,7 +649,7 @@ void DrawCylinderWiresEx(Vector3 startPos, Vector3 endPos, float startRadius, fl if (sides < 3) sides = 3; Vector3 direction = { endPos.x - startPos.x, endPos.y - startPos.y, endPos.z - startPos.z }; - if ((direction.x == 0) && (direction.y == 0) && (direction.z == 0))return; + if ((direction.x == 0) && (direction.y == 0) && (direction.z == 0)) return; // Security check // Construct a basis of the base and the top face: Vector3 b1 = Vector3Normalize(Vector3Perpendicular(direction)); @@ -755,8 +755,8 @@ void DrawCapsule(Vector3 startPos, Vector3 endPos, float radius, int slices, int capCenter.z + (sinf(baseRingAngle * ( i + 1 ))*b0.z + ringSin4*b1.z + ringCos4*b2.z) * radius }; - // make sure cap triangle normals are facing outwards - if(c == 0) + // Make sure cap triangle normals are facing outwards + if (c == 0) { rlVertex3f(w1.x, w1.y, w1.z); rlVertex3f(w2.x, w2.y, w2.z); @@ -1104,13 +1104,17 @@ Model LoadModelFromMesh(Mesh mesh) // Check if a model is ready bool IsModelReady(Model model) { - return ((model.meshes != NULL) && // Validate model contains some mesh - (model.materials != NULL) && // Validate model contains some material (at least default one) - (model.meshMaterial != NULL) && // Validate mesh-material linkage - (model.meshCount > 0) && // Validate mesh count - (model.materialCount > 0)); // Validate material count + bool result = false; + + if ((model.meshes != NULL) && // Validate model contains some mesh + (model.materials != NULL) && // Validate model contains some material (at least default one) + (model.meshMaterial != NULL) && // Validate mesh-material linkage + (model.meshCount > 0) && // Validate mesh count + (model.materialCount > 0)) result = true; // Validate material count // NOTE: This is a very general model validation, many elements could be validated from a model... + + return result; } // Unload model (meshes/materials) from memory (RAM and/or VRAM) @@ -2033,8 +2037,12 @@ Material LoadMaterialDefault(void) // Check if a material is ready bool IsMaterialReady(Material material) { - return ((material.maps != NULL) && // Validate material contain some map - (material.shader.id > 0)); // Validate material shader is valid + bool result = false; + + if ((material.maps != NULL) && // Validate material contain some map + (material.shader.id > 0)) result = true; // Validate material shader is valid + + return result; } // Unload material from memory @@ -2230,7 +2238,7 @@ Mesh GenMeshPoly(int sides, float radius) { Mesh mesh = { 0 }; - if (sides < 3) return mesh; + if (sides < 3) return mesh; // Security check int vertexCount = sides*3; @@ -4493,7 +4501,7 @@ static Model LoadIQM(const char *fileName) BuildPoseFromParentJoints(model.bones, model.boneCount, model.bindPose); - RL_FREE(fileData); + UnloadFileData(fileData); RL_FREE(imesh); RL_FREE(tri); @@ -4725,7 +4733,7 @@ static ModelAnimation *LoadModelAnimationsIQM(const char *fileName, int *animCou } } - RL_FREE(fileData); + UnloadFileData(fileData); RL_FREE(joints); RL_FREE(framedata); @@ -6102,7 +6110,7 @@ static Model LoadM3D(const char *fileName) // called, but not before, however DrawMesh uses these if they exist (so not good if they are left empty). if (m3d->numbone && m3d->numskin) { - for(i = 0; i < model.meshCount; i++) + for (i = 0; i < model.meshCount; i++) { memcpy(model.meshes[i].animVertices, model.meshes[i].vertices, model.meshes[i].vertexCount*3*sizeof(float)); memcpy(model.meshes[i].animNormals, model.meshes[i].normals, model.meshes[i].vertexCount*3*sizeof(float)); diff --git a/src/rshapes.c b/src/rshapes.c index 5c6900b2..bb3a736c 100644 --- a/src/rshapes.c +++ b/src/rshapes.c @@ -2345,11 +2345,16 @@ Rectangle GetCollisionRec(Rectangle rec1, Rectangle rec2) // NOTE: Used by DrawLineBezier() only static float EaseCubicInOut(float t, float b, float c, float d) { - if ((t /= 0.5f*d) < 1) return 0.5f*c*t*t*t + b; - - t -= 2; - - return 0.5f*c*(t*t*t + 2.0f) + b; + float result = 0.0f; + + if ((t /= 0.5f*d) < 1) result = 0.5f*c*t*t*t + b; + else + { + t -= 2; + result = 0.5f*c*(t*t*t + 2.0f) + b; + } + + return result; } #endif // SUPPORT_MODULE_RSHAPES diff --git a/src/rtext.c b/src/rtext.c index 51c10b55..2ff6fd92 100644 --- a/src/rtext.c +++ b/src/rtext.c @@ -434,7 +434,7 @@ Font LoadFontFromImage(Image image, Color key, int firstChar) if (!COLOR_EQUAL(pixels[y*image.width + x], key)) break; } - if ((x == 0) || (y == 0)) return font; + if ((x == 0) || (y == 0)) return font; // Security check charSpacing = x; lineSpacing = y; @@ -823,7 +823,7 @@ Image GenImageFontAtlas(const GlyphInfo *glyphs, Rectangle **glyphRecs, int glyp if (offsetY > (atlas.height - fontSize - padding)) { - for(int j = i + 1; j < glyphCount; j++) + for (int j = i + 1; j < glyphCount; j++) { TRACELOG(LOG_WARNING, "FONT: Failed to package character (%i)", j); // Make sure remaining recs contain valid data @@ -1282,7 +1282,7 @@ Vector2 MeasureTextEx(Font font, const char *text, float fontSize, float spacing { Vector2 textSize = { 0 }; - if ((font.texture.id == 0) || (text == NULL)) return textSize; + if ((font.texture.id == 0) || (text == NULL)) return textSize; // Security check int size = TextLength(text); // Get size in bytes of text int tempByteCounter = 0; // Used to count longer text line num chars @@ -2029,21 +2029,21 @@ int GetCodepointNext(const char *text, int *codepointSize) if (0xf0 == (0xf8 & ptr[0])) { // 4 byte UTF-8 codepoint - if(((ptr[1] & 0xC0) ^ 0x80) || ((ptr[2] & 0xC0) ^ 0x80) || ((ptr[3] & 0xC0) ^ 0x80)) { return codepoint; } // 10xxxxxx checks + if (((ptr[1] & 0xC0) ^ 0x80) || ((ptr[2] & 0xC0) ^ 0x80) || ((ptr[3] & 0xC0) ^ 0x80)) { return codepoint; } // 10xxxxxx checks codepoint = ((0x07 & ptr[0]) << 18) | ((0x3f & ptr[1]) << 12) | ((0x3f & ptr[2]) << 6) | (0x3f & ptr[3]); *codepointSize = 4; } else if (0xe0 == (0xf0 & ptr[0])) { // 3 byte UTF-8 codepoint */ - if(((ptr[1] & 0xC0) ^ 0x80) || ((ptr[2] & 0xC0) ^ 0x80)) { return codepoint; } // 10xxxxxx checks + if (((ptr[1] & 0xC0) ^ 0x80) || ((ptr[2] & 0xC0) ^ 0x80)) { return codepoint; } // 10xxxxxx checks codepoint = ((0x0f & ptr[0]) << 12) | ((0x3f & ptr[1]) << 6) | (0x3f & ptr[2]); *codepointSize = 3; } else if (0xc0 == (0xe0 & ptr[0])) { // 2 byte UTF-8 codepoint - if((ptr[1] & 0xC0) ^ 0x80) { return codepoint; } // 10xxxxxx checks + if ((ptr[1] & 0xC0) ^ 0x80) { return codepoint; } // 10xxxxxx checks codepoint = ((0x1f & ptr[0]) << 6) | (0x3f & ptr[1]); *codepointSize = 2; } diff --git a/src/rtextures.c b/src/rtextures.c index c82232d8..d47df762 100644 --- a/src/rtextures.c +++ b/src/rtextures.c @@ -71,10 +71,10 @@ #if defined(SUPPORT_MODULE_RTEXTURES) #include "utils.h" // Required for: TRACELOG() -#include "rlgl.h" // OpenGL abstraction layer to OpenGL 1.1, 3.3 or ES2 +#include "rlgl.h" // OpenGL abstraction layer to multiple versions -#include // Required for: malloc(), free() -#include // Required for: strlen() [Used in ImageTextEx()], strcmp() [Used in LoadImageFromMemory()] +#include // Required for: malloc(), calloc(), free() +#include // Required for: strlen() [Used in ImageTextEx()], strcmp() [Used in LoadImageFromMemory()/LoadImageAnimFromMemory()/ExportImageToMemory()] #include // Required for: fabsf() [Used in DrawTextureRec()] #include // Required for: sprintf() [Used in ExportImageAsCode()] @@ -293,9 +293,12 @@ Image LoadImage(const char *fileName) unsigned char *fileData = LoadFileData(fileName, &dataSize); // Loading image from memory data - if (fileData != NULL) image = LoadImageFromMemory(GetFileExtension(fileName), fileData, dataSize); + if (fileData != NULL) + { + image = LoadImageFromMemory(GetFileExtension(fileName), fileData, dataSize); - RL_FREE(fileData); + UnloadFileData(fileData); + } return image; } @@ -322,7 +325,7 @@ Image LoadImageRaw(const char *fileName, int width, int height, int format, int image.mipmaps = 1; image.format = format; - RL_FREE(fileData); + UnloadFileData(fileData); } return image; @@ -431,7 +434,7 @@ Image LoadImageAnim(const char *fileName, int *frames) image.mipmaps = 1; image.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8; - RL_FREE(fileData); + UnloadFileData(fileData); RL_FREE(delays); // NOTE: Frames delays are discarded } } @@ -494,6 +497,9 @@ Image LoadImageAnimFromMemory(const char *fileType, const unsigned char *fileDat Image LoadImageFromMemory(const char *fileType, const unsigned char *fileData, int dataSize) { Image image = { 0 }; + + // Security check for input data + if ((fileType == NULL) || (fileData == NULL) || (dataSize == 0)) return image; if ((false) #if defined(SUPPORT_FILEFORMAT_PNG) @@ -699,11 +705,15 @@ Image LoadImageFromScreen(void) // Check if an image is ready bool IsImageReady(Image image) { - return ((image.data != NULL) && // Validate pixel data available - (image.width > 0) && - (image.height > 0) && // Validate image size - (image.format > 0) && // Validate image format - (image.mipmaps > 0)); // Validate image mipmaps (at least 1 for basic mipmap level) + bool result = false; + + if ((image.data != NULL) && // Validate pixel data available + (image.width > 0) && + (image.height > 0) && // Validate image size + (image.format > 0) && // Validate image format + (image.mipmaps > 0)) result = true; // Validate image mipmaps (at least 1 for basic mipmap level) + + return result; } // Unload image from CPU memory (RAM) @@ -718,6 +728,7 @@ bool ExportImage(Image image, const char *fileName) { int result = 0; + // Security check for input data if ((image.width == 0) || (image.height == 0) || (image.data == NULL)) return result; #if defined(SUPPORT_IMAGE_EXPORT) @@ -805,6 +816,7 @@ unsigned char *ExportImageToMemory(Image image, const char *fileType, int *dataS unsigned char *fileData = NULL; *dataSize = 0; + // Security check for input data if ((image.width == 0) || (image.height == 0) || (image.data == NULL)) return NULL; #if defined(SUPPORT_IMAGE_EXPORT) @@ -2184,7 +2196,7 @@ void ImageKernelConvolution(Image *image, float* kernel, int kernelSize) endRange = kernelWidth/2 + 1; } - for(int x = 0; x < image->height; x++) + for (int x = 0; x < image->height; x++) { for (int y = 0; y < image->width; y++) { @@ -3940,13 +3952,17 @@ RenderTexture2D LoadRenderTexture(int width, int height) // Check if a texture is ready bool IsTextureReady(Texture2D texture) { + bool result = false; + // TODO: Validate maximum texture size supported by GPU? - return ((texture.id > 0) && // Validate OpenGL id - (texture.width > 0) && - (texture.height > 0) && // Validate texture size - (texture.format > 0) && // Validate texture pixel format - (texture.mipmaps > 0)); // Validate texture mipmaps (at least 1 for basic mipmap level) + if ((texture.id > 0) && // Validate OpenGL id + (texture.width > 0) && + (texture.height > 0) && // Validate texture size + (texture.format > 0) && // Validate texture pixel format + (texture.mipmaps > 0)) result = true; // Validate texture mipmaps (at least 1 for basic mipmap level) + + return result; } // Unload texture from GPU memory (VRAM) @@ -3963,9 +3979,13 @@ void UnloadTexture(Texture2D texture) // Check if a render texture is ready bool IsRenderTextureReady(RenderTexture2D target) { - return ((target.id > 0) && // Validate OpenGL id - IsTextureReady(target.depth) && // Validate FBO depth texture/renderbuffer - IsTextureReady(target.texture)); // Validate FBO texture + bool result = false; + + if ((target.id > 0) && // Validate OpenGL id + IsTextureReady(target.depth) && // Validate FBO depth texture/renderbuffer + IsTextureReady(target.texture)) result = true; // Validate FBO texture + + return result; } // Unload render texture from GPU memory (VRAM) @@ -4473,16 +4493,22 @@ bool ColorIsEqual(Color col1, Color col2) // Get color with alpha applied, alpha goes from 0.0f to 1.0f Color Fade(Color color, float alpha) { + Color result = color; + if (alpha < 0.0f) alpha = 0.0f; else if (alpha > 1.0f) alpha = 1.0f; + + result.a = (unsigned char)(255.0f*alpha); - return (Color){ color.r, color.g, color.b, (unsigned char)(255.0f*alpha) }; + return result; } // Get hexadecimal value for a Color int ColorToInt(Color color) { - return (((int)color.r << 24) | ((int)color.g << 16) | ((int)color.b << 8) | (int)color.a); + int result = (((int)color.r << 24) | ((int)color.g << 16) | ((int)color.b << 8) | (int)color.a); + + return result; } // Get color normalized as float [0..1] @@ -4701,10 +4727,14 @@ Color ColorContrast(Color color, float contrast) // Get color with alpha applied, alpha goes from 0.0f to 1.0f Color ColorAlpha(Color color, float alpha) { + Color result = color; + if (alpha < 0.0f) alpha = 0.0f; else if (alpha > 1.0f) alpha = 1.0f; - return (Color){color.r, color.g, color.b, (unsigned char)(255.0f*alpha)}; + result.a = (unsigned char)(255.0f*alpha); + + return result; } // Get src alpha-blended into dst color with tint @@ -5007,21 +5037,31 @@ int GetPixelDataSize(int width, int height, int format) // REF: https://stackoverflow.com/questions/1659440/32-bit-to-16-bit-floating-point-conversion/60047308#60047308 static float HalfToFloat(unsigned short x) { + float result = 0.0f; + const unsigned int e = (x & 0x7C00) >> 10; // Exponent const unsigned int m = (x & 0x03FF) << 13; // Mantissa const float fm = (float)m; const unsigned int v = (*(unsigned int*)&fm) >> 23; // Evil log2 bit hack to count leading zeros in denormalized format const unsigned int r = (x & 0x8000) << 16 | (e != 0)*((e + 112) << 23 | m) | ((e == 0)&(m != 0))*((v - 37) << 23 | ((m << (150 - v)) & 0x007FE000)); // sign : normalized : denormalized - return *(float*)&r; + + result = *(float *)&r; + + return result; } // Convert float to half-float (stored as unsigned short) static unsigned short FloatToHalf(float x) { + unsigned short result = 0; + const unsigned int b = (*(unsigned int*) & x) + 0x00001000; // Round-to-nearest-even: add last bit after truncated mantissa const unsigned int e = (b & 0x7F800000) >> 23; // Exponent const unsigned int m = b & 0x007FFFFF; // Mantissa; in line below: 0x007FF000 = 0x00800000-0x00001000 = decimal indicator flag - initial rounding - return (b & 0x80000000) >> 16 | (e > 112)*((((e - 112) << 10) & 0x7C00) | m >> 13) | ((e < 113) & (e > 101))*((((0x007FF000 + m) >> (125 - e)) + 1) >> 1) | (e > 143)*0x7FFF; // sign : normalized : denormalized : saturate + + result = (b & 0x80000000) >> 16 | (e > 112)*((((e - 112) << 10) & 0x7C00) | m >> 13) | ((e < 113) & (e > 101))*((((0x007FF000 + m) >> (125 - e)) + 1) >> 1) | (e > 143)*0x7FFF; // sign : normalized : denormalized : saturate + + return result; } // Get pixel data from image as Vector4 array (float normalized)