@@ -144,8 +144,8 @@ status_t ColorConverter::convertCbYCrY(
144144 return ERROR_UNSUPPORTED;
145145 }
146146
147- uint32_t *dst_ptr = (uint32_t *)dst.mBits
148- + ( dst.mCropTop * dst.mWidth + dst.mCropLeft ) / 2 ;
147+ uint16_t *dst_ptr = (uint16_t *)dst.mBits
148+ + dst.mCropTop * dst.mWidth + dst.mCropLeft ;
149149
150150 const uint8_t *src_ptr = (const uint8_t *)src.mBits
151151 + (src.mCropTop * dst.mWidth + src.mCropLeft ) * 2 ;
@@ -182,11 +182,15 @@ status_t ColorConverter::convertCbYCrY(
182182 | ((kAdjustedClip [g2] >> 2 ) << 5 )
183183 | (kAdjustedClip [b2] >> 3 );
184184
185- dst_ptr[x / 2 ] = (rgb2 << 16 ) | rgb1;
185+ if (x + 1 < src.cropWidth ()) {
186+ *(uint32_t *)(&dst_ptr[x]) = (rgb2 << 16 ) | rgb1;
187+ } else {
188+ dst_ptr[x] = rgb1;
189+ }
186190 }
187191
188192 src_ptr += src.mWidth * 2 ;
189- dst_ptr += dst.mWidth / 2 ;
193+ dst_ptr += dst.mWidth ;
190194 }
191195
192196 return OK;
@@ -290,15 +294,14 @@ status_t ColorConverter::convertQCOMYUV420SemiPlanar(
290294 const BitmapParams &src, const BitmapParams &dst) {
291295 uint8_t *kAdjustedClip = initClip ();
292296
293- if (!((dst.mWidth & 3 ) == 0
294- && (src.mCropLeft & 1 ) == 0
297+ if (!((src.mCropLeft & 1 ) == 0
295298 && src.cropWidth () == dst.cropWidth ()
296299 && src.cropHeight () == dst.cropHeight ())) {
297300 return ERROR_UNSUPPORTED;
298301 }
299302
300- uint32_t *dst_ptr = (uint32_t *)dst.mBits
301- + ( dst.mCropTop * dst.mWidth + dst.mCropLeft ) / 2 ;
303+ uint16_t *dst_ptr = (uint16_t *)dst.mBits
304+ + dst.mCropTop * dst.mWidth + dst.mCropLeft ;
302305
303306 const uint8_t *src_y =
304307 (const uint8_t *)src.mBits + src.mCropTop * src.mWidth + src.mCropLeft ;
@@ -340,7 +343,11 @@ status_t ColorConverter::convertQCOMYUV420SemiPlanar(
340343 | ((kAdjustedClip [g2] >> 2 ) << 5 )
341344 | (kAdjustedClip [r2] >> 3 );
342345
343- dst_ptr[x / 2 ] = (rgb2 << 16 ) | rgb1;
346+ if (x + 1 < src.cropWidth ()) {
347+ *(uint32_t *)(&dst_ptr[x]) = (rgb2 << 16 ) | rgb1;
348+ } else {
349+ dst_ptr[x] = rgb1;
350+ }
344351 }
345352
346353 src_y += src.mWidth ;
@@ -349,7 +356,7 @@ status_t ColorConverter::convertQCOMYUV420SemiPlanar(
349356 src_u += src.mWidth ;
350357 }
351358
352- dst_ptr += dst.mWidth / 2 ;
359+ dst_ptr += dst.mWidth ;
353360 }
354361
355362 return OK;
@@ -361,15 +368,14 @@ status_t ColorConverter::convertYUV420SemiPlanar(
361368
362369 uint8_t *kAdjustedClip = initClip ();
363370
364- if (!((dst.mWidth & 3 ) == 0
365- && (src.mCropLeft & 1 ) == 0
371+ if (!((src.mCropLeft & 1 ) == 0
366372 && src.cropWidth () == dst.cropWidth ()
367373 && src.cropHeight () == dst.cropHeight ())) {
368374 return ERROR_UNSUPPORTED;
369375 }
370376
371- uint32_t *dst_ptr = (uint32_t *)dst.mBits
372- + ( dst.mCropTop * dst.mWidth + dst.mCropLeft ) / 2 ;
377+ uint16_t *dst_ptr = (uint16_t *)dst.mBits
378+ + dst.mCropTop * dst.mWidth + dst.mCropLeft ;
373379
374380 const uint8_t *src_y =
375381 (const uint8_t *)src.mBits + src.mCropTop * src.mWidth + src.mCropLeft ;
@@ -411,7 +417,11 @@ status_t ColorConverter::convertYUV420SemiPlanar(
411417 | ((kAdjustedClip [g2] >> 2 ) << 5 )
412418 | (kAdjustedClip [r2] >> 3 );
413419
414- dst_ptr[x / 2 ] = (rgb2 << 16 ) | rgb1;
420+ if (x + 1 < src.cropWidth ()) {
421+ *(uint32_t *)(&dst_ptr[x]) = (rgb2 << 16 ) | rgb1;
422+ } else {
423+ dst_ptr[x] = rgb1;
424+ }
415425 }
416426
417427 src_y += src.mWidth ;
@@ -420,7 +430,7 @@ status_t ColorConverter::convertYUV420SemiPlanar(
420430 src_u += src.mWidth ;
421431 }
422432
423- dst_ptr += dst.mWidth / 2 ;
433+ dst_ptr += dst.mWidth ;
424434 }
425435
426436 return OK;
@@ -430,15 +440,14 @@ status_t ColorConverter::convertTIYUV420PackedSemiPlanar(
430440 const BitmapParams &src, const BitmapParams &dst) {
431441 uint8_t *kAdjustedClip = initClip ();
432442
433- if (!((dst.mWidth & 3 ) == 0
434- && (src.mCropLeft & 1 ) == 0
443+ if (!((src.mCropLeft & 1 ) == 0
435444 && src.cropWidth () == dst.cropWidth ()
436445 && src.cropHeight () == dst.cropHeight ())) {
437446 return ERROR_UNSUPPORTED;
438447 }
439448
440- uint32_t *dst_ptr = (uint32_t *)dst.mBits
441- + ( dst.mCropTop * dst.mWidth + dst.mCropLeft ) / 2 ;
449+ uint16_t *dst_ptr = (uint16_t *)dst.mBits
450+ + dst.mCropTop * dst.mWidth + dst.mCropLeft ;
442451
443452 const uint8_t *src_y = (const uint8_t *)src.mBits ;
444453
@@ -478,7 +487,11 @@ status_t ColorConverter::convertTIYUV420PackedSemiPlanar(
478487 | ((kAdjustedClip [g2] >> 2 ) << 5 )
479488 | (kAdjustedClip [b2] >> 3 );
480489
481- dst_ptr[x / 2 ] = (rgb2 << 16 ) | rgb1;
490+ if (x + 1 < src.cropWidth ()) {
491+ *(uint32_t *)(&dst_ptr[x]) = (rgb2 << 16 ) | rgb1;
492+ } else {
493+ dst_ptr[x] = rgb1;
494+ }
482495 }
483496
484497 src_y += src.mWidth ;
@@ -487,7 +500,7 @@ status_t ColorConverter::convertTIYUV420PackedSemiPlanar(
487500 src_u += src.mWidth ;
488501 }
489502
490- dst_ptr += dst.mWidth / 2 ;
503+ dst_ptr += dst.mWidth ;
491504 }
492505
493506 return OK;
0 commit comments