# If I want to add a drawing mode to TCastleImage.DrawFrom TDrawMode implements dmAnti mode how do I manipulate image pixels to achieve Anti effect

**URL:** <https://forum.castle-engine.io/t/if-i-want-to-add-a-drawing-mode-to-tcastleimage-drawfrom-tdrawmode-implements-dmanti-mode-how-do-i-manipulate-image-pixels-to-achieve-anti-effect/1005>\
**Category:** Uncategorized\
**Created:** [November 29, 2023, 10:18am UTC](https://forum.castle-engine.io/t/if-i-want-to-add-a-drawing-mode-to-tcastleimage-drawfrom-tdrawmode-implements-dmanti-mode-how-do-i-manipulate-image-pixels-to-achieve-anti-effect/1005 "2023-11-29T10:18:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![a8265348](https://forum.castle-engine.io/letter_avatar_proxy/v4/letter/a/43a26b/32.png) [@a8265348](https://forum.castle-engine.io/u/a8265348)\
**Post date:** [November 29, 2023, 10:18am UTC](https://forum.castle-engine.io/t/if-i-want-to-add-a-drawing-mode-to-tcastleimage-drawfrom-tdrawmode-implements-dmanti-mode-how-do-i-manipulate-image-pixels-to-achieve-anti-effect/1005/1 "2023-11-29T10:18:45Z")

</div>

- Thank you very much for guiding me

---

<div class="post-metadata">

**Author:** ![a8265348](https://forum.castle-engine.io/letter_avatar_proxy/v4/letter/a/43a26b/32.png) [@a8265348](https://forum.castle-engine.io/u/a8265348)\
**Post date:** [November 29, 2023, 10:50am UTC](https://forum.castle-engine.io/t/if-i-want-to-add-a-drawing-mode-to-tcastleimage-drawfrom-tdrawmode-implements-dmanti-mode-how-do-i-manipulate-image-pixels-to-achieve-anti-effect/1005/2 "2023-11-29T10:50:46Z")

</div>

- The cache template set by D3D implements anti  
FD3DDevice.SetRenderState(D3DRS\_ALPHABLENDENABLE, iTrue);  
D3DDevice.SetRenderState(D3DRS\_SRCBLEND, D3DBLEND\_INVDESTCOLOR);  
FD3DDevice.SetRenderState(D3DRS\_DESTBLEND, D3DBLEND\_ONE);

---

<div class="post-metadata">

**Author:** ![michalis](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/michalis/32/3_2.png) [@michalis](https://forum.castle-engine.io/u/michalis)\
**Post date:** [February 24, 2024, 9:03pm UTC](https://forum.castle-engine.io/t/if-i-want-to-add-a-drawing-mode-to-tcastleimage-drawfrom-tdrawmode-implements-dmanti-mode-how-do-i-manipulate-image-pixels-to-achieve-anti-effect/1005/3 "2024-02-24T21:03:08Z")

</div>

I see this was left unanswered for a long time. Sorry! In case my answer may still be useful:

1. `DrawFrom` is implemented in `src/images/castleimages_draw.inc` and you can follow the implementation of any other existing mode to see how to add a new one. For “anti”, I understand you want to negate pixel values, so basically `GrayScaleValue := 255-GrayScaleValue`.

2. So, a better approach to do this using TDrawableImage:

3. Note that, depends on how you want to use the image, maybe you don’t need to modify if at all. You can use effects and shaders when displaying (e.g. `TCastleImageControl.CustomShader`) without the need to modify the image.
