Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8629609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:51:05+00:00 2026-06-12T08:51:05+00:00

I have the next standard code for JPEG image decompression which is based on

  • 0

I have the next standard code for JPEG image decompression which is based on libjpeg.

jpeg_decompress_struct cinfo;
// ...Set error manager and data source...
jpeg_read_header(&cinfo, TRUE);
jpeg_start_decompress(&cinfo);
while (cinfo.output_scanline < cinfo.output_height) {
    JSAMPLE* scanlines[1];
    // ...Set target pointer for scanline...
    jpeg_read_scanlines(&cinfo, scanlines, 1);
}
jpeg_destroy_decompress(&cinfo);

I want to read a part of the image, cropped by a rectangle:

// struct RECT {
//     int left;
//     int top;
//     int right;
//     int bottom;
// };
RECT cropRect; // Coordinates of the crop rectangle relative to the output image size

What should I modify in the code below to tell libjpeg to crop the image immediately?

This is how I can implement it:

  1. Ignore first top - 1 lines;
  2. For each of the next bottom - top lines:
    1) Read scanline to temporary buffer;
    2) Copy pixels from column range [left, right) from temporary buffer to the target buffer.
  3. Abort the decompression.

But this code is redundant.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T08:51:06+00:00Added an answer on June 12, 2026 at 8:51 am

    Performance-wise, especially if the original image is high resolution and you need a relatively small part of it, you should perhaps first crop/trim the image losslessly without decompressing it, which is possible at 16×16 px (8×8?) granularity and fast, and then decompress skipping just a few lines and pixels off the margins. You might also like this approach for smaller amount of memory in use for the operation.

    If you are cropping just a bit, then the original plan to start decompressing in full is perhaps the best. There is almost no redundancy here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want the next and prev buttons to have two uses. First: the standard
I have next code, <form id=form1 runat=server> <asp:Label runat=server ID=Label1 EnableViewState=false /> <asp:CheckBox runat=server
I have next interface public interface IMyInterface { string this[string key] { get; set;
I have next 2 blocks of code: def replace_re(text): start = time.time() new_text =
I have next code: int main() { OwnSelect(23, FD_READ | FD_WRITE); // <---- Several
I have next code require 'rack/rpc' class Server < Rack::RPC::Server def hello_world Hello, world!
I'm using the standard Apple moviePlayer sample code and have customized it to play
I have the following code. #include <set> #include <algorithm> using namespace std; int _tmain(int
I have a standard grid filled with a collection, which is filterable. I would
I have a standard code that prints all charts in your active sheet to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.