static bool ImageOpen(ImageRec &image, std::istream &is) { image.is = &is; is.read(reinterpret_cast<char*>(&image), 12); if(is.gcount() != 12) return false; bool swapFlag = !osgIsBigEndian(); if(swapFlag == true) ConvertShort(&image.imagic, 6); if((image.type & 0xFF00) == 0x0100) { is.ignore(512 - 12); if (is.gcount() != 512 - 12) return false; int n = image.ysize * image.zsize; int len = n * sizeof(unsigned); image.rowStart.resize(n); is.read(reinterpret_cast<char*>(&(image.rowStart.front())), len); if(is.gcount() != len) return false; image.rowSize.resize(n); is.read(reinterpret_cast<char*>(&(image.rowSize.front())), len); if(is.gcount() != len) return false; if(swapFlag == true) { ConvertLong(&(image.rowStart.front()), n); ConvertLong(&(image.rowSize .front()), n); } unsigned int maxSize = 0; for(int i = 0; i < n; ++i) { if(image.rowSize[i] > maxSize) maxSize = image.rowSize[i]; } image.tmp.resize(maxSize); } else { image.tmp.resize(image.xsize); } return true; }
static rawImageRec *RawImageOpen(char *fileName) { union { int testWord; char testByte[4]; } endianTest; rawImageRec *raw; GLenum swapFlag; int x; endianTest.testWord = 1; if (endianTest.testByte[0] == 1) { swapFlag = GL_TRUE; } else { swapFlag = GL_FALSE; } raw = (rawImageRec *)malloc(sizeof(rawImageRec)); if (raw == NULL) { return NULL; } if ((raw->file = fopen(fileName, "rb")) == NULL) { return NULL; } fread(raw, 1, 12, raw->file); if (swapFlag) { ConvertShort(&raw->imagic, 6); } raw->tmp = (unsigned char *)malloc(raw->sizeX*256); raw->tmpR = (unsigned char *)malloc(raw->sizeX*256); raw->tmpG = (unsigned char *)malloc(raw->sizeX*256); raw->tmpB = (unsigned char *)malloc(raw->sizeX*256); if (raw->tmp == NULL || raw->tmpR == NULL || raw->tmpG == NULL || raw->tmpB == NULL) { return NULL; } if ((raw->type & 0xFF00) == 0x0100) { x = raw->sizeY * raw->sizeZ * sizeof(GLuint); raw->rowStart = (GLuint *)malloc(x); raw->rowSize = (GLint *)malloc(x); if (raw->rowStart == NULL || raw->rowSize == NULL) { return NULL; } raw->rleEnd = 512 + (2 * x); fseek(raw->file, 512, SEEK_SET); fread(raw->rowStart, 1, x, raw->file); fread(raw->rowSize, 1, x, raw->file); if (swapFlag) { ConvertLong(raw->rowStart, x/sizeof(GLuint)); ConvertLong((GLuint *)raw->rowSize, x/sizeof(GLint)); } } return raw; }
static ImageRec *ImageOpen(char *fileName) { union { int testWord; char testByte[4]; } endianTest; ImageRec *image; int swapFlag; int x; endianTest.testWord = 1; if (endianTest.testByte[0] == 1) { swapFlag = 1; } else { swapFlag = 0; } image = (ImageRec *)malloc(sizeof(ImageRec)); if (image == NULL) { fprintf(stderr, "Out of memory!\n"); exit(1); } if ((image->file = fopen(fileName, "rb")) == NULL) { return NULL; } fread(image, 1, 12, image->file); if (swapFlag) { ConvertShort(&image->imagic, 6); } image->tmp = (unsigned char *)malloc(image->xsize*256); if (image->tmp == NULL) { fprintf(stderr, "\nOut of memory!\n"); exit(1); } if ((image->type & 0xFF00) == 0x0100) { x = image->ysize * image->zsize * (int) sizeof(unsigned); image->rowStart = (unsigned *)malloc(x); image->rowSize = (int *)malloc(x); if (image->rowStart == NULL || image->rowSize == NULL) { fprintf(stderr, "\nOut of memory!\n"); exit(1); } image->rleEnd = 512 + (2 * x); fseek(image->file, 512, SEEK_SET); fread(image->rowStart, 1, x, image->file); fread(image->rowSize, 1, x, image->file); if (swapFlag) { ConvertUint(image->rowStart, x/(int) sizeof(unsigned)); ConvertUint((unsigned *)image->rowSize, x/(int) sizeof(int)); } } return image; }
static rawImageRec *RawImageOpen(const char *fileName) { union { int testWord; char testByte[4]; } endianTest; rawImageRec *raw; GLenum swapFlag; int x; size_t result; endianTest.testWord = 1; if (endianTest.testByte[0] == 1) { swapFlag = GL_TRUE; } else { swapFlag = GL_FALSE; } raw = (rawImageRec *)calloc(1, sizeof(rawImageRec)); if (raw == NULL) { fprintf(stderr, "Out of memory!\n"); return NULL; } raw->file = fopen(fileName, "rb"); if (raw->file == NULL) { const char *baseName = strrchr(fileName, '/'); if(baseName) raw->file = fopen(baseName + 1, "rb"); if(raw->file == NULL) { perror(fileName); free(raw); return NULL; } } result = fread(raw, 1, 12, raw->file); assert(result == 12); if (swapFlag) { ConvertShort(&raw->imagic, 1); ConvertShort(&raw->type, 1); ConvertShort(&raw->dim, 1); ConvertShort(&raw->sizeX, 1); ConvertShort(&raw->sizeY, 1); ConvertShort(&raw->sizeZ, 1); } raw->tmp = (unsigned char *)malloc(raw->sizeX*256); raw->tmpR = (unsigned char *)malloc(raw->sizeX*256); raw->tmpG = (unsigned char *)malloc(raw->sizeX*256); raw->tmpB = (unsigned char *)malloc(raw->sizeX*256); if (raw->sizeZ==4) { raw->tmpA = (unsigned char *)malloc(raw->sizeX*256); } if (raw->tmp == NULL || raw->tmpR == NULL || raw->tmpG == NULL || raw->tmpB == NULL) { fprintf(stderr, "Out of memory!\n"); free(raw->tmp); free(raw->tmpR); free(raw->tmpG); free(raw->tmpB); free(raw->tmpA); free(raw); return NULL; } if ((raw->type & 0xFF00) == 0x0100) { x = raw->sizeY * raw->sizeZ * sizeof(GLuint); raw->rowStart = (GLuint *)malloc(x); raw->rowSize = (GLint *)malloc(x); if (raw->rowStart == NULL || raw->rowSize == NULL) { fprintf(stderr, "Out of memory!\n"); free(raw->tmp); free(raw->tmpR); free(raw->tmpG); free(raw->tmpB); free(raw->tmpA); free(raw->rowStart); free(raw->rowSize); free(raw); return NULL; } raw->rleEnd = 512 + (2 * x); fseek(raw->file, 512, SEEK_SET); result = fread(raw->rowStart, 1, x, raw->file); assert(result == x); result = fread(raw->rowSize, 1, x, raw->file); assert(result == x); if (swapFlag) { ConvertLong(raw->rowStart, (long) (x/sizeof(GLuint))); ConvertLong((GLuint *)raw->rowSize, (long) (x/sizeof(GLint))); } } return raw; }
static rawImageRec *RawImageOpen(char *fileName) { union { int testWord; char testByte[4]; } endianTest; rawImageRec *raw; int swapFlag; int x; endianTest.testWord = 1; if (endianTest.testByte[0] == 1) { swapFlag = 1; } else { swapFlag = 0; } /* 23Oct06 Phil McDonald */ raw = (rawImageRec *) TMP_CALLOC (1, sizeof (rawImageRec)); /* end PM */ if (raw == NULL) { fprintf(stderr, "Out of memory!\n"); return NULL; } if ((raw->file = fopen(fileName, "rb")) == NULL) { perror(fileName); return NULL; } fread(raw, 1, 12, raw->file); if (swapFlag) { ConvertShort(&raw->imagic, 6); } /* 23Oct06 Phil McDonald */ raw->tmp = (unsigned char *) TMP_MALLOC (raw->sizeX*256); raw->tmpR = (unsigned char *) TMP_MALLOC (raw->sizeX*256); raw->tmpG = (unsigned char *) TMP_MALLOC (raw->sizeX*256); raw->tmpB = (unsigned char *) TMP_MALLOC (raw->sizeX*256); if (raw->tmp == NULL || raw->tmpR == NULL || raw->tmpG == NULL || raw->tmpB == NULL) { fprintf(stderr, "Out of memory!\n"); RawImageClose (raw); /* end PM */ return NULL; } if ((raw->type & 0xFF00) == 0x0100) { x = raw->sizeY * raw->sizeZ * sizeof(unsigned int); /* 23Oct06 Phil McDonald */ raw->rowStart = (unsigned int *) TMP_MALLOC (x); raw->rowSize = (int *) TMP_MALLOC (x); if (raw->rowStart == NULL || raw->rowSize == NULL) { fprintf(stderr, "Out of memory!\n"); RawImageClose (raw); /* end PM */ return NULL; } raw->rleEnd = 512 + (2 * x); fseek(raw->file, 512, SEEK_SET); fread(raw->rowStart, 1, x, raw->file); fread(raw->rowSize, 1, x, raw->file); if (swapFlag) { ConvertLong(raw->rowStart, x/sizeof(unsigned int)); ConvertLong((unsigned int *)raw->rowSize, x/sizeof(int)); } } return raw; }
/* Open RGB Image */ static ImageRec *ImageOpen(FILE *f) { union { int testWord; char testByte[4]; } endianTest; ImageRec *image; int swapFlag; int x; endianTest.testWord = 1; if (endianTest.testByte[0] == 1) swapFlag = 1; else swapFlag = 0; image = (ImageRec *)malloc(sizeof(ImageRec)); if (image == NULL) { fprintf(stderr, "Out of memory!\n"); exit(1); } image->file = f; fread(image, 1, 12, image->file); if (swapFlag) ConvertShort(&image->imagic, 6); image->tmp = (unsigned char *)malloc(image->xsize*256); image->tmpR = (unsigned char *)malloc(image->xsize*256); image->tmpG = (unsigned char *)malloc(image->xsize*256); image->tmpB = (unsigned char *)malloc(image->xsize*256); if (image->tmp == NULL || image->tmpR == NULL || image->tmpG == NULL || image->tmpB == NULL) { fprintf(stderr, "Out of memory!\n"); exit(1); } if ((image->type & 0xFF00) == 0x0100) { x = image->ysize * image->zsize * sizeof(unsigned); image->rowStart = (unsigned *)malloc(x); image->rowSize = (int *)malloc(x); if (image->rowStart == NULL || image->rowSize == NULL) { fprintf(stderr, "Out of memory!\n"); exit(1); } image->rleEnd = 512 + (2 * x); fseek(image->file, 512+SEEK_SET_POS, SEEK_SET); fread(image->rowStart, 1, x, image->file); fread(image->rowSize, 1, x, image->file); if (swapFlag) { ConvertLong(image->rowStart, x/(int)sizeof(unsigned)); ConvertLong((unsigned *)image->rowSize, x/(int)sizeof(int)); } } else { image->rowStart = NULL; image->rowSize = NULL; } return image; }