// Avisynth C Interface Version 0.11 Examples File // Copyright 2003 Kevin Atkinson // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // See example.html for a detailed explanation of this filter. #include "avisynth_c.h" AVS_VideoFrame * AVSC_CC invert_get_frame (AVS_FilterInfo * p, int n) { AVS_VideoFrame * src, * dest; int row_size, height, src_pitch, dest_pitch; const BYTE * src_data; BYTE * dest_data; int y, x; src = avs_get_frame(p->child, n); dest = avs_new_video_frame(p->env, &p->vi); src_data = avs_get_read_ptr(src); dest_data = avs_get_write_ptr(dest); src_pitch = avs_get_pitch(src); dest_pitch = avs_get_pitch(dest); row_size = avs_get_row_size(src); height = avs_get_height(src); for (y = 0; y < height; y++) { for (x = 0; x < row_size; x++) dest_data[x] = src_data[x] ^ 255; src_data += src_pitch; dest_data += dest_pitch; } avs_release_video_frame(src); return dest; } AVS_VideoFrame * AVSC_CC invert_inplace_get_frame (AVS_FilterInfo * p, int n) { AVS_VideoFrame * frame; int row_size, height, pitch; BYTE * data; int y, x; frame = avs_get_frame(p->child, n); avs_make_writable(p->env, &frame); data = avs_get_write_ptr(frame); pitch = avs_get_pitch(frame); row_size = avs_get_row_size(frame); height = avs_get_height(frame); for (y = 0; y < height; y++) { for (x = 0; x < row_size; x++) data[x] ^= 255; data += pitch; } return frame; } AVS_Value AVSC_CC invert (AVS_ScriptEnvironment * env, AVS_Value args, void * use_inplace) { AVS_Value v; AVS_FilterInfo * fi; AVS_Clip * new_clip = avs_new_c_filter(env, &fi, avs_array_elt(args, 0), 1); if (avs_is_planar(&fi->vi)) { v = avs_new_value_error("Video must be on a single plane"); } else { fi->get_frame = use_inplace ? invert_get_frame : invert_inplace_get_frame; v = avs_new_value_clip(new_clip); } avs_release_clip(new_clip); return v; } const char * avisynth_c_plugin_init(AVS_ScriptEnvironment * env) { avs_add_function(env, "Invert", "c", invert, 0); avs_add_function(env, "InvertInplace", "c", invert, (void *)1); return "`Invert' sample plugin"; }