Welcome, Guest. Please login or register.

Author Topic: HAM8 friendliness statistics for 24 pictures ImageFX hook I made...  (Read 1345 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline JoseTopic starter

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2869
    • Show only replies by Jose
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.

Code: [Select]
#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 = &quot;HAM8_?&quot;;
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; /* &quot;&quot; but between 17 and 32 */
 WORD LinesBtwn33_64NonHAMPxls = 0; /* &quot;&quot; but between 33 and 64 */
 WORD LinesMore64NonHAMPxls = 0; /* &quot;&quot; but with more than 64 */

 if (ImFxBuff->Depth != 3)
   printf (&quot;Non 24bit buffer. Only works with 24bit buffers for now ...\n&quot;);
 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 (&quot;Total nr. of different colors:%ld\n&quot;, 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 (&quot;Nr. of different 1st pixels in lines:%ld&quot;, 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 (&quot;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 &quot;, NrNonHAM8Pxls, NrBiggstNHAM8P, LinesTill16NonHAMPxls, LinesBtwn17_32NonHAMPxls, LinesBtwn33_64NonHAMPxls, LinesMore64NonHAMPxls);
   }
}
\\"We made Amiga, they {bleep}ed it up\\"
 

Offline JoseTopic starter

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2869
    • Show only replies by Jose
Re: HAM8 friendliness statistics for 24 pictures ImageFX hook I made...
« Reply #1 on: February 03, 2006, 12:53:13 PM »
Ok, it should be "& 0x7" not "> 0x3F".
Not that anyone seems to care. It's a mere curiosity but I like having this kind of information.
\\"We made Amiga, they {bleep}ed it up\\"
 

Offline Steady

Re: HAM8 friendliness statistics for 24 pictures ImageFX hook I made...
« Reply #2 on: February 03, 2006, 12:59:01 PM »
Can you give the exact error message from the compiler? It might help.
 

Offline justthatgood

  • Hero Member
  • *****
  • Join Date: Dec 2003
  • Posts: 579
  • Country: us
    • Show only replies by justthatgood
Re: HAM8 friendliness statistics for 24 pictures ImageFX hook I made...
« Reply #3 on: February 03, 2006, 01:06:14 PM »
Is that any particular version of ImageFX.

I know have these white and grey GVP ImageFx with a Install, Support 1, Support 2, and Demo disk.

And I also have the SAS C version 6.50 with the 6.51 patch.

Who knows I might try it if I can get all my other Amiga problems fixed.
[color=008000]Pluto[/color]:Amiga4KD- 64040/16megs/1GB WD/PAR 2150/1942/WB3.0,3.1,3.9
[color=800080]Amanda[/color]:Amiga2KHD/A2620/8MegSupraRam2k/A2091/VLab
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16867
  • Country: gb
  • Thanked: 4 times
    • Show only replies by Karlos
Re: HAM8 friendliness statistics for 24 pictures ImageFX hook I made...
« Reply #4 on: February 03, 2006, 01:20:24 PM »
@Jose

You are gonna hate me for this but I have a suggestion...

First of all, try splitting your large function into 2 or 3 helper functions, it makes it a hell of a lot easier to read and maintain :-)

Anyway, assuming I understood it correctly, you are working on the assumption that every pixel other than the start of a line would be a HAM pixel. What you might consider doing is finding some code for quantitative colour reduction and finding the best 64 colours from the source data. You can then use these as a base palette for your calculation and try to find (within each pixel row) if it is better to use a palette colour or a HAM pixel.

I'm sure most good RGB ->HAM conversions would do something like this anyway.

As for your compiler problem, I don't generally use SAS-C, so I am not sure I can help there :-/
int p; // A
 

Offline JoseTopic starter

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2869
    • Show only replies by Jose
Re: HAM8 friendliness statistics for 24 pictures ImageFX hook I made...
« Reply #5 on: February 03, 2006, 01:39:33 PM »
@steady

SAS/C_SMAKE 6.50 (26.8.93)
Copyright (c) 1988-1993 SAS Institute, Inc.
SAS/C Amiga Compiler 6.50
Copyright (c) 1988-1993 SAS Institute Inc.
Slink - Version 6.50
Copyright (c) 1988-1993 SAS Institute, Inc.  All Rights Reserved.

Undefined symbols        First Referenced
_main                    File 'LIB:sc.lib'
Enter a DEFINE value for _main (default ___stub):
_ObtainCurrentBuffer     File 'HAM8Friend.o'
Enter a DEFINE value for _ObtainCurrentBuffer (default ___stub):

SLINK Complete - Maximum code size = 8504 ($00002138) bytes

Final output file size = 8408 ($000020d8) bytes

Hit RETURN to Exit


@justthatgood
I don't know. Maybe the scan lib or start up code are different on early versions.
\\"We made Amiga, they {bleep}ed it up\\"
 

Offline JoseTopic starter

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2869
    • Show only replies by Jose
Re: HAM8 friendliness statistics for 24 pictures ImageFX hook I made...
« Reply #6 on: February 03, 2006, 02:04:22 PM »
@Karlos

"You are gonna hate me for this but I have a suggestion..."
Yes:)

"First of all, try splitting your large function into 2 or 3 helper functions, it makes it a hell of a lot easier to read and maintain"
Yeah, maybe later, I don't wanna lose more time with this, it's was just for fun. But I'd like the damn thing to compile at least...:roll:

"Anyway, assuming I understood it correctly, you are working on the assumption that every pixel other than the start of a line would be a HAM pixel. "
Would be an hypothetical HAM pixel that can be represented by the difference with the previous one (we know how it works...). If it canĀ“t I just count it as a non HAM pixel in the statistics, even if I could have a register in the color table with the right RGB value. This will give me info on if it's possible to use the copper to change colors to have true RGB values;) I remember with Dynamic HAM, SHAM and whatever the copper could only change about 16 colour registers per line. I'd like to mess with that on AGA and see what I can get, just for the sake of it ...

"What you might consider doing is finding some code for quantitative colour reduction and finding the best 64 colours from the source data. You can then use these as a base palette for your calculation and try to find (within each pixel row) if it is better to use a palette colour or a HAM pixel."
As I said above, the cool thing to me would be to be able to avoid the color reduction in the first place using the copper. The would be very cool. I think Brilliance does this, given the 24bit images I've seen on it. One of these days I might try to disassemble it's cooper lists to see what it does.

"I'm sure most good RGB ->HAM conversions would do something like this anyway.

As for your compiler problem, I don't generally use SAS-C, so I am not sure I can help there :-/"

It must be something very trivial. I don't use SAS-C either...
\\"We made Amiga, they {bleep}ed it up\\"
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: HAM8 friendliness statistics for 24 pictures ImageFX hook I made...
« Reply #7 on: February 03, 2006, 02:48:49 PM »
@Jose
[EDIT]
Code: [Select]

#include <scan/scan_protos.h>
#include <scan/hooks.h>


This suggests the ObtainCurrentBuffer is in fact function in some scan.library or so. It can also be some static library (in which case you should use LIB somescanthing.lib).
If not, the symbol must be linked in from some object file (or the code pasted directly into the program).

Once you figure out where ObtainCurrentBuffer comes from, fixing the problem should be easier...
[/EDIT]
 

Offline Steady

Re: HAM8 friendliness statistics for 24 pictures ImageFX hook I made...
« Reply #8 on: February 03, 2006, 05:09:00 PM »
@Jose

On top of what Piru is saying, you also have no main defined. You'll need to either rename hook_main to main or create as separate main function that calls hook_main with argc & argv passed as parameters.
 

Offline JoseTopic starter

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2869
    • Show only replies by Jose
Re: HAM8 friendliness statistics for 24 pictures ImageFX hook I made...
« Reply #9 on: February 06, 2006, 05:47:00 PM »
Hi. I still haven't took the time to try to fix this... just a couple of notes:
1- It should be "& 0x03" not "& 0x7" or "> 0x3F".
00000011 to be more precise (I suck doing number conversions).
This is because I want to XOR the two values to have only the different  bits as a result, then I check if the lower 2 bits are also different, if they're not then the pixel can be HAM8 represented.

2- IIRC accoring to the docs the scan library with wich I link has the main function, wich also takes care of startup.
There's two version of it, one that uses registerized arguments the other not. I'm pretty sure I was using the non registerized version with out linking with the appropriate .lib library.
\\"We made Amiga, they {bleep}ed it up\\"