/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2006,2007 Free Software Foundation, Inc.
*
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
GRUB_MOD_LICENSE ("GPLv3+");
/* Uncomment following define to enable TGA debug. */
//#define TGA_DEBUG
#if defined(TGA_DEBUG)
#endif
enum
{
};
enum
{
};
enum
{
};
struct grub_tga_header
{
/* Color Map Specification. */
/* Image Specification. */
} __attribute__ ((packed));
static grub_err_t
struct grub_tga_header *header,
{
unsigned int x;
unsigned int y;
for (y = 0; y < header->image_height; y++)
{
else
for (x = 0; x < header->image_width;)
{
return grub_errno;
if (type & 0x80)
{
/* RLE-encoded packet. */
type &= 0x7f;
type++;
!= bytes_per_pixel)
return grub_errno;
while (type)
{
if (x < header->image_width)
{
ptr += 3;
}
type--;
x++;
}
}
else
{
/* RAW-encoded packet. */
type++;
while (type)
{
!= bytes_per_pixel)
return grub_errno;
if (x < header->image_width)
{
ptr += 3;
}
type--;
x++;
}
}
}
}
return GRUB_ERR_NONE;
}
static grub_err_t
struct grub_tga_header *header,
{
unsigned int x;
unsigned int y;
for (y = 0; y < header->image_height; y++)
{
else
for (x = 0; x < header->image_width;)
{
return grub_errno;
if (type & 0x80)
{
/* RLE-encoded packet. */
type &= 0x7f;
type++;
!= bytes_per_pixel)
return grub_errno;
while (type)
{
if (x < header->image_width)
{
ptr += 4;
}
type--;
x++;
}
}
else
{
/* RAW-encoded packet. */
type++;
while (type)
{
!= bytes_per_pixel)
return grub_errno;
if (x < header->image_width)
{
ptr += 4;
}
type--;
x++;
}
}
}
}
return GRUB_ERR_NONE;
}
static grub_err_t
struct grub_tga_header *header,
{
unsigned int x;
unsigned int y;
for (y = 0; y < header->image_height; y++)
{
else
for (x = 0; x < header->image_width; x++)
{
!= bytes_per_pixel)
return grub_errno;
ptr += 3;
}
}
return GRUB_ERR_NONE;
}
static grub_err_t
struct grub_tga_header *header,
{
unsigned int x;
unsigned int y;
for (y = 0; y < header->image_height; y++)
{
else
for (x = 0; x < header->image_width; x++)
{
!= bytes_per_pixel)
return grub_errno;
ptr += 4;
}
}
return GRUB_ERR_NONE;
}
static grub_err_t
const char *filename)
{
int has_alpha;
if (! file)
return grub_errno;
/* TGA Specification states that we SHOULD start by reading
ID from end of file, but we really don't care about that as we are
not going to support developer area & extensions at this point. */
/* Read TGA header from beginning of file. */
!= sizeof (header))
{
return grub_errno;
}
/* Skip ID field. */
if (grub_errno != GRUB_ERR_NONE)
{
return grub_errno;
}
#if defined(TGA_DEBUG)
grub_printf("tga: header\n");
#endif
/* Check that bitmap encoding is supported. */
switch (header.image_type)
{
break;
default:
return grub_error (GRUB_ERR_BAD_FILE_TYPE,
"unsupported bitmap format (unknown encoding)");
}
/* Check that bitmap depth is supported. */
{
case 24:
has_alpha = 0;
break;
case 32:
has_alpha = 1;
break;
default:
return grub_error (GRUB_ERR_BAD_FILE_TYPE,
"unsupported bitmap format (bpp=%d)",
}
/* Allocate bitmap. If there is alpha information store it too. */
if (has_alpha)
{
if (grub_errno != GRUB_ERR_NONE)
{
return grub_errno;
}
/* Load bitmap data. */
switch (header.image_type)
{
break;
break;
}
}
else
{
if (grub_errno != GRUB_ERR_NONE)
{
return grub_errno;
}
/* Load bitmap data. */
switch (header.image_type)
{
break;
break;
}
}
/* If there was a loading problem, destroy bitmap. */
if (grub_errno != GRUB_ERR_NONE)
{
*bitmap = 0;
}
return grub_errno;
}
#if defined(TGA_DEBUG)
static grub_err_t
{
if (argc != 1)
if (grub_errno != GRUB_ERR_NONE)
return grub_errno;
return GRUB_ERR_NONE;
}
#endif
.extension = ".tga",
.next = 0
};
{
#if defined(TGA_DEBUG)
"FILE", "Tests loading of TGA bitmap.");
#endif
}
{
#if defined(TGA_DEBUG)
#endif
}