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 114793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:55:01+00:00 2026-05-11T02:55:01+00:00

I’m on Ubuntu Intrepid and I’m using jpeglib62 6b-14. I was working on some

  • 0

I’m on Ubuntu Intrepid and I’m using jpeglib62 6b-14. I was working on some code, which only gave a black screen with some garbled output at the top when I tried to run it. After a few hours of debugging I got it down to pretty much the JPEG base, so I took the example code, wrote a little piece of code around it and the output was exactly the same.

I’m convinced jpeglib is used in a lot more places on this system and it’s simply the version from the repositories so I’m hesitant to say that this is a bug in jpeglib or the Ubuntu packaging.

I put the example code below (most comments stripped). The input JPEG file is an uncompressed 640×480 file with 3 channels, so it should be 921600 bytes (and it is). The output image is JFIF and around 9000 bytes.

If you could help me with even a hint, I’d be very grateful.

Thanks!

#include <stdio.h> #include <stdlib.h> #include 'jpeglib.h' #include <setjmp.h>  int main () {   // read data   FILE *input = fopen('input.jpg', 'rb');   JSAMPLE *image_buffer = (JSAMPLE*) malloc(sizeof(JSAMPLE) * 640 * 480 * 3);   if(input == NULL or image_buffer == NULL)     exit(1);   fread(image_buffer, 640 * 3, 480, input);    // initialise jpeg library   struct jpeg_compress_struct cinfo;   struct jpeg_error_mgr jerr;   cinfo.err = jpeg_std_error(&jerr);   jpeg_create_compress(&cinfo);    // write to foo.jpg   FILE *outfile = fopen('foo.jpg', 'wb');   if (outfile == NULL)     exit(1);   jpeg_stdio_dest(&cinfo, outfile);    // setup library   cinfo.image_width = 640;   cinfo.image_height = 480;   cinfo.input_components = 3; // 3 components (R, G, B)   cinfo.in_color_space = JCS_RGB; // RGB   jpeg_set_defaults(&cinfo); // set defaults    // start compressing   int row_stride = 640 * 3; // number of characters in a row   JSAMPROW row_pointer[1]; // pointer to the current row data   jpeg_start_compress(&cinfo, TRUE); // start compressing to jpeg    while (cinfo.next_scanline < cinfo.image_height) {     row_pointer[0] = & image_buffer[cinfo.next_scanline * row_stride];     (void) jpeg_write_scanlines(&cinfo, row_pointer, 1);   }    jpeg_finish_compress(&cinfo);    // clean up   fclose(outfile);   jpeg_destroy_compress(&cinfo); } 
  • 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. 2026-05-11T02:55:02+00:00Added an answer on May 11, 2026 at 2:55 am

    You’re reading a JPEG file into memory (without decompressing it) and writing out that buffer as if it were uncompressed, that’s why you’re getting garbage. You need to decompress the image first before you can feed it into the JPEG compressor.

    In other words, the JPEG compressor assumes that its input is raw pixels.

    You can convert your input image into raw RGB using ImageMagick:

    convert input.jpg rgb:input.raw 

    It should be exactly 921600 bytes in size.

    EDIT: Your question is misleading when you state that your input JPEG file in uncompressed. Anyway, I compiled your code and it works fine, compresses the image correctly. If you can upload the file you’re using as input, it might be possible to debug further. If not, I suggest you test your program using an image created from a known JPEG using ImageMagick:

    convert some_image_that_is_really_a_jpg.jpg -resize 640x480! rgb:input.jpg 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the SimpleRSS gem to parse a WordPress RSS feed. The only
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I am using JSon response to parse title,date content and thumbnail images and place
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have this code to decode numeric html entities to the UTF8 equivalent character.
I want use html5's new tag to play a wav file (currently only supported

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.