ImagingDebug.pas 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. {
  2. $Id$
  3. Vampyre Imaging Library
  4. by Marek Mauder
  5. http://imaginglib.sourceforge.net
  6. The contents of this file are used with permission, subject to the Mozilla
  7. Public License Version 1.1 (the "License"); you may not use this file except
  8. in compliance with the License. You may obtain a copy of the License at
  9. http://www.mozilla.org/MPL/MPL-1.1.html
  10. Software distributed under the License is distributed on an "AS IS" basis,
  11. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
  12. the specific language governing rights and limitations under the License.
  13. Alternatively, the contents of this file may be used under the terms of the
  14. GNU Lesser General Public License (the "LGPL License"), in which case the
  15. provisions of the LGPL License are applicable instead of those above.
  16. If you wish to allow use of your version of this file only under the terms
  17. of the LGPL License and not to allow others to use your version of this file
  18. under the MPL, indicate your decision by deleting the provisions above and
  19. replace them with the notice and other provisions required by the LGPL
  20. License. If you do not delete the provisions above, a recipient may use
  21. your version of this file under either the MPL or the LGPL License.
  22. For more information about the LGPL: http://www.gnu.org/copyleft/lesser.html
  23. }
  24. { This unit is a wrapper to "The Image Debugger" library/utility.}
  25. unit ImagingDebug;
  26. {$I ImagingOptions.inc}
  27. interface
  28. uses
  29. SysUtils, ImagingTypes, Imaging, ImagingUtility, PasImDebug;
  30. { Wrapper to PasImDebug.ImDebug function which automaticaly creates proper
  31. format string for given image. ImageDebugger's DLL and viewer app must
  32. be in system's search path.}
  33. procedure DebugImage(const Img: TImageData);
  34. implementation
  35. procedure DebugImage(const Img: TImageData);
  36. var
  37. FmtInfo: TImageFormatInfo;
  38. PF: PPixelFormatInfo;
  39. FmtString: string;
  40. DebugImg: TImageData;
  41. begin
  42. if TestImage(Img) then
  43. begin
  44. GetImageFormatInfo(Img.Format, FmtInfo);
  45. if FmtInfo.IsSpecial or FmtInfo.IsIndexed then
  46. begin
  47. CloneImage(Img, DebugImg);
  48. ConvertImage(DebugImg, ifDefault);
  49. GetImageFormatInfo(DebugImg.Format, FmtInfo);
  50. end
  51. else
  52. DebugImg := Img;
  53. // first determine proper channel format
  54. if FmtInfo.HasGrayChannel then
  55. begin
  56. FmtString := 'lum';
  57. if FmtInfo.HasAlphaChannel then
  58. FmtString := FmtString + 'a';
  59. end
  60. else
  61. begin
  62. if FmtInfo.IsRBSwapped then
  63. FmtString := 'rgb'
  64. else
  65. FmtString := 'bgr';
  66. if FmtInfo.HasAlphaChannel then
  67. FmtString := FmtString + 'a';
  68. end;
  69. FmtString := FmtString + ' b=';
  70. // Now determine proper channel bit counts
  71. if FmtInfo.UsePixelFormat then
  72. begin
  73. PF := FmtInfo.PixelFormat;
  74. FmtString := FmtString + Iff(PF.BBitCount > 0, IntToStr(PF.BBitCount), '');
  75. FmtString := FmtString + Iff(PF.GBitCount > 0, ',' + IntToStr(PF.GBitCount), '');
  76. FmtString := FmtString + Iff(PF.RBitCount > 0, ',' + IntToStr(PF.RBitCount), '');
  77. FmtString := FmtString + Iff(PF.ABitCount > 0, ',' + IntToStr(PF.ABitCount), '');
  78. end
  79. else
  80. begin
  81. if FmtInfo.HasGrayChannel then
  82. begin
  83. case FmtInfo.Format of
  84. ifGray8, ifA8Gray8: FmtString := FmtString + '8';
  85. ifGray16, ifA16Gray16: FmtString := FmtString + '16';
  86. ifGray32: FmtString := FmtString + '32';
  87. ifGray64: FmtString := FmtString + '64';
  88. end;
  89. end
  90. else if FmtInfo.IsFloatingPoint then
  91. begin
  92. case FmtInfo.BytesPerPixel of
  93. 4: FmtString := 'r b=32f';
  94. 6, 8: FmtString := FmtString + '16f';
  95. 12, 16: FmtString := FmtString + '32f';
  96. end;
  97. end
  98. else
  99. begin
  100. case FmtInfo.BytesPerPixel of
  101. 3..4: FmtString := FmtString + '8';
  102. 6..8: FmtString := FmtString + '16';
  103. 12..16: FmtString := FmtString + '32';
  104. end;
  105. end;
  106. end;
  107. imdebug(PChar(FmtString + ' w=%d h=%d %p'), DebugImg.Width, DebugImg.Height, DebugImg.Bits);
  108. if DebugImg.Bits <> Img.Bits then
  109. FreeImage(DebugImg);
  110. end
  111. else
  112. DebugMsg('DebugImage: Invalid input image %s', [ImageToStr(Img)]);
  113. end;
  114. end.