| 68 | } |
| 69 | |
| 70 | void LibRaw::stretch() |
| 71 | { |
| 72 | ushort newdim, (*img)[4], *pix0, *pix1; |
| 73 | int row, col, c; |
| 74 | double rc, frac; |
| 75 | |
| 76 | if (pixel_aspect == 1) |
| 77 | return; |
| 78 | RUN_CALLBACK(LIBRAW_PROGRESS_STRETCH, 0, 2); |
| 79 | if (pixel_aspect < 1) |
| 80 | { |
| 81 | newdim = ushort(height / pixel_aspect + 0.5); |
| 82 | img = (ushort(*)[4])calloc(width, newdim * sizeof *img); |
| 83 | for (rc = row = 0; row < newdim; row++, rc += pixel_aspect) |
| 84 | { |
| 85 | frac = int(rc - double(c = int(rc))); |
| 86 | pix0 = pix1 = image[c * width]; |
| 87 | if (c + 1 < height) |
| 88 | pix1 += width * 4; |
| 89 | for (col = 0; col < width; col++, pix0 += 4, pix1 += 4) |
| 90 | FORCC img[row * width + col][c] = |
| 91 | ushort(pix0[c] * (1 - frac) + pix1[c] * frac + 0.5); |
| 92 | } |
| 93 | height = newdim; |
| 94 | } |
| 95 | else |
| 96 | { |
| 97 | newdim = ushort(width * pixel_aspect + 0.5); |
| 98 | img = (ushort(*)[4])calloc(height, newdim * sizeof *img); |
| 99 | for (rc = col = 0; col < newdim; col++, rc += 1 / pixel_aspect) |
| 100 | { |
| 101 | frac = int(rc - double(c = int(rc))); |
| 102 | pix0 = pix1 = image[c]; |
| 103 | if (c + 1 < width) |
| 104 | pix1 += 4; |
| 105 | for (row = 0; row < height; row++, pix0 += width * 4, pix1 += width * 4) |
| 106 | FORCC img[row * newdim + col][c] = |
| 107 | ushort(pix0[c] * (1 - frac) + pix1[c] * frac + 0.5); |
| 108 | } |
| 109 | width = newdim; |
| 110 | } |
| 111 | free(image); |
| 112 | image = img; |
| 113 | RUN_CALLBACK(LIBRAW_PROGRESS_STRETCH, 1, 2); |
| 114 | } |