Index: /trunk/core/histogram.c
===================================================================
--- /trunk/core/histogram.c	(revision 1103)
+++ /trunk/core/histogram.c	(revision 1104)
@@ -61,4 +61,7 @@
 }
 
+// Define how many viewport blocks to step in each loop iteration. Each block is 6 bytes (UYVYYY) or 4 image pixels
+#define	HISTO_STEP_SIZE	6
+
 void histogram_process()
 {
@@ -66,5 +69,5 @@
     int i, hi, c;
     int y, v, u;
-	static int x, img_offset;
+	static int x;
     static int viewport_size;
     unsigned int histo_fill[5];
@@ -77,5 +80,5 @@
 	    	  img = vid_get_viewport_fb();
 		    }
-			img_offset = vid_get_viewport_image_offset();		// offset into viewport for when image size != viewport size (e.g. 16:9 image on 4:3 LCD)
+			img += vid_get_viewport_image_offset();		// offset into viewport for when image size != viewport size (e.g. 16:9 image on 4:3 LCD)
             viewport_size = vid_get_viewport_height() * vid_get_viewport_buffer_width();
             for (c=0; c<5; ++c) {
@@ -92,10 +95,10 @@
         case 2:
         case 3:
-			x = 0;
-            for (i=(histogram_stage-1)*6; i<viewport_size*3; i+=6*3*2) {
-                y = img[img_offset+i+1];
-                u = *(signed char*)(&img[img_offset+i]);
+			x = 0;	// count how many blocks we have done on the current row (to skip unused buffer space at end of each row)
+            for (i=(histogram_stage-1)*6; i<viewport_size*3; i+=HISTO_STEP_SIZE*6) {
+                y = img[i+1];
+                u = *(signed char*)(&img[i]);
                 if (u&0x00000080) u|=0xFFFFFF00;
-                v = *(signed char*)(&img[img_offset+i+2]);
+                v = *(signed char*)(&img[i+2]);
                 if (v&0x00000080) v|=0xFFFFFF00;
 
@@ -110,5 +113,5 @@
 
 				// Handle case where viewport memory buffer is wider than the actual buffer.
-				x++;
+				x += HISTO_STEP_SIZE * 2;	// viewport width is measured in blocks of three bytes each even though the data is stored in six byte chunks !
 				if (x == vid_get_viewport_width())
 				{
