Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

475 lines
9.7 KiB

  1. /**************************************************************************\
  2. *
  3. * Copyright (c) 1999 Microsoft Corporation
  4. *
  5. * Module Name:
  6. *
  7. * ImageAttr.cpp
  8. *
  9. * Abstract:
  10. *
  11. * GpImageAttributes (recolor) methods
  12. *
  13. * Revision History:
  14. *
  15. * 14-Nov-1999 gilmanw
  16. * Created it.
  17. *
  18. \**************************************************************************/
  19. #include "precomp.hpp"
  20. #include "..\imaging\api\comutils.hpp"
  21. #include "..\imaging\api\decodedimg.hpp"
  22. /**************************************************************************\
  23. *
  24. * Function Description:
  25. *
  26. * Create a default GpImageAttributes.
  27. *
  28. * Arguments:
  29. *
  30. * NONE
  31. *
  32. * Return Value:
  33. *
  34. * NONE
  35. *
  36. \**************************************************************************/
  37. GpImageAttributes::GpImageAttributes()
  38. {
  39. SetValid(TRUE); // default is valid
  40. recolor = new GpRecolor();
  41. // default WrapMode settings;
  42. DeviceImageAttributes.wrapMode = WrapModeClamp;
  43. DeviceImageAttributes.clampColor = (ARGB)0x00000000; // Fully transparent black
  44. DeviceImageAttributes.srcRectClamp = FALSE;
  45. cachedBackground = TRUE;
  46. }
  47. /**************************************************************************\
  48. *
  49. * Function Description:
  50. *
  51. * Release GpImageAttributes.
  52. *
  53. * Arguments:
  54. *
  55. * NONE
  56. *
  57. * Return Value:
  58. *
  59. * NONE
  60. *
  61. \**************************************************************************/
  62. VOID GpImageAttributes::Dispose()
  63. {
  64. delete this;
  65. }
  66. GpImageAttributes::~GpImageAttributes()
  67. {
  68. if (recolor)
  69. recolor->Dispose();
  70. }
  71. /**************************************************************************\
  72. *
  73. * Function Description:
  74. *
  75. * Clone GpImageAttributes.
  76. *
  77. * Arguments:
  78. *
  79. * NONE
  80. *
  81. * Return Value:
  82. *
  83. * Pointer to new GpImageAttributes if successful.
  84. *
  85. \**************************************************************************/
  86. GpImageAttributes* GpImageAttributes::Clone() const
  87. {
  88. GpImageAttributes* clone = new GpImageAttributes();
  89. if (clone)
  90. {
  91. if ( clone->IsValid() && this->IsValid() )
  92. {
  93. *clone->recolor = *this->recolor;
  94. }
  95. else
  96. {
  97. clone->Dispose();
  98. clone = NULL;
  99. }
  100. }
  101. return clone;
  102. }
  103. // Set to identity, regardless of what the default color adjustment is.
  104. GpStatus
  105. GpImageAttributes::SetToIdentity(
  106. ColorAdjustType type
  107. )
  108. {
  109. recolor->SetToIdentity(type);
  110. UpdateUid();
  111. return Ok;
  112. }
  113. // Remove any individual color adjustments, and go back to using the default
  114. GpStatus
  115. GpImageAttributes::Reset(
  116. ColorAdjustType type
  117. )
  118. {
  119. recolor->Reset(type);
  120. UpdateUid();
  121. return Ok;
  122. }
  123. GpStatus
  124. GpImageAttributes::SetColorMatrix(
  125. ColorAdjustType type,
  126. BOOL enable,
  127. ColorMatrix* colorMatrix,
  128. ColorMatrix* grayMatrix,
  129. ColorMatrixFlags flags)
  130. {
  131. HRESULT result;
  132. if (enable)
  133. result = recolor->SetColorMatrices(type, colorMatrix, grayMatrix, flags);
  134. else
  135. result = recolor->ClearColorMatrices(type);
  136. UpdateUid();
  137. if (FAILED(result))
  138. {
  139. if (result == E_OUTOFMEMORY)
  140. return OutOfMemory;
  141. else
  142. return InvalidParameter;
  143. }
  144. else
  145. return Ok;
  146. }
  147. GpStatus
  148. GpImageAttributes::SetThreshold(
  149. ColorAdjustType type,
  150. BOOL enable,
  151. REAL threshold)
  152. {
  153. HRESULT result;
  154. if (enable)
  155. result = recolor->SetThreshold(type, threshold);
  156. else
  157. result = recolor->ClearThreshold(type);
  158. UpdateUid();
  159. if (FAILED(result))
  160. return InvalidParameter;
  161. else
  162. return Ok;
  163. }
  164. GpStatus
  165. GpImageAttributes::SetGamma(
  166. ColorAdjustType type,
  167. BOOL enable,
  168. REAL gamma)
  169. {
  170. HRESULT result;
  171. if (enable)
  172. result = recolor->SetGamma(type, gamma);
  173. else
  174. result = recolor->ClearGamma(type);
  175. UpdateUid();
  176. if (FAILED(result))
  177. return InvalidParameter;
  178. else
  179. return Ok;
  180. }
  181. GpStatus GpImageAttributes::SetNoOp(
  182. ColorAdjustType type,
  183. BOOL enable
  184. )
  185. {
  186. HRESULT result;
  187. if (enable)
  188. result = recolor->SetNoOp(type);
  189. else
  190. result = recolor->ClearNoOp(type);
  191. UpdateUid();
  192. if (FAILED(result))
  193. return InvalidParameter;
  194. else
  195. return Ok;
  196. }
  197. GpStatus
  198. GpImageAttributes::SetColorKeys(
  199. ColorAdjustType type,
  200. BOOL enable,
  201. Color* colorLow,
  202. Color* colorHigh)
  203. {
  204. HRESULT result;
  205. if (enable)
  206. result = recolor->SetColorKey(type, colorLow, colorHigh);
  207. else
  208. result = recolor->ClearColorKey(type);
  209. UpdateUid();
  210. if (FAILED(result))
  211. return InvalidParameter;
  212. else
  213. return Ok;
  214. }
  215. GpStatus
  216. GpImageAttributes::SetOutputChannel(
  217. ColorAdjustType type,
  218. BOOL enable,
  219. ColorChannelFlags channelFlags
  220. )
  221. {
  222. HRESULT result;
  223. if (enable)
  224. result = recolor->SetOutputChannel(type, channelFlags);
  225. else
  226. result = recolor->ClearOutputChannel(type);
  227. UpdateUid();
  228. if (FAILED(result))
  229. return InvalidParameter;
  230. else
  231. return Ok;
  232. }
  233. GpStatus
  234. GpImageAttributes::SetOutputChannelProfile(
  235. ColorAdjustType type,
  236. BOOL enable,
  237. WCHAR *profile)
  238. {
  239. HRESULT result;
  240. if (enable)
  241. result = recolor->SetOutputChannelProfile(type, profile);
  242. else
  243. result = recolor->ClearOutputChannelProfile(type);
  244. UpdateUid();
  245. if (SUCCEEDED(result))
  246. return Ok;
  247. else
  248. {
  249. if (result == E_INVALIDARG)
  250. return InvalidParameter;
  251. else if (result == E_OUTOFMEMORY)
  252. return OutOfMemory;
  253. else
  254. return Win32Error;
  255. }
  256. }
  257. GpStatus
  258. GpImageAttributes::SetRemapTable(
  259. ColorAdjustType type,
  260. BOOL enable,
  261. UINT mapSize,
  262. ColorMap* map)
  263. {
  264. HRESULT result;
  265. if (enable)
  266. result = recolor->SetRemapTable(type, mapSize, map);
  267. else
  268. result = recolor->ClearRemapTable(type);
  269. UpdateUid();
  270. if (FAILED(result))
  271. return InvalidParameter;
  272. else
  273. return Ok;
  274. }
  275. GpStatus
  276. GpImageAttributes::SetCachedBackground(
  277. BOOL enableFlag
  278. )
  279. {
  280. if (cachedBackground != enableFlag)
  281. {
  282. cachedBackground = enableFlag;
  283. UpdateUid();
  284. }
  285. return Ok;
  286. }
  287. BOOL
  288. GpImageAttributes::HasRecoloring(
  289. ColorAdjustType type
  290. ) const
  291. {
  292. return (recolor) && (recolor->HasRecoloring(type) != 0);
  293. }
  294. GpStatus GpImageAttributes::SetWrapMode(WrapMode wrap, ARGB color, BOOL Clamp)
  295. {
  296. DeviceImageAttributes.wrapMode = wrap;
  297. DeviceImageAttributes.clampColor = color;
  298. DeviceImageAttributes.srcRectClamp = Clamp;
  299. UpdateUid();
  300. return Ok;
  301. }
  302. GpStatus GpImageAttributes::SetICMMode(BOOL on)
  303. {
  304. if( DeviceImageAttributes.ICMMode!= on)
  305. {
  306. DeviceImageAttributes.ICMMode = on;
  307. UpdateUid();
  308. }
  309. return Ok;
  310. }
  311. VOID GpImageAttributes::GetAdjustedPalette(
  312. ColorPalette * colorPalette,
  313. ColorAdjustType colorAdjustType
  314. )
  315. {
  316. ASSERT((colorPalette != NULL) && (colorPalette->Count > 0));
  317. if (!this->HasRecoloring(colorAdjustType))
  318. {
  319. return;
  320. }
  321. this->recolor->Flush();
  322. this->recolor->ColorAdjust(colorPalette->Entries, colorPalette->Count,
  323. colorAdjustType);
  324. }
  325. // Serialization
  326. class ImageAttributesData : public ObjectData
  327. {
  328. public:
  329. BOOL CachedBackground;
  330. DpImageAttributes DeviceImageAttributes;
  331. };
  332. /**************************************************************************\
  333. *
  334. * Function Description:
  335. *
  336. * Get the data from the GpImageAttributes for serialization.
  337. *
  338. * Return - size of GpImageAttributes
  339. *
  340. * 05/15/2000 asecchia - created it.
  341. *
  342. \**************************************************************************/
  343. GpStatus
  344. GpImageAttributes::GetData(
  345. IStream * stream
  346. ) const
  347. {
  348. ASSERT (stream != NULL);
  349. ImageAttributesData imageAttributesData;
  350. imageAttributesData.CachedBackground = cachedBackground;
  351. imageAttributesData.DeviceImageAttributes = DeviceImageAttributes;
  352. stream->Write(&imageAttributesData, sizeof(imageAttributesData), NULL);
  353. return Ok;
  354. }
  355. UINT
  356. GpImageAttributes::GetDataSize() const
  357. {
  358. return sizeof(ImageAttributesData);
  359. }
  360. /**************************************************************************\
  361. *
  362. * Function Description:
  363. *
  364. * Set the GpImageAttributes from the data buffer for serialization.
  365. *
  366. * 05/15/2000 asecchia - created it.
  367. *
  368. \**************************************************************************/
  369. GpStatus
  370. GpImageAttributes::SetData(
  371. const BYTE * dataBuffer,
  372. UINT size
  373. )
  374. {
  375. if (dataBuffer == NULL)
  376. {
  377. WARNING(("dataBuffer is NULL"));
  378. return InvalidParameter;
  379. }
  380. if (size < sizeof(ImageAttributesData))
  381. {
  382. WARNING(("size too small"));
  383. return InvalidParameter;
  384. }
  385. const ImageAttributesData *imageAttributes;
  386. imageAttributes = reinterpret_cast<const ImageAttributesData *>(dataBuffer);
  387. if (!imageAttributes->MajorVersionMatches())
  388. {
  389. WARNING(("Version number mismatch"));
  390. return InvalidParameter;
  391. }
  392. cachedBackground = imageAttributes->CachedBackground;
  393. DeviceImageAttributes = imageAttributes->DeviceImageAttributes;
  394. UpdateUid();
  395. // Might consider resetting the recolor objects to identity, but
  396. // for now don't need to since we know this method only gets called
  397. // right after the object has been constructed.
  398. return Ok;
  399. }