[Spice-devel] [PATCH spice-server 1/2] jpeg-encoder: Avoid useless conversions
Frediano Ziglio
fziglio at redhat.com
Tue Jun 19 10:05:23 UTC 2018
Define JpegEncoderContext as an abstract structure.
This allows to reduce casts.
Also remove some alignment warnings on some architecture like mips.
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
server/jpeg-encoder.c | 14 +++++++-------
server/jpeg-encoder.h | 2 +-
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/server/jpeg-encoder.c b/server/jpeg-encoder.c
index a6eaf86f..e6591876 100644
--- a/server/jpeg-encoder.c
+++ b/server/jpeg-encoder.c
@@ -24,7 +24,7 @@
#include "red-common.h"
#include "jpeg-encoder.h"
-typedef struct JpegEncoder {
+struct JpegEncoderContext {
JpegEncoderUsrContext *usr;
struct jpeg_destination_mgr dest_mgr;
@@ -39,7 +39,9 @@ typedef struct JpegEncoder {
unsigned int out_size;
void (*convert_line_to_RGB24) (void *line, int width, uint8_t **out_line);
} cur_image;
-} JpegEncoder;
+};
+
+typedef struct JpegEncoderContext JpegEncoder;
/* jpeg destination manager callbacks */
@@ -97,12 +99,12 @@ JpegEncoderContext* jpeg_encoder_create(JpegEncoderUsrContext *usr)
jpeg_create_compress(&enc->cinfo);
enc->cinfo.client_data = enc;
enc->cinfo.dest = &enc->dest_mgr;
- return (JpegEncoderContext*)enc;
+ return enc;
}
void jpeg_encoder_destroy(JpegEncoderContext* encoder)
{
- jpeg_destroy_compress(&((JpegEncoder*)encoder)->cinfo);
+ jpeg_destroy_compress(&encoder->cinfo);
g_free(encoder);
}
@@ -202,12 +204,10 @@ static void do_jpeg_encode(JpegEncoder *jpeg, uint8_t *lines, unsigned int num_l
}
}
-int jpeg_encode(JpegEncoderContext *jpeg, int quality, JpegEncoderImageType type,
+int jpeg_encode(JpegEncoderContext *enc, int quality, JpegEncoderImageType type,
int width, int height, uint8_t *lines, unsigned int num_lines, int stride,
uint8_t *io_ptr, unsigned int num_io_bytes)
{
- JpegEncoder *enc = (JpegEncoder *)jpeg;
-
enc->cur_image.type = type;
enc->cur_image.width = width;
enc->cur_image.height = height;
diff --git a/server/jpeg-encoder.h b/server/jpeg-encoder.h
index 665cf9f7..0a1c2e78 100644
--- a/server/jpeg-encoder.h
+++ b/server/jpeg-encoder.h
@@ -43,7 +43,7 @@ typedef enum {
JPEG_IMAGE_TYPE_BGRX32,
} JpegEncoderImageType;
-typedef void* JpegEncoderContext;
+typedef struct JpegEncoderContext JpegEncoderContext;
typedef struct JpegEncoderUsrContext JpegEncoderUsrContext;
struct JpegEncoderUsrContext {
--
2.17.1
More information about the Spice-devel
mailing list