@@ -143,6 +143,8 @@ static size_t channelsFromPixelFormat(ofPixelFormat format){
143143 return 1 ;
144144 break ;
145145 case OF_PIXELS_GRAY_ALPHA:
146+
147+ // FIXME: this is not true for OF_PIXELS_RGB565. it has 3 channels and 2 bytes.
146148 case OF_PIXELS_RGB565:
147149 return 2 ;
148150 break ;
@@ -393,10 +395,10 @@ template<typename PixelType>
393395void ofPixels_<PixelType>::setFromExternalPixels(PixelType * newPixels, size_t w, size_t h, ofPixelFormat _pixelFormat){
394396 clear ();
395397 pixelFormat = _pixelFormat;
396- width= w;
398+ width = w;
397399 height = h;
398400
399- pixelsSize = bytesFromPixelFormat (w,h,_pixelFormat );
401+ pixelsSize = w * h * getNumChannels ( );
400402
401403 pixels = newPixels;
402404 pixelsOwner = false ;
@@ -513,8 +515,8 @@ void ofPixels_<PixelType>::allocate(size_t w, size_t h, ofPixelFormat format){
513515 return ;
514516 }
515517
516- size_t newSize = bytesFromPixelFormat (w,h, format);
517- size_t oldSize = getTotalBytes ( );
518+ size_t newSize = w * h * pixelBitsFromPixelFormat ( format);
519+ size_t oldSize = width * height * pixelBitsFromPixelFormat (pixelFormat );
518520 // we check if we are already allocated at the right size
519521 if (bAllocated && newSize==oldSize){
520522 pixelFormat = format;
@@ -530,9 +532,12 @@ void ofPixels_<PixelType>::allocate(size_t w, size_t h, ofPixelFormat format){
530532 width = w;
531533 height = h;
532534
533- pixelsSize = newSize ;
535+ pixelsSize = w * h * getNumChannels () ;
534536
537+ // we have some incongruence here, if we use PixelType
538+ // we are not able to use RGB565 format
535539 pixels = new PixelType[pixelsSize];
540+ // pixels = new uint8_t[newSize];
536541 bAllocated = true ;
537542 pixelsOwner = true ;
538543}
@@ -583,11 +588,11 @@ void ofPixels_<PixelType>::clear(){
583588 pixels = nullptr ;
584589 }
585590
586- width = 0 ;
587- height = 0 ;
588- pixelFormat = OF_PIXELS_UNKNOWN;
589- pixelsSize = 0 ;
590- bAllocated = false ;
591+ width = 0 ;
592+ height = 0 ;
593+ pixelFormat = OF_PIXELS_UNKNOWN;
594+ pixelsSize = 0 ;
595+ bAllocated = false ;
591596}
592597
593598template <typename PixelType>
0 commit comments