Results 1 to 7 of 7

Thread: how to cut an image to small?

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2002
    Location
    china
    Posts
    9

    how to cut an image to small?

    I want to texturemap an image of 3450*5678 pixel ,but the max matrix of texturemap in my pc is 1024*1024,how can i solve it? is cutting map is a good way? how to do it?
    thanks for any help.
    yang

  2. #2
    Senior Member Regular Contributor
    Join Date
    Oct 2002
    Posts
    201

    Re: how to cut an image to small?

    Yeah cut it or shrink it. All texture maps have to be square and a power of 2

  3. #3
    Senior Member Regular Contributor
    Join Date
    Mar 2002
    Location
    Melbourne, Australia
    Posts
    224

    Re: how to cut an image to small?

    I recommend you shrink it
    Pseudocode in case...
    Code :
    for i := 0 to 1023 do begin
      for j := 0 to 1023 do begin
        _i := (i * 3450) div 1023;
        _j := (j * 5678) div 1023;
        final_texture[i][j] := your_texture[_i][_j];
      end;
    end;
    Hope you don't mind my Pascal code

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,753

    Re: how to cut an image to small?

    Originally posted by mdog1234:
    Yeah cut it or shrink it. All texture maps have to be square and a power of 2
    You're right about the power of 2, but not about them needing to be square. As long as both dimensions are a power of 2, you can have rectangular textures. (e.g. 256x12
    Deiussum
    Software Engineer and OpenGL enthusiast

  5. #5
    Senior Member Regular Contributor
    Join Date
    Oct 2002
    Posts
    201

    Re: how to cut an image to small?

    oh ok, thats good to know

  6. #6
    Guest

    Re: how to cut an image to small?

    I copy pasted parts of my imagelibrary that does the trick

    [source]
    inline unsigned int toPowerOf2(unsigned int w) { // Returns maximum power of 2 value that is smaller than or equals w
    unsigned int p=1;
    while (p<=w) { p<<=1; }
    return p>>1;
    }

    void Image: ower2() // Scale down to nearest 2^n x 2^m size.
    {
    int p2_width = toPowerOf2(getWidth());
    int p2_height = toPowerOf2(getHeight());
    if (p2_width==getWidth() && p2_height==getHeight())
    return;

    //printf("Scaling image to power of 2\n");

    Image p2img(p2_width,p2_height,getComponents());
    int x,y;
    for (x=0; x<p2_width; x++)
    for (y=0; y<p2_height; y++)
    {
    int x2 = getWidth()*x / p2_width;
    int y2 = getHeight()*y / p2_height;
    p2img.setPixel(x, y, getPixel(x2,y2));
    }
    *this = p2img;
    }
    void Image::halve() // Halve image
    {
    Image half(getWidth()>>1,getHeight()>>1,getComponents()) ;
    int x,x2,y,y2;
    for (x=0,x2=0; x2<getWidth(); x++, x2+=2)
    for (y=0,y2=0; y2<getHeight(); y++, y2+=2)
    half.setPixel(x, y, getPixel(x2,y2));
    *this = half;
    }


    Image img("fname.png");
    img.power2();
    while (img.getWidth()>1024 &#0124; &#0124; img.getHeight()>1024) img.halve();

    [/source]

  7. #7
    Senior Member Regular Contributor
    Join Date
    Mar 2002
    Location
    Melbourne, Australia
    Posts
    224

    Re: how to cut an image to small?

    Actually our codes could be optimized a bit .
    This would probably save you a lot of time:
    Code :
     
    i_step := (3450 << 16) div 1023;
    j_step := (5678 << 16) div 1023;
     
    _i := 0;
    for i := 0 to 1023 do begin
      _j := 0;
      for j := 0 to 1023 do begin
        _i := i + i_step;
        _j := j + j_step;
        final_texture[i][j] := your_texture[_i >> 16][_j >> 16];
      end;
    end;
    Just for fun

Similar Threads

  1. small help needed
    By brett01 in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 10-19-2008, 05:43 PM
  2. Big image in small area
    By alexei_shk in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 11-21-2005, 05:56 AM
  3. VBO: many small / few big?
    By in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 08-26-2003, 08:51 AM
  4. SMALL GL
    By in forum OpenGL: Linux
    Replies: 1
    Last Post: 01-12-2002, 03:55 PM
  5. Small Prob ????
    By in forum OpenGL: Linux
    Replies: 3
    Last Post: 03-21-2001, 05:44 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean