2007-08-09 04:42:20 +02:00
|
|
|
/*
|
|
|
|
* Unit test suite for images
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 Google (Evan Stade)
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "windows.h"
|
|
|
|
#include "gdiplus.h"
|
|
|
|
#include "wine/test.h"
|
2008-02-27 10:36:44 +01:00
|
|
|
#include <math.h>
|
2008-03-22 00:39:22 +01:00
|
|
|
#include "wingdi.h"
|
2007-08-09 04:42:20 +02:00
|
|
|
|
|
|
|
#define expect(expected, got) ok(((UINT)got) == ((UINT)expected), "Expected %.8x, got %.8x\n", (UINT)expected, (UINT)got)
|
|
|
|
|
2007-08-29 21:42:28 +02:00
|
|
|
static void test_Scan0(void)
|
2007-08-09 04:42:20 +02:00
|
|
|
{
|
|
|
|
GpBitmap *bm;
|
|
|
|
GpStatus stat;
|
|
|
|
BYTE buff[360];
|
|
|
|
|
|
|
|
bm = NULL;
|
|
|
|
stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat24bppRGB, NULL, &bm);
|
2007-08-09 04:42:24 +02:00
|
|
|
expect(Ok, stat);
|
|
|
|
ok(NULL != bm, "Expected bitmap to be initialized\n");
|
2008-01-14 02:42:28 +01:00
|
|
|
if (stat == Ok)
|
|
|
|
GdipDisposeImage((GpImage*)bm);
|
2007-08-09 04:42:20 +02:00
|
|
|
|
|
|
|
bm = (GpBitmap*)0xdeadbeef;
|
|
|
|
stat = GdipCreateBitmapFromScan0(10, -10, 10, PixelFormat24bppRGB, NULL, &bm);
|
|
|
|
expect(InvalidParameter, stat);
|
2008-12-04 12:13:01 +01:00
|
|
|
ok( !bm, "expected null bitmap\n" );
|
2007-08-09 04:42:20 +02:00
|
|
|
|
|
|
|
bm = (GpBitmap*)0xdeadbeef;
|
|
|
|
stat = GdipCreateBitmapFromScan0(-10, 10, 10, PixelFormat24bppRGB, NULL, &bm);
|
|
|
|
expect(InvalidParameter, stat);
|
2008-12-04 12:13:01 +01:00
|
|
|
ok( !bm, "expected null bitmap\n" );
|
2007-08-09 04:42:20 +02:00
|
|
|
|
|
|
|
bm = (GpBitmap*)0xdeadbeef;
|
|
|
|
stat = GdipCreateBitmapFromScan0(10, 0, 10, PixelFormat24bppRGB, NULL, &bm);
|
|
|
|
expect(InvalidParameter, stat);
|
2008-12-04 12:13:01 +01:00
|
|
|
ok( !bm, "expected null bitmap\n" );
|
2007-08-09 04:42:20 +02:00
|
|
|
|
|
|
|
bm = NULL;
|
|
|
|
stat = GdipCreateBitmapFromScan0(10, 10, 12, PixelFormat24bppRGB, buff, &bm);
|
|
|
|
expect(Ok, stat);
|
|
|
|
ok(NULL != bm, "Expected bitmap to be initialized\n");
|
2008-01-14 02:42:28 +01:00
|
|
|
if (stat == Ok)
|
|
|
|
GdipDisposeImage((GpImage*)bm);
|
2007-08-09 04:42:20 +02:00
|
|
|
|
|
|
|
bm = (GpBitmap*) 0xdeadbeef;
|
|
|
|
stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat24bppRGB, buff, &bm);
|
2007-08-09 04:42:24 +02:00
|
|
|
expect(InvalidParameter, stat);
|
2008-12-04 12:13:01 +01:00
|
|
|
ok( !bm, "expected null bitmap\n" );
|
2007-08-09 04:42:20 +02:00
|
|
|
|
|
|
|
bm = (GpBitmap*)0xdeadbeef;
|
|
|
|
stat = GdipCreateBitmapFromScan0(10, 10, 0, PixelFormat24bppRGB, buff, &bm);
|
2007-08-09 04:42:24 +02:00
|
|
|
expect(InvalidParameter, stat);
|
2008-12-04 12:13:01 +01:00
|
|
|
ok( bm == (GpBitmap*)0xdeadbeef, "expected deadbeef bitmap\n" );
|
2008-07-19 00:31:58 +02:00
|
|
|
|
|
|
|
bm = NULL;
|
|
|
|
stat = GdipCreateBitmapFromScan0(10, 10, -8, PixelFormat24bppRGB, buff, &bm);
|
|
|
|
todo_wine{
|
|
|
|
expect(Ok, stat);
|
|
|
|
ok(NULL != bm, "Expected bitmap to be initialized\n");
|
|
|
|
}
|
|
|
|
if (stat == Ok)
|
|
|
|
GdipDisposeImage((GpImage*)bm);
|
|
|
|
|
|
|
|
bm = (GpBitmap*)0xdeadbeef;
|
|
|
|
stat = GdipCreateBitmapFromScan0(10, 10, -10, PixelFormat24bppRGB, buff, &bm);
|
|
|
|
expect(InvalidParameter, stat);
|
2008-12-04 12:13:01 +01:00
|
|
|
ok( !bm, "expected null bitmap\n" );
|
2007-08-09 04:42:20 +02:00
|
|
|
}
|
|
|
|
|
2008-02-27 10:36:44 +01:00
|
|
|
static void test_GetImageDimension(void)
|
|
|
|
{
|
|
|
|
GpBitmap *bm;
|
|
|
|
GpStatus stat;
|
|
|
|
const REAL WIDTH = 10.0, HEIGHT = 20.0;
|
|
|
|
REAL w,h;
|
|
|
|
|
|
|
|
bm = (GpBitmap*)0xdeadbeef;
|
|
|
|
stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB,NULL, &bm);
|
|
|
|
expect(Ok,stat);
|
|
|
|
ok((GpBitmap*)0xdeadbeef != bm, "Expected bitmap to not be 0xdeadbeef\n");
|
|
|
|
ok(NULL != bm, "Expected bitmap to not be NULL\n");
|
|
|
|
|
|
|
|
stat = GdipGetImageDimension(NULL,&w,&h);
|
|
|
|
expect(InvalidParameter, stat);
|
|
|
|
|
|
|
|
stat = GdipGetImageDimension((GpImage*)bm,NULL,&h);
|
|
|
|
expect(InvalidParameter, stat);
|
|
|
|
|
|
|
|
stat = GdipGetImageDimension((GpImage*)bm,&w,NULL);
|
|
|
|
expect(InvalidParameter, stat);
|
|
|
|
|
|
|
|
w = -1;
|
|
|
|
h = -1;
|
|
|
|
stat = GdipGetImageDimension((GpImage*)bm,&w,&h);
|
|
|
|
expect(Ok, stat);
|
2008-03-01 21:13:09 +01:00
|
|
|
ok(fabs(WIDTH - w) < 0.0001, "Width wrong\n");
|
|
|
|
ok(fabs(HEIGHT - h) < 0.0001, "Height wrong\n");
|
2008-02-27 10:36:44 +01:00
|
|
|
GdipDisposeImage((GpImage*)bm);
|
|
|
|
}
|
|
|
|
|
2008-06-19 10:38:09 +02:00
|
|
|
static void test_GdipImageGetFrameDimensionsCount(void)
|
|
|
|
{
|
|
|
|
GpBitmap *bm;
|
|
|
|
GpStatus stat;
|
|
|
|
const REAL WIDTH = 10.0, HEIGHT = 20.0;
|
|
|
|
UINT w;
|
|
|
|
|
|
|
|
bm = (GpBitmap*)0xdeadbeef;
|
|
|
|
stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB,NULL, &bm);
|
|
|
|
expect(Ok,stat);
|
|
|
|
ok((GpBitmap*)0xdeadbeef != bm, "Expected bitmap to not be 0xdeadbeef\n");
|
|
|
|
ok(NULL != bm, "Expected bitmap to not be NULL\n");
|
|
|
|
|
|
|
|
stat = GdipImageGetFrameDimensionsCount(NULL,&w);
|
|
|
|
expect(InvalidParameter, stat);
|
|
|
|
|
|
|
|
stat = GdipImageGetFrameDimensionsCount((GpImage*)bm,NULL);
|
|
|
|
expect(InvalidParameter, stat);
|
|
|
|
|
|
|
|
w = -1;
|
|
|
|
stat = GdipImageGetFrameDimensionsCount((GpImage*)bm,&w);
|
|
|
|
expect(Ok, stat);
|
|
|
|
expect(1, w);
|
|
|
|
GdipDisposeImage((GpImage*)bm);
|
|
|
|
}
|
|
|
|
|
2008-02-24 16:41:28 +01:00
|
|
|
static void test_LoadingImages(void)
|
|
|
|
{
|
|
|
|
GpStatus stat;
|
|
|
|
|
|
|
|
stat = GdipCreateBitmapFromFile(0, 0);
|
|
|
|
expect(InvalidParameter, stat);
|
|
|
|
|
|
|
|
stat = GdipCreateBitmapFromFile(0, (GpBitmap**)0xdeadbeef);
|
|
|
|
expect(InvalidParameter, stat);
|
2008-02-24 16:41:29 +01:00
|
|
|
|
|
|
|
stat = GdipLoadImageFromFile(0, 0);
|
|
|
|
expect(InvalidParameter, stat);
|
|
|
|
|
|
|
|
stat = GdipLoadImageFromFile(0, (GpImage**)0xdeadbeef);
|
|
|
|
expect(InvalidParameter, stat);
|
2008-05-09 14:40:21 +02:00
|
|
|
|
|
|
|
stat = GdipLoadImageFromFileICM(0, 0);
|
|
|
|
expect(InvalidParameter, stat);
|
|
|
|
|
|
|
|
stat = GdipLoadImageFromFileICM(0, (GpImage**)0xdeadbeef);
|
|
|
|
expect(InvalidParameter, stat);
|
2008-02-24 16:41:28 +01:00
|
|
|
}
|
|
|
|
|
2008-03-10 16:16:54 +01:00
|
|
|
static void test_SavingImages(void)
|
|
|
|
{
|
|
|
|
GpStatus stat;
|
|
|
|
GpBitmap *bm;
|
|
|
|
UINT n;
|
|
|
|
UINT s;
|
2008-03-10 16:16:57 +01:00
|
|
|
const REAL WIDTH = 10.0, HEIGHT = 20.0;
|
|
|
|
REAL w, h;
|
2008-03-10 16:16:54 +01:00
|
|
|
ImageCodecInfo *codecs;
|
|
|
|
static const WCHAR filename[] = { 'a','.','b','m','p',0 };
|
|
|
|
|
|
|
|
codecs = NULL;
|
|
|
|
|
|
|
|
stat = GdipSaveImageToFile(0, 0, 0, 0);
|
|
|
|
expect(InvalidParameter, stat);
|
|
|
|
|
|
|
|
bm = NULL;
|
2008-03-10 16:16:57 +01:00
|
|
|
stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
|
2008-03-10 16:16:54 +01:00
|
|
|
expect(Ok, stat);
|
|
|
|
if (!bm)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* invalid params */
|
|
|
|
stat = GdipSaveImageToFile((GpImage*)bm, 0, 0, 0);
|
|
|
|
expect(InvalidParameter, stat);
|
|
|
|
|
|
|
|
stat = GdipSaveImageToFile((GpImage*)bm, filename, 0, 0);
|
|
|
|
expect(InvalidParameter, stat);
|
|
|
|
|
2008-03-10 16:16:57 +01:00
|
|
|
/* encoder tests should succeed -- already tested */
|
2008-03-10 16:16:54 +01:00
|
|
|
stat = GdipGetImageEncodersSize(&n, &s);
|
|
|
|
if (stat != Ok || n == 0) goto cleanup;
|
|
|
|
|
|
|
|
codecs = GdipAlloc(s);
|
|
|
|
if (!codecs) goto cleanup;
|
|
|
|
|
|
|
|
stat = GdipGetImageEncoders(n, s, codecs);
|
|
|
|
if (stat != Ok) goto cleanup;
|
|
|
|
|
2008-03-10 16:16:56 +01:00
|
|
|
stat = GdipSaveImageToFile((GpImage*)bm, filename, &codecs[0].Clsid, 0);
|
|
|
|
expect(stat, Ok);
|
2008-03-10 16:16:54 +01:00
|
|
|
|
2008-03-10 16:16:57 +01:00
|
|
|
GdipDisposeImage((GpImage*)bm);
|
|
|
|
bm = 0;
|
|
|
|
|
|
|
|
/* re-load and check image stats */
|
|
|
|
stat = GdipLoadImageFromFile(filename, (GpImage**)&bm);
|
|
|
|
expect(stat, Ok);
|
|
|
|
if (stat != Ok) goto cleanup;
|
|
|
|
|
|
|
|
stat = GdipGetImageDimension((GpImage*)bm, &w, &h);
|
|
|
|
if (stat != Ok) goto cleanup;
|
|
|
|
|
|
|
|
ok((fabs(w - WIDTH) < 0.01) && (fabs(h - HEIGHT) < 0.01),
|
|
|
|
"Saved image dimensions are different!\n");
|
|
|
|
|
2008-03-10 16:16:54 +01:00
|
|
|
cleanup:
|
2008-03-11 21:08:27 +01:00
|
|
|
GdipFree(codecs);
|
2008-03-10 16:16:54 +01:00
|
|
|
if (bm)
|
|
|
|
GdipDisposeImage((GpImage*)bm);
|
2008-03-10 16:16:57 +01:00
|
|
|
ok(DeleteFileW(filename), "Delete failed.\n");
|
2008-03-10 16:16:54 +01:00
|
|
|
}
|
|
|
|
|
2008-03-06 10:17:00 +01:00
|
|
|
static void test_encoders(void)
|
|
|
|
{
|
|
|
|
GpStatus stat;
|
|
|
|
UINT n;
|
|
|
|
UINT s;
|
|
|
|
ImageCodecInfo *codecs;
|
|
|
|
int i;
|
|
|
|
int bmp_found;
|
|
|
|
|
|
|
|
static const WCHAR bmp_format[] = {'B', 'M', 'P', 0};
|
|
|
|
|
|
|
|
stat = GdipGetImageEncodersSize(&n, &s);
|
|
|
|
expect(stat, Ok);
|
|
|
|
|
|
|
|
codecs = GdipAlloc(s);
|
|
|
|
if (!codecs)
|
|
|
|
return;
|
|
|
|
|
|
|
|
stat = GdipGetImageEncoders(n, s, NULL);
|
|
|
|
expect(GenericError, stat);
|
|
|
|
|
|
|
|
stat = GdipGetImageEncoders(0, s, codecs);
|
|
|
|
expect(GenericError, stat);
|
|
|
|
|
|
|
|
stat = GdipGetImageEncoders(n, s-1, codecs);
|
|
|
|
expect(GenericError, stat);
|
|
|
|
|
|
|
|
stat = GdipGetImageEncoders(n, s+1, codecs);
|
|
|
|
expect(GenericError, stat);
|
|
|
|
|
|
|
|
stat = GdipGetImageEncoders(n, s, codecs);
|
|
|
|
expect(stat, Ok);
|
|
|
|
|
|
|
|
bmp_found = FALSE;
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
{
|
|
|
|
if (CompareStringW(LOCALE_SYSTEM_DEFAULT, 0,
|
|
|
|
codecs[i].FormatDescription, -1,
|
|
|
|
bmp_format, -1) == CSTR_EQUAL) {
|
|
|
|
bmp_found = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!bmp_found)
|
|
|
|
ok(FALSE, "No BMP codec found.\n");
|
|
|
|
|
|
|
|
GdipFree(codecs);
|
|
|
|
}
|
|
|
|
|
2008-03-07 10:19:02 +01:00
|
|
|
static void test_LockBits(void)
|
|
|
|
{
|
|
|
|
GpStatus stat;
|
|
|
|
GpBitmap *bm;
|
|
|
|
GpRect rect;
|
|
|
|
BitmapData bd;
|
2008-05-21 17:47:50 +02:00
|
|
|
const INT WIDTH = 10, HEIGHT = 20;
|
2008-03-07 10:19:02 +01:00
|
|
|
|
|
|
|
bm = NULL;
|
|
|
|
stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
|
|
|
|
expect(Ok, stat);
|
|
|
|
|
|
|
|
rect.X = 2;
|
|
|
|
rect.Y = 3;
|
|
|
|
rect.Width = 4;
|
|
|
|
rect.Height = 5;
|
|
|
|
|
|
|
|
/* read-only */
|
|
|
|
stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
|
|
|
|
expect(Ok, stat);
|
|
|
|
|
|
|
|
if (stat == Ok) {
|
|
|
|
stat = GdipBitmapUnlockBits(bm, &bd);
|
|
|
|
expect(Ok, stat);
|
|
|
|
}
|
|
|
|
|
2008-05-21 17:47:50 +02:00
|
|
|
/* read-only, with NULL rect -> whole bitmap lock */
|
|
|
|
stat = GdipBitmapLockBits(bm, NULL, ImageLockModeRead, PixelFormat24bppRGB, &bd);
|
|
|
|
expect(Ok, stat);
|
|
|
|
expect(bd.Width, WIDTH);
|
|
|
|
expect(bd.Height, HEIGHT);
|
|
|
|
|
|
|
|
if (stat == Ok) {
|
|
|
|
stat = GdipBitmapUnlockBits(bm, &bd);
|
|
|
|
expect(Ok, stat);
|
|
|
|
}
|
|
|
|
|
2008-03-07 10:19:02 +01:00
|
|
|
/* read-only, consecutive */
|
|
|
|
stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
|
|
|
|
expect(Ok, stat);
|
|
|
|
|
|
|
|
if (stat == Ok) {
|
|
|
|
stat = GdipBitmapUnlockBits(bm, &bd);
|
|
|
|
expect(Ok, stat);
|
|
|
|
}
|
|
|
|
|
|
|
|
stat = GdipDisposeImage((GpImage*)bm);
|
|
|
|
expect(Ok, stat);
|
|
|
|
stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
|
|
|
|
expect(Ok, stat);
|
|
|
|
|
|
|
|
/* read x2 */
|
|
|
|
stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
|
|
|
|
expect(Ok, stat);
|
2008-03-07 10:19:05 +01:00
|
|
|
stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
|
|
|
|
expect(WrongState, stat);
|
2008-03-07 10:19:02 +01:00
|
|
|
|
|
|
|
stat = GdipBitmapUnlockBits(bm, &bd);
|
|
|
|
expect(Ok, stat);
|
|
|
|
|
|
|
|
stat = GdipDisposeImage((GpImage*)bm);
|
|
|
|
expect(Ok, stat);
|
|
|
|
stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
|
|
|
|
expect(Ok, stat);
|
|
|
|
|
|
|
|
/* write, no modification */
|
|
|
|
stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
|
|
|
|
expect(Ok, stat);
|
|
|
|
|
|
|
|
if (stat == Ok) {
|
|
|
|
stat = GdipBitmapUnlockBits(bm, &bd);
|
|
|
|
expect(Ok, stat);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* write, consecutive */
|
2008-03-07 10:19:04 +01:00
|
|
|
stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
|
|
|
|
expect(Ok, stat);
|
2008-03-07 10:19:02 +01:00
|
|
|
|
|
|
|
if (stat == Ok) {
|
|
|
|
stat = GdipBitmapUnlockBits(bm, &bd);
|
|
|
|
expect(Ok, stat);
|
|
|
|
}
|
|
|
|
|
|
|
|
stat = GdipDisposeImage((GpImage*)bm);
|
|
|
|
expect(Ok, stat);
|
|
|
|
stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
|
|
|
|
expect(Ok, stat);
|
|
|
|
|
|
|
|
/* write, modify */
|
|
|
|
stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
|
|
|
|
expect(Ok, stat);
|
|
|
|
|
|
|
|
if (stat == Ok) {
|
|
|
|
if (bd.Scan0)
|
|
|
|
((char*)bd.Scan0)[2] = 0xff;
|
|
|
|
|
|
|
|
stat = GdipBitmapUnlockBits(bm, &bd);
|
|
|
|
expect(Ok, stat);
|
|
|
|
}
|
|
|
|
|
|
|
|
stat = GdipDisposeImage((GpImage*)bm);
|
|
|
|
expect(Ok, stat);
|
|
|
|
|
|
|
|
/* dispose locked */
|
|
|
|
stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
|
|
|
|
expect(Ok, stat);
|
|
|
|
stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
|
|
|
|
expect(Ok, stat);
|
|
|
|
stat = GdipDisposeImage((GpImage*)bm);
|
|
|
|
expect(Ok, stat);
|
|
|
|
}
|
|
|
|
|
2008-03-22 00:39:22 +01:00
|
|
|
static void test_GdipCreateBitmapFromHBITMAP(void)
|
|
|
|
{
|
|
|
|
GpBitmap* gpbm = NULL;
|
|
|
|
HBITMAP hbm = NULL;
|
|
|
|
HPALETTE hpal = NULL;
|
|
|
|
GpStatus stat;
|
|
|
|
BYTE buff[1000];
|
|
|
|
LOGPALETTE* LogPal = NULL;
|
|
|
|
REAL width, height;
|
|
|
|
const REAL WIDTH1 = 5;
|
|
|
|
const REAL HEIGHT1 = 15;
|
|
|
|
const REAL WIDTH2 = 10;
|
|
|
|
const REAL HEIGHT2 = 20;
|
|
|
|
HDC hdc;
|
|
|
|
BITMAPINFO bmi;
|
|
|
|
|
|
|
|
stat = GdipCreateBitmapFromHBITMAP(NULL, NULL, NULL);
|
|
|
|
expect(InvalidParameter, stat);
|
|
|
|
|
|
|
|
hbm = CreateBitmap(WIDTH1, HEIGHT1, 1, 1, NULL);
|
|
|
|
stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, NULL);
|
|
|
|
expect(InvalidParameter, stat);
|
|
|
|
|
|
|
|
stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
|
|
|
|
expect(Ok, stat);
|
|
|
|
expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
|
|
|
|
ok(fabs(WIDTH1 - width) < .0001, "width wrong\n");
|
|
|
|
ok(fabs(HEIGHT1 - height) < .0001, "height wrong\n");
|
|
|
|
if (stat == Ok)
|
|
|
|
GdipDisposeImage((GpImage*)gpbm);
|
|
|
|
GlobalFree(hbm);
|
|
|
|
|
|
|
|
hbm = CreateBitmap(WIDTH2, HEIGHT2, 1, 1, &buff);
|
|
|
|
stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
|
|
|
|
expect(Ok, stat);
|
|
|
|
expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
|
|
|
|
ok(fabs(WIDTH2 - width) < .0001, "width wrong\n");
|
|
|
|
ok(fabs(HEIGHT2 - height) < .0001, "height wrong\n");
|
|
|
|
if (stat == Ok)
|
|
|
|
GdipDisposeImage((GpImage*)gpbm);
|
|
|
|
GlobalFree(hbm);
|
|
|
|
|
|
|
|
hdc = CreateCompatibleDC(0);
|
|
|
|
ok(hdc != NULL, "CreateCompatibleDC failed\n");
|
|
|
|
bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
|
|
|
|
bmi.bmiHeader.biHeight = HEIGHT1;
|
|
|
|
bmi.bmiHeader.biWidth = WIDTH1;
|
|
|
|
bmi.bmiHeader.biBitCount = 24;
|
|
|
|
bmi.bmiHeader.biPlanes = 1;
|
|
|
|
bmi.bmiHeader.biCompression = BI_RGB;
|
|
|
|
|
|
|
|
hbm = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, NULL, NULL, 0);
|
|
|
|
ok(hbm != NULL, "CreateDIBSection failed\n");
|
|
|
|
|
|
|
|
stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
|
|
|
|
expect(Ok, stat);
|
|
|
|
expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
|
|
|
|
ok(fabs(WIDTH1 - width) < .0001, "width wrong\n");
|
|
|
|
ok(fabs(HEIGHT1 - height) < .0001, "height wrong\n");
|
|
|
|
if (stat == Ok)
|
|
|
|
GdipDisposeImage((GpImage*)gpbm);
|
|
|
|
|
|
|
|
LogPal = GdipAlloc(sizeof(LOGPALETTE));
|
|
|
|
ok(LogPal != NULL, "unable to allocate LOGPALETTE\n");
|
|
|
|
LogPal->palVersion = 0x300;
|
2009-01-14 09:52:24 +01:00
|
|
|
hpal = CreatePalette(LogPal);
|
2008-03-22 00:39:22 +01:00
|
|
|
ok(hpal != NULL, "CreatePalette failed\n");
|
|
|
|
GdipFree(LogPal);
|
|
|
|
|
|
|
|
stat = GdipCreateBitmapFromHBITMAP(hbm, hpal, &gpbm);
|
|
|
|
todo_wine
|
|
|
|
{
|
|
|
|
expect(Ok, stat);
|
|
|
|
}
|
|
|
|
if (stat == Ok)
|
|
|
|
GdipDisposeImage((GpImage*)gpbm);
|
|
|
|
|
|
|
|
GlobalFree(hpal);
|
|
|
|
GlobalFree(hbm);
|
|
|
|
}
|
|
|
|
|
2008-05-09 14:39:43 +02:00
|
|
|
static void test_GdipGetImageFlags(void)
|
|
|
|
{
|
|
|
|
GpImage *img;
|
|
|
|
GpStatus stat;
|
|
|
|
UINT flags;
|
|
|
|
|
|
|
|
img = (GpImage*)0xdeadbeef;
|
|
|
|
|
|
|
|
stat = GdipGetImageFlags(NULL, NULL);
|
|
|
|
expect(InvalidParameter, stat);
|
|
|
|
|
|
|
|
stat = GdipGetImageFlags(NULL, &flags);
|
|
|
|
expect(InvalidParameter, stat);
|
|
|
|
|
|
|
|
stat = GdipGetImageFlags(img, NULL);
|
|
|
|
expect(InvalidParameter, stat);
|
|
|
|
}
|
|
|
|
|
2008-07-02 03:04:10 +02:00
|
|
|
static void test_GdipCloneImage(void)
|
|
|
|
{
|
|
|
|
GpStatus stat;
|
|
|
|
GpRectF rectF;
|
|
|
|
GpUnit unit;
|
|
|
|
GpBitmap *bm;
|
|
|
|
GpImage *image_src, *image_dest = NULL;
|
|
|
|
const INT WIDTH = 10, HEIGHT = 20;
|
|
|
|
|
|
|
|
/* Create an image, clone it, delete the original, make sure the copy works */
|
|
|
|
stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
|
|
|
|
expect(Ok, stat);
|
2008-09-05 12:41:49 +02:00
|
|
|
|
2008-07-02 03:04:10 +02:00
|
|
|
image_src = ((GpImage*)bm);
|
|
|
|
stat = GdipCloneImage(image_src, &image_dest);
|
|
|
|
expect(Ok, stat);
|
2008-09-05 12:41:49 +02:00
|
|
|
|
2008-07-02 03:04:10 +02:00
|
|
|
stat = GdipDisposeImage((GpImage*)bm);
|
|
|
|
expect(Ok, stat);
|
|
|
|
stat = GdipGetImageBounds(image_dest, &rectF, &unit);
|
|
|
|
expect(Ok, stat);
|
2008-09-05 12:41:49 +02:00
|
|
|
|
2008-10-20 15:10:10 +02:00
|
|
|
/* Treat FP values carefully */
|
|
|
|
ok(fabsf(rectF.Width-WIDTH)<1e-5, "Expected: %d, got %.05f\n", WIDTH, rectF.Width);
|
|
|
|
ok(fabsf(rectF.Height-HEIGHT)<1e-5, "Expected: %d, got %.05f\n", HEIGHT, rectF.Height);
|
|
|
|
|
2008-07-02 03:04:10 +02:00
|
|
|
stat = GdipDisposeImage(image_dest);
|
|
|
|
expect(Ok, stat);
|
|
|
|
}
|
|
|
|
|
2008-09-06 23:40:26 +02:00
|
|
|
static void test_testcontrol(void)
|
|
|
|
{
|
|
|
|
GpStatus stat;
|
|
|
|
DWORD param;
|
|
|
|
|
|
|
|
param = 0;
|
|
|
|
stat = GdipTestControl(TestControlGetBuildNumber, ¶m);
|
|
|
|
expect(Ok, stat);
|
|
|
|
ok(param != 0, "Build number expected, got %u\n", param);
|
|
|
|
}
|
|
|
|
|
2007-08-09 04:42:20 +02:00
|
|
|
START_TEST(image)
|
|
|
|
{
|
2007-08-11 01:22:47 +02:00
|
|
|
struct GdiplusStartupInput gdiplusStartupInput;
|
|
|
|
ULONG_PTR gdiplusToken;
|
|
|
|
|
|
|
|
gdiplusStartupInput.GdiplusVersion = 1;
|
|
|
|
gdiplusStartupInput.DebugEventCallback = NULL;
|
|
|
|
gdiplusStartupInput.SuppressBackgroundThread = 0;
|
|
|
|
gdiplusStartupInput.SuppressExternalCodecs = 0;
|
|
|
|
|
|
|
|
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
|
|
|
|
|
2007-08-09 04:42:20 +02:00
|
|
|
test_Scan0();
|
2008-02-27 10:36:44 +01:00
|
|
|
test_GetImageDimension();
|
2008-06-19 10:38:09 +02:00
|
|
|
test_GdipImageGetFrameDimensionsCount();
|
2008-02-24 16:41:28 +01:00
|
|
|
test_LoadingImages();
|
2008-03-10 16:16:54 +01:00
|
|
|
test_SavingImages();
|
2008-03-06 10:17:00 +01:00
|
|
|
test_encoders();
|
2008-03-07 10:19:02 +01:00
|
|
|
test_LockBits();
|
2008-03-22 00:39:22 +01:00
|
|
|
test_GdipCreateBitmapFromHBITMAP();
|
2008-05-09 14:39:43 +02:00
|
|
|
test_GdipGetImageFlags();
|
2008-07-02 03:04:10 +02:00
|
|
|
test_GdipCloneImage();
|
2008-09-06 23:40:26 +02:00
|
|
|
test_testcontrol();
|
2007-08-11 01:22:47 +02:00
|
|
|
|
|
|
|
GdiplusShutdown(gdiplusToken);
|
2007-08-09 04:42:20 +02:00
|
|
|
}
|