Foro de elhacker.net

Programación => Programación C/C++ => Mensaje iniciado por: Assasin92 en 11 Diciembre 2024, 11:01 am



Título: Simple tga writer no funciona correctamente.
Publicado por: Assasin92 en 11 Diciembre 2024, 11:01 am
Hola. Escribí un código para escribir un simple archivo de formato tga.

Por desgracia, no parece funcionar como se esperaba. La imagen resultante es siempre negro, no importa los valores de color que escribo en el archivo. Aquí está el código:

Código:
#include <fstream>

using namespace std;

main () {
   int a = 1024;
   int b = 768;
   int c = 24;
   ofstream ofs ("x.tga", ios::binary);
         ofs.put (0), ofs.put (0), ofs.put (2), ofs.put (0), ofs.put (0), ofs.put (0);
         ofs.put (0), ofs.put (0), ofs.put (0), ofs.put (0), ofs.put (0), ofs.put (0);
         ofs.put (a), ofs.put (a >> 8), ofs.put (b), ofs.put (b >> 8);
         ofs.put (c),   ofs.put (0);   
   for (int i=0; i<a; i++)
      for (int j=0; j<b; j++)
         ofs.put (1),          ofs.put (0),          ofs.put (0);         
   ofs.close ();


Título: Re: Simple tga writer no funciona correctamente.
Publicado por: Eternal Idol en 11 Diciembre 2024, 13:44 pm
https://en.wikipedia.org/wiki/Truevision_TGA

"Uncompressed 24-bit TGA images are relatively simple compared to several other prominent 24-bit storage formats: A 24-bit TGA contains only an 18-byte header followed by the image data as packed RGB data."

Código
  1. for (int i=0; i<a; i++)
  2.      for (int j=0; j<b; j++)
  3.         ofs.put (1),          ofs.put (0),          ofs.put (0);

Entonces tu codigo esta escribiendo 1, 0, 0 en RGB. Cambialo por 0, 128, 0 y veras solo verde por ejemplo.