<div dir="ltr"><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Mon, Mar 3, 2025 at 2:36 AM <<a href="mailto:liweishi@kylinos.cn">liweishi@kylinos.cn</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">From: Weishi Li <<a href="mailto:liweishi@kylinos.cn" target="_blank">liweishi@kylinos.cn</a>><br>
<br>
similiar to mjpeg, when defined JCS_EXTENSIONS, there<br>
is no need to convert BGR24/BGRX32 to RGB24.<br>
<br>
Signed-off-by: Weishi Li <<a href="mailto:liweishi@kylinos.cn" target="_blank">liweishi@kylinos.cn</a>><br>
---<br>
server/jpeg-encoder.c | 38 +++++++++++++++++++++++++++++++++++---<br>
1 file changed, 35 insertions(+), 3 deletions(-)<br>
<br>
diff --git a/server/jpeg-encoder.c b/server/jpeg-encoder.c<br>
index fee07105..ba9058a2 100644<br>
--- a/server/jpeg-encoder.c<br>
+++ b/server/jpeg-encoder.c<br>
@@ -27,6 +27,16 @@<br>
#include "red-common.h"<br>
#include "jpeg-encoder.h"<br>
<br>
+#ifdef JCS_EXTENSIONS<br>
+# ifndef WORDS_BIGENDIAN<br>
+# define JCS_EXT_LE_BGRX JCS_EXT_BGRX<br>
+# define JCS_EXT_LE_BGR JCS_EXT_BGR<br>
+# else<br>
+# define JCS_EXT_LE_BGRX JCS_EXT_XRGB<br>
+# define JCS_EXT_LE_BGR JCS_EXT_RGB<br>
+# endif<br>
+#endif<br>
+<br>
struct JpegEncoderContext {<br>
JpegEncoderUsrContext *usr;<br>
<br>
@@ -130,6 +140,7 @@ static void convert_RGB16_to_RGB24(void *line, int width, uint8_t **out_line)<br>
}<br>
}<br>
<br>
+#ifndef JCS_EXTENSIONS<br>
static void convert_BGR24_to_RGB24(void *in_line, int width, uint8_t **out_line)<br>
{<br>
int x;<br>
@@ -165,7 +176,7 @@ static void convert_BGRX32_to_RGB24(void *line, int width, uint8_t **out_line)<br>
*out_pix++ = pixel & 0xff;<br>
}<br>
}<br>
-<br>
+#endif<br>
<br>
#define FILL_LINES() { \<br>
if (lines == lines_end) { \<br>
@@ -186,10 +197,21 @@ static void do_jpeg_encode(JpegEncoder *jpeg, uint8_t *lines, unsigned int num_l<br>
width = jpeg->cur_image.width;<br>
stride = jpeg->cur_image.stride;<br>
<br>
- RGB24_line = g_new(uint8_t, width*3);<br>
-<br>
lines_end = lines + (stride * num_lines);<br>
<br>
+#ifdef JCS_EXTENSIONS<br>
+ if (enc->cur_image.convert_line_to_RGB24 == NULL) {<br>
+ for (;jpeg->cinfo.next_scanline < jpeg->cinfo.image_height; lines += stride) {<br>
+ FILL_LINES();<br>
+ row_pointer[0] = lines;<br>
+ jpeg_write_scanlines(&jpeg->cinfo, row_pointer, 1);<br>
+ }<br>
+ return;<br>
+ }<br>
+#endif<br>
+<br>
+ RGB24_line = g_new(uint8_t, width*3);<br>
+<br>
for (;jpeg->cinfo.next_scanline < jpeg->cinfo.image_height; lines += stride) {<br>
FILL_LINES();<br>
jpeg->cur_image.convert_line_to_RGB24(lines, width, &RGB24_line);<br>
@@ -215,10 +237,20 @@ int jpeg_encode(JpegEncoderContext *enc, int quality, JpegEncoderImageType type,<br>
enc->cur_image.convert_line_to_RGB24 = convert_RGB16_to_RGB24;<br>
break;<br>
case JPEG_IMAGE_TYPE_BGR24:<br>
+#ifdef JCS_EXTENSIONS<br>
+ enc->cinfo.in_color_space = JCS_EXT_LE_BGR;<br>
+ enc->cinfo.input_components = 3;<br>
+#else<br>
enc->cur_image.convert_line_to_RGB24 = convert_BGR24_to_RGB24;<br>
+#endif<br>
break;<br>
case JPEG_IMAGE_TYPE_BGRX32:<br>
+#ifdef JCS_EXTENSIONS<br>
+ enc->cinfo.in_color_space = JCS_EXT_LE_BGRX;<br>
+ enc->cinfo.input_components = 4;<br>
+#else<br>
enc->cur_image.convert_line_to_RGB24 = convert_BGRX32_to_RGB24;<br>
+#endif<br>
break;<br>
default:<br>
spice_error("bad image type");</blockquote><div><br></div><div>Hi,</div><div> tested, fixed and merged.</div><div><br></div><div>Thanks,</div><div> Frediano</div><div> <br></div></div></div>