Hey. Let me know what you think about this. I bet HAM8 called up your attention right 8-) I like stuff about it.
Yesterday I was so fed up with the program I've been coding that I just left it all behind. I was playing around with ImageFX studio a bit when I stumbled across dev docs.
The routine only works with 24 bit buffers.
I can't get this to compile and I was hoping you could help. I never really used SASC, only VBCC but the ImageFX docs say the includes are only granted to work with SASC so I decided to give it a try but I can't get it to work. I complains that there is an unexisting symbol at compile time or something, regarding main and the call to GetCurrentBuffer. I set the linker options to link to hooks.o. so I don't know what the problem is.
I'm pretty sure this is my complete lack of experience using SASC.
What the hook does is calculating how many pixels in the image can't be represented by HAM8 mode (e.g. are more different than the six upper bits of one and only one color component of the previous pixel), how many lines have 1-16, 17-32, 33-64 and more than 64 non HAM8 representable pixels, the biggest array of successive non HAM8 representable pixels in all lines, the line with the biggest number of non HAM8 representable pixels, the total number of different colors and finally, the total number of different colors of the first pixels of all lines (wich are allways non HAM8).
Anyway, enouph of talking the code (maybe a few bugs.. hope not) is bellow.
#include <stdio.h>
#include <exec/types.h>
#include <scan/buf.h>
#include <scan/scan_protos.h>
#include <scan/hooks.h>
/* Global necessary variables */
char *HookName = "HAM8_?";
char *HookText = 0;
char *HookTextCount = 0; /* Yeah, maybe I'll set up these later... */
void hook_main(int argc, char **argv)
{
struct Buffer *ImFxBuff = ObtainCurrentBuffer ();
UBYTE *RedPlanePtr1, *GreenPlanePtr1, *BluePlanePtr1, *RedPlanePtr2, *GreenPlanePtr2, *BluePlanePtr2;
WORD Width = ImFxBuff->Width, Height = ImFxBuff->Height;
WORD WidthCounter = 0, HeightCounter = 0;
WORD YACounter = 0; /* Yet another counter */
LONG NrColors = 0; /* Nr of different colors on image */
WORD NrDiff1stPxls = 0; /* Nr of different 1st pixels in lines */
LONG NrNonHAM8Pxls = 0; /* Total number of non HAM8 pixels */
WORD NrBiggstNHAM8P = 0; /* Biggest number of successive non HAM8 pixels in any line */
WORD NHAM8PLC = 0; /* Successive non HAM8 pixels in line counter */
WORD NHAM8PC = 0; /* Total number of non HAM8 pixels in line counter */
WORD LinesTill16NonHAMPxls = 0; /* Number of lines with between 1 and 16 non HAM8 pixels */
WORD LinesBtwn17_32NonHAMPxls = 0; /* "" but between 17 and 32 */
WORD LinesBtwn33_64NonHAMPxls = 0; /* "" but between 33 and 64 */
WORD LinesMore64NonHAMPxls = 0; /* "" but with more than 64 */
if (ImFxBuff->Depth != 3)
printf ("Non 24bit buffer. Only works with 24bit buffers for now ...\n");
else
{ RedPlanePtr1 = ImFxBuff->Planes[0];
GreenPlanePtr1 = ImFxBuff->Planes[1];
BluePlanePtr1 = ImFxBuff->Planes[2];
RedPlanePtr2 = RedPlanePtr1 + 1;
GreenPlanePtr2 = GreenPlanePtr1 + 1;
BluePlanePtr2 = BluePlanePtr1 + 1;
/* Calculate nr. of total different colors (disregard lines, consider a big row Width x Height */
for (NrColors = 1; WidthCounter != Width * Height - 1; WidthCounter++)
{ for (YACounter = 0; YACounter != Width * Height - WidthCounter - 1; YACounter++)
{ if (RedPlanePtr1 != RedPlanePtr2 || GreenPlanePtr1 != GreenPlanePtr2 || BluePlanePtr1 != BluePlanePtr2)
NrColors++;
RedPlanePtr1++;
RedPlanePtr2++;
GreenPlanePtr1++;
GreenPlanePtr2++;
BluePlanePtr1++;
BluePlanePtr2++;
}
RedPlanePtr1 = ImFxBuff->Planes[0] + WidthCounter;
GreenPlanePtr1 = ImFxBuff->Planes[1] + WidthCounter;
BluePlanePtr1 = ImFxBuff->Planes[2] + WidthCounter;
RedPlanePtr2 = RedPlanePtr1 + 1 + WidthCounter;
GreenPlanePtr2 = GreenPlanePtr1 + 1 + WidthCounter;
BluePlanePtr2 = BluePlanePtr1 + 1 + WidthCounter;
}
/* Reset stuff for next calculation */
RedPlanePtr1 = ImFxBuff->Planes[0];
GreenPlanePtr1 = ImFxBuff->Planes[1];
BluePlanePtr1 = ImFxBuff->Planes[2];
RedPlanePtr2 = RedPlanePtr1 + Width;
GreenPlanePtr2 = GreenPlanePtr1 + Width;
BluePlanePtr2 = BluePlanePtr1 + Width;
printf ("Total nr. of different colors:%ld\n", NrColors);
/* Calculate nr. of different 1st pixels in lines */
for (NrDiff1stPxls = 1; HeightCounter != Height -1 ; HeightCounter++)
{ for (YACounter = 0; YACounter != Height - HeightCounter - 1; YACounter++)
{ if (RedPlanePtr1 != RedPlanePtr2 || GreenPlanePtr1 != GreenPlanePtr2 || BluePlanePtr1 != BluePlanePtr2)
NrDiff1stPxls++;
RedPlanePtr1 += Width;
RedPlanePtr2 += Width;
GreenPlanePtr1 += Width;
GreenPlanePtr2 += Width;
BluePlanePtr1 += Width;
BluePlanePtr2 += Width;
}
RedPlanePtr1 = ImFxBuff->Planes[0] + HeightCounter * Width;
GreenPlanePtr1 = ImFxBuff->Planes[1] + HeightCounter * Width;
BluePlanePtr1 = ImFxBuff->Planes[2] + HeightCounter * Width;
RedPlanePtr2 = RedPlanePtr1 + 1 + HeightCounter * Width;
GreenPlanePtr2 = GreenPlanePtr1 + 1 + HeightCounter * Width;
BluePlanePtr2 = BluePlanePtr1 + 1 + HeightCounter * Width;
}
/* Reset stuff for next calculation */
RedPlanePtr1 = ImFxBuff->Planes[0];
GreenPlanePtr1 = ImFxBuff->Planes[1];
BluePlanePtr1 = ImFxBuff->Planes[2];
RedPlanePtr2 = RedPlanePtr1 + 1;
GreenPlanePtr2 = GreenPlanePtr1 + 1;
BluePlanePtr2 = BluePlanePtr1 + 1;
printf ("Nr. of different 1st pixels in lines:%ld", NrDiff1stPxls);
/* Calculate number of non HAM8 pixel statistics */
for (HeightCounter = 0; HeightCounter != Height; HeightCounter++)
{ for (WidthCounter = 0; WidthCounter != Width - 1; WidthCounter++)
{ if ((*RedPlanePtr1 ^ *RedPlanePtr2) > 0x3F)
goto NHAM8PXL;
else if (*RedPlanePtr1 != *RedPlanePtr2)
/* Red component can be represented by HAM8, but others must be equal (HAM can only change one component at a time), proceed to check them */
goto CHCKGRNEQ;
/* Red component is equal */
else if ((*GreenPlanePtr1 ^ *GreenPlanePtr2) > 0x3F)
goto NHAM8PXL;
else if (*GreenPlanePtr1 != *RedPlanePtr2)
/* Blue component can be represented by HAM8, but others must be equal, we already know red is so proceed to check blue */
goto CHCKBLUEQ;
/* Green component is equal */
else if ((*BluePlanePtr1 ^ *BluePlanePtr2) > 0x3F)
goto NHAM8PXL;
/* Whatever blue is now, it can be represented by HAM8 mode */
goto HAM8PXL;
/** Check if other color components are equal **/
/* Green */
CHCKGRNEQ:
if (*GreenPlanePtr1 = *GreenPlanePtr2)
{ /* Blue */
CHCKBLUEQ:
if (*BluePlanePtr1 = *BluePlanePtr2)
goto HAM8PXL;
}
/** Non HAM8 pixel detected: **/
NHAM8PXL:
NrNonHAM8Pxls++;
NHAM8PLC++;
NHAM8PC++;
RedPlanePtr1++;
RedPlanePtr2++;
GreenPlanePtr1++;
GreenPlanePtr2++;
BluePlanePtr1++;
BluePlanePtr2++;
continue;
/** This is a HAM8 Pixel, take note if it was the biggest non HAM8 array so far and interrupt non HAM8 counter **/
HAM8PXL:
if (NrNonHAM8Pxls > NrBiggstNHAM8P)
NrBiggstNHAM8P = NHAM8PLC;
NHAM8PLC = 0;
RedPlanePtr1++;
RedPlanePtr2++;
GreenPlanePtr1++;
GreenPlanePtr2++;
BluePlanePtr1++;
BluePlanePtr2++;
}
/* If last pixel in line is still a non HAM8 one counters per line must stop anyway so: */
if (NrNonHAM8Pxls > NrBiggstNHAM8P)
NrBiggstNHAM8P = NHAM8PLC;
NHAM8PLC = 0;
/* Continue taking conforming notes and reseting counters */
if (NHAM8PC >= 1 || NHAM8PC <= 16)
LinesTill16NonHAMPxls++;
else if (NHAM8PC >= 17 || NHAM8PC <= 32)
LinesBtwn17_32NonHAMPxls++;
else if (NHAM8PC >= 33 || NHAM8PC <= 64)
LinesBtwn33_64NonHAMPxls++;
else if (NHAM8PC >64)
LinesMore64NonHAMPxls++;
NHAM8PC = 0;
/* Raise pixel pointers one pixel ahead (wouldn't make sense to compare 1st in line with last in previous line!) */
RedPlanePtr1++;
RedPlanePtr2++;
GreenPlanePtr1++;
GreenPlanePtr2++;
BluePlanePtr1++;
BluePlanePtr2++;
}
printf ("Total nr. of non HAM8 pixels:%lu\nMaximum nr. of successive non HAM8 pixels:%d\n\nNr. of lines with 1-16 non HAM8 pixels:%d\nNr. of lines with 17-32 non HAM8 pixels:%d\nNr. of lines with 33-64 non HAM8 pixels:%d\nNr. of lines with more than 64 non HAM8 pixels:%d\n ", NrNonHAM8Pxls, NrBiggstNHAM8P, LinesTill16NonHAMPxls, LinesBtwn17_32NonHAMPxls, LinesBtwn33_64NonHAMPxls, LinesMore64NonHAMPxls);
}
}