MCPcopy Create free account
hub / github.com/captain-amygdala/pistorm / LoadImageDataNormalized

Function LoadImageDataNormalized

raylib/textures.c:4564–4672  ·  view source on GitHub ↗

Get pixel data from image as Vector4 array (float normalized)

Source from the content-addressed store, hash-verified

4562
4563// Get pixel data from image as Vector4 array (float normalized)
4564static Vector4 *LoadImageDataNormalized(Image image)
4565{
4566 Vector4 *pixels = (Vector4 *)RL_MALLOC(image.width*image.height*sizeof(Vector4));
4567
4568 if (image.format >= PIXELFORMAT_COMPRESSED_DXT1_RGB) TRACELOG(LOG_WARNING, "IMAGE: Pixel data retrieval not supported for compressed image formats");
4569 else
4570 {
4571 for (int i = 0, k = 0; i < image.width*image.height; i++)
4572 {
4573 switch (image.format)
4574 {
4575 case PIXELFORMAT_UNCOMPRESSED_GRAYSCALE:
4576 {
4577 pixels[i].x = (float)((unsigned char *)image.data)[i]/255.0f;
4578 pixels[i].y = (float)((unsigned char *)image.data)[i]/255.0f;
4579 pixels[i].z = (float)((unsigned char *)image.data)[i]/255.0f;
4580 pixels[i].w = 1.0f;
4581
4582 } break;
4583 case PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA:
4584 {
4585 pixels[i].x = (float)((unsigned char *)image.data)[k]/255.0f;
4586 pixels[i].y = (float)((unsigned char *)image.data)[k]/255.0f;
4587 pixels[i].z = (float)((unsigned char *)image.data)[k]/255.0f;
4588 pixels[i].w = (float)((unsigned char *)image.data)[k + 1]/255.0f;
4589
4590 k += 2;
4591 } break;
4592 case PIXELFORMAT_UNCOMPRESSED_R5G5B5A1:
4593 {
4594 unsigned short pixel = ((unsigned short *)image.data)[i];
4595
4596 pixels[i].x = (float)((pixel & 0b1111100000000000) >> 11)*(1.0f/31);
4597 pixels[i].y = (float)((pixel & 0b0000011111000000) >> 6)*(1.0f/31);
4598 pixels[i].z = (float)((pixel & 0b0000000000111110) >> 1)*(1.0f/31);
4599 pixels[i].w = ((pixel & 0b0000000000000001) == 0)? 0.0f : 1.0f;
4600
4601 } break;
4602 case PIXELFORMAT_UNCOMPRESSED_R5G6B5:
4603 {
4604 unsigned short pixel = ((unsigned short *)image.data)[i];
4605
4606 pixels[i].x = (float)((pixel & 0b1111100000000000) >> 11)*(1.0f/31);
4607 pixels[i].y = (float)((pixel & 0b0000011111100000) >> 5)*(1.0f/63);
4608 pixels[i].z = (float)(pixel & 0b0000000000011111)*(1.0f/31);
4609 pixels[i].w = 1.0f;
4610
4611 } break;
4612 case PIXELFORMAT_UNCOMPRESSED_R4G4B4A4:
4613 {
4614 unsigned short pixel = ((unsigned short *)image.data)[i];
4615
4616 pixels[i].x = (float)((pixel & 0b1111000000000000) >> 12)*(1.0f/15);
4617 pixels[i].y = (float)((pixel & 0b0000111100000000) >> 8)*(1.0f/15);
4618 pixels[i].z = (float)((pixel & 0b0000000011110000) >> 4)*(1.0f/15);
4619 pixels[i].w = (float)(pixel & 0b0000000000001111)*(1.0f/15);
4620
4621 } break;

Callers 1

ImageFormatFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected