package org.jcodec.codecs.h264;

import static org.junit.Assert.assertNotNull;

import java.nio.ByteBuffer;

import org.jcodec.codecs.h264.encode.H264FixedRateControl;
import org.jcodec.common.VideoEncoder.EncodedFrame;
import org.jcodec.common.model.ColorSpace;
import org.jcodec.common.model.Picture;
import org.junit.Test;

public class H264EncoderTest {
    @Test
    public void canEncodeYuv444() throws Exception {
        H264Encoder encoder = H264Encoder.createH264Encoder();
        encode444(encoder);
    }

    /**
     * test for issue https://github.com/jcodec/jcodec/issues/231
     */
    @Test
    public void canEncodeYuv444WithRateControl() throws Exception {
        H264Encoder encoder = new H264Encoder(new H264FixedRateControl(4));
        encode444(encoder);
    }

    private void encode444(H264Encoder encoder) {
        int displayWidth = 1920;
        int displayHeight = 1080;
        int uncompressedSize = displayWidth * displayHeight * 3;

        Picture picture = Picture.create(displayWidth, displayHeight, ColorSpace.YUV444);

        ByteBuffer buffer = ByteBuffer.allocate(uncompressedSize);

        EncodedFrame encodedFrame = encoder.encodeFrame(picture, buffer);
        assertNotNull(encodedFrame);
    }

}

@@ -487,35 +487,32 @@
       encode
-444
 (encoder
 );%0A    %7D%0A%0A  
@@ -491,32 +491,415 @@
   encode(encoder
+, ColorSpace.YUV444);%0A    %7D%0A    %0A    @Test%0A    public void canEncodeYuv420() throws Exception %7B%0A        H264Encoder encoder = H264Encoder.createH264Encoder();%0A        encode(encoder, ColorSpace.YUV420);%0A    %7D%0A    %0A    @Test%0A    public void canEncodeYuv420J() throws Exception %7B%0A        H264Encoder encoder = H264Encoder.createH264Encoder();%0A        encode(encoder, ColorSpace.YUV420J
 );%0A    %7D%0A%0A    /*
@@ -1146,19 +1146,16 @@
 code
-444
 (encoder
 );%0A 
@@ -1150,16 +1150,35 @@
 (encoder
+, ColorSpace.YUV444
 );%0A    %7D
@@ -1202,19 +1202,16 @@
 d encode
-444
 (H264Enc
@@ -1222,16 +1222,39 @@
  encoder
+, ColorSpace colorSpace
 ) %7B%0A    
@@ -1452,17 +1452,17 @@
 Height, 
-C
+c
 olorSpac
@@ -1462,23 +1462,16 @@
 lorSpace
-.YUV444
 );%0A%0A    

test other commonly used colorspaces