unit mipmaps; {$MODE OBJFPC} {$M+} interface uses contnrs, classes, images, type_fixes, colors; // TODO don't refcount all over the place!!! // a mipmap is a set of images. // the images usually, but not always, have different sizes. // the images usually, but not always, have different color spaces. type TMipmap = class private fItems : TInterfaceList; // list of bitmaps in order of size (smallest first). // TODO on-demand loading of more detailed mipmaps. public destructor Destroy(); override; protected function GetItemCount() : Integer; inline; published constructor Create(); property ItemCount : Integer read GetItemCount; function GetItem(aIndex : Integer) : IImage; inline; // add: return index. public property Items[aIndex : Integer] : IImage read GetItem; function GetBestFit(aColorspace : TColorspace; aScaleWidth, aScaleHeight : TCardinal) : Integer; // index into "Items", or -1. IImage; public function Add(const aImage : IImage) : Integer; end; implementation uses sysutils; destructor TMipmap.Destroy(); begin FreeAndNil(fItems); inherited Destroy(); end; function TMipmap.GetItem(aIndex : Integer) : IImage; inline; begin Result := IImage(fItems[aIndex]); end; function TMipmap.GetItemCount() : Integer; inline; begin Result := fItems.Count; end; constructor TMipmap.Create(); begin inherited Create(); fItems := TInterfaceList.Create(); end; { returns the first pixmap that is >= a given size. } function TMipmap.GetBestFit(aColorspace : TColorspace; aScaleWidth, aScaleHeight : TCardinal) : Integer; var vIndex : Integer; vItem : IImage; begin // FIXME handle aColorspace. Result := -1; if fItems.Count = 0 then Exit; // TODO binary search. for vIndex := 0 to fItems.Count - 1 do begin vItem := GetItem(vIndex); if (vItem.Width >= aScaleWidth) and (vItem.Height >= aScaleHeight) then begin Result := vIndex; // Item; Exit; end; end; Result := fItems.Count - 1; // GetItem(fItems.Count - 1); end; function TMipmap.Add(const aImage : IImage) : Integer; begin Result := fItems.Count; fItems.Add(aImage); end; end.