estoy leyendo una imagen tiff usando TIFFReadEncodedStrip, la lee bien, al momento de mostrarla en una textura los pixeles se muestran desplazados, con cierta inclinacion hacia la derecha, es decir el limite de la imagen aparece en medio de la textura mostrando los pixeles de manera continua, se muestra una imagen con inclinacion
Translation:
I'm reading a tiff image using TIFFReadEncodedStrip, it reads it well, at the time of display in a texture pixels are displaced, with certain inclination to the right, i.e. the limit of the image appears in the middle of the texture showing pixels continuously, shows an image with tilt
I Show the code to test:
#include <stdio.h>
#include <stdlib.h>
#include <tiffio.h>
#include <tiffiop.h>
#include <GL/glut.h>
#include "tr.h"
#include "arraycontainer.h";
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <windows.h>
#include <tiffio.h>
#include <GL/glut.h>
typedef unsigned short ushort;
TIFF *image, *out_image;
uint16 photo, bps, spp, fillorder, rps;
uint16 bpp, res_unit;
unsigned char* raster;
ushort* raster1;
uint16 width, length, n_length;
tsize_t stripSize;
unsigned long imageOffset, result;
int stripMax, stripCount;
char tempbyte;
unsigned char* buffer;
unsigned long bufferSize, count;
GLuint gl_Tex;
uint32 tileWidth, tileLength, tilezise;
char *lpBits;
unsigned long rowsperstrip;
int initGL(int *argc, char **argv)
{
printf("Initializing GLUT...\n");
glutInit(argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(width, length);
glutInitWindowPosition(512 - width / 2, 384 - length / 2);
glutCreateWindow(argv[0]);
printf("OpenGL window created.\n");
return 0;
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, length, GL_LUMINANCE, GL_UNSIGNED_SHORT, raster);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, gl_Tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0); glVertex2f(0.0, 0.0);
glTexCoord2f(1.0, 0.0); glVertex2f(0.50, 0.0);
glTexCoord2f(1.0, 1.0); glVertex2f(0.50, 0.50);
glTexCoord2f(0.0, 1.0); glVertex2f(0.0, 0.50);
glEnd();
glFinish();
glutSwapBuffers();
glutPostRedisplay();
}
void initOpenGLBuffers()
{
printf("Creating GL texture...\n");
glGenTextures(1, &gl_Tex);
glBindTexture(GL_TEXTURE_2D, gl_Tex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width-1, length-1, 0, GL_RGB, GL_UNSIGNED_BYTE, raster);
printf("Texture created.\n");
}
int main(int argc, char *argv[]){
if ((image = TIFFOpen("C:\\temp\\L04-01Irfan.tif", "r")) == NULL){
fprintf(stderr, "Could not open incoming image\n");
exit(42);
}
rowsperstrip = (uint32)-1;
TIFFGetField(image, TIFFTAG_IMAGEWIDTH, &width);
TIFFGetField(image, TIFFTAG_IMAGELENGTH, &length);
TIFFGetField(image, TIFFTAG_ROWSPERSTRIP, &rps);
TIFFGetField(image, TIFFTAG_BITSPERSAMPLE, &bps);
TIFFGetField(image, TIFFTAG_SAMPLESPERPIXEL, &spp);
TIFFGetField(image, TIFFTAG_PHOTOMETRIC, &photo);
TIFFGetField(image, TIFFTAG_TILEWIDTH, &tileWidth);
TIFFGetField(image, TIFFTAG_TILELENGTH, &tileLength);
TIFFGetField(image, TIFFTAG_ROWSPERSTRIP, &rowsperstrip);
imageOffset = 0;
printf("The width of the image is %d\n", width);
printf("The length of the image is %d\n", length);
printf("The rows per strip is %d\n", rps);
printf("The bits per sample is %d\n", bps);
printf("The Samples per pixel is %d\n", spp);
printf("The photometric is %d\n", photo);
printf("The tile width per pixel is %d\n", tileWidth);
printf("The tile height is %d\n", tileLength);
if (length%rps != 0)
n_length = length + (rps - (length%rps));
stripSize = TIFFStripSize(image);
stripMax = TIFFNumberOfStrips(image);
printf("The number of strips is %d\n", stripMax);
printf("The strip size is %d\n", stripSize);
bufferSize = TIFFNumberOfStrips(image) * stripSize;
printf("The buffer size is %d\n", bufferSize);
unsigned long row;
long nrow;
unsigned long LineSize;
int i, l;
unsigned int SamplePerPixel;
UINT32 next_row = 0;
UINT32 current_row = 0;
UINT32 img_row = 0;
UINT32 src_col, src_row, dst_ndx;
UINT32 row_incr = 0.50;
LineSize = TIFFScanlineSize(image); SamplePerPixel = (int)(LineSize / width);
buffer = (unsigned char*)_TIFFmalloc(TIFFStripSize(image));
lpBits = (char *)_TIFFmalloc((length*width*sizeof(char)) * 3);
for (row = 0; row < length; row ++){
nrow = (row + rowsperstrip > length ? length - row :
rowsperstrip);
if (TIFFReadEncodedStrip(image, TIFFComputeStrip(image, row, 0),
buffer, nrow*LineSize) == -1)
{
}
else
{
for (l = 0; l < nrow; l++){
if (SamplePerPixel == 3)
{
for (i = 0; i<width; i++){
src_col = i + 0.50;
if (src_col > width) src_col = width;
src_row = l*LineSize;
dst_ndx = 3 * (i + (length - img_row - 1) * width);
lpBits[dst_ndx] = buffer[src_row + src_col*SamplePerPixel + 2];
lpBits[++dst_ndx] = buffer[src_row + src_col*SamplePerPixel + 1];
lpBits[++dst_ndx] = buffer[src_row + src_col*SamplePerPixel + 0];
}
img_row++;
if (img_row == length) break;
}
}
if (img_row == length) break;
}
}
result++;
raster = (unsigned char*)(lpBits);
I´m updating the code, to read a tiff using TIFFReadEncodedStrip, but again my display showing the image whith displacement and inclination using texture