   Resizing an image....    
  Ok, I'm having a little trouble... I'm trying to make a function that will resize an image, by a scale value.  It uses interpolation to figure out the value of the new vertices.  But it isn't working right, and iv'e been pulling out my hair, and gritting my teeth for two days!So I thought maybe someone here might be willing to look trhough the code, and tell me where I' screwing up.  I know it's boring, but I really need help...Thanks, in advance!void TGATexture::stretch(float scale) {if (scale == 1.0f)// Can't scale it to the size which it already is!return;// Return from the functionGLubyte *pixels, r, g, b;// The temporary pixel-arrayn and other temp valuesGLubyte thisPixelx, thisPixely, thisPixelz, nextPixelx, nextPixely, nextPixelz;// Pixeldataint newWidth, newHeight, x, y;// The new width and height of the texturefloat count = 0.0f;// Counterint bytesPerPixel = bpp / 8;// Bytes per-pixel of the textureFloatToInt(&newWidth, width * scale);// Convert the new width from a floating-point value to an intFloatToInt(&newHeight, height * scale);// Convert the new height from a floating-point value to an intpixels = new GLubyte[newWidth * height * bytesPerPixel];// Allocate memory for the new pixelsy = 0;for (x = 0; x < height * width; ) {// Loop through all the pixelsif (count > 1) {// If the counter is greater than 1while (count > 1) {// Loop until it isn'tpixels[y * 3 + 0] = thisPixelx + (nextPixelx - thisPixelx) / (GLubyte)count;// Set the value of the empty pixel,pixels[y * 3 + 1] = thisPixely + (nextPixely - thisPixely) / (GLubyte)count;// by interpolating between the values ofpixels[y * 3 + 2] = thisPixelz + (nextPixelz - thisPixelz) / (GLubyte)count;// the previous and next pixel in the original imagey++;// Increment the pointer to the position in the new array of pixelscount--;// and the counter}} else {// If count isn't greater than 1getcolor(x, r, g, b);// Get the color of the original images pixel; at x in the arraypixels[y * 3 + 0] = r;// Set the values of the new array of pixels,pixels[y * 3 + 1] = g;// to the value of the pixel we just selectedpixels[y * 3 + 2] = b;// from the original imagethisPixelx = r;// These variable will hold the values we selectedthisPixely = g;// from the original image, and will be used whenthisPixelz = b;// we interpolate the values for new pixelsgetcolor(x + 1, r, g, b);// Get the color of the original images' next pixel; at x + 1 in the arraynextPixelx = r;// These variable will hold the values we selectednextPixely = g;// from the original image, and will be used whennextPixelz = b;// we interpolate the values for new pixelscount += scale - 1;// add to the countery++, x++;// Increment the pointer to the current positions in the arrays}}width = newWidth;// Set the width of the image to the width of the resized imagedelete[] imageData;// Delete the old dataimageData = new GLubyte[width * height * bytesPerPixel];// And allocate newfor (x = 0; x < height * width * bytesPerPixel; x++) {// And then loop through the arraysimageData[x] = pixels[x];// Setting the imageData values}delete[] pixels;// Delete the temporary pixeldata array[edited by - James Trotter on March 4, 2003 11:34:02 AM]