@Bart:
Don't worry too much. Most of that information that is/was presented can easily be obtained by running an executable through a debugger or disassembler. Unless you count that as "having seen the source-code". For me (but also for most if not all compilers) it is not the same as having looked at the original code. Usually a compiler allows the binary produced data to be distributed without it being copyrighted by the original author/copyright holder of the used compiler. And thank heavens for that as that would be an instant wet dream for all copyright trolls out there.
Well, the formulation was a bit inaccurate:
Yeah, sorry about that but since I can only check fpc's implementation the conclusion from what I've read is that it needs to add the header to the stream in order for the rest of the code to be able to properly load the resource from the stream because the fileheader is expected to exist. It is almost impossible to write that down without a whole lot of cringe feelings about that (the requirement to add something to raw data so that the rest of the code is able to properly process it *chills running down spine*).
They do not "reconstruct" the header.
Thank you very much for that detailed process of how Delphi seem to be doing things. That process makes a whole lot more sense to me as there is no need to add data to anything but just checking if something exist or not and the rest of the code acting accordingly (e.g. skip loading the fileheader but start processing the data that does exist (or is suppose to exist))
As a consequence Delphi cannot use LoadFromStream to read RT_BITMAP resources provided by a ResourceStream - maybe this is intentional (because RT_BITMAP is "known" to provide an incomplete bitmap stream), but I tend to say that it is a bug because it makes the resourcetype parameter of the TResourceStream constructor obsolete, at least for bitmaps.
I think we have a different opinion on that
For me it makes absolute sense that loadfromstream is not able to load any other arbitrary data to construct a bitmap out of it. And I know I exaggerate with the example here but before you know it people expect to feed it a stream of jpeg data and for that data to be converted into a proper bitmap automagically because, why not ?
If you so must then you can use the designated loadfromresourceXXX functionality, and if that is not enough then perhaps introduce a loadfromresourcestream method that directly loads the resource data stream without the needs to use (fall back to) existing functionality ?
Btw, have you noticed the implementation of function CreateBitmapFromResourceName inside unit graphics ?
Lazarus, on the other hand, uses an internal "THeaderStream" class to fake (reconstruct) the presence of a TBitmapFileHeader for the main reading done by fcl-image.
Yeah I've noticed that Lazarus relies on the LoadFromStream method but not have looked at the readers in detail. fwiw I understand why it would have ended up in LoadFromStream as most (if not all) the other graph formats are loaded from a resource of type RT_DATA only and that is always the raw data as stored on disk.
But GetReaderClass is a class method, and I don't know an easy way of telling this method whether the reader is needed for LoadFromStream or for LoadFromResourceName. And even if it could be done, it would leave us in the same situation as Delphi where RT_BITMAP resources cannot be read by LoadFromStream.
afaik as it stands now only for LoadFromStream() /but/ LoadFromResourceName() depends on LoadFromStream() so indirectly for that function as well. That is the reason this issue exist in the first place.
I have not seen any (online) example in Delphi that directly loads a bitmap from a (bitmap)resource using LoadFromStream, Even embarcadero's examples (that are publicly available) uses the LoadFromResourceXXX functions in order to construct a bitmap out of a (bitmap) resource. So I personally would not regret it one bit if it wasn't possible (anymore) to load a bitmap resource using LoadFromStream() but that is a pure personal opinion on the matter. Just to avoid misunderstandings RT_DATA is ofc just raw data and can be loaded using LoadFromStream.
In one of my earlier replies I stated (I had it removed after I posted) to opt for overloading/reintroducing the LoadFromResourceXXX functionality to do it more in the style Delphi seems to be doing (ans I could now more or less verify it for as far as I was able to understand from your detailed descriptions) but that does have some implications such as not being able to use LoadFromStream for loading a bitmap resource anymore and some care needs to be taken for other formats that can be loaded by TBitmap and that supports loading from a resource other than RT_DATA. I haven't had time yet to look into that into more detail (which also requires some better understanding of the reader).
fwiw it is not about beating the dead horse and trying for someone (else) to revive that horse in case it isn't necessary. Your otherwise excellent solution works as expected/intended just not how I would have done it (and according to your findings Delphi doesn't seem to do so either).