From e9c492a02e3cd63927b423798e45a4de61d5ac8a Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 27 Sep 2013 11:13:36 +0200 Subject: [PATCH] * grub-core/video/readers/jpeg.c: Support grayscale. --- ChangeLog | 4 ++ grub-core/video/readers/jpeg.c | 74 ++++++++++++++++++++++------------ 2 files changed, 52 insertions(+), 26 deletions(-) diff --git a/ChangeLog b/ChangeLog index f1a6ac277..f57b3faa6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2013-09-24 Vladimir Serbinenko + + * grub-core/video/readers/jpeg.c: Support grayscale. + 2013-09-24 Jon McCune * grub-core/commands/loadenv.c: Support skipping signature check diff --git a/grub-core/video/readers/jpeg.c b/grub-core/video/readers/jpeg.c index 0067b7dc1..7dea37344 100644 --- a/grub-core/video/readers/jpeg.c +++ b/grub-core/video/readers/jpeg.c @@ -33,21 +33,24 @@ GRUB_MOD_LICENSE ("GPLv3+"); #define JPEG_SAMPLING_1x1 0x11 -#define JPEG_MARKER_SOI 0xd8 -#define JPEG_MARKER_EOI 0xd9 -#define JPEG_MARKER_DHT 0xc4 -#define JPEG_MARKER_DQT 0xdb -#define JPEG_MARKER_SOF0 0xc0 -#define JPEG_MARKER_SOS 0xda -#define JPEG_MARKER_DRI 0xdd -#define JPEG_MARKER_RST0 0xd0 -#define JPEG_MARKER_RST1 0xd1 -#define JPEG_MARKER_RST2 0xd2 -#define JPEG_MARKER_RST3 0xd3 -#define JPEG_MARKER_RST4 0xd4 -#define JPEG_MARKER_RST5 0xd5 -#define JPEG_MARKER_RST6 0xd6 -#define JPEG_MARKER_RST7 0xd7 +enum + { + JPEG_MARKER_SOF0 = 0xc0, + JPEG_MARKER_DHT = 0xc4, + JPEG_MARKER_SOI = 0xd8, + JPEG_MARKER_EOI = 0xd9, + JPEG_MARKER_RST0 = 0xd0, + JPEG_MARKER_RST1 = 0xd1, + JPEG_MARKER_RST2 = 0xd2, + JPEG_MARKER_RST3 = 0xd3, + JPEG_MARKER_RST4 = 0xd4, + JPEG_MARKER_RST5 = 0xd5, + JPEG_MARKER_RST6 = 0xd6, + JPEG_MARKER_RST7 = 0xd7, + JPEG_MARKER_SOS = 0xda, + JPEG_MARKER_DQT = 0xdb, + JPEG_MARKER_DRI = 0xdd, + }; #define SHIFT_BITS 8 #define CONST(x) ((int) ((x) * (1L << SHIFT_BITS) + 0.5)) @@ -97,6 +100,8 @@ struct grub_jpeg_data int dc_value[3]; + int color_components; + int bit_mask, bit_save; }; @@ -294,9 +299,10 @@ grub_jpeg_decode_sof (struct grub_jpeg_data *data) return grub_error (GRUB_ERR_BAD_FILE_TYPE, "jpeg: invalid image size"); cc = grub_jpeg_get_byte (data); - if (cc != 3) + if (cc != 1 && cc != 3) return grub_error (GRUB_ERR_BAD_FILE_TYPE, - "jpeg: component count must be 3"); + "jpeg: component count must be 1 or 3"); + data->color_components = cc; for (i = 0; i < cc; i++) { @@ -571,9 +577,10 @@ grub_jpeg_decode_sos (struct grub_jpeg_data *data) cc = grub_jpeg_get_byte (data); - if (cc != 3) + if (cc != 3 && cc != 1) return grub_error (GRUB_ERR_BAD_FILE_TYPE, - "jpeg: component count must be 3"); + "jpeg: component count must be 1 or 3"); + data->color_components = cc; for (i = 0; i < cc; i++) { @@ -626,8 +633,13 @@ grub_jpeg_decode_data (struct grub_jpeg_data *data) for (c2 = 0; c2 < data->hs; c2++) grub_jpeg_decode_du (data, 0, data->ydu[r2 * 2 + c2]); - grub_jpeg_decode_du (data, 1, data->cbdu); - grub_jpeg_decode_du (data, 2, data->crdu); + if (data->color_components >= 3) + { + grub_jpeg_decode_du (data, 1, data->cbdu); + grub_jpeg_decode_du (data, 2, data->crdu); + } + grub_memset (&data->cbdu, 0, sizeof (data->cbdu)); + grub_memset (&data->crdu, 0, sizeof (data->crdu)); if (grub_errno) return grub_errno; @@ -639,14 +651,24 @@ grub_jpeg_decode_data (struct grub_jpeg_data *data) for (r2 = 0; r2 < nr2; r2++, ptr2 += (data->image_width - nc2) * 3) for (c2 = 0; c2 < nc2; c2++, ptr2 += 3) { - int i0, yy, cr, cb; + int i0, yy; i0 = (r2 / data->vs) * 8 + (c2 / data->hs); - cr = data->crdu[i0]; - cb = data->cbdu[i0]; yy = data->ydu[(r2 / 8) * 2 + (c2 / 8)][(r2 % 8) * 8 + (c2 % 8)]; - grub_jpeg_ycrcb_to_rgb (yy, cr, cb, ptr2); + if (data->color_components >= 3) + { + int cr, cb; + cr = data->crdu[i0]; + cb = data->cbdu[i0]; + grub_jpeg_ycrcb_to_rgb (yy, cr, cb, ptr2); + } + else + { + ptr2[0] = yy; + ptr2[1] = yy; + ptr2[2] = yy; + } } } @@ -778,7 +800,7 @@ grub_video_reader_jpeg (struct grub_video_bitmap **bitmap, #if defined(JPEG_DEBUG) static grub_err_t -grub_cmd_jpegtest (grub_command_t cmd __attribute__ ((unused)), +grub_cmd_jpegtest (grub_command_t cmdd __attribute__ ((unused)), int argc, char **args) { struct grub_video_bitmap *bitmap = 0;