/*-
 *  * Copyright 2016 Skymind, Inc.
 *  *
 *  *    Licensed under the Apache License, Version 2.0 (the "License");
 *  *    you may not use this file except in compliance with the License.
 *  *    You may obtain a copy of the License at
 *  *
 *  *        http://www.apache.org/licenses/LICENSE-2.0
 *  *
 *  *    Unless required by applicable law or agreed to in writing, software
 *  *    distributed under the License is distributed on an "AS IS" BASIS,
 *  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  *    See the License for the specific language governing permissions and
 *  *    limitations under the License.
 */
package org.datavec.image.transform;

import org.bytedeco.javacv.FFmpegFrameFilter;
import org.bytedeco.javacv.FrameFilter;
import org.datavec.image.data.ImageWritable;
import org.nd4j.shade.jackson.annotation.JsonIgnoreProperties;
import org.nd4j.shade.jackson.annotation.JsonInclude;
import org.nd4j.shade.jackson.annotation.JsonProperty;

import java.util.Random;

import static org.bytedeco.javacpp.avutil.*;

/**
 * Filters images using FFmpeg (libavfilter):
 * <a href="https://ffmpeg.org/ffmpeg-filters.html">FFmpeg Filters Documentation</a>.
 *
 * @author saudet
 * @see FFmpegFrameFilter
 */
@JsonIgnoreProperties({"filter", "converter"})
@JsonInclude(JsonInclude.Include.NON_NULL)
public class FilterImageTransform extends BaseImageTransform {

    /**
     * see the javadoc comments of this class
     */
    private FFmpegFrameFilter filter;

    /**
     * filter strings to use
     */
    private String filters;

    /**
     * width    of the input images
     */
    private int width;

    /**
     * height   of the input images
     */
    private int height;

    /**
     * channels of the input images
     */
    private int channels;

    /** Calls {@code this(filters, width, height, 3)}. */
    public FilterImageTransform(String filters, int width, int height) {
        this(filters, width, height, 3);
    }

    /**
     * Constructs a filtergraph out of the filter specification.
     *
     * @param filters  to use
     * @param width    of the input images
     * @param height   of the input images
     * @param channels of the input images
     */
    public FilterImageTransform(@JsonProperty("filters") String filters,
                                @JsonProperty("width") int width,
                                @JsonProperty("height") int height,
                                @JsonProperty("channels") int channels) {
        super(null);

        this.filters = filters;
        this.width = width;
        this.height = height;
        this.channels = channels;

        int pixelFormat = channels == 1 ? AV_PIX_FMT_GRAY8
                        : channels == 3 ? AV_PIX_FMT_BGR24 : channels == 4 ? AV_PIX_FMT_RGBA : AV_PIX_FMT_NONE;
        if (pixelFormat == AV_PIX_FMT_NONE) {
            throw new IllegalArgumentException("Unsupported number of channels: " + channels);
        }
        try {
            filter = new FFmpegFrameFilter(filters, width, height);
            filter.setPixelFormat(pixelFormat);
            filter.start();
        } catch (FrameFilter.Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public ImageWritable transform(ImageWritable image, Random random) {
        if (image == null) {
            return null;
        }
        try {
            filter.push(image.getFrame());
            image = new ImageWritable(filter.pull());
        } catch (FrameFilter.Exception e) {
            throw new RuntimeException(e);
        }
        return image;
    }

}

@@ -1420,383 +1420,117 @@
     
-/**%0A     * see the javadoc comments of this class%0A     */%0A    private FFmpegFrameFilter filter;%0A%0A    /**%0A     * filter strings to use%0A     */%0A    private String filters;%0A%0A    /**%0A     * width    of the input images%0A     */%0A    private int width;%0A%0A    /**%0A     * height   of the input images%0A     */%0A    private int height;%0A%0A    /**%0A     * channels of the input images%0A     */
+private FFmpegFrameFilter filter;%0A%0A    private String filters;%0A    private int width;%0A    private int height;
 %0A   

remove unnecessary java docs