This repository was archived by the owner on Mar 7, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 174
Implement CachedBitmap functionality #654
Open
reflectronic
wants to merge
16
commits into
mono:main
Choose a base branch
from
reflectronic:cachedbitmap
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 10 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
1edd1ff
Define CachedBitmap and implmement creation of CachedBitmap
reflectronic 214944c
Initial implementation of drawing
reflectronic 8d93375
Fix build
reflectronic 1b50fd3
Copy image to surface
reflectronic df49539
Small fixes
reflectronic 90c8c1f
Add tests
reflectronic 9604d0a
Use correct formatting
reflectronic 09d203c
Free surface when out of memory
reflectronic 25def1a
Fix build error
reflectronic 74dcbab
Remove unused variable
reflectronic e55ff2a
Add .NET foundation license headers
reflectronic 84efade
Add delete test
reflectronic e335c2f
Fix formatting
reflectronic bc6ab5c
Fix tests
reflectronic d2f545a
Add support for translation matrices for Windows compat
reflectronic f0d5700
Test clip regions and translation matrices
reflectronic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| #ifndef __CACHEDBITMAP_PRIVATE_H__ | ||
| #define __CACHEDBITMAP_PRIVATE_H__ | ||
|
|
||
| typedef struct _CachedBitmap { | ||
| cairo_surface_t *surface; | ||
| } CachedBitmap; | ||
|
|
||
| #include "cachedbitmap.h" | ||
|
|
||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| #include "general-private.h" | ||
| #include "bitmap-private.h" | ||
| #include "graphics-private.h" | ||
| #include "cachedbitmap-private.h" | ||
|
|
||
| GpStatus WINGDIPAPI | ||
| GdipCreateCachedBitmap (GpBitmap *bitmap, GpGraphics *graphics, GpCachedBitmap **cachedBitmap) | ||
| { | ||
| cairo_t *ct; | ||
| cairo_surface_t *surface; | ||
| GpCachedBitmap *newCachedBitmap; | ||
| cairo_status_t status; | ||
|
|
||
| if (!bitmap || !graphics || !cachedBitmap) | ||
| return InvalidParameter; | ||
| if (bitmap->type != ImageTypeBitmap) | ||
| return InvalidParameter; | ||
|
|
||
| gdip_bitmap_ensure_surface (bitmap); | ||
|
|
||
| surface = cairo_surface_create_similar (bitmap->surface, CAIRO_CONTENT_COLOR_ALPHA, bitmap->active_bitmap->width, bitmap->active_bitmap->height); | ||
|
|
||
| ct = cairo_create (surface); | ||
|
|
||
| cairo_set_source_surface (ct, bitmap->surface, 0, 0); | ||
| cairo_paint (ct); | ||
|
|
||
| cairo_destroy (ct); | ||
|
|
||
| status = cairo_surface_status (surface); | ||
| if (status != CAIRO_STATUS_SUCCESS) { | ||
| cairo_surface_destroy (surface); | ||
| return gdip_get_status (status); | ||
| } | ||
|
|
||
| newCachedBitmap = GdipAlloc (sizeof (GpCachedBitmap)); | ||
| if (!newCachedBitmap) | ||
| { | ||
| cairo_surface_destroy(surface); | ||
| return OutOfMemory; | ||
| } | ||
|
|
||
| newCachedBitmap->surface = surface; | ||
| *cachedBitmap = newCachedBitmap; | ||
|
|
||
| return Ok; | ||
| } | ||
|
|
||
| GpStatus WINGDIPAPI | ||
| GdipDeleteCachedBitmap (GpCachedBitmap *cachedBitmap) | ||
| { | ||
| if (!cachedBitmap) | ||
| return InvalidParameter; | ||
|
|
||
| cairo_surface_destroy (cachedBitmap->surface); | ||
| GdipFree (cachedBitmap); | ||
|
|
||
| return Ok; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| #ifndef __CACHEDBITMAP_H__ | ||
| #define __CACHEDBITMAP_H__ | ||
|
|
||
| GpStatus WINGDIPAPI GdipCreateCachedBitmap (GpBitmap *bitmap, GpGraphics *graphics, GpCachedBitmap **cachedBitmap); | ||
|
|
||
| GpStatus WINGDIPAPI GdipDeleteCachedBitmap (GpCachedBitmap *cachedBitmap); | ||
|
|
||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| #ifdef WIN32 | ||
| #ifndef __cplusplus | ||
| #error Please compile with a C++ compiler. | ||
| #endif | ||
| #endif | ||
|
|
||
| #if defined(USE_WINDOWS_GDIPLUS) | ||
| #include <Windows.h> | ||
| #include <GdiPlus.h> | ||
|
|
||
| #pragma comment(lib, "gdiplus.lib") | ||
| #else | ||
| #include <GdiPlusFlat.h> | ||
| #endif | ||
|
|
||
| #if defined(USE_WINDOWS_GDIPLUS) | ||
| using namespace Gdiplus; | ||
| using namespace DllExports; | ||
| #endif | ||
|
|
||
| #include <assert.h> | ||
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
| #include "testhelpers.h" | ||
|
|
||
| #define C(func) assert (func == Ok) | ||
reflectronic marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| static GpGraphics *getImageGraphics (GpImage **image) | ||
| { | ||
| WCHAR *filePath; | ||
| GpGraphics *graphics; | ||
|
|
||
| filePath = createWchar ("test.bmp"); | ||
| C (GdipLoadImageFromFile (filePath, image)); | ||
|
|
||
| freeWchar (filePath); | ||
|
|
||
| C (GdipGetImageGraphicsContext (*image, &graphics)); | ||
|
|
||
| return graphics; | ||
| } | ||
|
|
||
| static GpImage* getImage (const char* fileName) | ||
| { | ||
| GpStatus status; | ||
| WCHAR *wFileName = wcharFromChar (fileName); | ||
| GpImage *image; | ||
|
|
||
| status = GdipLoadImageFromFile (wFileName, &image); | ||
| assertEqualInt (status, Ok); | ||
|
|
||
| freeWchar (wFileName); | ||
|
|
||
| return image; | ||
| } | ||
|
|
||
| static void test_roundtrip () | ||
| { | ||
| UINT width; | ||
| UINT height; | ||
| GpBitmap *originalBitmap; | ||
| GpBitmap *surface; | ||
| GpGraphics *graphics; | ||
| GpCachedBitmap *cached; | ||
|
|
||
| originalBitmap = getImage ("test.bmp"); | ||
|
|
||
| C (GdipGetImageWidth (originalBitmap, &width)); | ||
| C (GdipGetImageHeight (originalBitmap, &height)); | ||
|
|
||
| C (GdipCreateBitmapFromScan0 (width, height, 0, PixelFormat32bppARGB, 0, &surface)); | ||
| C (GdipGetImageGraphicsContext (surface, &graphics)); | ||
|
|
||
| GpRect rect = { | ||
| .X = 0, | ||
| .Y = 0, | ||
| .Width = width, | ||
| .Height = height | ||
| }; | ||
|
|
||
| C (GdipSetVisibleClip_linux (graphics, &rect)); | ||
| C (GdipCreateCachedBitmap (originalBitmap, graphics, &cached)); | ||
| C (GdipDrawCachedBitmap (graphics, cached, 0, 0)); | ||
|
|
||
| for (int x = 0; x < width; x++) | ||
| { | ||
| for (int y = 0; y < height; y++) | ||
| { | ||
| ARGB drawn, original; | ||
|
|
||
| C (GdipBitmapGetPixel (originalBitmap, x, y, &original)); | ||
| C (GdipBitmapGetPixel (surface, x, y, &drawn)); | ||
|
|
||
| assertEqualInt (drawn, original); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| static void test_create () | ||
| { | ||
| GpImage *image; | ||
| GpGraphics *graphics; | ||
| GpCachedBitmap* cachedBitmap; | ||
|
|
||
| graphics = getImageGraphics (&image); | ||
|
|
||
| C (GdipCreateCachedBitmap(image, graphics, &cachedBitmap)); | ||
|
|
||
| // Negative tests. | ||
| image = getImage ("test.wmf"); | ||
| assertEqualInt (GdipCreateCachedBitmap(image, graphics, &cachedBitmap), InvalidParameter); | ||
|
|
||
| assertEqualInt (GdipCreateCachedBitmap(image, graphics, NULL), InvalidParameter); | ||
| assertEqualInt (GdipCreateCachedBitmap(image, NULL, &cachedBitmap), InvalidParameter); | ||
| assertEqualInt (GdipCreateCachedBitmap(NULL, graphics, &cachedBitmap), InvalidParameter); | ||
|
|
||
| C (GdipDeleteGraphics(graphics)); | ||
| C (GdipDisposeImage(image)); | ||
| } | ||
|
|
||
| int main (int argc, char**argv) | ||
| { | ||
| STARTUP; | ||
|
|
||
| test_create (); | ||
reflectronic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| test_roundtrip (); | ||
|
|
||
| SHUTDOWN; | ||
| return 0; | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.