Thread: Will this work

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    104

    Will this work

    Hi everyone , can someone please double check that this should work :
    Code:
    // A procedure that will scroll an image vertically and return back into matrix
    void Image_vertical_scroll(int image_data[EP100_LIB_MAX_X][EP100_LIB_MAX_Y], int scroll, int height, int width)
    {
    	
    	int row, column, row_new;
    	int inverted_image[EP100_LIB_MAX_X][EP100_LIB_MAX_Y];
    	
            for (row=0;row<height;row++)
            {
                    //We must loop the columns of the image's array , increasing it by 1  until the width of the image becomes the same as the height.
                    for (column=0;column<width;column++)
                    {
                            // Adding the scroll ammount
                            row_new = row + scroll;
    
                            while (row_new >= height) // Have to make sure that total is less than height 
                            {
                                    
                                    row_new = row_new - height;
                            }
    
                            
                            inverted_image[row_new][column] = image_data[row][column];
                    }
            }
    
    }
    I have no way to test this code . In theory it should work ?

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    If we assume that scroll is less than height, then the "while" only needs to be an "if".
    Code:
                            row_new = row + scroll;
    
                            while (row_new >= height) // Have to make sure that total is less than height 
                            {
                                    
                                    row_new = row_new - height;
                            }
    Another option is to do "row_new = (row + scroll) % height;"

    Also, you can use memcpy() to copy the data in the whole row at once:
    Code:
         memcpy(inverted_image[row], image_data[row], sizeof(image_data[0][0]) * width);
    Although, on second thought, I'm not sure that works - you seem to have swapped your columns and rows around - the first dimension in your array appears to be X by the incoming variable declaration - X in my world is column, Y is row. So you probably want to switch your row/column around. [Which means that memcpy doesn't work in this case]

    --
    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.

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