at_fitting_opts_type * at_fitting_opts_copy (at_fitting_opts_type * original) { at_fitting_opts_type * new_opts; if (original == NULL) return NULL; new_opts = at_fitting_opts_new (); *new_opts = *original; new_opts->backgroundSpec = original->backgroundSpec; new_opts->background_color = original->background_color; return new_opts; }
AVSValue __cdecl Create_AutoTrace(AVSValue args, void* user_data, IScriptEnvironment* env) { PClip clip = args[0].AsClip(); const VideoInfo& vi = clip->GetVideoInfo(); if (vi.IsRGB24()) { at_fitting_opts_type* fitting_opts = at_fitting_opts_new(); // Setting fitting opts based on input fitting_opts->color_count = args[3].AsInt(0); int destWidth = args[1].AsInt(0); int destHeight = args[2].AsInt(0); // If the inputs are left off entirely (or 0 or negative), then use the // input size. If either one is left off (or 0 or negative), then // determine that one based on presevering the aspect ratio of the // given value. if (destWidth <= 0) { if (destHeight <= 0) { destWidth = vi.width; destHeight = vi.height; } else { // Calculate width based off desired height destWidth = destHeight * vi.width / vi.height; } } else if (destHeight <= 0) { // Calculate height based off desired width destHeight = destWidth * vi.height / vi.width; } if (args[4].Defined()) { // background_color int background = args[4].AsInt(); if (background != -1) { // To match the documentation, ignore -1, even though it would // be a valid color. (And argueably makes more sense than // 0xFFFFFF, as it has the alpha channel set to full.) // Note that R and B are swapped. This is by design - rather // than convert a BGR image into an RGB image as AutoTrace // expects, we just let the B and R channels be "backwards" as // within AutoTrace. fitting_opts->background_color = at_color_new( (background & 0x0000FF), (background & 0x00FF00) >> 8, (background & 0xFF0000) >> 16); }
AutoTraceFilter::AutoTraceFilter(PClip aChild, int aWidth, int aHeight, at_fitting_opts_type* aFittingOpts) : GenericVideoFilter(aChild), destWidth(aWidth), destHeight(aHeight) { const VideoInfo& info = child->GetVideoInfo(); srcWidth = info.width; srcHeight = info.height; // At this point, create our bitmap for rendering a frame to renderedFrameData = new BYTE[destWidth * destHeight * 4]; renderedFramePitch = destWidth * 4; memset(renderedFrameData, 0, destWidth * destHeight * 4); renderedFrame = new Gdiplus::Bitmap(destWidth, destHeight, renderedFramePitch, PixelFormat32bppPARGB, (BYTE*) renderedFrameData); graphics = new Gdiplus::Graphics(renderedFrame); graphics->SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias); backgroundColor = new Gdiplus::Color(0); // TODO: Allow RGB32 images //rgb24 = info.IsRGB24(); vi.width = destWidth; vi.height = destHeight; vi.pixel_type = VideoInfo::CS_BGR32; fitting_opts = aFittingOpts == NULL ? at_fitting_opts_new() : aFittingOpts; }