Esempio n. 1
0
	Orientation rotate( int8_t amount ) const{
		switch( normalizedRotation( amount ) ){
			case 1: return rotateRight();
			case 2: return rotate180();
			case 3: return rotate180().rotateRight();
			default: return *this;
		}
	}
bool
ImageBufAlgo::rotate180 (ImageBuf &dst, const ImageBuf &src,
                         ROI roi, int nthreads)
{
    if (&dst == &src) {    // Handle in-place operation
        ImageBuf tmp;
        tmp.swap (const_cast<ImageBuf&>(src));
        return rotate180 (dst, tmp, roi, nthreads);
    }

    pvt::LoggedTimer logtime("IBA::rotate180");
    ROI src_roi = roi.defined() ? roi : src.roi();
    ROI src_roi_full = src.roi_full();
    int xoffset = src_roi.xbegin - src_roi_full.xbegin;
    int xstart = src_roi_full.xend - xoffset - src_roi.width();
    int yoffset = src_roi.ybegin - src_roi_full.ybegin;
    int ystart = src_roi_full.yend - yoffset - src_roi.height();
    ROI dst_roi (xstart, xstart+src_roi.width(),
                 ystart, ystart+src_roi.height(),
                 src_roi.zbegin, src_roi.zend,
                 src_roi.chbegin, src_roi.chend);
    ASSERT (dst_roi.width() == src_roi.width() &&
            dst_roi.height() == src_roi.height());

    // Compute the destination ROI, it's the source ROI reflected across
    // the midline of the display window.
    if (! IBAprep (dst_roi, &dst, &src))
        return false;
    bool ok;
    OIIO_DISPATCH_COMMON_TYPES2 (ok, "rotate180", rotate180_,
                          dst.spec().format, src.spec().format,
                          dst, src, dst_roi, nthreads);
    return ok;
}
Esempio n. 3
0
void CApp::onLoop() {
  CFPS::FPSControl.onLoop();

  CEntityCol::entColList.clear();

  map< int, GnmsCursor*>::iterator it;
  tuioClient->lockCursorList(); // lock the cursor list
  for (it=gnmsCursors.begin(); it!=gnmsCursors.end(); it++) {
    GnmsCursor* cur = it->second;
    if (it->second != NULL) {
      if (cur->isLive() == false && cur->isDead() == false) {
	float x, y;
	if (cur->singleTouch(x, y) == true) {
	  bool refreshed = onSingleTouch(x, y);
	  if (refreshed == true) {
	    break;
	  }
	} else if (cur->swipeDown(WHEIGHT/5, WWIDTH/8) == true) {
	  onPrevPage();
	} else if (cur->swipeUp(WHEIGHT/5, WWIDTH/8) == true) {
	  onNextPage();
	} else if (cur->drewCircle(WWIDTH/3, WHEIGHT/4, WWIDTH/8, WHEIGHT/12)
		   == true) {
	  rotate180();
	}
	cur->killCursor();     // cursor has been serviced
      }
    }
  }
  tuioClient->unlockCursorList(); // unlock cursor list

  return;
}
Esempio n. 4
0
File: main.c Progetto: murph141/CTCI
int rotate(int ** arr, int degrees, int size)
{
  if(degrees % 90 != 0)
  {
    printf("Rotation must be a positive factor of 90.\n");
    return(-1);
  }

  while(degrees > 270)
  {
    degrees -= 360;
  }

  switch(degrees)
  {
    case 90:
      rotate90(arr, size);
      break;
    case 180:
      rotate180(arr, size);
      break;
    case 270:
      rotate270(arr, size);
      break;
  }

  return(0);
}
Esempio n. 5
0
// rotate == 1 is 90 degrees, 2 is 180, 3 is 270 (positive is CCW).
static __inline__ void rotate_fun(int rotate, char * source, int srcWidth, int srcHeight, char * destination, int dstWidth, int dstHeight){
    switch( rotate )
    {
        case 1:
            rotate90(source, srcWidth, srcHeight, destination, dstWidth, dstHeight);
            break;
        case 2:
            rotate180(source, srcWidth, srcHeight, destination, dstWidth, dstHeight);
            break;
        case 3:
            rotate270(source, srcWidth, srcHeight, destination, dstWidth, dstHeight);
            break;
        default:
            break;
    }
}
Esempio n. 6
0
CBC_PDF417DetectorResult* CBC_Detector::detect(CBC_BinaryBitmap* image,
                                               int32_t hints,
                                               FX_BOOL multiple,
                                               int32_t& e) {
  CBC_CommonBitMatrix* bitMatrix = image->GetBlackMatrix(e);
  BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
  CFX_PtrArray* barcodeCoordinates = detect(multiple, bitMatrix);
  if (barcodeCoordinates->GetSize() == 0) {
    rotate180(bitMatrix);
    barcodeCoordinates = detect(multiple, bitMatrix);
  }
  if (barcodeCoordinates->GetSize() == 0) {
    e = BCExceptionUnSupportedBarcode;
    BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
  }
  CBC_PDF417DetectorResult* detectorResult =
      new CBC_PDF417DetectorResult(bitMatrix, barcodeCoordinates);
  return detectorResult;
}
Esempio n. 7
0
void 
img_rotate( Handle self, Byte * new_data, int new_line_size, int degrees)
{
	PImage i = ( PImage ) self;

	if (( i-> type & imBPP) < 8 )
		croak("Not implemented");

	switch ( degrees ) {
	case 90:
		rotate90(i, new_data, new_line_size);
		break;
	case 180:
		rotate180(i, new_data);
		break;
	case 270:
		rotate270(i, new_data, new_line_size);
		break;
	}
}
Esempio n. 8
0
void CApp::onKeyUp(SDLKey sym, SDLMod mod, Uint16 unicode) {
  switch(sym) {
  case SDLK_ESCAPE: {
    onExit();
    break;
  }
  case SDLK_n: {
    onNextPage();
    break;
  }
  case SDLK_p: {
    onPrevPage();
    break;
  }
  case SDLK_f: {
    // toggle fullscreen
    SDL_WM_ToggleFullScreen(dispSurf);
    break;
  }
  case SDLK_r: {
    // rotate
    rotate180();
    break;
  }
  case SDLK_c: {
    // toggle cursor
    if (SDL_ShowCursor(SDL_QUERY) == SDL_DISABLE) {
      SDL_ShowCursor(SDL_ENABLE);
    } else {
      SDL_ShowCursor(SDL_DISABLE);
    }
    break;
  }
  default: { // do nothing
  }
  }
  return;
}
ToolsMenu::ToolsMenu(ImageViewer* iv, QWidget* parent) :
    QWidget(parent),
    ui(new Ui::ToolsMenu)
{
    ui->setupUi(this);
    setLayout(ui->verticalLayoutWidget->layout());

    m_viewer = (ImageViewer*) iv;
    m_tools = new Tools(m_viewer, this);

    // locking tools menu when performing transformation

    connect(m_viewer, SIGNAL(lockTools()), this, SLOT(disableAllTools()));
    connect(m_viewer, SIGNAL(unlockTools()), this, SLOT(enableAllTools()));

    /* -------------------------------------------------------
     * ROTATION
     * ------------------------------------------------------- */

    connect(ui->rotate90Button, SIGNAL(clicked()), m_tools, SLOT(rotate90()));
    connect(ui->rotate180Button, SIGNAL(clicked()), m_tools, SLOT(rotate180()));
    connect(ui->rotate270Button, SIGNAL(clicked()), m_tools, SLOT(rotate270()));

    /* -------------------------------------------------------
     * HISTOGRAM
     * ------------------------------------------------------- */

    QMenu* hMenu = new QMenu(ui->histogramButton);
    hMenu->addAction(
                QIcon(":/icons/icons/chart_curve_error.png"),
                QString("Equalize histograms"),
                m_tools,
                SLOT(histogramEqualize())
                );
    hMenu->addAction(
                QIcon(":/icons/icons/chart_curve_go.png"),
                QString("Stretch histograms"),
                m_tools,
                SLOT(histogramStretch())
                );

    ui->histogramButton->setMenu(hMenu);

    /* -------------------------------------------------------
     * FILTERS (convolution, blur)
     * ------------------------------------------------------- */

    QMenu* bMenu = new QMenu(ui->blurButton);
    bMenu->addAction(
                QIcon(":/icons/icons/draw_convolve.png"),
                QString("Gaussian blur"),
                m_tools,
                SLOT(blurGauss())
                );
    bMenu->addAction(
                QIcon(":/icons/icons/draw_convolve.png"),
                QString("Uniform blur"),
                m_tools,
                SLOT(blurUniform())
                );
    bMenu->addAction(
                QIcon(":/icons/icons/flag_airfield_vehicle_safety.png"),
                QString("Custom linear filter"),
                m_tools,
                SLOT(blurLinear())
                );

    ui->blurButton->setMenu(bMenu);

    /* -------------------------------------------------------
     * BINARIZATION
     * ------------------------------------------------------- */

    QMenu* binMenu = new QMenu(ui->binarizationButton);
    binMenu->addAction(
                QIcon(":/icons/icons/universal_binary.png"),
                QString("Manual"),
                m_tools,
                SLOT(binManual())
                );
    binMenu->addAction(
                QIcon(":/icons/icons/universal_binary.png"),
                QString("Gradient"),
                m_tools,
                SLOT(binGradient())
                );
    binMenu->addAction(
                QIcon(":/icons/icons/universal_binary.png"),
                QString("Iterative bimodal"),
                m_tools,
                SLOT(binIterBimodal())
                );
    binMenu->addAction(
                QIcon(":/icons/icons/universal_binary.png"),
                QString("Niblack"),
                m_tools,
                SLOT(binNiblack())
                );
    binMenu->addAction(
                QIcon(":/icons/icons/universal_binary.png"),
                QString("Otsu"),
                m_tools,
                SLOT(binOtsu())
                );

    ui->binarizationButton->setMenu(binMenu);

    /* -------------------------------------------------------
     * NOISE REDUCTION
     * ------------------------------------------------------- */

    QMenu* nMenu = new QMenu(ui->noiseButton);
    nMenu->addAction(
                QIcon(":/icons/icons/checkerboard.png"),
                QString("Median"),
                m_tools,
                SLOT(noiseMedian())
                );
    nMenu->addAction(
                QIcon(":/icons/icons/checkerboard.png"),
                QString("Bilateral"),
                m_tools,
                SLOT(noiseBilateral())
                );

    ui->noiseButton->setMenu(nMenu);

    /* -------------------------------------------------------
     * MORPHOLOGICAL
     * ------------------------------------------------------- */

    QMenu* morphMenu = new QMenu(ui->morphButton);
    morphMenu->addAction(
                QIcon(":/icons/icons/arrow_out.png"),
                QString("Dilate"),
                m_tools,
                SLOT(morphDilate())
                );
    morphMenu->addAction(
                QIcon(":/icons/icons/arrow_in.png"),
                QString("Erode"),
                m_tools,
                SLOT(morphErode())
                );
    morphMenu->addAction(
                QIcon(":/icons/icons/arrow_divide.png"),
                QString("Open"),
                m_tools,
                SLOT(morphOpen())
                );
    morphMenu->addAction(
                QIcon(":/icons/icons/arrow_join.png"),
                QString("Close"),
                m_tools,
                SLOT(morphClose())
                );

    ui->morphButton->setMenu(morphMenu);

    /* -------------------------------------------------------
     * EDGE DETECTION
     * ------------------------------------------------------- */

    QMenu* eMenu = new QMenu(ui->edgeButton);
    eMenu->addAction(
                QIcon(":/icons/icons/key_s.png"),
                QString("Sobel"),
                m_tools,
                SLOT(edgeSobel())
                );
    eMenu->addAction(
                QIcon(":/icons/icons/key_p.png"),
                QString("Prewitt"),
                m_tools,
                SLOT(edgePrewitt())
                );
    eMenu->addAction(
                QIcon(":/icons/icons/key_r.png"),
                QString("Roberts"),
                m_tools,
                SLOT(edgeRoberts())
                );
    eMenu->addAction(
                QIcon(":/icons/icons/edge_detection.png"),
                QString("Laplacian"),
                m_tools,
                SLOT(edgeLaplacian())
                );
    eMenu->addAction(
                QIcon(":/icons/icons/edge_detection.png"),
                QString("Zero-crossing (LoG)"),
                m_tools,
                SLOT(edgeZero())
                );

    eMenu->addAction(
                QIcon(":/icons/icons/edge_detection.png"),
                QString("Canny"),
                m_tools,
                SLOT(edgeCanny())
                );

    ui->edgeButton->setMenu(eMenu);

    /* -------------------------------------------------------
     * TEXTURES
     * ------------------------------------------------------- */

    QMenu* texMenu = new QMenu(ui->textureButton);
    texMenu->addAction(
                QIcon(":/icons/icons/flag_airfield_vehicle_safety.png"),
                QString("Height map"),
                m_tools,
                SLOT(mapHeight())
                );
    texMenu->addAction(
                QIcon(":/icons/icons/flag_airfield_vehicle_safety.png"),
                QString("Normal map"),
                m_tools,
                SLOT(mapNormal())
                );
    texMenu->addAction(
                QIcon(":/icons/icons/flag_airfield_vehicle_safety.png"),
                QString("Horizon map"),
                m_tools,
                SLOT(mapHorizon())
                );
    ui->textureButton->setMenu(texMenu);

    /* -------------------------------------------------------
     * TRANSFORMATIONS
     * ------------------------------------------------------- */

    QMenu* transMenu = new QMenu(ui->transformationsButton);
    transMenu->addAction(
                QIcon(":/icons/icons/videodisplay.png"),
                QString("Hough"),
                m_tools,
                SLOT(houghTransform())
                );
    transMenu->addAction(
                QIcon(":/icons/icons/videodisplay.png"),
                QString("Hough - lines"),
                m_tools,
                SLOT(houghLines())
                );
    transMenu->addAction(
                QIcon(":/icons/icons/videodisplay.png"),
                QString("Hough - rectangles"),
                m_tools,
                SLOT(houghRectangles())
                );
    transMenu->addAction(
                QIcon(":/icons/icons/videodisplay.png"),
                QString("Segmentation"),
                m_tools,
                SLOT(segmentation())
                );
    ui->transformationsButton->setMenu(transMenu);

    /* -------------------------------------------------------
     * CORNER DETECTION
     * ------------------------------------------------------- */

    QMenu* cornerMenu = new QMenu(ui->cornerButton);
    cornerMenu->addAction(
                QIcon(":/icons/icons/things_digital.png"),
                QString("Harris"),
                m_tools,
                SLOT(cornerHarris())
                );
    ui->cornerButton->setMenu(cornerMenu);

}
Esempio n. 10
0
int main(void)
{
    char property[PROPERTY_VALUE_MAX];
    int fd = dup(STDOUT_FILENO);
    //unsigned long fb_lock[2]   = {MTKFB_LOCK_FRONT_BUFFER,   (unsigned long)NULL};
    //unsigned long fb_unlock[2] = {MTKFB_UNLOCK_FRONT_BUFFER, (unsigned long)NULL};
    //unsigned long fb_capture[2] = {MTKFB_CAPTURE_FRAMEBUFFER, (unsigned long)NULL};
    void *base = NULL, *base_align = NULL;
    int capture_buffer_size = 0, capture_buffer_size_align = 0;
    struct fb_var_screeninfo vinfo;
    int fb;
    uint32_t bytespp;
    uint32_t w, h, f;
    size_t size = 0;
    int should_munlock = 0;

	ALOGI("Enter lcdc_screen_cap.");
    if (fd < 0)
    {
        ALOGE("[DDMSCap]Dup STDOUT_FILENO failed!\n");
        goto done;
    }
    if (0 > (fb = open("/dev/graphics/fb0", O_RDONLY))) {
    	ALOGE("[DDMSCap]Open /dev/graphics/fb0 failed!\n");
    	goto done;
    }

    fcntl(fb, F_SETFD, FD_CLOEXEC);
    if(ioctl(fb, FBIOGET_VSCREENINFO, &vinfo) < 0) {
    	ALOGI("[DDMSCap]FBIOGET_VSCREENINFO FAILED!\n");
    	goto done;
    }

    if (vinfoToPixelFormat(&vinfo, &bytespp, &f) == 0) 
    {
        w = vinfo.xres;
        h = vinfo.yres;
        size = w * h * bytespp;
        ALOGI("[DDMSCap]screen_width = %d, screen_height = %d, bpp = %d, format = %d, size = %d\n", w, h, bytespp, f, size);
    }
    {
        capture_buffer_size = w * h * bytespp;
        capture_buffer_size_align = capture_buffer_size + 32; //for M4U 32-byte alignment
        base_align = malloc(capture_buffer_size_align);

        if(base_align == NULL)
        {
            ALOGE("[DDMSCap]pmem_alloc size 0x%08x failed", capture_buffer_size_align);
            goto done;
        }
        else
        {
            ALOGE("[DDMSCap]pmem_alloc size = 0x%08x, addr = 0x%08x", capture_buffer_size_align, (unsigned int)base_align);
        }

        if(mlock(base_align, capture_buffer_size_align))
        {
            ALOGI("[DDMSCap] mlock fail! va=0x%x, size=%d, err=%d, %s\n",
                    base_align, capture_buffer_size_align, errno, strerror(errno));
            should_munlock = 0;
            //goto done;
        }
        else
        {
            should_munlock = 1;
        }


        base = (void *)((unsigned long)base_align + 32 - ((unsigned long)base_align & 0x1F)); //for M4U 32-byte alignment
        ALOGI("[DDMSCap]pmem_alloc base = 0x%08x", (unsigned int)base);
        //fb_capture[1] = (unsigned long)&base;
    	ALOGI("[DDMSCap]start capture\n");
        if(ioctl(fb, MTKFB_CAPTURE_FRAMEBUFFER, (unsigned long)&base) < 0)
        {
            ALOGE("[DDMSCap]ioctl of MTKFB_CAPTURE_FRAMEBUFFER fail\n");
            goto done;
        }
    	ALOGI("[DDMSCap]capture finished\n");
    }

    if (base) 
    {
    	int displayOrientation = 0;

    	if (property_get("ro.sf.hwrotation", property, NULL) > 0) {
    		displayOrientation = atoi(property);
    	}

    	switch(displayOrientation)
    	{
    	case 0:
    	{
    		ALOGI("[DDMSCap]rotate 0 degree\n");
    		write(fd, &w, 4);
    		write(fd, &h, 4);
    		write(fd, &f, 4);			
    		//write(fd, base, size);			
			writex(fd, base, size);
			
    	}
    	break;

    	case 90:
    		ALOGI("[DDMSCap]rotate 90 degree\n");
    		if(rotate90(w,h,f,bytespp,base,size,capture_buffer_size,fd) < 0)
    			goto done;
    		break;

    	case 180:
    		ALOGI("[DDMSCap]rotate 180 degree\n");
    		if(rotate180(w,h,f,bytespp,base,size,capture_buffer_size,fd) < 0)
    			goto done;
    		break;

    	case 270:
    		ALOGI("[DDMSCap]rotate 270 degree\n");
    		if(rotate270(w,h,f,bytespp,base,size,capture_buffer_size,fd) < 0)
    			goto done;
    		break;

    	}
    }

done:
    if (NULL != base_align)
    {
        if(should_munlock)
            munlock(base_align, capture_buffer_size_align);
        free(base_align);
    }
    if(fb >= 0)
        close(fb);
    if(fd >= 0)
        close(fd);
   	ALOGI("[DDMSCap]all capture procedure finished\n");

    return 0;
}
Esempio n. 11
0
bool
ImageBufAlgo::flipflop (ImageBuf &dst, const ImageBuf &src,
                        ROI roi, int nthreads)
{
    return rotate180 (dst, src, roi, nthreads);
}
Esempio n. 12
0
void Java_com_lightbox_android_photoprocessing_PhotoProcessing_nativeRotate180(JNIEnv* env, jobject thiz) {
	rotate180(&bitmap, 1, 1, 1);
}
Esempio n. 13
0
void Java_editimage_fliter_PhotoProcessing_nativeRotate180(JNIEnv *env, jobject thiz) {
	rotate180(&bitmap, 1, 1, 1);
}
Esempio n. 14
0
int main()
{
// load image and get some image properties
    IplImage *p_image = cvLoadImage("lena.jpg");
    //IplImage *p_image = cvLoadImage("obama_90_sw.bmp");

    // create new image structure
    // for the grayscale output image
    IplImage *p_grayImage = cvCreateImage(cvSize( p_image->width, p_image->height ), IPL_DEPTH_8U, 1 );
    // set type CV_RGB2GRAY to convert
    // RGB image to grayscale
    cvCvtColor(p_image, p_grayImage,CV_RGB2GRAY);

// some local variables
    int width      = p_grayImage->width;
    int height     = p_grayImage->height;
    int width_step = p_grayImage->widthStep;
    int x,y;
    printf("width:     %i\n", width);
    printf("heigth:    %i\n", height);

// allocation of a two-dimensional array
    uchar ** array    = (uchar **) malloc(sizeof(uchar *) * height);
    uchar ** tmpArray = (uchar **) malloc(sizeof(uchar *) * height);
    for (y = 0; y < height; y++)
    {
        array[y]    = (uchar *) malloc(sizeof(uchar ) * width);
        tmpArray[y] = (uchar *) malloc(sizeof(uchar ) * width);
    }

// copy IplImage to allocated array
    copyIplImageToArray(height,width,p_grayImage,tmpArray);


// implementation of algorithm 1
    invertGray(height,width,tmpArray,array);

// save result
    saveArrayToImage(height,width,array,p_grayImage);

// create a new image (90 Grad Drehung)
    IplImage *p_rotate90 = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
    rotate90(height,width,tmpArray,array);
    saveArrayToImage(height,width,array,p_rotate90);
// create a new image (180 Grad Drehung)
    IplImage *p_rotate180 = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
    rotate180(height,width,tmpArray,array);
    saveArrayToImage(height,width,array,p_rotate180);
// create a new image (270 Grad Drehung)
    IplImage *p_rotate270 = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
    rotate270(height,width,tmpArray,array);
    saveArrayToImage(height,width,array,p_rotate270);
// create a new image (Vertikale Spiegelung)
    IplImage *p_flipvertical = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
    flipvertical(height,width,tmpArray,array);
    saveArrayToImage(height,width,array,p_flipvertical);
// create a new image (Horizontale Spiegelung)
    IplImage *p_fliphorizontal = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
    fliphorizontal(height,width,tmpArray,array);
    saveArrayToImage(height,width,array,p_fliphorizontal);
// create a new image (Beide Spiegelungen)
    IplImage *p_flipboth = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
    flipboth(height,width,tmpArray,array);
    saveArrayToImage(height,width,array,p_flipboth);
// create a new image (Skalierung Faktor 2)
    IplImage *p_scale2 = cvCreateImage(cvSize(width*2, height*2), IPL_DEPTH_8U, 1);
    scale2(height,width,tmpArray,p_scale2); //Speichert auch
// create a new image (Skalierung Faktor 1/2)
    IplImage *p_scalehalf = cvCreateImage(cvSize(width/2, height/2), IPL_DEPTH_8U, 1);
    scalehalf(height,width,tmpArray,p_scalehalf); //Speichert auch
// create a new image (GrauwertSprünge horizontal)
    IplImage *p_grayhor = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
    grayhor(height,width,tmpArray,array);
    saveArrayToImage(height,width,array,p_grayhor);
// create a new image (GrauwertSprünge vertikal)
    IplImage *p_grayvert = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
    grayvert(height,width,tmpArray,array);
    saveArrayToImage(height,width,array,p_grayvert);
// create a new image (GrauwertSprünge beide)
    IplImage *p_grayboth = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
    graytotal(height,width,tmpArray,array);
    saveArrayToImage(height,width,array,p_grayboth);
// create a new image (Mittelung 2x2)
    IplImage *p_mid2x2 = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
    mid2x2(height,width,tmpArray,array);
    saveArrayToImage(height,width,array,p_mid2x2);
// create a new image (Mittelung 2x2)
    IplImage *p_mid3x3 = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
    mid3x3(height,width,tmpArray,array);
    saveArrayToImage(height,width,array,p_mid3x3);



    // show images
    cvNamedWindow("original", 1);
    cvShowImage("original", p_image);
    cvNamedWindow("invertedGray", 1);
    cvShowImage("invertedGray", p_grayImage);
    cvNamedWindow("Drehung 90 Grad", 1);
    cvShowImage("Drehung 90 Grad", p_rotate90);
    cvNamedWindow("Drehung 180 Grad", 1);
    cvShowImage("Drehung 180 Grad", p_rotate180);
    cvNamedWindow("Drehung 270 Grad", 1);
    cvShowImage("Drehung 270 Grad", p_rotate270);
    cvNamedWindow("Spiegelung vertikal", 1);
    cvShowImage("Spiegelung vertikal", p_flipvertical);
    cvNamedWindow("Spiegelung horizontal", 1);
    cvShowImage("Spiegelung horizontal", p_fliphorizontal);
    cvNamedWindow("Beide Spiegelungen", 1);
    cvShowImage("Beide Spiegelungen", p_flipboth);
    cvNamedWindow("Skalierung Faktor 2", 1);
    cvShowImage("Skalierung Faktor 2", p_scale2);
    cvNamedWindow("Skalierung Faktor 1/2", 1);
    cvShowImage("Skalierung Faktor 1/2", p_scalehalf);
    cvNamedWindow("Grauwertsprünge horizontal", 1);
    cvShowImage("Grauwertsprünge horizontal", p_grayhor);
    cvNamedWindow("Grauwertsprünge vertikal", 1);
    cvShowImage("Grauwertsprünge vertikal", p_grayvert);
    cvNamedWindow("Grauwertsprünge beide", 1);
    cvShowImage("Grauwertsprünge beide", p_grayboth);
    cvNamedWindow("Mittelung 2x2", 1);
    cvShowImage("Mittelung 2x2", p_mid2x2);
    cvNamedWindow("Mittelung 3x3", 1);
    cvShowImage("Mittelung 3x3", p_mid3x3);

    // wait for 'esc' key
    cvWaitKey(0);

    // clean up
    cvReleaseImage(&p_grayImage);
    cvDestroyWindow("invertedGray");
    cvReleaseImage(&p_image);
    cvDestroyWindow("original");
    cvReleaseImage(&p_rotate90);
    cvDestroyWindow("Drehung 90 Grad");
    cvReleaseImage(&p_rotate180);
    cvDestroyWindow("Drehung 180 Grad");
    cvReleaseImage(&p_rotate270);
    cvDestroyWindow("Drehung 270 Grad");
    cvReleaseImage(&p_flipvertical);
    cvDestroyWindow("Spiegelung vertikal");
    cvReleaseImage(&p_fliphorizontal);
    cvDestroyWindow("Spiegelung horizontal");
    cvReleaseImage(&p_flipboth);
    cvDestroyWindow("Beide Spiegelungen");
    cvReleaseImage(&p_scale2);
    cvDestroyWindow("Skalierung Faktor 2");
    cvReleaseImage(&p_scalehalf);
    cvDestroyWindow("Skalierung Faktor 1/2");
    cvReleaseImage(&p_grayhor);
    cvDestroyWindow("Grauwertsprünge horizontal");
    cvReleaseImage(&p_grayvert);
    cvDestroyWindow("Grauwertsprünge vertikal");
    cvReleaseImage(&p_grayboth);
    cvDestroyWindow("Grauwertsprünge beide");
    cvReleaseImage(&p_mid2x2);
    cvDestroyWindow("Mittelung 2x2");
    cvReleaseImage(&p_mid3x3);
    cvDestroyWindow("Mittelung 3x3");



    for (y = 0; y < height; y++)
    {
        free(array[y]);
        free(tmpArray[y]);
    }
    free(array);
    free(tmpArray);

//cvSaveImage
    // bye bye
    printf("Goodbye\n");

    return 0;
}
/**
 * Method:    rotate180AndFlipHorizontal
 */
void rotate180AndFlipHorizontal(uint32* sourceBuffer, uint32* targetBuffer, int width, int height) {
    uint32* aux = (uint32*)malloc(width*height*sizeof(uint32));
    rotate180(sourceBuffer, aux, width, height);
    flipHorizontal(aux, targetBuffer, width, height);
    free(aux);
}
/**
 * Method:    DecodeAndConvert
 */
JNIEXPORT jintArray JNICALL Java_com_orangelabs_rcs_core_ims_protocol_rtp_codec_video_h264_decoder_NativeH264Decoder_DecodeAndConvert
  (JNIEnv *env, jclass clazz, jbyteArray h264Frame, int rotateOrientation, jintArray dimensions) {
    pthread_mutex_lock(&iMutex);

    int32 size = 0;
    int32 status;
    jintArray decoded;

    // Check if decoder is initialized
    if(!decoderInitialized) {
        decoded = (env)->NewIntArray(0);
        pthread_mutex_unlock(&iMutex);
        iStatus = FAIL_NOT_INITIALIZED;
        return decoded;
    }

    // Copy jbyteArray to uint8*
    jint len = env->GetArrayLength(h264Frame);
    jbyte data[len];
    env->GetByteArrayRegion(h264Frame, 0, len, data);
    uint8* aInputBuf = (uint8*)malloc(len);
    memcpy(aInputBuf, (uint8*)data, len);
    size = len;

    // Get type of NAL
    u_int8_t type = aInputBuf[0] & 0x1f;
    iStatus = FAIL;
    switch (type) {
        case 7: // SPS
            if ((status = decoder->DecodeSPS(aInputBuf, size)) != AVCDEC_SUCCESS) {
                __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "Failed decode SPS: %ld", status);
                decoded = (env)->NewIntArray(0);
                pthread_mutex_unlock(&iMutex);
                iStatus = FAIL_TO_DECODE_SPS;
                return decoded;
            }
            iStatus = SPS_DECODED;
            decoded = (env)->NewIntArray(0);
            __android_log_print(ANDROID_LOG_INFO, LOG_TAG, "Receive SPS");
            break;

        case 8: // PPS
            if ((status = decoder->DecodePPS(aInputBuf, size)) != AVCDEC_SUCCESS) {
                __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "Failed to decode PPS: %ld", status);
                decoded = (env)->NewIntArray(0);
                pthread_mutex_unlock(&iMutex);
                iStatus = FAIL_TO_DECODE_PPS;
                return decoded;
            }
            iStatus = PPS_DECODED;
            decoded = (env)->NewIntArray(0);
            __android_log_print(ANDROID_LOG_INFO, LOG_TAG, "Receive PPS");
            break;

        case 5: // IDR slice
        case 1: // non-IDR slice
            // Decode the buffer
            status = decoder->DecodeAVCSlice(aInputBuf, &size);
            if (status > AVCDEC_FAIL) {
                iStatus = SUCCESS;
                AVCFrameIO outVid;
                int indexFrame;
                int releaseFrame;
                if (!decoder->GetDecOutput(&indexFrame, &releaseFrame, &outVid)) {
                    decoded = (env)->NewIntArray(0);
                    pthread_mutex_unlock(&iMutex);
                    iStatus = FAIL_TO_GET_OUTPUT;
                    return decoded;
                }

                // Set width and height
                uint32* resultDimensions= (uint32*) malloc(2*sizeof(uint32));
                if (resultDimensions == NULL) {
                    decoded = (env)->NewIntArray(0);
                    pthread_mutex_unlock(&iMutex);
                    iStatus = FAIL_TO_CREATE_DIMENSIONS;
                    return decoded;
                }
                resultDimensions[0] = outVid.pitch;
                resultDimensions[1] = outVid.height;

                if(aOutBuffer == NULL) {
                    aOutBuffer = (uint8*)malloc(resultDimensions[0]*resultDimensions[1]*3/2);
                }
                decoded = (env)->NewIntArray(resultDimensions[0]*resultDimensions[1]);

                // Copy result to YUV array
                memcpy(aOutBuffer, outVid.YCbCr[0], resultDimensions[0] * resultDimensions[1]);
                memcpy(aOutBuffer + (resultDimensions[0] * resultDimensions[1]), outVid.YCbCr[1], (resultDimensions[0] * resultDimensions[1]) / 4);
                memcpy(aOutBuffer + (resultDimensions[0] * resultDimensions[1]) + ((resultDimensions[0] * resultDimensions[1]) / 4), outVid.YCbCr[2], (resultDimensions[0] * resultDimensions[1]) / 4);

                // Create the output buffer
                uint32* resultBuffer = (uint32*) malloc(resultDimensions[0] * resultDimensions[1] * sizeof(uint32));
                if (resultBuffer == NULL) {
                    decoded = (env)->NewIntArray(0);
                    pthread_mutex_unlock(&iMutex);
                    iStatus = FAIL_TO_CREATE_OUTPUT;
                    return decoded;
                }

                // Convert to RGB
                convert(resultDimensions[0], resultDimensions[1], aOutBuffer, resultBuffer);

                // Frame rotation
                bool freeResultBuffer = true;
                VideoEncoderRotateOrientation videoEncoderRotateOrientation = (VideoEncoderRotateOrientation) rotateOrientation;
                if (videoEncoderRotateOrientation != NONE) {
                    // Alloc rotated frame buffer
                    rotatedFrame = (uint32*)malloc(outVid.pitch*outVid.height*sizeof(uint32));
                    switch (videoEncoderRotateOrientation) {
                        case ROTATE_90_CW:
                            rotate90CW(resultBuffer, rotatedFrame, outVid.pitch, outVid.height);
                            break;
                        case ROTATE_180:
                            rotate180(resultBuffer, rotatedFrame, outVid.pitch, outVid.height);
                            break;
                        case ROTATE_90_CCW:
                            rotate90CCW(resultBuffer, rotatedFrame, outVid.pitch, outVid.height);
                            break;
                        case FLIP_HORIZONTAL:
                            flipHorizontal(resultBuffer, rotatedFrame, outVid.pitch, outVid.height);
                            break;
                        case ROTATE_90_CW_FLIP_HORIZONTAL:
                            rotate90CWAndFlipHorizontal(resultBuffer, rotatedFrame, outVid.pitch, outVid.height);
                            break;
                        case ROTATE_180_FLIP_HORIZONTAL:
                            rotate180AndFlipHorizontal(resultBuffer, rotatedFrame, outVid.pitch, outVid.height);
                            break;
                        case ROTATE_90_CCW_FLIP_HORIZONTAL:
                            rotate90CCWAndFlipHorizontal(resultBuffer, rotatedFrame, outVid.pitch, outVid.height);
                            break;
                    }

                    // Free original frame
                    free(resultBuffer);

                    // Update aOutBuffer variable with the rotated data
                    resultBuffer = rotatedFrame;

                    // Do not free result buffer because its the rotated frame buffer
                    freeResultBuffer = false;

                    if (videoEncoderRotateOrientation != ROTATE_180
                            && videoEncoderRotateOrientation != ROTATE_180_FLIP_HORIZONTAL
                            && videoEncoderRotateOrientation != FLIP_HORIZONTAL) {
                        // Switch width and height values
                        resultDimensions[0] = outVid.height; // width
                        resultDimensions[1] = outVid.pitch; // height
                    } else {
                        resultDimensions[0] = outVid.pitch; // width
                        resultDimensions[1] = outVid.height; // height
                    }
                }

                // Return Bitmap Dimensions
                (env)->SetIntArrayRegion(dimensions, 0, 2, (const jint*)resultDimensions);
                free(resultDimensions);

                // Return Bitmap image
                (env)->SetIntArrayRegion(decoded, 0, outVid.pitch*outVid.height, (const jint*)resultBuffer);
                if (freeResultBuffer) {
                    free(resultBuffer);
                    resultBuffer = NULL;
                }
                if (rotatedFrame != NULL) {
                    free(rotatedFrame);
                    rotatedFrame = NULL;
                }
            } else {
                __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "Decoder error %ld", status);
                decoded = (env)->NewIntArray(0);
                pthread_mutex_unlock(&iMutex);
                iStatus = FAIL_TO_DECODE_AVC;
                return decoded;
            }
            break;
    }
    free(aInputBuf);
    pthread_mutex_unlock(&iMutex);
    return decoded;
}