Skip to content

Commit

Permalink
Fix alignment and copy size for legacy QCOM OMX
Browse files Browse the repository at this point in the history
Change-Id: I6d13c67601da0f0c35d3dd455401f982406cefe3
  • Loading branch information
grigorig committed Jan 19, 2013
1 parent 76db918 commit 976d7e9
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions media/libstagefright/colorconversion/SoftwareRenderer.cpp
Expand Up @@ -42,6 +42,11 @@ static bool runningInEmulator() {
return (property_get("ro.kernel.qemu", prop, NULL) > 0);
}

static int ALIGN(int x, int y) {
// y must be a power of 2.
return (x + y - 1) & ~(y - 1);
}

SoftwareRenderer::SoftwareRenderer(
const sp<ANativeWindow> &nativeWindow, const sp<MetaData> &meta)
: mConverter(NULL),
Expand Down Expand Up @@ -90,9 +95,9 @@ SoftwareRenderer::SoftwareRenderer(
case OMX_QCOM_COLOR_FormatYVU420SemiPlanar:
{
halFormat = HAL_PIXEL_FORMAT_YCrCb_420_SP;
bufWidth = (mCropWidth + 1) & ~1;
bufHeight = (mCropHeight + 1) & ~1;
mAlign = ((mWidth + 15) & -16) * ((mHeight + 15) & -16);
bufWidth = ALIGN(mCropWidth, 16);
bufHeight = ALIGN(mCropHeight, 2);
mAlign = ALIGN(mWidth, 16) * ALIGN(mHeight, 16);
break;
}
#endif
Expand Down Expand Up @@ -168,11 +173,6 @@ SoftwareRenderer::~SoftwareRenderer() {
mConverter = NULL;
}

static int ALIGN(int x, int y) {
// y must be a power of 2.
return (x + y - 1) & ~(y - 1);
}

void SoftwareRenderer::render(
const void *data, size_t size, void *platformPrivate) {
ANativeWindowBuffer *buf;
Expand Down Expand Up @@ -236,10 +236,11 @@ void SoftwareRenderer::render(
uint8_t *src_u = src_y + mAlign;
uint8_t *dst_y = (uint8_t *)dst;
uint8_t *dst_u = dst_y + buf->stride * buf->height;
size_t bufsz = ALIGN(mCropWidth, 16) * ALIGN(mCropHeight, 2);

// Legacy codec doesn't return crop params. Ignore it for speedup :)
memcpy(dst_y, src_y, mCropWidth * mCropHeight);
memcpy(dst_u, src_u, mCropWidth * mCropHeight / 2);
memcpy(dst_y, src_y, bufsz);
memcpy(dst_u, src_u, bufsz / 2);

/*for(size_t y = 0; y < mCropHeight; ++y) {
memcpy(dst_y, src_y, mCropWidth);
Expand Down

2 comments on commit 976d7e9

@C3C0
Copy link

@C3C0 C3C0 commented on 976d7e9 Jan 19, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job, man :)
Gonna try it on my ParanoidJelly 4.1.2.

@C3C0
Copy link

@C3C0 C3C0 commented on 976d7e9 Jan 19, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to confirm it seems to be working great :)
Huge thanks.

Please sign in to comment.