From 61954eb47d0a64c8252cededca1fbc392da843fc Mon Sep 17 00:00:00 2001 From: Yonit Halperin Date: Wed, 9 Oct 2013 13:24:44 -0400 Subject: quic: add x-offset option to bitmap encoding Support for bitmap cropping: encode only the bitmap part that is determined by (width x height) and the horizontal offset. --- common/quic.c | 47 +++++++++++++++++++++++++---------------------- common/quic.h | 3 ++- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/common/quic.c b/common/quic.c index bcbf093..a2934fa 100644 --- a/common/quic.c +++ b/common/quic.c @@ -1221,32 +1221,35 @@ static void quic_image_params(Encoder *encoder, QuicImageType type, int *channel encoder->usr->error(encoder->usr, "more lines failed\n"); \ } \ lines_end = line + n * stride; \ + line_shifted = line + x_offset; \ } \ } -#define NEXT_LINE() { \ - line += stride; \ - FILL_LINES(); \ +#define NEXT_LINE() { \ + line += stride; \ + FILL_LINES(); \ + line_shifted = line + x_offset; \ } #define QUIC_COMPRESS_RGB(bits) \ encoder->channels[0].correlate_row[-1] = 0; \ encoder->channels[1].correlate_row[-1] = 0; \ encoder->channels[2].correlate_row[-1] = 0; \ - quic_rgb##bits##_compress_row0(encoder, (rgb##bits##_pixel_t *)(line), width); \ + quic_rgb##bits##_compress_row0(encoder, (rgb##bits##_pixel_t *)(line_shifted), width); \ encoder->rows_completed++; \ for (row = 1; row < height; row++) { \ - prev = line; \ + prev = line_shifted; \ NEXT_LINE(); \ encoder->channels[0].correlate_row[-1] = encoder->channels[0].correlate_row[0]; \ encoder->channels[1].correlate_row[-1] = encoder->channels[1].correlate_row[0]; \ encoder->channels[2].correlate_row[-1] = encoder->channels[2].correlate_row[0]; \ quic_rgb##bits##_compress_row(encoder, (rgb##bits##_pixel_t *)prev, \ - (rgb##bits##_pixel_t *)line, width); \ + (rgb##bits##_pixel_t *)line_shifted, width); \ encoder->rows_completed++; \ } -int quic_encode(QuicContext *quic, QuicImageType type, int width, int height, +int quic_encode(QuicContext *quic, QuicImageType type, + int width, int height, unsigned int x_offset, uint8_t *line, unsigned int num_lines, int stride, uint32_t *io_ptr, unsigned int num_io_words) { @@ -1254,7 +1257,7 @@ int quic_encode(QuicContext *quic, QuicImageType type, int width, int height, uint32_t *io_ptr_end = io_ptr + num_io_words; uint8_t *lines_end; int row; - uint8_t *prev; + uint8_t *line_shifted, *prev; int channels; int bpc; #ifndef QUIC_RGB @@ -1305,24 +1308,24 @@ int quic_encode(QuicContext *quic, QuicImageType type, int width, int height, encoder->channels[0].correlate_row[-1] = 0; encoder->channels[1].correlate_row[-1] = 0; encoder->channels[2].correlate_row[-1] = 0; - quic_rgb32_compress_row0(encoder, (rgb32_pixel_t *)(line), width); + quic_rgb32_compress_row0(encoder, (rgb32_pixel_t *)(line_shifted), width); encoder->channels[3].correlate_row[-1] = 0; - quic_four_compress_row0(encoder, &encoder->channels[3], (four_bytes_t *)(line + 3), width); + quic_four_compress_row0(encoder, &encoder->channels[3], (four_bytes_t *)(line_shifted + 3), width); encoder->rows_completed++; for (row = 1; row < height; row++) { - prev = line; + prev = line_shifted; NEXT_LINE(); encoder->channels[0].correlate_row[-1] = encoder->channels[0].correlate_row[0]; encoder->channels[1].correlate_row[-1] = encoder->channels[1].correlate_row[0]; encoder->channels[2].correlate_row[-1] = encoder->channels[2].correlate_row[0]; - quic_rgb32_compress_row(encoder, (rgb32_pixel_t *)prev, (rgb32_pixel_t *)line, width); + quic_rgb32_compress_row(encoder, (rgb32_pixel_t *)prev, (rgb32_pixel_t *)line_shifted, width); encoder->channels[3].correlate_row[-1] = encoder->channels[3].correlate_row[0]; quic_four_compress_row(encoder, &encoder->channels[3], (four_bytes_t *)(prev + 3), - (four_bytes_t *)(line + 3), width); + (four_bytes_t *)(line_shifted + 3), width); encoder->rows_completed++; } break; @@ -1331,17 +1334,17 @@ int quic_encode(QuicContext *quic, QuicImageType type, int width, int height, spice_assert(ABS(stride) >= width * 3); for (i = 0; i < 3; i++) { encoder->channels[i].correlate_row[-1] = 0; - quic_three_compress_row0(encoder, &encoder->channels[i], (three_bytes_t *)(line + i), + quic_three_compress_row0(encoder, &encoder->channels[i], (three_bytes_t *)(line_shifted + i), width); } encoder->rows_completed++; for (row = 1; row < height; row++) { - prev = line; + prev = line_shifted; NEXT_LINE(); for (i = 0; i < 3; i++) { encoder->channels[i].correlate_row[-1] = encoder->channels[i].correlate_row[0]; quic_three_compress_row(encoder, &encoder->channels[i], (three_bytes_t *)(prev + i), - (three_bytes_t *)(line + i), width); + (three_bytes_t *)(line_shifted + i), width); } encoder->rows_completed++; } @@ -1351,17 +1354,17 @@ int quic_encode(QuicContext *quic, QuicImageType type, int width, int height, spice_assert(ABS(stride) >= width * 4); for (i = 0; i < channels; i++) { encoder->channels[i].correlate_row[-1] = 0; - quic_four_compress_row0(encoder, &encoder->channels[i], (four_bytes_t *)(line + i), + quic_four_compress_row0(encoder, &encoder->channels[i], (four_bytes_t *)(line_shifted + i), width); } encoder->rows_completed++; for (row = 1; row < height; row++) { - prev = line; + prev = line_shifted; NEXT_LINE(); for (i = 0; i < channels; i++) { encoder->channels[i].correlate_row[-1] = encoder->channels[i].correlate_row[0]; quic_four_compress_row(encoder, &encoder->channels[i], (four_bytes_t *)(prev + i), - (four_bytes_t *)(line + i), width); + (four_bytes_t *)(line_shifted + i), width); } encoder->rows_completed++; } @@ -1370,14 +1373,14 @@ int quic_encode(QuicContext *quic, QuicImageType type, int width, int height, case QUIC_IMAGE_TYPE_GRAY: spice_assert(ABS(stride) >= width); encoder->channels[0].correlate_row[-1] = 0; - quic_one_compress_row0(encoder, &encoder->channels[0], (one_byte_t *)line, width); + quic_one_compress_row0(encoder, &encoder->channels[0], (one_byte_t *)line_shifted, width); encoder->rows_completed++; for (row = 1; row < height; row++) { - prev = line; + prev = line_shifted; NEXT_LINE(); encoder->channels[0].correlate_row[-1] = encoder->channels[0].correlate_row[0]; quic_one_compress_row(encoder, &encoder->channels[0], (one_byte_t *)prev, - (one_byte_t *)line, width); + (one_byte_t *)line_shifted, width); encoder->rows_completed++; } break; diff --git a/common/quic.h b/common/quic.h index ee5fb17..8774b9b 100644 --- a/common/quic.h +++ b/common/quic.h @@ -51,7 +51,8 @@ struct QuicUsrContext { // lines bunch must still be valid }; -int quic_encode(QuicContext *quic, QuicImageType type, int width, int height, +int quic_encode(QuicContext *quic, QuicImageType type, + int width, int height, unsigned int x_offset, uint8_t *lines, unsigned int num_lines, int stride, uint32_t *io_ptr, unsigned int num_io_words); -- cgit v1.2.3