Thread: work?

  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    270

    Post work?

    Hi
    I got the following partial code:

    Code:
    elseif (strcmp(argv[1],"-i")==0)
    	ep100_lib_open_image(filename);
    	width = ep100_lib_image_width();
    	height = ep100_lib_image_height();
    	
    	ep100_lib_get_data(image_data);
    	ep100_lib_print_data(image_data);
    
    	invert_image(image_data);
    
    	ep100_lib_set_data(invert_image(image_data));
    
    	sleep(5);
    
    	ep100_lib_display_image();
    
    	ep100_lib_close();
    	
    	return(0);
    I would just like someone to have a look at it and see if it makes sense to work?

    see attachment if you would like to see my library am using

    thanks

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You may want (need?) to pass width and height to the image_invert().

    You probably don't want to call image_invert AGAIN n the call to image_set_data() - that would, assuming it worked, take the image back to original form, since you have already inverted it.

    I object to the "sleep" function here - because it makes more sense to use a getchar() or similar function. That is since the getchar() will wait EXACTLY as long as the user needs to view the picture, rather than a too short or too long time - how long does it take someone to inspect the picture - depends on how closely you want to look at it, and who it is, how many times the image have been seen, etc, etc.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Aug 2007
    Posts
    270
    ok yea i understand.

    the set i used again is to show the difference after inverting. so thats why i put it there.
    It shows the old image followed by new one

  4. #4
    Registered User
    Join Date
    Aug 2007
    Posts
    270

    Question

    ok when i pass widthe and height here:

    Code:
    invert_image(image_data,width,height);
    would i also have to add it here:

    Code:
    ep100_lib_set_data(invert_image(image_data));
    ?
    thanks

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by taurus View Post
    ok when i pass widthe and height here:

    Code:
    invert_image(image_data,width,height);
    would i also have to add it here:

    Code:
    ep100_lib_set_data(invert_image(image_data));
    ?
    thanks
    I don't think invert_image() belongs in the ep100_lib_set_data() function at all.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    Registered User
    Join Date
    Aug 2007
    Posts
    270
    Quote Originally Posted by matsp View Post
    I don't think invert_image() belongs in the ep100_lib_set_data() function at all.

    --
    Mats
    but then how does it get the new array that has been inverted. it need to know doesnt it?

  7. #7
    Registered User
    Join Date
    Aug 2007
    Posts
    270
    so do i need it or not?

  8. #8
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    We're thinking, we're thinking . . . hold your horses . . .

    Code:
    	sleep(5);
    
    	ep100_lib_display_image();
    Perhaps you want to delay after you display the image, not before.

    Assuming that invert_image()'s prototype looks sort of like this:
    Code:
    void invert_image(int data[EP100_LIB_MAX_X][EP100_LIB_MAX_Y]);
    then you might want something like this:
    Code:
    invert_image(image_data);
    ep100_lib_set_data(image_data);
    Have you started writing invert_image() yet? [I have insider information via PMs.]
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  9. #9
    Registered User
    Join Date
    Aug 2007
    Posts
    270
    oooo reaally, wat kind of info. I havent started that one yet, going to start tomorrow on the functions and procedures

    here i think i need to enter the width and heigh as well:
    invert_image(image_data);

    so it wud have to be

    invert_image(image_data, width, height);
    Last edited by taurus; 10-17-2007 at 12:33 PM.

  10. #10
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    oooo reaally, wat kind of info.
    You asked for it!
    1) You will need to find out about how images are stored as pixels,
    and how these pixels are often stored in integers.
    You should look at how to use the ’<<’ and ’>>’ operators in C
    as well as the ’&’ operator for isolating the red, green and blue
    components of an image. See http://en.wikipedia.org/wiki/Pixels
    Each pixel is a 32 bit integer and has the upper 8 bits as the alpha
    channel (which you can ignore) and the lower 8 bits are the blue
    pixel value (0-255). So a pixel’s bits are ARGB (from most to least
    significant, 8 bits per channel). So you can extract the colours via:
    red is ((image_data[row][column]>>16)&0xff)
    blue is ((image_data[row][column]>>8)&0xff)
    green is ((image_data[row][column])&0xff)
    2) You will need to find out how to include the existing library
    supplied by me, as well as your library in your compilation "cc"
    command. Most of this is handled by the supplied Makefile. Once you
    have adjusted this file, you should simply be able to type make &#191;
    Or make run &#191; will display the default image.
    Or make run IMAGE=images/silhouette_76_small.jpg &#191; will display the
    specified image.
    See section on Makefiles in:
    [edited]
    3) Write a C library function that will invert the pixels in an image
    whose name is supplied on the command line. The function will IMPORT a
    2-D pixel array and EXPORT
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  11. #11
    Registered User
    Join Date
    Aug 2007
    Posts
    270
    lol
    so as i was saying do i have to do this:

    invert_image(image_data, width, height);

  12. #12
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by taurus View Post
    lol
    so as i was saying do i have to do this:

    invert_image(image_data, width, height);

    Well, if your programatic ESP is strong, you could always use the mind-reading method of figuring out the sizes of the image - but I find that _EVERY_ time I try that trick, it doesn't work quite right - I always get some other random value that isn't matchng the data-size I've got.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  13. #13
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Most likely. It depends on how you define invert_image(), of course. But if the prototype is
    Code:
    void invert_image(int data[EP100_LIB_MAX_X][EP100_LIB_MAX_Y], int width, int height);
    then you'd call it just as you have it.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. strcmp returning 1...
    By Axel in forum C Programming
    Replies: 12
    Last Post: 09-08-2006, 07:48 PM
  2. getline() don't want to work anymore...
    By mikahell in forum C++ Programming
    Replies: 7
    Last Post: 07-31-2006, 10:50 AM
  3. Why don't the tutorials on this site work on my computer?
    By jsrig88 in forum C++ Programming
    Replies: 3
    Last Post: 05-15-2006, 10:39 PM
  4. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM
  5. DLL __cdecl doesnt seem to work?
    By Xei in forum C++ Programming
    Replies: 6
    Last Post: 08-21-2002, 04:36 PM