Kaynağa Gözat

REVIEWED: example: Replaced GetImageData()

pull/1570/head
raysan5 4 yıl önce
ebeveyn
işleme
b7b718a545
1 değiştirilmiş dosya ile 21 ekleme ve 18 silme
  1. +21
    -18
      examples/textures/textures_image_processing.c

+ 21
- 18
examples/textures/textures_image_processing.c Dosyayı Görüntüle

@ -4,7 +4,7 @@
*
* NOTE: Images are loaded in CPU memory (RAM); textures are loaded in GPU memory (VRAM)
*
* This example has been created using raylib 1.4 (www.raylib.com)
* This example has been created using raylib 3.5 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
* Copyright (c) 2016 Ramon Santamaria (@raysan5)
@ -50,9 +50,11 @@ int main(void)
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
Image image = LoadImage("resources/parrots.png"); // Loaded in CPU memory (RAM)
ImageFormat(&image, UNCOMPRESSED_R8G8B8A8); // Format image to RGBA 32bit (required for texture update) <-- ISSUE
Texture2D texture = LoadTextureFromImage(image); // Image converted to texture, GPU memory (VRAM)
Image imOrigin = LoadImage("resources/parrots.png"); // Loaded in CPU memory (RAM)
ImageFormat(&imOrigin, UNCOMPRESSED_R8G8B8A8); // Format image to RGBA 32bit (required for texture update) <-- ISSUE
Texture2D texture = LoadTextureFromImage(imOrigin); // Image converted to texture, GPU memory (VRAM)
Image imCopy = ImageCopy(imOrigin);
int currentProcess = NONE;
bool textureReload = false;
@ -92,7 +94,7 @@ int main(void)
if (IsKeyPressed(KEY_DOWN))
{
currentProcess++;
if (currentProcess > mi">7) currentProcess = 0;
if (currentProcess > p">(NUM_PROCESSES - 1)) currentProcess = 0;
textureReload = true;
}
else if (IsKeyPressed(KEY_UP))
@ -105,27 +107,27 @@ int main(void)
// Reload texture when required
if (textureReload)
{
UnloadImage(image); // Unload current image data
image = LoadImage("resources/parrots.png"); // Re-load image data
UnloadImage(imCopy); // Unload image-copy data
imCopy = ImageCopy(imOrigin); // Restore image-copy from image-origin
// NOTE: Image processing is a costly CPU process to be done every frame,
// If image processing is required in a frame-basis, it should be done
// with a texture and by shaders
switch (currentProcess)
{
case COLOR_GRAYSCALE: ImageColorGrayscale(&image); break;
case COLOR_TINT: ImageColorTint(&image, GREEN); break;
case COLOR_INVERT: ImageColorInvert(&image); break;
case COLOR_CONTRAST: ImageColorContrast(&image, -40); break;
case COLOR_BRIGHTNESS: ImageColorBrightness(&image, -80); break;
case FLIP_VERTICAL: ImageFlipVertical(&image); break;
case FLIP_HORIZONTAL: ImageFlipHorizontal(&image); break;
case COLOR_GRAYSCALE: ImageColorGrayscale(&imCopy); break;
case COLOR_TINT: ImageColorTint(&imCopy, GREEN); break;
case COLOR_INVERT: ImageColorInvert(&imCopy); break;
case COLOR_CONTRAST: ImageColorContrast(&imCopy, -40); break;
case COLOR_BRIGHTNESS: ImageColorBrightness(&imCopy, -80); break;
case FLIP_VERTICAL: ImageFlipVertical(&imCopy); break;
case FLIP_HORIZONTAL: ImageFlipHorizontal(&imCopy); break;
default: break;
}
Color *pixels = GetImageData(image); // Get pixel data from image (RGBA 32bit)
Color *pixels = LoadImageColors(imCopy); // Load pixel data from image (RGBA 32bit)
UpdateTexture(texture, pixels); // Update texture with new image data
free(pixels); // Unload pixels data from RAM
UnloadImageColors(pixels); // Unload pixels data from RAM
textureReload = false;
}
@ -157,7 +159,8 @@ int main(void)
// De-Initialization
//--------------------------------------------------------------------------------------
UnloadTexture(texture); // Unload texture from VRAM
UnloadImage(image); // Unload image from RAM
UnloadImage(imOrigin); // Unload image-origin from RAM
UnloadImage(imCopy); // Unload image-copy from RAM
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------

Yükleniyor…
İptal
Kaydet