INDEX


Reading an Icon file in Delphi


     If you ever need to maniipulate the bits and the information in an Icon file you will need to go beyond the standard loading and saving functions available in Delphi. As well Delphi's saving and loading functions for Icons seems to only save and load small 16 by 16, 16 color Icons, which then display terribly as 32 by 32 icons as you would expect. The code associated with this page demos opening and viewing Icons by loading them directly from disk, and was written in preparation for the writing of code to directly save an Icon, bypassing Delphi. (The Windows API also does not include routines to save Icons. Some of the puzzles you have to solve to accomplish this are not trivial, and apparently its supposed to be that way - why are you trying to save someone else's icon, they must have thought.)


YOu can download the code associated with this article as a Delphi 3 / Delphi 5 project here ... icon_file.zip (17 KB) or you can view the source code as a text file by following these links ... icon_file_d3.txt Delphi 3 version or icon_file_d5.txt Delphi 5 version


      The following page describes the Icon file format and includes code for directly reading an icon file from disk. An Icon file begins with a File Header in the following format...Since an icon file can have more than one icon present, the total number of icons in the file is indicated by the value idCount.


TIconHeader = record
  idReserved: Word; {always 0}
  idType: Word; {always 1, identifies file as Icon file}
  idCount: Word; {total number of icon pics in file}
end;


     Immediately after the header follows idCount number of Icon Directory Records which describe each of the icons in the file.


TIconDirEntry = record
  bWidth: Byte; {ie: 16 or 32}
  bHeight: Byte; {ie: 16 or 32}
  bColorCount: Byte; {number of entires in pallette table below}
  bReserved: Byte; { not used = 0}
  wPlanes: Word; { not used = 0}
  wBitCount: Word; { not used = 0}
  dwBytesInRes: Longint; {total number bytes in images including pallette data XOR, AND and bitmap info header}
  dwImageOffset: Longint; {pos of image as offset from the beginning of file}
end;


     After the Directory entries is the actual image data for each icon. The data is arranged as a BitMapInfoHeader, palette data, and the Color image pixel data (the XOR Mask) and the Black and White pixel data (the AND mask). In order to display an icon 'transparently' the AND mask is applied to the screen using the AND operation and the XOR mask is applied using the exclusive or operation. The code accompanying this page displays both masks in Image objects, and you can see that the color image is surrounded by Black while the AND mask (monochrome black and white) is black where the color image is present and then white outside the image. Black is encoded as color zero and white as a complete set of binary ones, so when the AND mask is applied to the screen using the AND operation, where the image is black, the screen pixels are excluded (1 and 0 = 0). When the color Mask is then applied using the exclusive or operation, only those places where the screen has been excluded (made zero by the AND operation described above) will the pixels of the color XOR map be applied to the screen (an exclusive or operation, only one or the other but not both).

     For this reason the Icon includes two bitmaps, one larger bitmap (in color) and one smaller bitmap in Black and white (one bit per pixel).

     The Bitmap info Header is found at the start of each icon in the icon file (although, I have found that most icon files contain only one 32 by 32 16 color icon, and a smaller icon is created by the system by compressing the data of this larger icon). The Bitmap info header for an icon file is identical to a standard Bitmap info header with the difference being that the 'height' field is doubled (the height of the XOR mask plus the height of the AND mask). The size image, however, refers to the color bitmap. Since icons are so small, compression is not used, and most icons are 4 bit/16 color although some are 8 bit/256 color and I have seen one icon that was 24 bit, but this was probably an anomaly.


TBitmapInfoHeader = record
   biSize: Longint; {size of tbitmapinfoheader = 40}
  biWidth: Longint; {bitmap width}
  biHeight: Longint; (height of bitmap)
  biPlanes: Word; {always 1}
  biBitCount: Word; {number color bits 4 = 16 colors, 8 = 256 pixel is a byte}
  biCompression: Longint; {compression used, 0 }
  biSizeImage: Longint; ( size of the pixel data)
  biXPelsPerMeter: Longint; {not used, 0 }
  biYPelsPerMeter: Longint; {not used, 0 }
  biClrUsed: Longint; {number of colors used, set to 0 }
  biClrImportant: Longint; {important colors, set to 0 }
end;


     The Bit Map info header is followed by the palette data in the form of RGB quads, as described on the page on the Bitmap file format. The number of bytes in the palette entries will be IconDirEntry.bColorCount * 4.

     After the palette entries comes the bit data for the color Bitmap, followed by the Bit data for the Black and white 1 bit AND bitmap. If more icons follow this will be followed by a Bitmap info header, a palette, a color bit map, a black and white bit map, etc.

     A few points to discuss concerning the source code accompanying this page. Windows API functions will only return icons that are deemed suitable for the display. When you actually open an icon file yourself, and find that it includes multiple icons, and then use the API, it will report that only 1 icon was found. Some icon files do not seem to conform to specs. For example the 'Windows Update' Icon file contains 6 icons. Three can be read fine. Two do not seem to have an AND mask in the location that it is supposed to be in, and a thorough search of the area did not turn up an AND mask. The last icon in the file returns a suitable color and black and white bitmap, but then comes back from the API strangely colored. The RGB quad bytes for a bitmap must be red in byte by byte in the order Blue, Green, Red or the Bitmap will display with its colors reversed. The situation with icons is less clear to me at the moment because icons are returned with no Palette (the handle is zero) and sometimes the API seems to ignore the palette altogether, making it more difficult to determine the exact order of the RGB quads in an icon file. Delphi 5 includes dynamic arrays. This crashes Delphi 3 and so the arrays have been made static. If you know something more about Delphi 3 you might want to modify the code at this point. I have also achieved weird results when using untyped binary files to read and write to record structures (something to do with four byte boundaries and so on) and have made some fruitless searches on the net for more info. For this reason temporary variables are read from disk and then inserted into the records. If you know more about this matter you can also modify the code at this point.


Delphi INDEX




A Unified Field Theory

failed_gravity_theory.gif - 10361 Bytes



The Unified Field Theory
is also available as a zip file ->
unified.zip

Introduction :The Pioneer Effect and the New Physics. A brief description of the new physics required to explain the 'Pioneer Effect', which is the constant deceleration of space craft as they fly through space.




Principles of Evolution: A Study in the Evolution of Bedbugs



A couple of years ago my bedroom was invaded by bedbugs. There were two variant genetic lines. One type of bedbug was an enlongated, thin, tubular insect, and the second genetic line was a flat, perfectly circular insect. The result of the cross breeding of these two genetically distinct variants was the production of a bedbug with charcteristics of both, an enlongated, flat bedbug with a central bulge (such that the shape of the bedbug was somewhere between 'long' and 'circular'). The long skinny bedbugs were such strange and unfamiliar looking insects that at first I did not recognize them as being bedbugs, and considered them to be a seperate species of insect. However, as the photographs of bedbugs above indicate, enlongated and skinny bedbugs are not uncommon, and the photographs also show the variants that are produced by genetic combinations that result in an insect somewhere in between 'circular' and 'enlongated'.

Therefore it is my hypothesis that evolution occurs by means of the transfer of dominate genes, with the production of such dominant genes being the product of 'biological algorithms', a genetic software program that brings physical characteristics into harmony with behavior, such that when behavior changes, and a conflict then exists, this acts as a trigger and causes the release of dominant genes. The result is rapid evolution of species. The bedbug is a relatively new insect, not the product of millions of years of evolution but rather an insect that is evolving in real time. The newly emerging dominant form of the insect is the flat, round ciruclar insect, well adapted to living in human bedrooms (it is flat, rather than tubular, thus allowing it to hide in the smallest cracks, living a stealthy lifestyle, and it is round, which gives the insect a maximum storage capacity such that it must endanger itself only a few times a month by emerging to feed.

Other examples of rapid evolution include the development of long legs in an invasive species of toad in Australia. As the toads move into the mountainous regions of Australia, and their behvaior changes, making them 'climbing toads', over the course of just a couple of decades the toads in the highlands have grown long legs specially adapted to climbing. It is worth noting here that the toads are poisonous, and are a successful invasive species because they have no natural predators in Australia, and so it would not be the case that the toads with long legs were 'the fittest survivors', because all the toads are survivors, and therefore predation does not explain the rapid emergence and spread of such well adapted, long legged toads. Once again we see evidence for the existence of biological algorithms and the rapid spread of dominant genes through a population, which once introduced proceed to overwhelm the older genes which are being replaced (making toad long legged and a bed bug round and flat).


A Theological Experiment

My interest in pursuing the Unified Field Theory is spurred on by my need to discover the theoretical explanation of a new form of propulsion (as explained on this page: Why the Unified Field Theory?). The experiment involving the bedbugs came out of nowhere.

I also believe that it is possible to justify theological propositions using experimental methods. If a thing is an objective truth then it can be verified and proven true by means of experimentation. Such a theological proposition is of more value than a ‘divine revelation’, since such revelations depend upon nothing more than establishing authority figures which requires the creation of artificial hierarchies, for the only reason why I might be encouraged to believe an authority figure who orders me to believe unsubstantiated opinions is if I could somehow be convinced that this authority possessed a mind that was somehow superior to mine, and thus was fit to express opinions as though opinions were unquestionable facts and thus worthy of being elevated to the status of absolute dogma.

There is a self evident human inequality which is visibly apparent. Some people are ‘beautiful’ and thus are the true elite on this planet, and some people are not. It is this sexual inequality and the degeneration that follows upon beauty that is the true driving force behind all the evil that happens on earth. The need for ruthless oppression and the pursuit of wealth and the consequent creation of suffering and poverty which must follow upon this practice is for the purpose of creating an artificial alpha elite.

The true elites are the young and the beautiful. The artificial elite are the rich and the wealthy. The elite aging rich artificial alpha male has no good looks, for he is physically degenerate, but he will be found escorting beauty because he has a beautiful wallet. If he loses his wallet he will be found at home with all the other unattractive aged beta males sitting in a rocking chair watching reruns of Bonanza. No money, no sex. It is for this reason that the alpha males are found to be so ruthless and so violent in pursuit of their goal. The alpha male has fallen. The beta male has arisen and now the whole planet is full of ruinous destruction for it.

We see in religion a confused and contradictory reaction to this reality. On the one hand religion preaches a sexless heaven where castration and the clitorectomy create ‘pure spirits’. Muslims throw women under sacks. On the other hand religion supports hierarchy and is the prop of the elite alpha male. It is for this reason that religion is incoherent when it comes to speaking about sex.

Now we see this same principle at work in all of nature. Guppies dance and show off their colorful tails and the guppy who dances with the most colorful tail is the sexually successful guppy. Therefore it is the doctrine of the ruthless oppressor which teaches that the solution to human sexual violence is to be found in castration and the creation of pure ghosts. This would be equivalent to damning an aardvark for having the ‘sinful aardvark nature’ or prosecuting an anteater for the high crime of ‘ant genocide’.

Therefore it was my theological hypothesis that the correct solution to this problem is to give every guppy a beautiful colorful tail. I compare this solution to the classic religious solution which is to cut off every tail since having a tail is ‘sinful’. If having a tail is sinful then God must be sinful for no human being has any choice in deciding whether or not they would be born with a colorful tail, or whether they would not.

When I was young I was a beautiful guppy with a lovely tail. So everyone seemed to think. I am older now. My nose became very badly sunburned and destroyed. It seemed good to me to test my hypothesis by using these ‘biological algorithms’ to correct this problem. I healed half my nose as you can see by the line separating the still very dark patch on the side in the photograph below.





I documented my experiment on these pages. one two t hree four fi ve six


I have confirmed to my own satisfaction that my theological proposition is correct and that religious dogma is erroneous, being based as it was upon nothing more than ‘divine revelation’ which is just a form of opinionated speculation. For the time being I am not continuing this experiment, for I must wait until the weather on this planet improves, and the dark clouds of ruthless oppression break letting a little sun shine come through so that I can show the world the truth about God, by showing people how God goes about giving an old guppy back his beautiful colorful tail.


Until then I will have to sit on the sidelines, while all my scientific breakthroughs are deliberately ignored, while I wonder to myself what ever in the world could be wrong with the human race, because what this all will prove at the end of it all is that there definitely was something wrong with the people on this planet.