//==============================================================================
//
// pgmblock8.c
//
// print brightnesses in block 8x8
//
// use:
//	pgmblock8 image.pgm  nRow  nCol
//
//==============================================================================

#include <stdio.h>
#include "pgm.h"

#define BLOCK_SIZE   8

//==============================================================================
int main(int nArg, char** ppArg)
{
	int i, j, ii;
	int nW, nH; // image width and height
	int nB;     // image brightness
	byte* pIm;  // pointer to image matrix
	int nSize;  // image size in bytes
	byte* pIm2;  // pointer to second image matrix 
	int nX, nY;
	
	if(nArg==1) 
	{
		puts("print brightnesses in block 8x8");
		puts("pgmblock8 image.pgm  nRow  nCol");
		exit(1);
	}

	ReadPGM(ppArg[1], &pIm,  &nW, &nH);
	nY = atoi(ppArg[2]);
	nX = atoi(ppArg[3]);	
	
	nSize = nW * nH;
	
	for(i=nY; i<(nY+BLOCK_SIZE); i++)
	{
		for(j=nX; j<(nX+BLOCK_SIZE); j++)
		{
			ii = i*nW + j;
			nB = pIm[ii];
			printf("%3d   ", nB);
		}
		printf("\n");
	}

	free(pIm);
	
	return 0;
}