<p><br>Thank you for your reminder. I will modify the patch and resubmit it.<br><br><br><br><br>----</p>
<div id="cs2c_mail_sigature"></div>
<p> </p>
<div id="re" style="margin-left: 0.5em; padding-left: 0.5em; border-left: 1px solid green;"><br><br><br>
<div style="background-color: #f5f7fa;"><strong>主 题:</strong><span id="subject">Re: [PATCH v1] jpeg: optimize compression process</span> <br><strong>日 期:</strong><span id="date">2025-03-03 01:24</span> <br><strong>发件人:</strong><span id="from">Frediano Ziglio</span> <br><strong>收件人:</strong><span id="to" style="word-break: break-all;">李唯实;</span></div>
<br>
<div id="content">
<div class="viewer_part" style="position: relative;">
<div>
<div>
<div class="gmail_quote gmail_quote_container">
<div class="gmail_attr">On Fri, Feb 28, 2025 at 9:53 PM <<a href="http://mailto:liweishi@kylinos.cn" target="_blank" rel="noopener">liweishi@kylinos.cn</a>> wrote:</div>
From: Weishi Li <<a href="http://mailto:liweishi@kylinos.cn" target="_blank" rel="noopener">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="http://mailto:liweishi@kylinos.cn" target="_blank" rel="noopener">liweishi@kylinos.cn</a>><br>---<br> server/jpeg-encoder.c | 42 +++++++++++++++++++++++++++++++++++++-----<br> 1 file changed, 37 insertions(+), 5 deletions(-)<br><br>diff --git a/server/jpeg-encoder.c b/server/jpeg-encoder.c<br>index fee07105..fe1038f3 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>@@ -177,7 +188,7 @@ static void convert_BGRX32_to_RGB24(void *line, int width, uint8_t **out_line)<br>     }                                                                   \<br> }<br><br>-static void do_jpeg_encode(JpegEncoder *jpeg, uint8_t *lines, unsigned int num_lines)<br>+static void do_jpeg_encode(JpegEncoder *jpeg, uint8_t *lines, unsigned int num_lines, JpegEncoderImageType type)<br> {<br>     uint8_t *lines_end;<br>     uint8_t *RGB24_line;<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 (type == JPEG_IMAGE_TYPE_BGR24 || type == JPEG_IMAGE_TYPE_BGRX32) {<br>
<div> </div>
<div>Why not check if jpeg->cur_image.convert_line_to_RGB24 is NULL instead ? It would remove the need to pass the type and reduce the difference.</div>
<div> </div>
+        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");<br>@@ -236,7 +268,7 @@ int jpeg_encode(JpegEncoderContext *enc, int quality, JpegEncoderImageType type,<br><br>     jpeg_start_compress(&enc->cinfo, TRUE);<br><br>-    do_jpeg_encode(enc, lines, num_lines);<br>+    do_jpeg_encode(enc, lines, num_lines, type);<br><br>     jpeg_finish_compress(&enc->cinfo);<br>     return enc->cur_image.out_size;<br>
<div> </div>
<div>Frediano</div>
<div> </div>
</div>
</div>
</div>
</div>
</div>
</div>