/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2008,2009 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 PNG debug. */
//#define PNG_DEBUG
#define PNG_COLOR_TYPE_GRAY 0
#define PNG_COMPRESSION_BASE 0
#define PNG_INTERLACE_NONE 0
#define PNG_FILTER_TYPE_BASE 0
#define PNG_FILTER_VALUE_NONE 0
#define INFLATE_STORED 0
#ifdef PNG_DEBUG
#endif
struct huff_table
{
};
struct grub_png_data
{
int wp;
};
static grub_uint32_t
{
r = 0;
return grub_be_to_cpu32 (r);
}
static grub_uint8_t
{
grub_uint8_t r;
{
do
{
/* Skip crc checksum. */
{
"png: chunk size error");
return 0;
}
if (type != PNG_CHUNK_IDAT)
{
"png: unexpected end of data");
return 0;
}
}
while (len == 0);
}
r = 0;
if (data->inside_idat)
data->idat_remain--;
return r;
}
static int
{
{
}
code = 0;
shift = 0;
while (grub_errno == 0)
{
int n;
if (n > num)
n = num;
num -= n;
if (!num)
{
break;
}
shift += n;
}
return code;
}
static grub_err_t
{
int color_type;
int color_bits;
return grub_error (GRUB_ERR_BAD_FILE_TYPE,
"png: bit depth must be 8 or 16");
if (color_type == PNG_COLOR_TYPE_RGB)
{
return grub_errno;
}
else if (color_type == PNG_COLOR_TYPE_RGBA)
{
return grub_errno;
}
else
return grub_error (GRUB_ERR_BAD_FILE_TYPE,
"png: color type not supported");
{
if (grub_errno)
return grub_errno;
}
else
{
data->image_data = 0;
}
data->cur_column = 0;
return grub_error (GRUB_ERR_BAD_FILE_TYPE,
"png: compression method not supported");
return grub_error (GRUB_ERR_BAD_FILE_TYPE,
"png: filter method not supported");
return grub_error (GRUB_ERR_BAD_FILE_TYPE,
"png: interlace method not supported");
/* Skip crc checksum. */
return grub_errno;
}
/* Order of the bit length code lengths. */
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
};
/* Copy lengths for literal codes 257..285. */
static const int cplens[] = {
3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0
};
/* Extra bits for literal codes 257..285. */
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 99, 99
}; /* 99==invalid */
/* Copy offsets for distance codes 0..29. */
static const int cpdist[] = {
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
8193, 12289, 16385, 24577
};
/* Extra bits for distance codes. */
0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
12, 12, 13, 13
};
static void
{
ht->num_values = 0;
}
static void
{
int i, n;
if (len == 0)
return;
{
return;
}
n = 0;
for (i = 0; i < n; i++)
ht->num_values++;
}
static void
{
base = 0;
ofs = 0;
for (i = 0; i < ht->max_length; i++)
{
base <<= 1;
}
}
static int
{
int code, i;
code = 0;
for (i = 0; i < ht->max_length; i++)
{
}
return 0;
}
static grub_err_t
{
int i;
data->code_offset);
for (i = 0; i < 144; i++)
for (; i < 256; i++)
for (; i < 280; i++)
for (; i < DEFLATE_HLIT_MAX; i++)
data->dist_offset);
for (i = 0; i < DEFLATE_HDIST_MAX; i++)
return grub_errno;
}
static grub_err_t
{
(nb > DEFLATE_HCLEN_MAX))
for (i = 0; i < nb; i++)
for (; i < DEFLATE_HCLEN_MAX; i++)
for (i = 0; i < DEFLATE_HCLEN_MAX; i++)
data->code_offset);
data->dist_offset);
prev = 0;
{
int n, code;
if (grub_errno)
return grub_errno;
if (i < nl)
{
code = i;
}
else
{
}
if (n < 16)
{
prev = n;
}
else if (n == 16)
{
int c;
while (c > 0)
{
i++;
c--;
}
i--;
}
else if (n == 17)
else
}
return grub_errno;
}
static grub_err_t
{
int row_bytes;
if (data->cur_column == 0)
{
if (n >= PNG_FILTER_VALUE_LAST)
data->cur_filter = n;
}
else
data->cur_column++;
{
if (data->first_line)
{
if (blank_line == NULL)
return grub_errno;
up = blank_line;
}
else
switch (data->cur_filter)
{
case PNG_FILTER_VALUE_SUB:
{
int i;
break;
}
case PNG_FILTER_VALUE_UP:
{
int i;
break;
}
case PNG_FILTER_VALUE_AVG:
{
int i;
break;
}
case PNG_FILTER_VALUE_PAETH:
{
int i;
{
a = *left;
b = *up;
c = *upper_left;
pa = b - c;
pb = a - c;
if (pa < 0)
if (pb < 0)
if (pc < 0)
}
}
}
data->cur_column = 0;
data->first_line = 0;
}
return grub_errno;
}
static grub_err_t
{
while (grub_errno == 0)
{
int n;
if (n < 256)
{
grub_png_output_byte (data, n);
}
else if (n == 256)
break;
else
{
n -= 257;
if (cplext[n])
if (cpdext[n])
if (pos < 0)
while (len > 0)
{
pos++;
pos = 0;
len--;
}
}
}
return grub_errno;
}
static grub_err_t
{
int final;
return grub_error (GRUB_ERR_BAD_FILE_TYPE,
"png: only support deflate compression method");
if (flg & Z_FLAG_DICT)
return grub_error (GRUB_ERR_BAD_FILE_TYPE,
"png: dictionary not supported");
do
{
int block_type;
switch (block_type)
{
case INFLATE_STORED:
{
/* Skip NLEN field. */
for (i = 0; i < len; i++)
break;
}
case INFLATE_FIXED:
break;
case INFLATE_DYNAMIC:
break;
default:
return grub_error (GRUB_ERR_BAD_FILE_TYPE,
"png: unknown block type");
}
}
while ((!final) && (grub_errno == 0));
/* Skip adler checksum. */
/* Skip crc checksum. */
return grub_errno;
}
{ 0x89, 0x50, 0x4e, 0x47, 0xd, 0xa, 0x1a, 0x0a };
static void
{
int i;
/* Only copy the upper 8 bit. */
}
static grub_err_t
{
return grub_errno;
while (1)
{
switch (type)
{
case PNG_CHUNK_IHDR:
break;
case PNG_CHUNK_IDAT:
data->inside_idat = 0;
break;
case PNG_CHUNK_IEND:
return grub_errno;
default:
}
if (grub_errno)
break;
return grub_error (GRUB_ERR_BAD_FILE_TYPE,
"png: chunk size error");
}
return grub_errno;
}
static grub_err_t
const char *filename)
{
if (!file)
return grub_errno;
{
}
if (grub_errno != GRUB_ERR_NONE)
{
*bitmap = 0;
}
return grub_errno;
}
#if defined(PNG_DEBUG)
static grub_err_t
{
if (argc != 1)
if (grub_errno != GRUB_ERR_NONE)
return grub_errno;
return GRUB_ERR_NONE;
}
#endif
.extension = ".png",
.next = 0
};
{
#if defined(PNG_DEBUG)
"FILE",
"Tests loading of PNG bitmap.");
#endif
}
{
#if defined(PNG_DEBUG)
#endif
}