ReactOS 0.4.15-dev-8116-gf69e256
drawdib.c File Reference
#include <windows.h>
#include <vfw.h>
#include <wincrypt.h>
#include <stdlib.h>
#include <string.h>
#include "wine/test.h"
Include dependency graph for drawdib.c:

Go to the source code of this file.

Macros

#define WIN32_LEAN_AND_MEAN
 
#define WIDTH   16
 
#define HEIGHT   12
 

Functions

static DWORD get_stride (const BITMAPINFO *bmi)
 
static DWORD get_dib_size (const BITMAPINFO *bmi)
 
static charhash_dib (const BITMAPINFO *bmi, const void *bits)
 
static void init_bmi (BITMAPINFO *bmi, LONG width, LONG height, DWORD size)
 
static void test_DrawDib_sizeimage (void)
 
 START_TEST (drawdib)
 

Variables

static HCRYPTPROV crypt_prov
 

Macro Definition Documentation

◆ HEIGHT

#define HEIGHT   12

Definition at line 30 of file drawdib.c.

◆ WIDTH

#define WIDTH   16

Definition at line 29 of file drawdib.c.

◆ WIN32_LEAN_AND_MEAN

#define WIN32_LEAN_AND_MEAN

Definition at line 19 of file drawdib.c.

Function Documentation

◆ get_dib_size()

static DWORD get_dib_size ( const BITMAPINFO bmi)
inlinestatic

Definition at line 39 of file drawdib.c.

40{
41 return get_stride(bmi) * abs(bmi->bmiHeader.biHeight);
42}
#define abs(i)
Definition: fconv.c:206
static DWORD get_stride(const BITMAPINFO *bmi)
Definition: drawdib.c:34
BITMAPINFOHEADER bmiHeader
Definition: wingdi.h:1476

Referenced by hash_dib(), and test_DrawDib_sizeimage().

◆ get_stride()

static DWORD get_stride ( const BITMAPINFO bmi)
inlinestatic

Definition at line 34 of file drawdib.c.

35{
36 return ((bmi->bmiHeader.biBitCount * bmi->bmiHeader.biWidth + 31) >> 3) & ~3;
37}
USHORT biBitCount
Definition: precomp.h:46

Referenced by get_dib_size().

◆ hash_dib()

static char * hash_dib ( const BITMAPINFO bmi,
const void bits 
)
static

Definition at line 44 of file drawdib.c.

45{
46 DWORD dib_size = get_dib_size(bmi);
48 char *buf;
49 BYTE hash_buf[20];
50 DWORD hash_size = sizeof(hash_buf);
51 int i;
52 static const char *hex = "0123456789abcdef";
53
54 if(!crypt_prov) return NULL;
55
56 if(!CryptCreateHash(crypt_prov, CALG_SHA1, 0, 0, &hash)) return NULL;
57
58 CryptHashData(hash, bits, dib_size, 0);
59
60 CryptGetHashParam(hash, HP_HASHVAL, NULL, &hash_size, 0);
61 if(hash_size != sizeof(hash_buf)) return NULL;
62
63 CryptGetHashParam(hash, HP_HASHVAL, hash_buf, &hash_size, 0);
65
66 buf = HeapAlloc(GetProcessHeap(), 0, hash_size * 2 + 1);
67
68 for(i = 0; i < hash_size; i++)
69 {
70 buf[i * 2] = hex[hash_buf[i] >> 4];
71 buf[i * 2 + 1] = hex[hash_buf[i] & 0xf];
72 }
73 buf[i * 2] = '\0';
74
75 return buf;
76}
#define NULL
Definition: types.h:112
BOOL WINAPI CryptCreateHash(HCRYPTPROV hProv, ALG_ID Algid, HCRYPTKEY hKey, DWORD dwFlags, HCRYPTHASH *phHash)
Definition: crypt.c:740
BOOL WINAPI CryptGetHashParam(HCRYPTHASH hHash, DWORD dwParam, BYTE *pbData, DWORD *pdwDataLen, DWORD dwFlags)
Definition: crypt.c:1610
BOOL WINAPI CryptDestroyHash(HCRYPTHASH hHash)
Definition: crypt.c:890
BOOL WINAPI CryptHashData(HCRYPTHASH hHash, const BYTE *pbData, DWORD dwDataLen, DWORD dwFlags)
Definition: crypt.c:1771
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
unsigned long DWORD
Definition: ntddk_ex.h:95
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLenum GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * bits
Definition: glext.h:10929
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
int hex(char ch)
static DWORD get_dib_size(const BITMAPINFO *bmi)
Definition: drawdib.c:39
static HCRYPTPROV crypt_prov
Definition: drawdib.c:32
Definition: _hash_fun.h:40
#define CALG_SHA1
Definition: wincrypt.h:1807
ULONG_PTR HCRYPTHASH
Definition: wincrypt.h:50
#define HP_HASHVAL
Definition: wincrypt.h:2183
unsigned char BYTE
Definition: xxhash.c:193

Referenced by test_DrawDib_sizeimage().

◆ init_bmi()

static void init_bmi ( BITMAPINFO bmi,
LONG  width,
LONG  height,
DWORD  size 
)
static

Definition at line 78 of file drawdib.c.

79{
80 memset(bmi, 0, sizeof(*bmi));
81 bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
82 bmi->bmiHeader.biWidth = width;
84 bmi->bmiHeader.biPlanes = 1;
85 bmi->bmiHeader.biBitCount = 32;
88}
#define BI_RGB
Definition: precomp.h:56
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
GLint GLint GLsizei width
Definition: gl.h:1546
GLsizeiptr size
Definition: glext.h:5919
#define memset(x, y, z)
Definition: compat.h:39
ULONG biCompression
Definition: precomp.h:47

Referenced by test_DrawDib_sizeimage().

◆ START_TEST()

START_TEST ( drawdib  )

Definition at line 174 of file drawdib.c.

175{
179}
BOOL WINAPI CryptReleaseContext(HCRYPTPROV hProv, DWORD dwFlags)
Definition: crypt.c:648
BOOL WINAPI CryptAcquireContextW(HCRYPTPROV *phProv, LPCWSTR pszContainer, LPCWSTR pszProvider, DWORD dwProvType, DWORD dwFlags)
Definition: crypt.c:358
static void test_DrawDib_sizeimage(void)
Definition: drawdib.c:90
#define PROV_RSA_FULL
Definition: wincrypt.h:2039
#define CRYPT_VERIFYCONTEXT
Definition: wincrypt.h:2069

◆ test_DrawDib_sizeimage()

static void test_DrawDib_sizeimage ( void  )
static

Definition at line 90 of file drawdib.c.

91{
92 const struct {
94 DWORD size;
95 char hash[41];
96 } test_data[] = {
97 /* [0] correct size */
98 { WIDTH, HEIGHT, WIDTH * HEIGHT * sizeof(RGBQUAD), "bc943d5ab024b8b0118d0a80aa283055d39942b8" },
99 /* [1] zero size */
100 { WIDTH, HEIGHT, 0, "bc943d5ab024b8b0118d0a80aa283055d39942b8" },
101 /* error patterns */
102 { WIDTH, -HEIGHT, 0, "" },
103 { -WIDTH, HEIGHT, 0, "" },
104 { -WIDTH, -HEIGHT, 0, "" },
105 { 0, 0, 0, "" },
106 { 0, HEIGHT, 0, "" },
107 { WIDTH, 0, 0, "" },
108 /* [8] zero size (to compare [9], [10] ) */
109 { WIDTH, HEIGHT/2, 0, "8b75bf6d54a8645380114fe77505ee0699ffffaa" },
110 /* [9] insufficient size */
111 { WIDTH, HEIGHT/2, sizeof(RGBQUAD), "8b75bf6d54a8645380114fe77505ee0699ffffaa" },
112 /* [10] too much size */
113 { WIDTH, HEIGHT/2, WIDTH * HEIGHT * sizeof(RGBQUAD), "8b75bf6d54a8645380114fe77505ee0699ffffaa" },
114 };
115 HDC hdc;
116 DWORD src_dib_size, dst_dib_size;
117 BOOL r;
118 HBITMAP dib;
119 BITMAPINFO src_info, dst_info;
120 RGBQUAD *src_bits = NULL, *dst_bits;
121 HDRAWDIB hdd;
122 unsigned int i;
123
125
126 init_bmi(&dst_info, WIDTH, HEIGHT, 0);
127 dib = CreateDIBSection(NULL, &dst_info, DIB_RGB_COLORS, (void **)&dst_bits, NULL, 0);
128 dst_dib_size = get_dib_size(&dst_info);
129 ok(dib != NULL, "CreateDIBSection failed\n");
131
132 init_bmi(&src_info, WIDTH, HEIGHT, 0);
133 src_dib_size = get_dib_size(&src_info);
134 src_bits = HeapAlloc(GetProcessHeap(), 0, src_dib_size);
135 ok(src_bits != NULL, "Can't allocate memory\n");
136 memset(src_bits, 0x88, src_dib_size);
137
138 hdd = DrawDibOpen();
139 ok(hdd != NULL, "DrawDibOpen failed\n");
140
141 for (i = 0; i < ARRAY_SIZE(test_data); i++) {
142 char *hash;
143 memset(dst_bits, 0xff, dst_dib_size);
145 r = DrawDibDraw(hdd, hdc,
146 0, 0, -1, -1, &src_info.bmiHeader, src_bits,
147 0, 0, test_data[i].width, test_data[i].height, 0);
148 if (test_data[i].hash[0])
149 ok(r, "[%u] DrawDibDraw failed, expected success\n", i);
150 else
151 ok(!r, "[%u] DrawDibDraw succeeded, expected failed\n", i);
152 if (!r || !test_data[i].hash[0])
153 continue;
154
155 hash = hash_dib(&dst_info, dst_bits);
156 if (!hash) {
157 win_skip("This platform doesn't support SHA-1 hash\n");
158 continue;
159 }
160 ok(strcmp(hash, test_data[i].hash) == 0,
161 "[%u] got %s, expected %s\n",
162 i, hash, test_data[i].hash);
164 }
165
166 r = DrawDibClose(hdd);
167 ok(r, "DrawDibClose failed\n");
168
169 HeapFree(GetProcessHeap(), 0, src_bits);
170
171 DeleteDC(hdc);
172}
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define ok(value,...)
Definition: atltest.h:57
#define ARRAY_SIZE(A)
Definition: main.h:33
#define HeapFree(x, y, z)
Definition: compat.h:735
BOOL VFWAPI DrawDibDraw(HDRAWDIB hdd, HDC hdc, INT xDst, INT yDst, INT dxDst, INT dyDst, LPBITMAPINFOHEADER lpbi, LPVOID lpBits, INT xSrc, INT ySrc, INT dxSrc, INT dySrc, UINT wFlags)
Definition: drawdib.c:308
BOOL VFWAPI DrawDibClose(HDRAWDIB hdd)
Definition: drawdib.c:101
HDRAWDIB VFWAPI DrawDibOpen(void)
Definition: drawdib.c:80
ULONG RGBQUAD
Definition: precomp.h:59
unsigned int BOOL
Definition: ntddk_ex.h:94
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
HDC hdc
Definition: main.c:9
static HBITMAP
Definition: button.c:44
static HDC
Definition: imagelist.c:92
#define WIDTH
Definition: drawdib.c:29
static void init_bmi(BITMAPINFO *bmi, LONG width, LONG height, DWORD size)
Definition: drawdib.c:78
#define HEIGHT
Definition: drawdib.c:30
static char * hash_dib(const BITMAPINFO *bmi, const void *bits)
Definition: drawdib.c:44
static const BYTE dib[]
Definition: ole2.c:201
long LONG
Definition: pedump.c:60
#define win_skip
Definition: test.h:163
HBITMAP WINAPI CreateDIBSection(HDC hDC, CONST BITMAPINFO *BitmapInfo, UINT Usage, VOID **Bits, HANDLE hSection, DWORD dwOffset)
Definition: bitmap.c:245
#define DIB_RGB_COLORS
Definition: wingdi.h:367
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1539
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
BOOL WINAPI DeleteDC(_In_ HDC)

Referenced by START_TEST().

Variable Documentation

◆ crypt_prov

HCRYPTPROV crypt_prov
static

Definition at line 32 of file drawdib.c.

Referenced by hash_dib(), and START_TEST().