static void VS_CC spliceCreate(const VSMap *in, VSMap *out, void *userData, VSCore *core, const VSAPI *vsapi) { SpliceData d; SpliceData *data; VSNodeRef *cref; int mismatch; int i; int err; int compat = 0; d.numclips = vsapi->propNumElements(in, "clips"); mismatch = !!vsapi->propGetInt(in, "mismatch", 0, &err); if (d.numclips == 1) { // passthrough for the special case with only one clip cref = vsapi->propGetNode(in, "clips", 0, 0); vsapi->propSetNode(out, "clip", cref, 0); vsapi->freeNode(cref); } else { d.node = malloc(sizeof(d.node[0]) * d.numclips); for (i = 0; i < d.numclips; i++) { d.node[i] = vsapi->propGetNode(in, "clips", i, 0); if (isCompatFormat(vsapi->getVideoInfo(d.node[i]))) compat = 1; } if (findCommonVi(d.node, d.numclips, &d.vi, 0, vsapi) && (!mismatch || compat) && !isSameFormat(&d.vi, vsapi->getVideoInfo(d.node[0]))) { for (i = 0; i < d.numclips; i++) vsapi->freeNode(d.node[i]); free(d.node); RETERROR("Splice: clip property mismatch"); } d.numframes = malloc(sizeof(d.numframes[0]) * d.numclips); d.vi.numFrames = 0; for (i = 0; i < d.numclips; i++) { d.numframes[i] = (vsapi->getVideoInfo(d.node[i]))->numFrames; d.vi.numFrames += d.numframes[i]; if (d.numframes[i] == 0 && i != d.numclips - 1) { for (i = 0; i < d.numclips; i++) vsapi->freeNode(d.node[i]); free(d.node); free(d.numframes); RETERROR("Splice: unknown length clips can only be last in a splice operation"); } } if (d.numframes[d.numclips - 1] == 0) d.vi.numFrames = 0; data = malloc(sizeof(d)); *data = d; vsapi->createFilter(in, out, "Splice", spliceInit, spliceGetframe, spliceFree, fmParallel, nfNoCache, data, core); } }
static void VS_CC selectEveryCreate(const VSMap *in, VSMap *out, void *userData, VSCore *core, const VSAPI *vsapi) { SelectEveryData d; SelectEveryData *data; int i; d.cycle = int64ToIntS(vsapi->propGetInt(in, "cycle", 0, 0)); if (d.cycle <= 1) RETERROR("SelectEvery: invalid cycle size"); d.num = vsapi->propNumElements(in, "offsets"); d.offsets = malloc(sizeof(d.offsets[0]) * d.num); for (i = 0; i < d.num; i++) { d.offsets[i] = int64ToIntS(vsapi->propGetInt(in, "offsets", i, 0)); if (d.offsets[i] < 0 || d.offsets[i] >= d.cycle) { free(d.offsets); RETERROR("SelectEvery: invalid offset specified"); } } d.node = vsapi->propGetNode(in, "clip", 0, 0); data = malloc(sizeof(d)); *data = d; vsapi->createFilter(in, out, "SelectEvery", selectEveryInit, selectEveryGetframe, selectEveryFree, fmParallel, nfNoCache, data, core); }
int map_unset(map_t map, void *key, void **olddata) { bucket_t *b, *prev; int hash; if (!map || !key) return RETERROR(EINVAL, -1); hash = map->hashf(map->size, key); b = map->buckets[hash]; prev = 0; while (b) { if (!map->compf(key, b->key)) { if (prev) prev->next = b->next; else map->buckets[hash] = b->next; mem_init(olddata, b->data); map_bucket_free(map, b); return -- map->count;; } prev = b; b = b->next; } return RETERROR(ERANGE, -1); }
static void VS_CC loopCreate(const VSMap *in, VSMap *out, void *userData, VSCore *core, const VSAPI *vsapi) { LoopData d; LoopData *data; int err; d.times = int64ToIntS(vsapi->propGetInt(in, "times", 0, &err)); d.node = vsapi->propGetNode(in, "clip", 0, 0); d.vi = vsapi->getVideoInfo(d.node); if (!d.vi->numFrames) { vsapi->freeNode(d.node); RETERROR("Loop: cannot loop clips with unknown length"); } // early termination for the trivial case if (d.times == 1) { vsapi->propSetNode(out, "clip", d.node, 0); vsapi->freeNode(d.node); return; } data = malloc(sizeof(d)); *data = d; vsapi->createFilter(in, out, "Loop", loopInit, loopGetframe, singleClipFree, fmParallel, nfNoCache, data, core); }
int map_iter_next(map_iter_t iter, void **key, void **data) { if (!iter) return RETERROR(EINVAL, -1); if (iter->index == -1) { iter->index = map_iter_nextbucket(iter, 0); } else { bucket_t *b = iter->bucket->next; if (!b) iter->index = map_iter_nextbucket(iter, iter->index + 1); else iter->bucket = b; } if (!iter->bucket) return 0; mem_init(key, iter->bucket->key); mem_init(data, iter->bucket->data); return ++ iter->count; }
int map_set(map_t map, void *key, void *data, void **olddata) { bucket_t *b; if (!map || !key) return RETERROR(EINVAL, -1); b = map_bucket_find(map, key); if (b) { mem_init(olddata, b->data); b->data = data; } else { int hash; if (!map_resize(map, map->count + 1, 0)) return -1; if (!(b = map_bucket_alloc(map, key, data))) return -1; hash = map->hashf(map->size, key); b->next = map->buckets[hash]; map->buckets[hash] = b; ++ map->count; } return map->count; }
int map_dump(map_t map) { bucket_t *b; int i; if (!map) return RETERROR(EINVAL, -1); printf("map at #%p (size %d, %d elements)\n", map, map->size, map->count); printf("buckets table at #%p\n", map->buckets); for (i = 0; i < map->size; ++i) { b = map->buckets[i]; if (!b) { printf("[%d]: empty\n", i); continue; } printf("[%d]: #%p - key %p - data %p\n", i, b, b->key, b->data); b = b->next; while (b) { printf(" -> #%p - key %p - data %p\n", b, b->key, b->data); b = b->next; } } return 0; }
int map_iter_delete(map_iter_t iter) { if (!iter) return RETERROR(EINVAL, -1); free(iter); return 0; }
void *map_get(map_t map, void *key) { bucket_t *b; if (!map || !key) return RETERROR(EINVAL, 0); b = map_bucket_find(map, key); return (b ? b->data : 0); }
int map_delete(map_t map) { if (!map) return RETERROR(EINVAL, -1); map_set_buckets(map, 0, 0); DPRINT(("freeing map at %p\n", map)); free(map); return 0; }
static void VS_CC interleaveCreate(const VSMap *in, VSMap *out, void *userData, VSCore *core, const VSAPI *vsapi) { InterleaveData d; InterleaveData *data; VSNodeRef *cref; int i; int err; int compat; int mismatch = !!vsapi->propGetInt(in, "mismatch", 0, &err); int extend = !!vsapi->propGetInt(in, "extend", 0, &err); d.numclips = vsapi->propNumElements(in, "clips"); if (d.numclips == 1) { // passthrough for the special case with only one clip cref = vsapi->propGetNode(in, "clips", 0, 0); vsapi->propSetNode(out, "clip", cref, 0); vsapi->freeNode(cref); } else { d.node = malloc(sizeof(d.node[0]) * d.numclips); compat = 0; for (i = 0; i < d.numclips; i++) { d.node[i] = vsapi->propGetNode(in, "clips", i, 0); if (isCompatFormat(vsapi->getVideoInfo(d.node[i]))) compat = 1; } if (findCommonVi(d.node, d.numclips, &d.vi, 1, vsapi) && (!mismatch || compat)) { for (i = 0; i < d.numclips; i++) vsapi->freeNode(d.node[i]); free(d.node); RETERROR("Interleave: clip property mismatch"); } if (extend) { d.vi.numFrames *= d.numclips; } else if (d.vi.numFrames) { // this is exactly how avisynth does it d.vi.numFrames = (vsapi->getVideoInfo(d.node[0])->numFrames - 1) * d.numclips + 1; for (i = 1; i < d.numclips; i++) d.vi.numFrames = VSMAX(d.vi.numFrames, (vsapi->getVideoInfo(d.node[i])->numFrames - 1) * d.numclips + i + 1); } d.vi.fpsNum *= d.numclips; data = malloc(sizeof(d)); *data = d; vsapi->createFilter(in, out, "Interleave", interleaveInit, interleaveGetframe, interleaveFree, fmParallel, nfNoCache, data, core); } }
static void lut2CreateHelper(const VSMap *in, VSMap *out, VSFuncRef *func, std::unique_ptr<Lut2Data> &d, VSCore *core, const VSAPI *vsapi) { int inrange = (1 << d->vi[0]->format->bitsPerSample) * (1 << d->vi[1]->format->bitsPerSample); int maxval = 1 << d->vi_out.format->bitsPerSample; d->lut = malloc(inrange * sizeof(V)); if (func) { std::string errstr; funcToLut2<V>(1 << d->vi[0]->format->bitsPerSample, 1 << d->vi[1]->format->bitsPerSample, maxval, d->lut, func, vsapi, errstr); vsapi->freeFunc(func); if (!errstr.empty()) RETERROR(errstr.c_str()); } else { V *lut = reinterpret_cast<V *>(d->lut); if (std::numeric_limits<V>::is_integer) { const int64_t *arr = vsapi->propGetIntArray(in, "lut", nullptr); for (int i = 0; i < inrange; i++) { int64_t v = arr[i]; if (v < 0 || v >= maxval) RETERROR(("Lut2: lut value " + std::to_string(v) + " out of valid range [0," + std::to_string(maxval) + "]").c_str()); lut[i] = static_cast<V>(v); } } else { const double *arr = vsapi->propGetFloatArray(in, "lutf", nullptr); for (int i = 0; i < inrange; i++) { double v = arr[i]; lut[i] = static_cast<V>(v); } } } vsapi->createFilter(in, out, "Lut2", lut2Init, lut2Getframe<T, U, V>, lut2Free, fmParallel, 0, d.release(), core); }
static void VS_CC reverseCreate(const VSMap *in, VSMap *out, void *userData, VSCore *core, const VSAPI *vsapi) { SingleClipData d; SingleClipData *data; d.node = vsapi->propGetNode(in, "clip", 0, 0); d.vi = vsapi->getVideoInfo(d.node); if (!d.vi->numFrames) { vsapi->freeNode(d.node); RETERROR("Reverse: cannot reverse clips with unknown length"); } data = malloc(sizeof(d)); *data = d; vsapi->createFilter(in, out, "Reverse", singleClipInit, reverseGetframe, singleClipFree, fmParallel, nfNoCache, data, core); }
map_iter_t map_iter_new(map_t map) { map_iter_t iter; if (!map) return RETERROR(EINVAL, 0); if (!(iter = (map_iter_t) malloc(sizeof(struct map_iter_type)))) return NULL; iter->map = map; iter->bucket = NULL; iter->index = -1; iter->count = 0; DPRINT(("iterator allocated at %p\n", iter)); return iter; }
int map_clear(map_t map, int newsize) { int i; bucket_t *b; if (!map || !newsize) return RETERROR(EINVAL, -1); for (i = 0; i < map->size; ++i) { b = map->buckets[i]; while (b) b = map_bucket_free(map, b); map->buckets[i] = 0; } DPRINT(("clear buckets table at %p\n", map->buckets)); map->count = 0; return (map_resize(map, newsize, 1) > 0 ? 0 : -1); }
static int map_calc_size(int size) { int i; if (size == MAP_SIZE_AUTO) size = table_sizes[0]; /* ensure using only prime numbers */ for (i = 0; i < num_table_sizes; ++i) { if (table_sizes[i] >= size) { size = table_sizes[i]; break; } } if (i == num_table_sizes) return RETERROR(ERANGE, -1); DPRINT(("calculated table size to %d\n", size)); return size; }
int mainPDF2SWF(int argn, char *argv[], void *stream, void *pdfDoc, ExportSWFParams *exportParams) #endif { char buf[256]; int numfonts = 0; int t; char t1searchpath[1024]; int nup_pos = 0; int x,y; int one_file_per_page = 0; int ret = 0; initLog(0,-1,0,0,-1,loglevel); srand(time(0)); processargs(argn, argv); driver = gfxsource_pdf_create(); /* pass global parameters to PDF driver*/ parameter_t*p = device_config; while(p) { driver->setparameter(driver, p->name, p->value); p = p->next; } #ifndef _CONSOLE if(openStream) filename = "stream"; #endif if(!filename) { fprintf(stderr, "Please specify an input file\n"); RETERROR(1); } if (!info_only) { if(!outputname) { if(filename) { outputname = stripFilename(filename, ".swf"); msg("<notice> Output filename not given. Writing to %s", outputname); } } if(!outputname) { fprintf(stderr, "Please use -o to specify an output file\n"); RETERROR(2); } } // test if the page range is o.k. is_in_range(0x7fffffff, pagerange); if (!filename) { args_callback_usage(argv[0]); RETERROR(1,0); } char fullname[256]; if(password && *password) { sprintf(fullname, "%s|%s", filename, password); filename = fullname; } if(pagerange) driver->setparameter(driver, "pages", pagerange); /* add fonts */ for(t=0;t<fontpathpos;t++) { driver->setparameter(driver, "fontdir", fontpaths[t]); } #ifdef _CONSOLE if(info_only) { show_info(driver, filename); return 0; } #endif char*u = 0; if((u = strchr(outputname, '%'))) { if(strchr(u+1, '%') || strchr(outputname, '%')!=u) { msg("<error> only one %% allowed in filename\n"); RETERROR(3); } if(preloader || viewer) { msg("<error> -b/-l/-B/-L not supported together with %% in filename\n"); RETERROR(4); } //msg("<notice> outputting one file per page"); one_file_per_page = 1; char*pattern = (char*)malloc(strlen(outputname)+2); /* convert % to %d */ int l = u-outputname+1; memcpy(pattern, outputname, l); pattern[l]='d'; strcpy(pattern+l+1, outputname+l); outputname = pattern; } #ifdef _CONSOLE gfxdocument_t* pdf = driver->open(driver, filename); #else gfxdocument_t* pdf; if(openStream) pdf = driver->open_stream(driver, stream, pdfDoc); else pdf = driver->open(driver, filename); #endif if(!pdf) { msg("<error> Couldn't open %s", filename); RETERROR(5); } /* pass global parameters document */ p = device_config; while(p) { pdf->setparameter(pdf, p->name, p->value); p = p->next; } struct mypage_t { int x; int y; gfxpage_t*page; } pages[4]; int pagenum = 0; int frame = 1; int pagenr; for(pagenr = 1; pagenr <= pdf->num_pages; pagenr++) { if(is_in_range(pagenr, pagerange)) { char mapping[80]; sprintf(mapping, "%d:%d", pagenr, frame); pdf->setparameter(pdf, "pagemap", mapping); pagenum++; } if(pagenum == xnup*ynup || (pagenr == pdf->num_pages && pagenum>1)) { pagenum = 0; frame++; } } if(pagerange && !pagenum && frame==1) { fprintf(stderr, "No pages in range %s", pagerange); RETERROR(6); } pagenum = 0; gfxdevice_t*out = create_output_device();; pdf->prepare(pdf, out); for(pagenr = 1; pagenr <= pdf->num_pages; pagenr++) { DWORD waitRes = WaitForSingleObject(exportParams->hExportSwfCancel,0); if(waitRes == WAIT_OBJECT_0){ SetEvent(exportParams->hExportSwfCancelled); ret = 1; goto clean; }else{ if(exportParams->m_ExportSwfProgressHandle != 0){ if(!exportParams->m_ExportSwfProgressHandle(pdf->num_pages,pagenr) !=0){ SetEvent(exportParams->hExportSwfCancelled); ret = 4; goto clean; } } } if(is_in_range(pagenr, pagerange)) { gfxpage_t* page = pages[pagenum].page = pdf->getpage(pdf, pagenr); pages[pagenum].x = 0; pages[pagenum].y = 0; pages[pagenum].page = page; pagenum++; } if(pagenum == xnup*ynup || (pagenr == pdf->num_pages && pagenum>1)) { int t; int *xmax = new int[xnup]; //[xnup] int *ymax = new int[xnup]; //[xnup]; int x,y; int width=0, height=0; memset(xmax, 0, xnup*sizeof(int)); memset(ymax, 0, ynup*sizeof(int)); for(y=0;y<ynup;y++) for(x=0;x<xnup;x++) { int t = y*xnup + x; if(pages[t].page->width > xmax[x]) xmax[x] = (int)pages[t].page->width; if(pages[t].page->height > ymax[y]) ymax[y] = (int)pages[t].page->height; } for(x=0;x<xnup;x++) { width += xmax[x]; xmax[x] = width; } for(y=0;y<ynup;y++) { height += ymax[y]; ymax[y] = height; } if(custom_clip) { out->startpage(out,clip_x2 - clip_x1, clip_y2 - clip_y1); } else { out->startpage(out,width,height); } for(t=0;t<pagenum;t++) { int x = t%xnup; int y = t/xnup; int xpos = x>0?xmax[x-1]:0; int ypos = y>0?ymax[y-1]:0; msg("<verbose> Render (%d,%d) move:%d/%d\n", (int)(pages[t].page->width + xpos), (int)(pages[t].page->height + ypos), xpos, ypos); pages[t].page->rendersection(pages[t].page, out, custom_move? move_x : xpos, custom_move? move_y : ypos, custom_clip? clip_x1 : 0 + xpos, custom_clip? clip_y1 : 0 + ypos, custom_clip? clip_x2 : pages[t].page->width + xpos, custom_clip? clip_y2 : pages[t].page->height + ypos); } out->endpage(out); for(t=0;t<pagenum;t++) { pages[t].page->destroy(pages[t].page); } pagenum = 0; if(one_file_per_page) { gfxresult_t*result = out->finish(out);out=0; char buf[1024]; sprintf(buf, outputname, pagenr); if(result->save(result, buf) < 0) { return 1; } result->destroy(result);result=0; out = create_output_device();; msg("<notice> Writing SWF file %s", buf); } delete xmax; delete ymax; } } if(one_file_per_page) { // remove empty device gfxresult_t*result = out->finish(out);out=0; result->destroy(result);result=0; } else { gfxresult_t*result = out->finish(out); msg("<notice> Writing SWF file %s", outputname); if(result->save(result, outputname) < 0) ret = 7; int width = (int)(ptroff_t)result->get(result, "width"); int height = (int)(ptroff_t)result->get(result, "height"); result->destroy(result);result=0; if(preloader && viewer && ret == 0) { #ifdef HAVE_MKSTEMP char tmpname[] = "__swf__XXXXXX"; int fileTmp = mkstemp(tmpname); close(fileTmp); #else char*tmpname = "__tmp__.swf"; #endif char buf[1024]; char buf2[1024];char buf3[1024];char buf4[1024];char buf5[50]; char buf6[50]; char buf7[50]; sprintf(buf,"viewport=%s", outputname); sprintf(buf2, "-o%s", tmpname); char *argvCombine[4] = {"swfcombine", viewer, buf, buf2 }; mainCombine(4, argvCombine); sprintf(buf, "%s/PreLoaderTemplate.swf", SWFDIR); sprintf(buf2, "loader=%s", preloader); sprintf(buf3, "movie=%s", tmpname); sprintf(buf4, "-o%s", outputname); sprintf(buf5, "-X %d", width); sprintf(buf6, "-Y %d", height); sprintf(buf7, "-r %f", getRate(preloader)); if(zlib) { char *argvCombine2[9] = {"swfcombine","-z", buf5, buf6, buf7, buf, buf2, buf3, buf4 }; ret = mainCombine(9, argvCombine2); } else { char *argvCombine2[8] = {"swfcombine", buf5, buf6, buf7, buf, buf2, buf3, buf4 }; ret = mainCombine(8, argvCombine2); } remove(tmpname); } } clean: pdf->destroy(pdf); driver->destroy(driver); SetEvent(exportParams->hExportSwfFinished); if(exportParams->m_ExportSwfFinishHandle !=0) exportParams->m_ExportSwfFinishHandle(); /* free global parameters */ p = device_config; while(p) { parameter_t*next = p->next; if(p->name) free((void*)p->name);p->name = 0; if(p->value) free((void*)p->value);p->value =0; p->next = 0; free(p); p = next; } device_config=0; if(filters) { free(filters); } filters=0; return ret; }
static void VS_CC lut2Create(const VSMap *in, VSMap *out, void *userData, VSCore *core, const VSAPI *vsapi) { std::unique_ptr<Lut2Data> d(new Lut2Data(vsapi)); d->node[0] = vsapi->propGetNode(in, "clipa", 0, 0); d->node[1] = vsapi->propGetNode(in, "clipb", 0, 0); d->vi[0] = vsapi->getVideoInfo(d->node[0]); d->vi[1] = vsapi->getVideoInfo(d->node[1]); if (!isConstantFormat(d->vi[0]) || !isConstantFormat(d->vi[1])) RETERROR("Lut2: only clips with constant format and dimensions supported"); if (isCompatFormat(d->vi[0]) || isCompatFormat(d->vi[1])) RETERROR("Lut2: compat formats are not supported"); if (d->vi[0]->format->sampleType != stInteger || d->vi[1]->format->sampleType != stInteger || (d->vi[0]->format->bitsPerSample + d->vi[1]->format->bitsPerSample) > 20 || d->vi[0]->format->subSamplingH != d->vi[1]->format->subSamplingH || d->vi[0]->format->subSamplingW != d->vi[1]->format->subSamplingW || d->vi[0]->width != d->vi[1]->width || d->vi[0]->height != d->vi[1]->height) RETERROR("Lut2: only clips with integer samples, same dimensions, same subsampling and up to a total of 20 indexing bits supported"); int n = d->vi[0]->format->numPlanes; int num_planes = vsapi->propNumElements(in, "planes"); for (int i = 0; i < 3; i++) d->process[i] = (num_planes <= 0); for (int i = 0; i < num_planes; i++) { int o = int64ToIntS(vsapi->propGetInt(in, "planes", i, 0)); if (o < 0 || o >= n) RETERROR("Lut2: plane index out of range"); if (d->process[o]) RETERROR("Lut2: plane specified twice"); d->process[o] = true; } int err; VSFuncRef *func = vsapi->propGetFunc(in, "function", 0, &err); int lut_elem = vsapi->propNumElements(in, "lut"); int lutf_elem = vsapi->propNumElements(in, "lutf"); bool floatout = !!vsapi->propGetInt(in, "floatout", 0, &err); int num_set = (lut_elem >= 0) + (lutf_elem >= 0) + !!func; if (!num_set) { vsapi->freeFunc(func); RETERROR("Lut2: none of lut, lutf and function are set"); } if (num_set > 1) { vsapi->freeFunc(func); RETERROR("Lut2: more than one of lut, lutf and function are set"); } if (lut_elem >= 0 && floatout) { vsapi->freeFunc(func); RETERROR("Lut2: lut set but float output specified"); } if (lutf_elem >= 0 && !floatout) { vsapi->freeFunc(func); RETERROR("Lut2: lutf set but float output not specified"); } n = 1 << (d->vi[0]->format->bitsPerSample + d->vi[1]->format->bitsPerSample); int lut_length = std::max(lut_elem, lutf_elem); if (lut_length >= 0 && lut_length != n) { vsapi->freeFunc(func); RETERROR(("Lut2: bad lut length. Expected " + std::to_string(n) + " elements, got " + std::to_string(lut_length) + " instead").c_str()); } int bitsout = int64ToIntS(vsapi->propGetInt(in, "bits", 0, &err)); if (err) bitsout = floatout ? sizeof(float) * 8 : d->vi[0]->format->bitsPerSample; if ((floatout && bitsout != 32) || (!floatout && (bitsout < 8 || bitsout > 16))) { vsapi->freeFunc(func); RETERROR("Lut2: only 8-16 bit integer and 32 bit float output supported"); } d->vi_out = *d->vi[0]; d->vi_out.format = vsapi->registerFormat(d->vi[0]->format->colorFamily, floatout ? stFloat : stInteger, bitsout, d->vi[0]->format->subSamplingW, d->vi[0]->format->subSamplingH, core); if (d->vi[0]->format->bytesPerSample == 1) { if (d->vi[1]->format->bytesPerSample == 1) { if (d->vi_out.format->bytesPerSample == 1 && d->vi_out.format->sampleType == stInteger) lut2CreateHelper<uint8_t, uint8_t, uint8_t>(in, out, func, d, core, vsapi); else if (d->vi_out.format->bytesPerSample == 2 && d->vi_out.format->sampleType == stInteger) lut2CreateHelper<uint8_t, uint8_t, uint16_t>(in, out, func, d, core, vsapi); else if (d->vi_out.format->bitsPerSample == 32 && d->vi_out.format->sampleType == stFloat) lut2CreateHelper<uint8_t, uint8_t, float>(in, out, func, d, core, vsapi); } else if (d->vi[1]->format->bytesPerSample == 2) { if (d->vi_out.format->bytesPerSample == 1 && d->vi_out.format->sampleType == stInteger) lut2CreateHelper<uint8_t, uint16_t, uint8_t>(in, out, func, d, core, vsapi); else if (d->vi_out.format->bytesPerSample == 2 && d->vi_out.format->sampleType == stInteger) lut2CreateHelper<uint8_t, uint16_t, uint16_t>(in, out, func, d, core, vsapi); else if (d->vi_out.format->bitsPerSample == 32 && d->vi_out.format->sampleType == stFloat) lut2CreateHelper<uint8_t, uint16_t, float>(in, out, func, d, core, vsapi); } } else if (d->vi[0]->format->bytesPerSample == 2) { if (d->vi[1]->format->bytesPerSample == 1) { if (d->vi_out.format->bytesPerSample == 1 && d->vi_out.format->sampleType == stInteger) lut2CreateHelper<uint16_t, uint8_t, uint8_t>(in, out, func, d, core, vsapi); else if (d->vi_out.format->bytesPerSample == 2 && d->vi_out.format->sampleType == stInteger) lut2CreateHelper<uint16_t, uint8_t, uint16_t>(in, out, func, d, core, vsapi); else if (d->vi_out.format->bitsPerSample == 32 && d->vi_out.format->sampleType == stFloat) lut2CreateHelper<uint16_t, uint8_t, float>(in, out, func, d, core, vsapi); } else if (d->vi[1]->format->bytesPerSample == 2) { if (d->vi_out.format->bytesPerSample == 1 && d->vi_out.format->sampleType == stInteger) lut2CreateHelper<uint16_t, uint16_t, uint8_t>(in, out, func, d, core, vsapi); else if (d->vi_out.format->bytesPerSample == 2 && d->vi_out.format->sampleType == stInteger) lut2CreateHelper<uint16_t, uint16_t, uint16_t>(in, out, func, d, core, vsapi); else if (d->vi_out.format->bitsPerSample == 32 && d->vi_out.format->sampleType == stFloat) lut2CreateHelper<uint16_t, uint16_t, float>(in, out, func, d, core, vsapi); } } }
static void VS_CC trimCreate(const VSMap *in, VSMap *out, void *userData, VSCore *core, const VSAPI *vsapi) { TrimData d; TrimData *data; int firstset; int lastset; int lengthset; int err; d.first = 0; d.last = -1; d.length = -1; d.first = int64ToIntS(vsapi->propGetInt(in, "first", 0, &err)); firstset = !err; d.last = int64ToIntS(vsapi->propGetInt(in, "last", 0, &err)); lastset = !err; d.length = int64ToIntS(vsapi->propGetInt(in, "length", 0, &err)); lengthset = !err; if (lastset && lengthset) RETERROR("Trim: both last frame and length specified"); if (lastset && d.last < d.first) RETERROR("Trim: invalid last frame specified"); if (lengthset && d.length < 1) RETERROR("Trim: invalid length specified"); if (d.first < 0) RETERROR("Trim: invalid first frame specified"); d.node = vsapi->propGetNode(in, "clip", 0, 0); d.vi = *vsapi->getVideoInfo(d.node); if ((lastset && d.vi.numFrames && d.last >= d.vi.numFrames) || (lengthset && d.vi.numFrames && (d.first + d.length) > d.vi.numFrames) || (d.vi.numFrames && d.vi.numFrames <= d.first)) { vsapi->freeNode(d.node); RETERROR("Trim: last frame beyond clip end"); } if (lastset) { d.trimlen = d.last - d.first + 1; } else if (lengthset) { d.trimlen = d.length; } else if (d.vi.numFrames) { d.trimlen = d.vi.numFrames - d.first; } else { d.trimlen = 0; } // obvious nop() so just pass through the input clip if ((!firstset && !lastset && !lengthset) || (d.trimlen && d.trimlen == d.vi.numFrames)) { vsapi->propSetNode(out, "clip", d.node, 0); vsapi->freeNode(d.node); return; } data = malloc(sizeof(d)); *data = d; vsapi->createFilter(in, out, "Trim", trimInit, trimGetframe, singleClipFree, fmParallel, nfNoCache, data, core); }
int map_count(map_t map) { if (!map) return RETERROR(EINVAL, -1); return map->count; }
static void VS_CC resizeCreate(const VSMap *in, VSMap *out, void *userData, VSCore *core, const VSAPI *vsapi) { ResizeData d; ResizeData *data; int id; int dstwidth; int dstheight; int pf; int err; d.context = 0; d.dstrange = 0; d.lsrcformat = 0; d.lsrch = 0; d.lsrcw = 0; d.node = 0; d.flags = (intptr_t)userData; d.node = vsapi->propGetNode(in, "clip", 0, 0); d.vi = *vsapi->getVideoInfo(d.node); dstwidth = int64ToIntS(vsapi->propGetInt(in, "width", 0, &err)); if (err) dstwidth = d.vi.width; dstheight = int64ToIntS(vsapi->propGetInt(in, "height", 0, &err)); if (err) dstheight = d.vi.height; id = int64ToIntS(vsapi->propGetInt(in, "format", 0, &err)); if (err && d.vi.format) id = d.vi.format->id; if (dstwidth > 0) d.vi.width = dstwidth; if (dstheight > 0) d.vi.height = dstheight; pf = formatIdToPixelFormat(id); if (pf == PIX_FMT_NONE) { vsapi->freeNode(d.node); RETERROR("Resize: unsupported output format"); } d.vi.format = vsapi->getFormatPreset(id, core); if ((d.vi.width % (1 << d.vi.format->subSamplingW)) || (d.vi.height % (1 << d.vi.format->subSamplingH))) { vsapi->freeNode(d.node); RETERROR("Resize: mod requirements of the target colorspace not fulfilled"); } if (!isConstantFormat(&d.vi)) { vsapi->freeNode(d.node); RETERROR("Resize: output format not constant, set width, height and format"); } data = malloc(sizeof(d)); *data = d; vsapi->createFilter(in, out, "Resize", resizeInit, resizeGetframe, resizeFree, fmParallelRequests, 0, data, core); }