TagTable *ZimExtractField(TagTable *image) { TagTable *newImage; ImVfb *vfb, *newVfb; int line, pixel; ImVfbPtr im, nim; char colorVal; newImage = ZimImageTagTableNew(ZimWidth(image), ZimHeight(image)/2, ZimFields(image)); TagEntryQValue(TagTableQDirect(image,"image vfb", 0), &vfb); TagEntryQValue(TagTableQDirect(newImage,"image vfb", 0), &newVfb); for (line = 0; line < ZimHeight(image); line+=2) { for (pixel = 0; pixel < ZimWidth(image); pixel++) { im = ImVfbQPtr(vfb, pixel, line); nim = ImVfbQPtr(newVfb, pixel, line/2); colorVal = ImVfbQRed(vfb, im); ImVfbSRed(newVfb, nim, colorVal); colorVal = ImVfbQGreen(vfb, im); ImVfbSGreen(newVfb, nim, colorVal); colorVal = ImVfbQBlue(vfb, im); ImVfbSBlue(newVfb, nim, colorVal); } } return newImage; }
TagTable *ParamImSeqNextImage(ParamImSeq *self) { ImVfb *vfb; TagTable *frameTagTable; time_t now; float rate; self->frameNum++; if (self->frameNum ==1) //The first frame (#0) could include a large amount of time seeking { self->start = time(NULL); } frameTagTable = ParamImSeqNextImageFromParam(self); if (ParamImSeqCurrentFade(self) != 1.0) { TagEntryQValue(TagTableQDirect(frameTagTable, "image vfb", 0), &vfb); ImVfbFade(vfb, ParamImSeqCurrentFade(self), IMVFBRGB, vfb); } self ->hasAlpha = ZimHasAlpha(frameTagTable); if (ParamScaleDown(self->param)) { TagTable *old; old = frameTagTable; frameTagTable = ZimExtractField(frameTagTable); ZimFree(old); } now = time(NULL); rate = 60.0f*(float) self->frameNum/((float) now - self->start); printf("\nParamImSeq: on %s frame %d out of %d, rate = %0.2f frames/min, ETA = %0.2f min\n\n", self ->currentImageFilename, self->frameNum, ParamNumberOfFrames(self->param), rate, ((float) ParamNumberOfFrames(self->param) - self->frameNum)/rate); return frameTagTable; }
TagTable *ZimImageTagTableFromFile(const char *filename, const char *informat) { FILE* fp; /* File pointer */ TagTable* flagsTable; /* Information about how to read the image */ TagTable* dataTable; /* The image data */ char *test; FILE *err; int ret; char format[1025]; if (informat && *informat) { strcpy(format, informat); } else { format[0]='\0'; } err = stderr; /* Open the file */ if (!(fp = fopen(filename,"rb"))) { fprintf(stderr,"Could not open %s\n", filename); exit(4); } if ( (dataTable = TagTableAlloc( )) == TAGTABLENULL ) { TagPError( "roqvq" ); exit( 1 ); } if ( (flagsTable = TagTableAlloc( )) == TAGTABLENULL ) { TagPError( "roqvq" ); exit( 1 ); } /* Add the file name to the flags table */ TagTableAppend( flagsTable, TagEntryAlloc( "file name", POINTER, &filename)); TagTableAppend( flagsTable, TagEntryAlloc( "error stream", POINTER, &err)); TagEntryQValue(TagTableQDirect(flagsTable, "file name", 0), &test); printf(test); printf("\n"); /* Read the file, getting the name of the format */ ret = ImFileFRead(fp, format, flagsTable, dataTable); if (ret == -1) { fprintf(stderr, "Problem reading %s, return code = %d, ImErrNo = %d\n", filename, ret, ImErrNo); ImPError("roqvq: ZimImageTagTableFromFile"); } fclose(fp); return dataTable; }
void ZimFree(TagTable *image) { ImVfb *vfb; if (image) { TagEntryQValue(TagTableQDirect(image, "image vfb", 0), &vfb); ImVfbFree(vfb); TagTableFree(image); } }
void ZimGetDataPlanes(TagTable *image, byte **iPlanes) { ImVfb *vfb; TagEntryQValue(TagTableQDirect(image,"image vfb", 0), &vfb); iPlanes[0] = vfb->vfb_pfirst + vfb->vfb_roff; iPlanes[1] = vfb->vfb_pfirst + vfb->vfb_goff; iPlanes[2] = vfb->vfb_pfirst + vfb->vfb_boff; iPlanes[3] = vfb->vfb_pfirst + vfb->vfb_aoff; return; }
void ZimResize(TagTable *image, int newx, int newy) { ImVfb *vfb; ImVfb *newt; TagEntry *tmpEntry; /* Tmp table entry holder */ int nEntry; /* Tag entry # */ TagEntryQValue(TagTableQDirect(image,"image vfb", 0), &vfb); newt = ImVfbResize( vfb, IMVFBBILINEAR, NULL, newx, newy ); /* Replace the VFB. */ tmpEntry = TagTableQDirect( image, "image vfb", 0 ); nEntry = TagEntryQNthEntry( tmpEntry ); TagTableReplace( image, TagEntryQNthEntry( tmpEntry ), TagEntryAlloc( "image vfb", POINTER, &newt ) ); ImVfbFree(vfb); return; }
BOOL ZimIsPlanar(TagTable *image) { ImVfb *vfb; TagEntryQValue(TagTableQDirect(image,"image vfb", 0), &vfb); return (vfb->vfb_goff - vfb->vfb_roff) > 1 ? 1:0 ; }
int ZimBpp(TagTable *image) { ImVfb *vfb; TagEntryQValue(TagTableQDirect(image,"image vfb", 0), &vfb); return vfb->vfb_nbytes; }
void *ZimData(TagTable *image) { ImVfb *vfb; TagEntryQValue(TagTableQDirect(image,"image vfb", 0), &vfb); return (void *) vfb->vfb_pfirst; }
int ZimFields(TagTable *image) { ImVfb *vfb; TagEntryQValue(TagTableQDirect(image,"image vfb", 0), &vfb); return ImVfbQFields(vfb); }
int ZimHeight(TagTable *image) { ImVfb *vfb; TagEntryQValue(TagTableQDirect(image,"image vfb", 0), &vfb); return ImVfbQHeight(vfb); }
int ZimWidth(TagTable *image) { ImVfb *vfb; TagEntryQValue(TagTableQDirect(image,"image vfb", 0), &vfb); return ImVfbQWidth(vfb); }
TagTable *ParamImSeqNextImageFromParam(ParamImSeq *self) { const char *str; char *ext; TagTable *nextImage = NULL, *unusedImage; int mpegSkipNum; if (self->mpeg) { if (MpegDecoderMoreFrames(self->mpeg)) { nextImage = MpegDecoderNextImage(self->mpeg); if (self->skipFields) { sprintf(self->currentImageFilename, "%s%.06db",MpegDecoderCurrentFilename(self->mpeg),MpegDecoderBitstreamFrameNum(self->mpeg)); } else { sprintf(self->currentImageFilename, "%s%.06d",MpegDecoderCurrentFilename(self->mpeg),MpegDecoderBitstreamFrameNum(self->mpeg)); } if (self->mpegSkipNum > 1) { // skip the required number of images so we're primed for the next pass mpegSkipNum = self->mpegSkipNum -1; while (mpegSkipNum--) { unusedImage = MpegDecoderNextImage(self->mpeg); ZimFree(unusedImage); } } return nextImage; } else { MpegDecoderFree(self->mpeg); self->mpeg = NULL; } } if (ParamMoreFrames(self->param) == YES) { str = ParamGetNextImageFilename(self->param); } else { return NULL; } if ((str == NULL) || (str[0] == '\0')) { return NULL; } else { strcpy(self->currentImageFilename, str); } if( (ext = strstr(self->currentImageFilename , ".mpg")) || (ext = strstr(self->currentImageFilename, ".m2v"))) { char *margv[] = { "mpegstream", "-b", NULL, "-r", "-o6", "-v0", NULL, NULL }; int margc = 6; char *fn; char *frameNum; self->mpegFirstFrame = 0; self->mpegLastFrame = 999999; self->mpegSkipNum = 1; if (ext[4] != '\0') { ParamGetCurrentRange(self->param, &self->mpegFirstFrame, &self->mpegLastFrame, &self->mpegSkipNum ,YES); if (self->mpegLastFrame ==999999) //we didn't have a range { self->mpegLastFrame = atoi(&ext[4]); //use the number by itself, only one frame } } fn = strdup(self->currentImageFilename); frameNum = strrchr(fn, '.')+4; *frameNum = '\0';//remove frame number so mpeg object can open the file margv[2] = fn; if (! self->skipFields) //specify frame flag { margv[margc++] = "-f"; } self->mpeg = MpegDecoderNew(margc, margv, self->mpegFirstFrame, self->mpegLastFrame); return ParamImSeqNextImage(self);/*in case it's an empty mpg...*/ } else { char *secondFilename,firstFilename[MAXPATHLEN+1]; TagTable *image1tt ; ImVfb *img, *image1; int fields; if (!(secondFilename= strchr(self->currentImageFilename,'\n'))) { //one filename, no compositing nextImage = ZimImageTagTableFromFile(self->currentImageFilename, ""); } else { strncpy(firstFilename,self->currentImageFilename,secondFilename-self->currentImageFilename); firstFilename[secondFilename-self->currentImageFilename]='\0'; secondFilename++;//point past the \n image1tt = ZimImageTagTableFromFile(firstFilename, ""); nextImage = ZimImageTagTableFromFile(secondFilename, "");//result will be in here TagEntryQValue(TagTableQDirect(image1tt, "image vfb", 0), &image1); TagEntryQValue(TagTableQDirect(nextImage, "image vfb", 0), &img); //image is the composite of those two fields = IMRED | IMGREEN | IMBLUE; if (ImVfbQFields(img) && IMVFBALPHA) { fields |= IMALPHA; } ImVfbComp(image1, 0, 0, ImVfbQWidth(img), ImVfbQHeight(img), fields, IMCOMPOVER, img, 0, 0); //free image1tt, it's not needed any more ZimFree(image1tt); } } return nextImage; }