// 22Jun2022

use tkopengl;


function Usage() {
   trace "png_to_raw <input.png> <argb32_output.bin>";
   exit(10);
}

if(Arguments.numElements < 2)
   Usage();

Texture tex;
if(tex.loadLocalImage(Arguments[0], 0, 0, 4))
{
   File f;
   f.byteOrder = YAC_LITTLE_ENDIAN;
   if(f.openLocal(Arguments[1], IOS_OUT))
   {
      int y = 0;
      loop(tex.sy)
      {
         int x = 0;
         loop(tex.sx)
         {
            int c32 = tex.getXY32(x++, y);
            f.i32 = c32;
         }
         y++;
      }

      f.close();

      trace "[...] wrote \""+Arguments[1]+"\" (raw ARGB32 little endian)";
   }
   else
   {
      trace "[---] failed to open output file \""+Arguments[1]+"\" for writing";
      exit(10);
   }
}
else
{
   trace "[---] failed to load input image \""+Arguments[0]+"\"";
   exit(10);
}
