Like Tree17Likes

How to use loadJPG function from library jpeg?

This is a discussion on How to use loadJPG function from library jpeg? within the C Programming forums, part of the General Programming Boards category; the histogram part weve done twice before. first time, it simply counted how many of each number (from 0-19) appeared ...

  1. #31
    Normander the Barbarian TheReceptionist's Avatar
    Join Date
    Jul 2011
    Location
    Gainesville,FL
    Posts
    24
    the histogram part weve done twice before.

    first time, it simply counted how many of each number (from 0-19) appeared in a list. the max number of entries was specified by the user.

    second time we made "bins" for the numbers: if the number of bins entered was 4, then each bin would contain 5 numbers (since were counting number 0-19 only). if the number of bins was 2, then bin[0]=0-9 and bin[1]=10-19.

    so the histogram in this part will be the same except read it from an input file. we would write a function with a pointer that points to the data in another file, and write a loop to count the values of each into the proper bins.

    the confusion comes in using the .o/.h files and the function. how do we have to compile main for this to work?

    in the main prog(int main) we call the function to decompose the jpg. we call the function
    loadJPG("C:\\mystuff\\low.jpeg", "C:\\other\\high.xxx");

    that part makes sense.

    hope this is a little clearer! thanks for any help ^_^

  2. #32
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    Quote Originally Posted by TheReceptionist View Post
    the confusion comes in using the .o/.h files and the function. how do we have to compile main for this to work?

    in the main prog(int main) we call the function to decompose the jpg. we call the function
    loadJPG("C:\\mystuff\\low.jpeg", "C:\\other\\high.xxx");

    that part makes sense.

    hope this is a little clearer! thanks for any help ^_^
    Do you not know how to link multiple source files? Is that the question?
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  3. #33
    Normander the Barbarian TheReceptionist's Avatar
    Join Date
    Jul 2011
    Location
    Gainesville,FL
    Posts
    24
    i follow what the book says (C a modern approach, king, 2ed) and type

    gcc -o load histogram.c jpeg32.o Lenna.jpg.

    it gives an error

    Lenna.jpg: file not recognized: File format not recognized.

    i used #include "/MinGw/bin/jpeg.h" in the header. the file jpeg.h is in c:\\MinGw\bin\

    is this not correct?

  4. #34
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You don't compile a .jpg into the executable. You just keep it where you can find it for fopen (or in your case loadJPG).


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #35
    Normander the Barbarian TheReceptionist's Avatar
    Join Date
    Jul 2011
    Location
    Gainesville,FL
    Posts
    24
    thanks, quzah. that takes care of that. so what about the .o file?

  6. #36
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You could do a quick search and figure it out:

    gcc -c myfile.c

    That will make myfile.o.

    gcc myofile1.o myofile2.o myfile.o -o myexecutable

    Will make an executable.


    Quzah.
    AndrewHunter likes this.
    Hope is the first step on the road to disappointment.

  7. #37
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,648
    Oh boy, the whole class is here! Maybe we can get a cut of Andrei's pay?
    AndrewHunter likes this.

  8. #38
    Normander the Barbarian TheReceptionist's Avatar
    Join Date
    Jul 2011
    Location
    Gainesville,FL
    Posts
    24
    Quote Originally Posted by rags_to_riches View Post
    Oh boy, the whole class is here! Maybe we can get a cut of Andrei's pay?
    if only! class is basically him reading from PPT lectures from the publisher of the book, so it would be great if someone who actually wanted to help us comprehend/understand programming would take over!

  9. #39
    Normander the Barbarian TheReceptionist's Avatar
    Join Date
    Jul 2011
    Location
    Gainesville,FL
    Posts
    24
    this is what i have so far:

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include "jpeg.h"
    
    int loadJPG(const char* input_file_name, const char* output_file_name);
     
    int main()
    	{
    		loadJPG("Lenna.jpg","output");
    	}
    compile it with
    Code:
    %gcc -c histogram3.c -o histogram3
    then to compile into executable:
    Code:
    %gcc -ljpeg jpeg64.o histogram3.o -o load
    when i run the program, it returns "can't open Lenna". i tried including the entire path to the file and the same. tried re-dling the jpg file and then recompiled. im getting no errors for each compilation.

    anything else i can try?

  10. #40
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Does Lenna.jpg open in, say, Picture Viewer?

    And it wouldn't hurt to make sure it's in the same directory as the executable.

  11. #41
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    1. The LoadJPG function is defined in your header file so why did you do it again? This could be an issue, just have the include file and use the function, don't prototype it again.

    2. You homework says this for the loadJPG function:
    (b) To get the pixels from an actual JPEG image, the image has to
    be decompressed rst. A library jpeg is provided, which contains
    the following function dened in jpeg:h that decompresses a JPEG
    image:
    // this function reads a JPEG image from file named
    // input_file_name
    // and stores the pixel data in the file named
    // output_file_name
    // The function returns the number of bytes written
    int loadJPG(const char* input_file_name,
    const char * output_file_name);
    So where are you running your program from and where is your JPEG that you are trying to load located on your computer?
    Last edited by AndrewHunter; 07-26-2011 at 10:16 PM. Reason: Too slow
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  12. #42
    Normander the Barbarian TheReceptionist's Avatar
    Join Date
    Jul 2011
    Location
    Gainesville,FL
    Posts
    24
    yup. def opens in pic viewer.

    im connected through putty and use winscp to transfer files over to a dedicated directory on the server. when i try to open the lenna.jpg copy thats copied onto the server its just a bunch of jibberish. i checked permissions and jpgs arent one of the allowed file transfer types and theres no way to override it. im thinking that might be the problem??

    i would check it on a windows system but my gcc doesnt have -ljpeg so it wont compile due to "undefined reference to".

  13. #43
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    If you want to "cheat", rename your .jpg to something like .txt and then copy it over, then rename it again. (Rename is called "mv" on *nix, but you probably know that.)

  14. #44
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    Your classmate posted a link so you could download them I thought....

    Index of /class/cgs3460su11/homework

    EDIT: And yes, I would be willing to bet your loadJPG function checks for the JPEG signature and aborts if it doesn't find it.
    Last edited by AndrewHunter; 07-26-2011 at 10:26 PM.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  15. #45
    Normander the Barbarian TheReceptionist's Avatar
    Join Date
    Jul 2011
    Location
    Gainesville,FL
    Posts
    24
    tried renaming to .txt and renaming after copying: no dice.

    i tried looking for the class directory in winscp to see if i can get it from the server: no dice either

    i guess im kinda stuck until i can reach the prof. UGGHH X O

    EDIT:

    i found the location of the .jpg on the server. it opens in pic viewer when i right click open, but opens text jibberish then i double click. still effed for the moment?
    Last edited by TheReceptionist; 07-26-2011 at 10:42 PM.

Page 3 of 6 FirstFirst 123456 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. function library (from scratch)?
    By SirJiub in forum C Programming
    Replies: 7
    Last Post: 06-05-2011, 01:48 PM
  2. how to know which function belongs to which library?
    By gibsosmat in forum Linux Programming
    Replies: 8
    Last Post: 11-18-2007, 06:46 AM
  3. The mathematical function library in C++
    By turkertopal in forum C++ Programming
    Replies: 3
    Last Post: 10-08-2005, 06:54 AM
  4. Library Function to verify Int
    By Mr_roboto in forum C++ Programming
    Replies: 24
    Last Post: 09-29-2005, 02:11 PM
  5. library function
    By darfader in forum C Programming
    Replies: 4
    Last Post: 09-10-2003, 09:38 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21