#### Archived

This topic is now archived and is closed to further replies.

# Resizing an image....

This topic is 5680 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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 function GLubyte *pixels, r, g, b; // The temporary pixel-arrayn and other temp values GLubyte thisPixelx, thisPixely, thisPixelz, nextPixelx, nextPixely, nextPixelz; // Pixeldata int newWidth, newHeight, x, y; // The new width and height of the texture float count = 0.0f; // Counter int bytesPerPixel = bpp / 8; // Bytes per-pixel of the texture FloatToInt(&newWidth, width * scale); // Convert the new width from a floating-point value to an int FloatToInt(&newHeight, height * scale); // Convert the new height from a floating-point value to an int pixels = new GLubyte[newWidth * height * bytesPerPixel]; // Allocate memory for the new pixels y = 0; for (x = 0; x < height * width; ) { // Loop through all the pixels if (count > 1) { // If the counter is greater than 1 while (count > 1) { // Loop until it isn't pixels[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 of pixels[y * 3 + 2] = thisPixelz + (nextPixelz - thisPixelz) / (GLubyte)count; // the previous and next pixel in the original image y++; // Increment the pointer to the position in the new array of pixels count--; // and the counter } } else { // If count isn't greater than 1 getcolor(x, r, g, b); // Get the color of the original images pixel; at x in the array pixels[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 selected pixels[y * 3 + 2] = b; // from the original image thisPixelx = r; // These variable will hold the values we selected thisPixely = g; // from the original image, and will be used when thisPixelz = b; // we interpolate the values for new pixels getcolor(x + 1, r, g, b); // Get the color of the original images' next pixel; at x + 1 in the array nextPixelx = r; // These variable will hold the values we selected nextPixely = g; // from the original image, and will be used when nextPixelz = b; // we interpolate the values for new pixels count += scale - 1; // add to the counter y++, 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 image delete[] imageData; // Delete the old data imageData = new GLubyte[width * height * bytesPerPixel]; // And allocate new for (x = 0; x < height * width * bytesPerPixel; x++) { // And then loop through the arrays imageData[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]

1. 1
2. 2
Rutin
20
3. 3
4. 4
frob
14
5. 5

• 12
• 9
• 17
• 18
• 9
• ### Forum Statistics

• Total Topics
632597
• Total Posts
3007329

×