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; Originally Posted by TheReceptionist i tried looking for the class directory in winscp to see if i can get it ...

  1. #46
    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
    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
    Did you look at the link your classmate posted. Is this not the same .o and .h file you need to download? At least then you could just do the assignment on your computer.
    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.

  2. #47
    Normander the Barbarian TheReceptionist's Avatar
    Join Date
    Jul 2011
    Location
    Gainesville,FL
    Posts
    24
    Quote Originally Posted by AndrewHunter View Post
    Did you look at the link your classmate posted. Is this not the same .o and .h file you need to download? At least then you could just do the assignment on your computer.
    yup. i have all those files. to compile in windows tho, i need to use
    Code:
    %gcc -ljpeg etc etc
    but i dont have the -ljpeg extension to compile it

  3. #48
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    If jpeg.o is the proper o file, then ditch -ljpeg and just put jpeg.o in your final gcc command.

  4. #49
    Normander the Barbarian TheReceptionist's Avatar
    Join Date
    Jul 2011
    Location
    Gainesville,FL
    Posts
    24
    im getting the following error
    Code:
    $ gcc jpeg64.o histogram3.o
    jpeg64.o: In function `loadJPG':
    jpeg.c:(.text+0xa7): undefined reference to `jpeg_std_error'
    jpeg.c:(.text+0xc7): undefined reference to `jpeg_CreateDecompress'
    jpeg.c:(.text+0xe0): undefined reference to `jpeg_stdio_src'
    jpeg.c:(.text+0xf4): undefined reference to `jpeg_read_header'
    jpeg.c:(.text+0x103): undefined reference to `jpeg_start_decompress'
    jpeg.c:(.text+0x1d0): undefined reference to `jpeg_read_scanlines'
    jpeg.c:(.text+0x332): undefined reference to `jpeg_finish_decompress'
    jpeg.c:(.text+0x341): undefined reference to `jpeg_destroy_decompress'
    collect2: ld returned 1 exit status
    norma@ubuntu:~/Desktop$
    (i switched ti ubuntu for a bit). im getting the same error in windows. its directly related to the jpeg lib that i dont have

  5. #50
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Okay, so libjpeg is actually needed. In Ubuntu, you can fire up synaptic and get "libjpeg62". (I already have it installed, and I don't remember installing it special, but I guess I must have.)

    You can also get libjpeg for Windows if you want.

  6. #51
    Registered User
    Join Date
    Mar 2009
    Posts
    344
    Trying to link the provided jpeg.o compiled for Linux using GCC for windows will bomb. Linux GCC doesn't add leading underscores to function names while Windows GCC does. You'll get lots of errors like "jpeg.c.text+0x57): undefined reference to fopen" because the lib function name under Win will be _fopen instead.

    There's a chance the file is getting corrupted. Do "md5sum Lenna.jpg" in the directory you're building and running your code in. It should look like this
    Code:
    94df9c5dd1ae4a348e858e4ea43cd023 *Lenna.jpg

    If you know where the file is on the server, can't you just use cp to copy if to your local working directory? If not, do you have curl on the linux machine? This would make it as simple as
    Code:
    curl http://www.cise.ufl.edu/class/cgs3460su11/homework/Lenna.jpg > Lenna.jpg
    to copy to whatever local directory you're working from.

    I did a simple test and everything works as expected :

    Code:
    evergrove{82}> cat jpeg_main.c
    #include <stdio.h>
    #include "jpeg.h"
    
    int main (void)
    {
       printf ("%d\n", loadJPG("Lenna.jpg", "Lenna.bin"));
       return 0;
    
    }
    
    evergrove{83}> gcc -o jpeg_main jpeg_main.c jpeg64.o -ljpeg
    evergrove{84}> ./jpeg_main
    262146
    ETA - the return value is incorrect but close enough - the real size of the file should be 2*8 + (256*256) * 4 = 262152. That's OK, you never need it for the homework you're asked to do.
    Last edited by KCfromNC; 07-27-2011 at 10:37 AM.

  7. #52
    Normander the Barbarian TheReceptionist's Avatar
    Join Date
    Jul 2011
    Location
    Gainesville,FL
    Posts
    24
    Thanks, tabstop and KCfromNC. My ubuntu crapped out yesterday so I'm going to reinstall and try to work through that.

    Were being told to compile using
    Code:
    gcc histogram.c jpeg64.o -ljpeg
    ./a.out lenna.jpg out.txt 4
    The server we sign onto using putty is linux. Would the linking of jpeg64.o still cause problems since im in windows? Basically, does the OS need to be linux or just where im compiling/linking?

    I totally appreciate all the responses btw! You guys rock! =D

  8. #53
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,047
    Quote Originally Posted by TheReceptionist View Post
    The server we sign onto using putty is linux. Would the linking of jpeg64.o still cause problems since im in windows?
    If compiling on windows then yes it'd be a problem.
    Quote Originally Posted by TheReceptionist View Post
    Basically, does the OS need to be linux or just where im compiling/linking?
    Only on the OS where you are compiling and linking.

  9. #54
    Normander the Barbarian TheReceptionist's Avatar
    Join Date
    Jul 2011
    Location
    Gainesville,FL
    Posts
    24
    Thanks for all the info! Ubuntu it is! =D

  10. #55
    Normander the Barbarian TheReceptionist's Avatar
    Join Date
    Jul 2011
    Location
    Gainesville,FL
    Posts
    24
    Code:
    evergrove{83}> gcc -o jpeg_main jpeg_main.c jpeg64.o -ljpeg
    evergrove{84}> ./jpeg_main
    262146
    this works perfectly! thanks!

    what does md5sum do? i read up a little on it and it seems its just an algorithm that verifies the file and 'returns' a value that indicates validity but doesnt create or change the original file?

  11. #56
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by TheReceptionist View Post
    what does md5sum do? i read up a little on it and it seems its just an algorithm that verifies the file and 'returns' a value that indicates validity but doesnt create or change the original file?
    It's a bit more complex than this, but basically it adds up each byte and gets a sum. If the sum for the exe is the same as the original, then it hasn't been tampered with. If it's different, the two files aren't exactly the same.
    Code:
    for( sum = x = 0; x < size of file in bytes; x++ )
        sum += this byte;
    Now it doesn't actually just do that, but basically that is what happens. (It actually matters if you take the first and second byte of the file and swap their positions - that would give a different md5sum, whereas what I did would not. But just as a way to understand what happens, that's basically what it does.


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

  12. #57
    Normander the Barbarian TheReceptionist's Avatar
    Join Date
    Jul 2011
    Location
    Gainesville,FL
    Posts
    24
    thanks for the clarification, quzah! ^_^

  13. #58
    Normander the Barbarian TheReceptionist's Avatar
    Join Date
    Jul 2011
    Location
    Gainesville,FL
    Posts
    24
    new issue: reading information from the binary file.

    this is the part of my code that reads the values from the file and its output. i know the dimension values are correct, not sure about pixel 1 values. either way, im assuming theyre right since the values for RGB(first 3 ints)are less than 255. the second set are way off. not sure what im doing wrong if the 1st set works...any ideas/insight?

    Code:
    thunder:112% ./load
    262146
    DIMENSIONS(in pixels): 256 x 256
    124 135 225 4198912     //pixel1
    32636 1788271239 225 4198912     //pixel2

    Code:
    	
            fread(&width,sizeof(width),1,fp);	//(char* str,int n,FILE* file)
    	fread(&height,sizeof(height),1,fp);
    	printf("DIMENSIONS(in pixels): %d x %d\n",width,height);				
    				
    	fread(&h_b,1,1,fp);
    	fread(&h_g,1,1,fp);
    	fread(&h_r,1,1,fp);
    	fread(&alpha,1,1,fp);
    
    	printf("%d %d %d %d\n",h_b,h_g,h_r,alpha);
    		
    	fread(&h_b2,1,1,fp);
    	fread(&h_g2,1,1,fp);
    	fread(&h_r2,1,1,fp);
    	fread(&alpha2,1,1,fp);
    	printf("%d %d %d %d\n",h_b2,h_g2,h_r2,alpha2);

  14. #59
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Is alpha an int or a char? If you are only filling one byte of it, you aren't zeroing out the other 3 (assuming 4 byte ints).


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

  15. #60
    Normander the Barbarian TheReceptionist's Avatar
    Join Date
    Jul 2011
    Location
    Gainesville,FL
    Posts
    24
    Quote Originally Posted by quzah View Post
    Is alpha an int or a char? If you are only filling one byte of it, you aren't zeroing out the other 3 (assuming 4 byte ints).
    not sure, actually. im assuming its an int, part of the binary file info and that its one byte (instructions say each value is a byte)

Page 4 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