Thread: How to use loadJPG function from library jpeg?

  1. #1
    Registered User
    Join Date
    Jul 2011
    Posts
    12

    How to use loadJPG function from library jpeg?

    Hi all,

    As my name implies, I just started learning how to program in C.
    I have a homework assignment that requires me to use the function loadJPG
    to decompress an image. I've never encounter this function before, so I have no idea how it works, or even how to call it. My instructor never explain it in class either.

    The function has the prototype:
    int loadJPG(const char* input_file_name,
    const char * output_file_name);

    So, I'm suppose to supply it with an input file name and a output file name, something that I'm totally unfamiliar with...

    How are we suppose to use a file name as an argument and expect it to give us another file of some sort?

    It'd be great if anyone can explain that function to me, and more importantly, teach me how to use it.

    Thanks!!!

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Presumably you know what filenames are. For now you can think of "const char *" as "things in quotes" if you want (but it could also be a char array).
    Code:
    loadJPG("file1", "file2");

  3. #3
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    What library is that in?

    Frankly if you haven't been taught about strings and filenames yet... this assignment would be way too advanced for your class.

  4. #4
    Registered User
    Join Date
    Jul 2011
    Posts
    12
    @tabstop
    If filename means anything other than the name of a file, then I don't know what it is...
    The idea of using the name of a file, something that's not declared inside a program, is totally foreign to me.
    But then again, if filename refers to something in a program, then it's a different story (A story that I've not yet been told).

    @CommonTater
    We've been taught about strings.
    My instructor does have a tendency to give assignments that are almost impossible to do, especially for a class that supposedly requires no previous programming experience.

  5. #5
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    If you know what a filename is, and you've been taught about strings, then you're done.

  6. #6
    Registered User
    Join Date
    Jul 2011
    Posts
    12
    Let's say I want to compress a file named low.jpeg, and save the output into a file named high, do I just call the function like this:
    loadJPG("low.jpeg, "high");
    ?

  7. #7
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    Quote Originally Posted by CNoobgrammer View Post
    Let's say I want to compress a file named low.jpeg, and save the output into a file named high, do I just call the function like this:
    loadJPG("low.jpeg, "high");
    ?
    Well, depending where the files are and where your program is you may need to include a path. Additionally, what is the format of your decompressed file? Without more knowledge lets say you were going to load your low.jpeg a directory C:\mystuff and save your high.xxx file into c:\other. The syntax would be:
    Code:
    loadJPG("C:\\mystuff\\low.jpeg", "C:\\other\\high.xxx");
    Notice the "\\" which is required so the compiler sees a "\" and not an escape sequence. Additionally, notice that each string literal has its own pair of quotation marks.
    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.

  8. #8
    Registered User
    Join Date
    Jul 2011
    Posts
    12
    The files are on my school's server (running on linux). According to the instruction, the output file is a "binary file". Since there are information I need to get from the output file, I thinkI should make it a text file so I can read it.

    Thank you for your help AndrewHunter!

  9. #9
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    What is the actual assignment? Also, the function you are using isn't a standard function; if you could provide the protoype and maybe description of what is does, we could help you better. Please note if the assignment specifies that the output file is in binary then just making the extension of the file .txt will not make it readable.
    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.

  10. #10
    Registered User
    Join Date
    Jul 2011
    Posts
    12
    The function is provided in the assignment; the function prototype is:
    Code:
    int loadJPG(const char* input_file_name,
    const char * output_file_name);
    The assignment itself is quite long with almost 3 pages of instructions. Essentially, we have to decompress an image file toobtain it's pixel data and read them into memory then compute the color histogram for the image.

    I really don't know anything about the function since it's not included in the book, or mentioned in the class.

  11. #11
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    But you have three pages of instructions, and I would be willing to bet $x for most any x that all the information you need is in the instructions, if only you were to read them.

  12. #12
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Your provided library should be telling you what each function does. The function prototype sure doesn't tell us anything useful:

    Name: loadJPG - Ok, this seems to say it's going to open a file for us and put its contents someplace.
    Returns: An int. Well that's unhelpful. It's obviously not putting it there. Must be an error value then for if it fails or nto.
    arg1: input_file_name - Ok, that's at least obvious.
    arg2: output_file_name - What? Why are we outputting anything? I thought we were loading a file? Why do I need an output file name?

    This function prototype tells us nothing of what this function does, so you'd better go hit up your teacher for what this actually does. Or as tabstop said, actually read your instructions.


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

  13. #13
    Registered User
    Join Date
    Jul 2011
    Posts
    12
    Quote Originally Posted by tabstop View Post
    But you have three pages of instructions, and I would be willing to bet $x for most any x that all the information you need is in the instructions, if only you were to read them.
    I don't know what made you think that I didn't read the instructions. Like I said in the beginning, I'm new to C programming and my instructor really do give long and hard HW problems.
    I'm not asking anyone here to write the program for me, only asking the particulars that I don't understand.

  14. #14
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    All that tabstop and quzah are saying is that since the function you are dealing with is not a standard function, as I pointed out to you in my previous post, it will be very hard for us to help you further than what has been provided. I would take a look again at quzah's questions and try to tell us some answers to those. That will help us understand what is going on.

    Contrary to popular belief, quzah and tabstop did not start posting here when they were 3, so they have been there and done that with the college thing. Listen to their questions and answer them.
    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. #15
    Registered User
    Join Date
    Jul 2011
    Posts
    12
    Quote Originally Posted by quzah View Post
    Your provided library should be telling you what each function does. The function prototype sure doesn't tell us anything useful:

    Name: loadJPG - Ok, this seems to say it's going to open a file for us and put its contents someplace.
    Returns: An int. Well that's unhelpful. It's obviously not putting it there. Must be an error value then for if it fails or nto.
    arg1: input_file_name - Ok, that's at least obvious.
    arg2: output_file_name - What? Why are we outputting anything? I thought we were loading a file? Why do I need an output file name?

    This function prototype tells us nothing of what this function does, so you'd better go hit up your teacher for what this actually does. Or as tabstop said, actually read your instructions.


    Quzah.
    Again, I don't know why people here think I'm not reading the instructions. If they were crystal clear, I wouldn't be here posting questions.
    I thought the function I'm using is somewhat prevalent, so there's a chance that someone here is familiar with it. That's obviously not the case

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, 07: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