You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by "keever50 (via GitHub)" <gi...@apache.org> on 2025/07/25 18:18:38 UTC
[PR] graphics/jpgresizetool: Add libjpeg resize tool [nuttx-apps]
keever50 opened a new pull request, #3143:
URL: https://github.com/apache/nuttx-apps/pull/3143
## Summary
Add a libjpeg based JPEG resize tool.
Simple resizer that can resize JPEGs using
"jpgresize input.jpg output.jpg scale_denom(1,2,4,8) quality%". Tries to use little memory by scanning per line.
## Impact
Allows users to quickly resize JPEG images using a simple command. Useful for in scripts to generate thumbnails or experiment with jpeg compression and size ratios.
## Testing
This app is tested during the development of a project where thumbnails are generated from photos.
<img width="525" height="73" alt="image" src="https://github.com/user-attachments/assets/ed2d0989-406b-44ef-a21f-d4ed3d21eeb7" />
<img width="522" height="109" alt="image" src="https://github.com/user-attachments/assets/d7b177dc-99d4-4e3a-be4b-5bb52b550e73" />
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] graphics/jpgresizetool: Add libjpeg resize tool [nuttx-apps]
Posted by "simbit18 (via GitHub)" <gi...@apache.org>.
simbit18 commented on code in PR #3143:
URL: https://github.com/apache/nuttx-apps/pull/3143#discussion_r2443388539
##########
graphics/jpgresizetool/CMakeLists.txt:
##########
@@ -20,14 +20,14 @@
#
# ##############################################################################
-if(CONFIG_NETUTILS_PLCATOOL)
+if(CONFIG_GRAPHICS_JPGRESIZETOOL)
nuttx_add_application(
NAME
- plcatool
+ jpgresize
STACKSIZE
- ${CONFIG_DEFAULT_TASK_STACKSIZE}
+ 4096
MODULE
- ${CONFIG_NETUTILS_PLCATOOL}
+ ${CONFIG_GRAPHICS_JPGRESIZETOOL}
SRCS
- plcatool.c)
-endif()
+ resize.c)
+endif()
Review Comment:
endif() -> press enter
https://github.com/apache/nuttx-apps/actions/runs/18632875759/job/53120040318?pr=3143#logs
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] graphics/jpgresizetool: Add libjpeg resize tool [nuttx-apps]
Posted by "simbit18 (via GitHub)" <gi...@apache.org>.
simbit18 commented on code in PR #3143:
URL: https://github.com/apache/nuttx-apps/pull/3143#discussion_r2236491358
##########
graphics/jpgresizetool/Make.defs:
##########
@@ -0,0 +1,3 @@
+ifneq ($(CONFIG_GRAPHICS_JPGRESIZETOOL),)
Review Comment:
@keever50 missing
```
############################################################################
# apps/graphics/jpgresizetool/Make.defs
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] graphics/jpgresizetool: Add libjpeg resize tool [nuttx-apps]
Posted by "simbit18 (via GitHub)" <gi...@apache.org>.
simbit18 commented on PR #3143:
URL: https://github.com/apache/nuttx-apps/pull/3143#issuecomment-3419778240
Hi @keever50 , could you add some basic documentation?
https://nuttx.apache.org/docs/latest/applications/graphics/index.html
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] graphics/jpgresizetool: Add libjpeg resize tool [nuttx-apps]
Posted by "keever50 (via GitHub)" <gi...@apache.org>.
keever50 commented on PR #3143:
URL: https://github.com/apache/nuttx-apps/pull/3143#issuecomment-3121865173
Also this tool allows a denom of 16, which is not possible. Should be removed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] graphics/jpgresizetool: Add libjpeg resize tool [nuttx-apps]
Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #3143:
URL: https://github.com/apache/nuttx-apps/pull/3143#discussion_r2443403064
##########
graphics/jpgresizetool/Kconfig:
##########
@@ -0,0 +1,10 @@
+#
+# For a description of the syntax of this configuration file,
+# see the file kconfig-language.txt in the NuttX tools repository.
+#
+
+config GRAPHICS_JPGRESIZETOOL
+ bool "JPGResizeTool"
+ default n
+ ---help---
+ Libjpeg JPEG resizer
Review Comment:
All indents in Kconfig need be tabs, not spaces
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] graphics/jpgresizetool: Add libjpeg resize tool [nuttx-apps]
Posted by "simbit18 (via GitHub)" <gi...@apache.org>.
simbit18 commented on PR #3143:
URL: https://github.com/apache/nuttx-apps/pull/3143#issuecomment-3419771889
> @simbit18 Hi, I'm not familiar with CMake in NuttX and I'm not sure how to get this to work with my current project, so I cannot test the addition of this. I hope it is okay to leave this out for now.
Hi, @keever50 add
```
# ##############################################################################
# apps/graphics/jpgresizetool/CMakeLists.txt
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
# license agreements. See the NOTICE file distributed with this work for
# additional information regarding copyright ownership. The ASF licenses this
# file to you under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
#
# ##############################################################################
if(CONFIG_GRAPHICS_JPGRESIZETOOL)
nuttx_add_application(
NAME
jpgresize
STACKSIZE
4096
MODULE
${CONFIG_GRAPHICS_JPGRESIZETOOL}
SRCS
resize.c)
endif()
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] graphics/jpgresizetool: Add libjpeg resize tool [nuttx-apps]
Posted by "keever50 (via GitHub)" <gi...@apache.org>.
keever50 commented on PR #3143:
URL: https://github.com/apache/nuttx-apps/pull/3143#issuecomment-3418383864
@simbit18 Hi, I'm not familiar with CMake in NuttX and I'm not sure how to get this to work with my current project, so I cannot test the addition of this. I hope it is okay to leave this out for now.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] graphics/jpgresizetool: Add libjpeg resize tool [nuttx-apps]
Posted by "keever50 (via GitHub)" <gi...@apache.org>.
keever50 commented on code in PR #3143:
URL: https://github.com/apache/nuttx-apps/pull/3143#discussion_r2233080562
##########
graphics/jpgresizetool/resize.c:
##########
@@ -0,0 +1,186 @@
+/****************************************************************************
+ * apps/graphics/jpgresizetool/resize.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <jpeglib.h>
+
+/****************************************************************************
+ * Definitions
+ ****************************************************************************/
+
+/* Every N line, report resizing progress */
+#define JPEGRESIZE_PROGRESS_INTERVAL 40
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/* Usage: jpgresize input.jpg output.jpg scale_denom quality%
+ * (scale_denom = 1, 2, 4, 8)
+ * thumbnail example: jpgresize /sd/PROC/100.jpg /sd/THUMBS/100.jpg 8 20
+ */
+
+int main(int argc, char *argv[])
+{
+ /* Take arguments */
+
+ if (argc != 5)
+ {
+ fprintf(stderr,
+ "Usage: %s input.jpg output.jpg scale_denom quality\n",
+ argv[0]);
+ return -1;
+ }
+
+ const char *input_filename = argv[1];
+ const char *output_filename = argv[2];
+ int scale_denom = atoi(argv[3]);
+ if (scale_denom != 1 && scale_denom != 2 && scale_denom != 4 &&
+ scale_denom != 8 && scale_denom != 16)
+ {
+ fprintf(stderr, "scale_denom must be 1, 2, 4, 8, or 16\n");
+ return -1;
+ }
+
+ int quality = atoi(argv[4]);
+
+ /* Opening input */
+
+ FILE *infile = fopen(input_filename, "rb");
+ if (!infile)
+ {
+ perror("fopen input");
+ return -1;
+ }
+
+ /* Configuring decompressor */
+
+ struct jpeg_decompress_struct cinfo;
+ struct jpeg_error_mgr jerr;
+ cinfo.err = jpeg_std_error(&jerr);
+ jpeg_create_decompress(&cinfo);
+ jpeg_stdio_src(&cinfo, infile);
+ jpeg_read_header(&cinfo, TRUE);
+
+ cinfo.scale_num = 1;
+ cinfo.scale_denom = scale_denom;
+ jpeg_start_decompress(&cinfo);
+
+ int width = cinfo.output_width;
+ int height = cinfo.output_height;
+ int pixel_size = cinfo.output_components;
+
+ /* Opening output */
+
+ FILE *outfile = fopen(output_filename, "wb");
+ if (!outfile)
+ {
+ perror("fopen output");
+ jpeg_destroy_decompress(&cinfo);
+ fclose(infile);
+ return -1;
+ }
+
+ /* Configuring compressor */
+
+ struct jpeg_compress_struct cinfo_out;
+ struct jpeg_error_mgr jerr_out;
+ cinfo_out.err = jpeg_std_error(&jerr_out);
+ jpeg_create_compress(&cinfo_out);
+ jpeg_stdio_dest(&cinfo_out, outfile);
+
+ cinfo_out.image_width = width;
+ cinfo_out.image_height = height;
+ cinfo_out.input_components = pixel_size;
+ cinfo_out.in_color_space = cinfo.out_color_space;
+ jpeg_set_defaults(&cinfo_out);
+ jpeg_set_quality(&cinfo_out, quality, TRUE);
+ jpeg_start_compress(&cinfo_out, TRUE);
+
+ /* Allocating memory by using JPEG their own allocator. Do not use malloc */
+
+ printf("Allocating... \r");
+ JSAMPARRAY buffer = (*cinfo.mem->alloc_sarray)
+ ((j_common_ptr)&cinfo, JPOOL_IMAGE, width * pixel_size, 1);
+
+ /* Start the job */
+
+ printf("Resizing... \n\r");
+ uint8_t togglechar = 0;
+ while (cinfo.output_scanline < cinfo.output_height)
+ {
+ /* Pretty loading bar... */
+
+ if (cinfo.output_scanline % JPEGRESIZE_PROGRESS_INTERVAL == 1)
+ {
+ printf("\r[%u%%]",
+ (unsigned)(((float)cinfo.output_scanline
+ / cinfo.output_height)
+ * 100));
+ togglechar = !togglechar;
+ }
+
+ if (togglechar)
+ {
+ printf("-");
+ }
+ else
+ {
+ printf("#");
+ }
+
+ fflush(stdout);
+
+ /* Actual work */
+
+ jpeg_read_scanlines(&cinfo, buffer, 1);
+ jpeg_write_scanlines(&cinfo_out, buffer, 1);
+ }
+
+ /* Erase progress bar */
+
+ printf("\r ");
+ for (size_t i = 0; i < JPEGRESIZE_PROGRESS_INTERVAL; i++)
+ {
+ printf(" ");
+ }
+
+ /* All done */
+
+ printf("\rDone\n\r");
Review Comment:
The single '\r' is intended in some parts of the code.
However, I can probably replace `\n\r` to `\n`. But keep single `\r` as is.
This is so we can reuse the same line to progress the loading bar instead of spawning a new loading bar on every new line. Your entire terminal would be filled up with loading bars otherwise.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] graphics/jpgresizetool: Add libjpeg resize tool [nuttx-apps]
Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 merged PR #3143:
URL: https://github.com/apache/nuttx-apps/pull/3143
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] graphics/jpgresizetool: Add libjpeg resize tool [nuttx-apps]
Posted by "linguini1 (via GitHub)" <gi...@apache.org>.
linguini1 commented on PR #3143:
URL: https://github.com/apache/nuttx-apps/pull/3143#issuecomment-3402962084
> Ill get back to this later this week if the tweaks are still required!
That would be great!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] graphics/jpgresizetool: Add libjpeg resize tool [nuttx-apps]
Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #3143:
URL: https://github.com/apache/nuttx-apps/pull/3143#discussion_r2233073162
##########
graphics/jpgresizetool/resize.c:
##########
@@ -0,0 +1,186 @@
+/****************************************************************************
+ * apps/graphics/jpgresizetool/resize.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <jpeglib.h>
+
+/****************************************************************************
+ * Definitions
+ ****************************************************************************/
+
+/* Every N line, report resizing progress */
+#define JPEGRESIZE_PROGRESS_INTERVAL 40
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/* Usage: jpgresize input.jpg output.jpg scale_denom quality%
+ * (scale_denom = 1, 2, 4, 8)
+ * thumbnail example: jpgresize /sd/PROC/100.jpg /sd/THUMBS/100.jpg 8 20
+ */
+
+int main(int argc, char *argv[])
+{
+ /* Take arguments */
+
+ if (argc != 5)
+ {
+ fprintf(stderr,
+ "Usage: %s input.jpg output.jpg scale_denom quality\n",
+ argv[0]);
+ return -1;
+ }
+
+ const char *input_filename = argv[1];
+ const char *output_filename = argv[2];
+ int scale_denom = atoi(argv[3]);
+ if (scale_denom != 1 && scale_denom != 2 && scale_denom != 4 &&
+ scale_denom != 8 && scale_denom != 16)
+ {
+ fprintf(stderr, "scale_denom must be 1, 2, 4, 8, or 16\n");
+ return -1;
+ }
+
+ int quality = atoi(argv[4]);
+
+ /* Opening input */
+
+ FILE *infile = fopen(input_filename, "rb");
+ if (!infile)
+ {
+ perror("fopen input");
+ return -1;
+ }
+
+ /* Configuring decompressor */
+
+ struct jpeg_decompress_struct cinfo;
+ struct jpeg_error_mgr jerr;
+ cinfo.err = jpeg_std_error(&jerr);
+ jpeg_create_decompress(&cinfo);
+ jpeg_stdio_src(&cinfo, infile);
+ jpeg_read_header(&cinfo, TRUE);
+
+ cinfo.scale_num = 1;
+ cinfo.scale_denom = scale_denom;
+ jpeg_start_decompress(&cinfo);
+
+ int width = cinfo.output_width;
+ int height = cinfo.output_height;
+ int pixel_size = cinfo.output_components;
+
+ /* Opening output */
+
+ FILE *outfile = fopen(output_filename, "wb");
+ if (!outfile)
+ {
+ perror("fopen output");
+ jpeg_destroy_decompress(&cinfo);
+ fclose(infile);
+ return -1;
+ }
+
+ /* Configuring compressor */
+
+ struct jpeg_compress_struct cinfo_out;
+ struct jpeg_error_mgr jerr_out;
+ cinfo_out.err = jpeg_std_error(&jerr_out);
+ jpeg_create_compress(&cinfo_out);
+ jpeg_stdio_dest(&cinfo_out, outfile);
+
+ cinfo_out.image_width = width;
+ cinfo_out.image_height = height;
+ cinfo_out.input_components = pixel_size;
+ cinfo_out.in_color_space = cinfo.out_color_space;
+ jpeg_set_defaults(&cinfo_out);
+ jpeg_set_quality(&cinfo_out, quality, TRUE);
+ jpeg_start_compress(&cinfo_out, TRUE);
+
+ /* Allocating memory by using JPEG their own allocator. Do not use malloc */
+
+ printf("Allocating... \r");
+ JSAMPARRAY buffer = (*cinfo.mem->alloc_sarray)
+ ((j_common_ptr)&cinfo, JPOOL_IMAGE, width * pixel_size, 1);
+
+ /* Start the job */
+
+ printf("Resizing... \n\r");
+ uint8_t togglechar = 0;
+ while (cinfo.output_scanline < cinfo.output_height)
+ {
+ /* Pretty loading bar... */
+
+ if (cinfo.output_scanline % JPEGRESIZE_PROGRESS_INTERVAL == 1)
+ {
+ printf("\r[%u%%]",
+ (unsigned)(((float)cinfo.output_scanline
+ / cinfo.output_height)
+ * 100));
+ togglechar = !togglechar;
+ }
+
+ if (togglechar)
+ {
+ printf("-");
+ }
+ else
+ {
+ printf("#");
+ }
+
+ fflush(stdout);
+
+ /* Actual work */
+
+ jpeg_read_scanlines(&cinfo, buffer, 1);
+ jpeg_write_scanlines(&cinfo_out, buffer, 1);
+ }
+
+ /* Erase progress bar */
+
+ printf("\r ");
+ for (size_t i = 0; i < JPEGRESIZE_PROGRESS_INTERVAL; i++)
+ {
+ printf(" ");
+ }
+
+ /* All done */
+
+ printf("\rDone\n\r");
Review Comment:
serial driver already do the conversion for you:
https://github.com/apache/nuttx/blob/master/drivers/serial/serial.c#L417-L433
you don't do it again in the code manually.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] graphics/jpgresizetool: Add libjpeg resize tool [nuttx-apps]
Posted by "keever50 (via GitHub)" <gi...@apache.org>.
keever50 commented on code in PR #3143:
URL: https://github.com/apache/nuttx-apps/pull/3143#discussion_r2232950470
##########
graphics/jpgresizetool/resize.c:
##########
@@ -0,0 +1,186 @@
+/****************************************************************************
+ * apps/graphics/jpgresizetool/resize.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <jpeglib.h>
+
+/****************************************************************************
+ * Definitions
+ ****************************************************************************/
+
+/* Every N line, report resizing progress */
+#define JPEGRESIZE_PROGRESS_INTERVAL 40
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/* Usage: jpgresize input.jpg output.jpg scale_denom quality%
+ * (scale_denom = 1, 2, 4, 8)
+ * thumbnail example: jpgresize /sd/PROC/100.jpg /sd/THUMBS/100.jpg 8 20
+ */
+
+int main(int argc, char *argv[])
+{
+ /* Take arguments */
+
+ if (argc != 5)
+ {
+ fprintf(stderr,
+ "Usage: %s input.jpg output.jpg scale_denom quality\n",
+ argv[0]);
+ return -1;
+ }
+
+ const char *input_filename = argv[1];
+ const char *output_filename = argv[2];
+ int scale_denom = atoi(argv[3]);
+ if (scale_denom != 1 && scale_denom != 2 && scale_denom != 4 &&
+ scale_denom != 8 && scale_denom != 16)
+ {
+ fprintf(stderr, "scale_denom must be 1, 2, 4, 8, or 16\n");
+ return -1;
+ }
+
+ int quality = atoi(argv[4]);
+
+ /* Opening input */
+
+ FILE *infile = fopen(input_filename, "rb");
+ if (!infile)
+ {
+ perror("fopen input");
+ return -1;
+ }
+
+ /* Configuring decompressor */
+
+ struct jpeg_decompress_struct cinfo;
+ struct jpeg_error_mgr jerr;
+ cinfo.err = jpeg_std_error(&jerr);
+ jpeg_create_decompress(&cinfo);
+ jpeg_stdio_src(&cinfo, infile);
+ jpeg_read_header(&cinfo, TRUE);
+
+ cinfo.scale_num = 1;
+ cinfo.scale_denom = scale_denom;
+ jpeg_start_decompress(&cinfo);
+
+ int width = cinfo.output_width;
+ int height = cinfo.output_height;
+ int pixel_size = cinfo.output_components;
+
+ /* Opening output */
+
+ FILE *outfile = fopen(output_filename, "wb");
+ if (!outfile)
+ {
+ perror("fopen output");
+ jpeg_destroy_decompress(&cinfo);
+ fclose(infile);
+ return -1;
+ }
+
+ /* Configuring compressor */
+
+ struct jpeg_compress_struct cinfo_out;
+ struct jpeg_error_mgr jerr_out;
+ cinfo_out.err = jpeg_std_error(&jerr_out);
+ jpeg_create_compress(&cinfo_out);
+ jpeg_stdio_dest(&cinfo_out, outfile);
+
+ cinfo_out.image_width = width;
+ cinfo_out.image_height = height;
+ cinfo_out.input_components = pixel_size;
+ cinfo_out.in_color_space = cinfo.out_color_space;
+ jpeg_set_defaults(&cinfo_out);
+ jpeg_set_quality(&cinfo_out, quality, TRUE);
+ jpeg_start_compress(&cinfo_out, TRUE);
+
+ /* Allocating memory by using JPEG their own allocator. Do not use malloc */
+
+ printf("Allocating... \r");
+ JSAMPARRAY buffer = (*cinfo.mem->alloc_sarray)
+ ((j_common_ptr)&cinfo, JPOOL_IMAGE, width * pixel_size, 1);
+
+ /* Start the job */
+
+ printf("Resizing... \n\r");
+ uint8_t togglechar = 0;
+ while (cinfo.output_scanline < cinfo.output_height)
+ {
+ /* Pretty loading bar... */
+
+ if (cinfo.output_scanline % JPEGRESIZE_PROGRESS_INTERVAL == 1)
+ {
+ printf("\r[%u%%]",
+ (unsigned)(((float)cinfo.output_scanline
+ / cinfo.output_height)
+ * 100));
+ togglechar = !togglechar;
+ }
+
+ if (togglechar)
+ {
+ printf("-");
+ }
+ else
+ {
+ printf("#");
+ }
+
+ fflush(stdout);
+
+ /* Actual work */
+
+ jpeg_read_scanlines(&cinfo, buffer, 1);
+ jpeg_write_scanlines(&cinfo_out, buffer, 1);
+ }
+
+ /* Erase progress bar */
+
+ printf("\r ");
+ for (size_t i = 0; i < JPEGRESIZE_PROGRESS_INTERVAL; i++)
+ {
+ printf(" ");
+ }
+
+ /* All done */
+
+ printf("\rDone\n\r");
Review Comment:
Thanks, why do I need to remove \r? This makes printing behave very differently. I want the cursor to return to the beginning of the line.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] graphics/jpgresizetool: Add libjpeg resize tool [nuttx-apps]
Posted by "keever50 (via GitHub)" <gi...@apache.org>.
keever50 commented on PR #3143:
URL: https://github.com/apache/nuttx-apps/pull/3143#issuecomment-3402872527
Ill get back to this later this week if the tweaks are still required!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] graphics/jpgresizetool: Add libjpeg resize tool [nuttx-apps]
Posted by "keever50 (via GitHub)" <gi...@apache.org>.
keever50 commented on PR #3143:
URL: https://github.com/apache/nuttx-apps/pull/3143#issuecomment-3419774450
> > @simbit18 Hi, I'm not familiar with CMake in NuttX and I'm not sure how to get this to work with my current project, so I cannot test the addition of this. I hope it is okay to leave this out for now.
>
> Hi @keever50, add
>
> ```
> # ##############################################################################
> # apps/graphics/jpgresizetool/CMakeLists.txt
> #
> # SPDX-License-Identifier: Apache-2.0
> #
> # Licensed to the Apache Software Foundation (ASF) under one or more contributor
> # license agreements. See the NOTICE file distributed with this work for
> # additional information regarding copyright ownership. The ASF licenses this
> # file to you under the Apache License, Version 2.0 (the "License"); you may not
> # use this file except in compliance with the License. You may obtain a copy of
> # the License at
> #
> # http://www.apache.org/licenses/LICENSE-2.0
> #
> # Unless required by applicable law or agreed to in writing, software
> # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
> # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
> # License for the specific language governing permissions and limitations under
> # the License.
> #
> # ##############################################################################
>
> if(CONFIG_GRAPHICS_JPGRESIZETOOL)
> nuttx_add_application(
> NAME
> jpgresize
> STACKSIZE
> 4096
> MODULE
> ${CONFIG_GRAPHICS_JPGRESIZETOOL}
> SRCS
> resize.c)
> endif()
> ```
Thanks, done!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] graphics/jpgresizetool: Add libjpeg resize tool [nuttx-apps]
Posted by "keever50 (via GitHub)" <gi...@apache.org>.
keever50 commented on code in PR #3143:
URL: https://github.com/apache/nuttx-apps/pull/3143#discussion_r2443423504
##########
graphics/jpgresizetool/Kconfig:
##########
@@ -0,0 +1,10 @@
+#
+# For a description of the syntax of this configuration file,
+# see the file kconfig-language.txt in the NuttX tools repository.
+#
+
+config GRAPHICS_JPGRESIZETOOL
+ bool "JPGResizeTool"
+ default n
+ ---help---
+ Libjpeg JPEG resizer
Review Comment:
Interesting. Something is happening that turns them into spaces. I have changed them to tabs. Ill look into this
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] graphics/jpgresizetool: Add libjpeg resize tool [nuttx-apps]
Posted by "simbit18 (via GitHub)" <gi...@apache.org>.
simbit18 commented on code in PR #3143:
URL: https://github.com/apache/nuttx-apps/pull/3143#discussion_r2443388539
##########
graphics/jpgresizetool/CMakeLists.txt:
##########
@@ -20,14 +20,14 @@
#
# ##############################################################################
-if(CONFIG_NETUTILS_PLCATOOL)
+if(CONFIG_GRAPHICS_JPGRESIZETOOL)
nuttx_add_application(
NAME
- plcatool
+ jpgresize
STACKSIZE
- ${CONFIG_DEFAULT_TASK_STACKSIZE}
+ 4096
MODULE
- ${CONFIG_NETUTILS_PLCATOOL}
+ ${CONFIG_GRAPHICS_JPGRESIZETOOL}
SRCS
- plcatool.c)
-endif()
+ resize.c)
+endif()
Review Comment:
endif() -> press enter
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] graphics/jpgresizetool: Add libjpeg resize tool [nuttx-apps]
Posted by "raiden00pl (via GitHub)" <gi...@apache.org>.
raiden00pl commented on code in PR #3143:
URL: https://github.com/apache/nuttx-apps/pull/3143#discussion_r2447672243
##########
graphics/jpgresizetool/Kconfig:
##########
@@ -0,0 +1,10 @@
+#
+# For a description of the syntax of this configuration file,
+# see the file kconfig-language.txt in the NuttX tools repository.
+#
+
+config GRAPHICS_JPGRESIZETOOL
+ bool "JPGResizeTool"
+ default n
+ ---help---
+ Libjpeg JPEG resizer
Review Comment:
It's possible that your IDE or coding style tool is converting TAB to spaces, which is quite a common feature that doesn't work well with Kconfig files :)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] graphics/jpgresizetool: Add libjpeg resize tool [nuttx-apps]
Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #3143:
URL: https://github.com/apache/nuttx-apps/pull/3143#discussion_r2232914642
##########
graphics/jpgresizetool/Kconfig:
##########
@@ -0,0 +1,10 @@
+#
+# For a description of the syntax of this configuration file,
+# see the file kconfig-language.txt in the NuttX tools repository.
+#
+
+config GRAPHICS_JPGRESIZETOOL
+ bool "JPGResizeTool"
Review Comment:
add depends on libjpeg
##########
graphics/jpgresizetool/Kconfig:
##########
@@ -0,0 +1,10 @@
+#
+# For a description of the syntax of this configuration file,
+# see the file kconfig-language.txt in the NuttX tools repository.
+#
+
+config GRAPHICS_JPGRESIZETOOL
+ bool "JPGResizeTool"
+ default n
+ ---help---
+ Libjpeg JPEG resizer
Review Comment:
use tab
##########
graphics/jpgresizetool/resize.c:
##########
@@ -0,0 +1,186 @@
+/****************************************************************************
+ * apps/graphics/jpgresizetool/resize.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <jpeglib.h>
+
+/****************************************************************************
+ * Definitions
+ ****************************************************************************/
+
+/* Every N line, report resizing progress */
+#define JPEGRESIZE_PROGRESS_INTERVAL 40
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/* Usage: jpgresize input.jpg output.jpg scale_denom quality%
+ * (scale_denom = 1, 2, 4, 8)
+ * thumbnail example: jpgresize /sd/PROC/100.jpg /sd/THUMBS/100.jpg 8 20
+ */
+
+int main(int argc, char *argv[])
+{
+ /* Take arguments */
+
+ if (argc != 5)
+ {
+ fprintf(stderr,
+ "Usage: %s input.jpg output.jpg scale_denom quality\n",
+ argv[0]);
+ return -1;
+ }
+
+ const char *input_filename = argv[1];
+ const char *output_filename = argv[2];
+ int scale_denom = atoi(argv[3]);
+ if (scale_denom != 1 && scale_denom != 2 && scale_denom != 4 &&
+ scale_denom != 8 && scale_denom != 16)
+ {
+ fprintf(stderr, "scale_denom must be 1, 2, 4, 8, or 16\n");
+ return -1;
+ }
+
+ int quality = atoi(argv[4]);
+
+ /* Opening input */
+
+ FILE *infile = fopen(input_filename, "rb");
+ if (!infile)
+ {
+ perror("fopen input");
+ return -1;
+ }
+
+ /* Configuring decompressor */
+
+ struct jpeg_decompress_struct cinfo;
Review Comment:
need move all variables definition to the begin of function to confirm to c89 spec.
##########
graphics/jpgresizetool/resize.c:
##########
@@ -0,0 +1,186 @@
+/****************************************************************************
+ * apps/graphics/jpgresizetool/resize.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <jpeglib.h>
+
+/****************************************************************************
+ * Definitions
+ ****************************************************************************/
+
+/* Every N line, report resizing progress */
+#define JPEGRESIZE_PROGRESS_INTERVAL 40
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/* Usage: jpgresize input.jpg output.jpg scale_denom quality%
+ * (scale_denom = 1, 2, 4, 8)
+ * thumbnail example: jpgresize /sd/PROC/100.jpg /sd/THUMBS/100.jpg 8 20
+ */
+
+int main(int argc, char *argv[])
+{
+ /* Take arguments */
+
+ if (argc != 5)
+ {
+ fprintf(stderr,
+ "Usage: %s input.jpg output.jpg scale_denom quality\n",
+ argv[0]);
+ return -1;
+ }
+
+ const char *input_filename = argv[1];
+ const char *output_filename = argv[2];
+ int scale_denom = atoi(argv[3]);
+ if (scale_denom != 1 && scale_denom != 2 && scale_denom != 4 &&
+ scale_denom != 8 && scale_denom != 16)
+ {
+ fprintf(stderr, "scale_denom must be 1, 2, 4, 8, or 16\n");
+ return -1;
+ }
+
+ int quality = atoi(argv[4]);
+
+ /* Opening input */
+
+ FILE *infile = fopen(input_filename, "rb");
+ if (!infile)
+ {
+ perror("fopen input");
+ return -1;
+ }
+
+ /* Configuring decompressor */
+
+ struct jpeg_decompress_struct cinfo;
+ struct jpeg_error_mgr jerr;
+ cinfo.err = jpeg_std_error(&jerr);
+ jpeg_create_decompress(&cinfo);
+ jpeg_stdio_src(&cinfo, infile);
+ jpeg_read_header(&cinfo, TRUE);
+
+ cinfo.scale_num = 1;
+ cinfo.scale_denom = scale_denom;
+ jpeg_start_decompress(&cinfo);
+
+ int width = cinfo.output_width;
+ int height = cinfo.output_height;
+ int pixel_size = cinfo.output_components;
+
+ /* Opening output */
+
+ FILE *outfile = fopen(output_filename, "wb");
+ if (!outfile)
+ {
+ perror("fopen output");
+ jpeg_destroy_decompress(&cinfo);
+ fclose(infile);
+ return -1;
+ }
+
+ /* Configuring compressor */
+
+ struct jpeg_compress_struct cinfo_out;
+ struct jpeg_error_mgr jerr_out;
+ cinfo_out.err = jpeg_std_error(&jerr_out);
+ jpeg_create_compress(&cinfo_out);
+ jpeg_stdio_dest(&cinfo_out, outfile);
+
+ cinfo_out.image_width = width;
+ cinfo_out.image_height = height;
+ cinfo_out.input_components = pixel_size;
+ cinfo_out.in_color_space = cinfo.out_color_space;
+ jpeg_set_defaults(&cinfo_out);
+ jpeg_set_quality(&cinfo_out, quality, TRUE);
+ jpeg_start_compress(&cinfo_out, TRUE);
+
+ /* Allocating memory by using JPEG their own allocator. Do not use malloc */
+
+ printf("Allocating... \r");
+ JSAMPARRAY buffer = (*cinfo.mem->alloc_sarray)
+ ((j_common_ptr)&cinfo, JPOOL_IMAGE, width * pixel_size, 1);
+
+ /* Start the job */
+
+ printf("Resizing... \n\r");
+ uint8_t togglechar = 0;
+ while (cinfo.output_scanline < cinfo.output_height)
+ {
+ /* Pretty loading bar... */
+
+ if (cinfo.output_scanline % JPEGRESIZE_PROGRESS_INTERVAL == 1)
+ {
+ printf("\r[%u%%]",
+ (unsigned)(((float)cinfo.output_scanline
+ / cinfo.output_height)
+ * 100));
+ togglechar = !togglechar;
+ }
+
+ if (togglechar)
+ {
+ printf("-");
+ }
+ else
+ {
+ printf("#");
+ }
+
+ fflush(stdout);
+
+ /* Actual work */
+
+ jpeg_read_scanlines(&cinfo, buffer, 1);
+ jpeg_write_scanlines(&cinfo_out, buffer, 1);
+ }
+
+ /* Erase progress bar */
+
+ printf("\r ");
+ for (size_t i = 0; i < JPEGRESIZE_PROGRESS_INTERVAL; i++)
+ {
+ printf(" ");
+ }
+
+ /* All done */
+
+ printf("\rDone\n\r");
Review Comment:
remove `\r` from all code
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] graphics/jpgresizetool: Add libjpeg resize tool [nuttx-apps]
Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #3143:
URL: https://github.com/apache/nuttx-apps/pull/3143#discussion_r2233889448
##########
graphics/jpgresizetool/resize.c:
##########
@@ -0,0 +1,186 @@
+/****************************************************************************
+ * apps/graphics/jpgresizetool/resize.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <jpeglib.h>
+
+/****************************************************************************
+ * Definitions
+ ****************************************************************************/
+
+/* Every N line, report resizing progress */
+#define JPEGRESIZE_PROGRESS_INTERVAL 40
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/* Usage: jpgresize input.jpg output.jpg scale_denom quality%
+ * (scale_denom = 1, 2, 4, 8)
+ * thumbnail example: jpgresize /sd/PROC/100.jpg /sd/THUMBS/100.jpg 8 20
+ */
+
+int main(int argc, char *argv[])
+{
+ /* Take arguments */
+
+ if (argc != 5)
+ {
+ fprintf(stderr,
+ "Usage: %s input.jpg output.jpg scale_denom quality\n",
+ argv[0]);
+ return -1;
+ }
+
+ const char *input_filename = argv[1];
+ const char *output_filename = argv[2];
+ int scale_denom = atoi(argv[3]);
+ if (scale_denom != 1 && scale_denom != 2 && scale_denom != 4 &&
+ scale_denom != 8 && scale_denom != 16)
+ {
+ fprintf(stderr, "scale_denom must be 1, 2, 4, 8, or 16\n");
+ return -1;
+ }
+
+ int quality = atoi(argv[4]);
+
+ /* Opening input */
+
+ FILE *infile = fopen(input_filename, "rb");
+ if (!infile)
+ {
+ perror("fopen input");
+ return -1;
+ }
+
+ /* Configuring decompressor */
+
+ struct jpeg_decompress_struct cinfo;
+ struct jpeg_error_mgr jerr;
+ cinfo.err = jpeg_std_error(&jerr);
+ jpeg_create_decompress(&cinfo);
+ jpeg_stdio_src(&cinfo, infile);
+ jpeg_read_header(&cinfo, TRUE);
+
+ cinfo.scale_num = 1;
+ cinfo.scale_denom = scale_denom;
+ jpeg_start_decompress(&cinfo);
+
+ int width = cinfo.output_width;
+ int height = cinfo.output_height;
+ int pixel_size = cinfo.output_components;
+
+ /* Opening output */
+
+ FILE *outfile = fopen(output_filename, "wb");
+ if (!outfile)
+ {
+ perror("fopen output");
+ jpeg_destroy_decompress(&cinfo);
+ fclose(infile);
+ return -1;
+ }
+
+ /* Configuring compressor */
+
+ struct jpeg_compress_struct cinfo_out;
+ struct jpeg_error_mgr jerr_out;
+ cinfo_out.err = jpeg_std_error(&jerr_out);
+ jpeg_create_compress(&cinfo_out);
+ jpeg_stdio_dest(&cinfo_out, outfile);
+
+ cinfo_out.image_width = width;
+ cinfo_out.image_height = height;
+ cinfo_out.input_components = pixel_size;
+ cinfo_out.in_color_space = cinfo.out_color_space;
+ jpeg_set_defaults(&cinfo_out);
+ jpeg_set_quality(&cinfo_out, quality, TRUE);
+ jpeg_start_compress(&cinfo_out, TRUE);
+
+ /* Allocating memory by using JPEG their own allocator. Do not use malloc */
+
+ printf("Allocating... \r");
+ JSAMPARRAY buffer = (*cinfo.mem->alloc_sarray)
+ ((j_common_ptr)&cinfo, JPOOL_IMAGE, width * pixel_size, 1);
+
+ /* Start the job */
+
+ printf("Resizing... \n\r");
+ uint8_t togglechar = 0;
+ while (cinfo.output_scanline < cinfo.output_height)
+ {
+ /* Pretty loading bar... */
+
+ if (cinfo.output_scanline % JPEGRESIZE_PROGRESS_INTERVAL == 1)
+ {
+ printf("\r[%u%%]",
+ (unsigned)(((float)cinfo.output_scanline
+ / cinfo.output_height)
+ * 100));
+ togglechar = !togglechar;
+ }
+
+ if (togglechar)
+ {
+ printf("-");
+ }
+ else
+ {
+ printf("#");
+ }
+
+ fflush(stdout);
+
+ /* Actual work */
+
+ jpeg_read_scanlines(&cinfo, buffer, 1);
+ jpeg_write_scanlines(&cinfo_out, buffer, 1);
+ }
+
+ /* Erase progress bar */
+
+ printf("\r ");
+ for (size_t i = 0; i < JPEGRESIZE_PROGRESS_INTERVAL; i++)
+ {
+ printf(" ");
+ }
+
+ /* All done */
+
+ printf("\rDone\n\r");
Review Comment:
Ok
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] graphics/jpgresizetool: Add libjpeg resize tool [nuttx-apps]
Posted by "simbit18 (via GitHub)" <gi...@apache.org>.
simbit18 commented on PR #3143:
URL: https://github.com/apache/nuttx-apps/pull/3143#issuecomment-3402992573
Hi @keever50 , Please add build with CMake
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org