title: Process image with android opengl es but output image is weird in a certain device
body: <p>I wrote a demo about camera which is similar to ContinuousCaptureActivity of grafika (<a href="https://github.com/google/grafika/blob/master/src/com/android/grafika/ContinuousCaptureActivity.java" rel="nofollow noreferrer">Source code of ContinuousCaptureActivity.java</a>). For every frame, I added some operations besides drawing the frame to screen.</p>
  
  <p>I create a fbo, then bind it and draw the frame to the fbo. In order to check the image rendered to the fbo, I read back the image data back to RAM using pbo and save the image as jpg every 50 frames.
  In this way, I got the jpg file but it was scaled, picture is as follows:
  <a href="https://i.stack.imgur.com/LkKEw.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LkKEw.jpg" alt="enter image description here"></a></p>
  
  <p>I supposed the matrix from SurfaceTexture caused the scaling because every drawFrame() applied that matrix.So I created anothter fbo and draw the frame of the first fbo to this fbo, then I save the image as jpg and the image turn OK as expected. Look at this one:
  <a href="https://i.stack.imgur.com/7hr92.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7hr92.jpg" alt="enter image description here"></a></p>
  
  <p>So the conclusion is that 2 draws will restore the image correctly.</p>
  
  <p>But the image is weird in a huawei phone of mine(model:huawei MT7-CL00). Look at it:
  <a href="https://i.stack.imgur.com/ezEVn.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ezEVn.jpg" alt="enter image description here"></a></p>
  
  <p>I have checked the image of the first fbo with the huawei phone, it is scaled as expected but not weird. So I think the error ocurred in the scecond fbo. But I can not figure out the reason. Who can give me some advices?</p>
  
  <p>Some source codes:</p>
  
  <p>fbo definitions:</p>
  
  <pre><code>private GlTexture mGlTexture;
  private GlFrameBuffer mGlFrameBuffer;
  private GlFrameBuffer mGlFrameBuffer1;
  </code></pre>
  
  <p>GlTexture and GlFrameBuffer class source codes:</p>
  
  <p><a href="http://www.paste.org/80680" rel="nofollow noreferrer">http://www.paste.org/80680
  </a></p>
  
  <p>bindFbo method:</p>
  
  <pre><code>private void bindFBO(int fbo)
  {
      GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fbo);
      GLES20.glClearColor(0.0F, 0.0F, 0.0F, 0.0F);
      GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
      SurfaceView sv = (SurfaceView) findViewById(R.id.continuousCapture_surfaceView);
      GLES20.glViewport(0, 0, 640, 480);
  }
  </code></pre>
  
  <p>the key codes in  drawFrame():</p>
  
  <pre><code>            mDisplaySurface.makeCurrent();
      mCameraTexture.updateTexImage();
      mCameraTexture.getTransformMatrix(mTmpMatrix);
  
      // Fill the SurfaceView with it.
      SurfaceView sv = (SurfaceView) findViewById(R.id.continuousCapture_surfaceView);
      int viewWidth = 640;
      int viewHeight = 480;
      GLES20.glViewport(0, 0, viewWidth, viewHeight);
      mFullFrameBlit.drawFrame(mTextureId, mTmpMatrix);
      //drawExtra(mFrameNum, viewWidth, viewHeight);
      mDisplaySurface.swapBuffers();
  
  
      bindFBO(mGlFrameBuffer.getID());
      mFullFrameBlit.drawFrame(mTextureId, mTmpMatrix);
      bindFBO(mGlFrameBuffer1.getID());
      mFullFrameBlit2d.drawFrame(mGlTexture.getID(), mTmpMatrix);
  
      String filename = "/sdcard/test/" + System.currentTimeMillis() + ".jpg";
      new File(filename).getParentFile().mkdirs();
      if (mFrameNum % 50 == 0)
      {
          try {
              getPixelFromPBO(viewWidth, viewHeight, filename);
          } 
          catch (Exception e) {
          }
      }
  </code></pre>