PPM file image crop bug

This is a discussion on PPM file image crop bug within the C++ Programming forums, part of the General Programming Boards category; Hey guys im working with a program that does manipulations to simple images( in PPM format). Im trying to crops ...

  1. #1
    Registered User cdonlan's Avatar
    Join Date
    Sep 2004
    Posts
    49

    PPM file image crop bug

    Hey guys im working with a program that does manipulations to simple images( in PPM format). Im trying to crops an image by a rectangle thats (x1,y1),(x2,y2). The image is 38 by 39, but I started the 2-d at [0][0]. When I crop the entire image x1=0; y1=38; x2=37; y2=0. It works fine, it just makes a cope of the original image.
    Here is the code.

    Code:
    void graphics::crop(int x1,int y1,int x2, int y2)
    {
        int i,j;
    
        xsize=((x2-x1)+1);   
        ysize=((y1-y2)+1); 
        
        cout<<xsize<<endl;
        cout<<ysize<<endl;
        
        for(i=0;i<xsize;i++)
        {        
            for(j=0;j<ysize;j++)
            {
                plot[i][j].red = plot[x1+i][y2+j].red;
                plot[i][j].green= plot[x1+i][y2+j].green;
                plot[i][j].blue = plot[x1+i][y2+j].blue;
            }
        }
    
    }
    after that it calls a function to load the date into a file....
    Code:
    void graphics::storePPM()
    {
        int i,j;
        //cout<<"in store"<<endl;
        ofstream outFile;
    
        outFile.open("output.PPM");
        if (outFile.fail())
        {
            cout << "Unable to open output file" << endl;
        }
    
        outFile<<"P3"<<endl;
        outFile<<"# This file was made using graphics program by Chris Donlan"<<endl;
        outFile<<xsize<<" "<<ysize<<endl;
        
        for(i=0;i<xsize;i++)
        {        
            for(j=0;j<ysize;j++)
            {
                
                    outFile<<plot[i][j].red<<endl;;
                    outFile<<plot[i][j].green<<endl;
                    outFile<<plot[i][j].blue<<endl;
            }
        }
    
        outFile<<"\r";
    }
    If I try to crop a smaller part of the image it becomes blured. Any ideas?

    Thanks
    Chris

  2. #2
    Registered User cdonlan's Avatar
    Join Date
    Sep 2004
    Posts
    49
    any ideas people?

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,590
    > If I try to crop a smaller part of the image it becomes blured. Any ideas?
    Check the raw data of the cropped image - use a debugger.
    At least one graphics viewer I know of starts interpolating images (that's fuzzy-making to you) when you zoom in too much.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 10:39 PM
  2. File transfer- the file sometimes not full transferred
    By shu_fei86 in forum C# Programming
    Replies: 13
    Last Post: 03-13-2009, 12:44 PM
  3. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-21-2008, 11:19 PM
  4. Simple File encryption
    By caroundw5h in forum C Programming
    Replies: 2
    Last Post: 10-13-2004, 10:51 PM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM

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