1 | /* Copyright (c) 2001, Stanford University
|
---|
2 | * All rights reserved
|
---|
3 | *
|
---|
4 | * See the file LICENSE.txt for information on redistributing this software.
|
---|
5 | */
|
---|
6 |
|
---|
7 | #include "unpacker.h"
|
---|
8 | #include "cr_error.h"
|
---|
9 | #include "cr_pixeldata.h"
|
---|
10 |
|
---|
11 | #include "state/cr_bufferobject.h"
|
---|
12 |
|
---|
13 | void crUnpackDrawPixels(PCrUnpackerState pState)
|
---|
14 | {
|
---|
15 | CHECK_BUFFER_SIZE_STATIC_LAST(pState, sizeof(int) + 20, GLint);
|
---|
16 |
|
---|
17 | GLsizei width = READ_DATA(pState, sizeof( int ) + 0, GLsizei );
|
---|
18 | GLsizei height = READ_DATA(pState, sizeof( int ) + 4, GLsizei );
|
---|
19 | GLenum format = READ_DATA(pState, sizeof( int ) + 8, GLenum );
|
---|
20 | GLenum type = READ_DATA(pState, sizeof( int ) + 12, GLenum );
|
---|
21 | GLint noimagedata = READ_DATA(pState, sizeof( int ) + 16, GLint );
|
---|
22 | GLvoid *pixels;
|
---|
23 |
|
---|
24 | if (noimagedata && !crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
|
---|
25 | return;
|
---|
26 |
|
---|
27 | if (noimagedata)
|
---|
28 | pixels = (void*) (uintptr_t) READ_DATA(pState, sizeof( int ) + 20, GLint);
|
---|
29 | else
|
---|
30 | {
|
---|
31 | size_t cbImg = crImageSize( format, type, width, height );
|
---|
32 | if (RT_UNLIKELY(cbImg == 0))
|
---|
33 | {
|
---|
34 | pState->rcUnpack = VERR_INVALID_PARAMETER;
|
---|
35 | return;
|
---|
36 | }
|
---|
37 |
|
---|
38 | pixels = DATA_POINTER(pState, sizeof( int ) + 24, GLvoid );
|
---|
39 | CHECK_ARRAY_SIZE_FROM_PTR_UPDATE_LAST(pState, pixels, cbImg, GLubyte);
|
---|
40 | }
|
---|
41 |
|
---|
42 | pState->pDispatchTbl->PixelStorei( GL_UNPACK_ROW_LENGTH, 0 );
|
---|
43 | pState->pDispatchTbl->PixelStorei( GL_UNPACK_SKIP_PIXELS, 0 );
|
---|
44 | pState->pDispatchTbl->PixelStorei( GL_UNPACK_SKIP_ROWS, 0 );
|
---|
45 | pState->pDispatchTbl->PixelStorei( GL_UNPACK_ALIGNMENT, 1 );
|
---|
46 |
|
---|
47 | pState->pDispatchTbl->DrawPixels( width, height, format, type, pixels );
|
---|
48 |
|
---|
49 | INCR_VAR_PTR(pState);
|
---|
50 | }
|
---|
51 |
|
---|
52 | void crUnpackBitmap(PCrUnpackerState pState)
|
---|
53 | {
|
---|
54 | CHECK_BUFFER_SIZE_STATIC_LAST(pState, sizeof(int) + 28, GLint);
|
---|
55 |
|
---|
56 | GLsizei width = READ_DATA(pState, sizeof( int ) + 0, GLsizei );
|
---|
57 | GLsizei height = READ_DATA(pState,sizeof( int ) + 4, GLsizei );
|
---|
58 | GLfloat xorig = READ_DATA(pState, sizeof( int ) + 8, GLfloat );
|
---|
59 | GLfloat yorig = READ_DATA(pState, sizeof( int ) + 12, GLfloat );
|
---|
60 | GLfloat xmove = READ_DATA(pState, sizeof( int ) + 16, GLfloat );
|
---|
61 | GLfloat ymove = READ_DATA(pState, sizeof( int ) + 20, GLfloat );
|
---|
62 | GLuint noimagedata = READ_DATA(pState, sizeof( int ) + 24, GLuint );
|
---|
63 | GLubyte *bitmap;
|
---|
64 |
|
---|
65 | if (noimagedata && !crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
|
---|
66 | return;
|
---|
67 |
|
---|
68 | if (noimagedata)
|
---|
69 | bitmap = (GLubyte *) (uintptr_t) READ_DATA(pState,sizeof(int) + 28, GLint);
|
---|
70 | else
|
---|
71 | {
|
---|
72 | /* Each pixel is one bit => 8 pixels per byte. */
|
---|
73 | size_t cbImg = crImageSize(GL_COLOR_INDEX, GL_BITMAP, width, height);
|
---|
74 | if (RT_UNLIKELY(cbImg == 0))
|
---|
75 | {
|
---|
76 | pState->rcUnpack = VERR_INVALID_PARAMETER;
|
---|
77 | return;
|
---|
78 | }
|
---|
79 |
|
---|
80 | bitmap = DATA_POINTER(pState, sizeof(int) + 32, GLubyte );
|
---|
81 | CHECK_ARRAY_SIZE_FROM_PTR_UPDATE_LAST(pState, bitmap, cbImg, GLubyte);
|
---|
82 | }
|
---|
83 |
|
---|
84 | pState->pDispatchTbl->PixelStorei( GL_UNPACK_ROW_LENGTH, 0 );
|
---|
85 | pState->pDispatchTbl->PixelStorei( GL_UNPACK_SKIP_PIXELS, 0 );
|
---|
86 | pState->pDispatchTbl->PixelStorei( GL_UNPACK_SKIP_ROWS, 0 );
|
---|
87 | pState->pDispatchTbl->PixelStorei( GL_UNPACK_ALIGNMENT, 1 );
|
---|
88 |
|
---|
89 | pState->pDispatchTbl->Bitmap( width, height, xorig, yorig, xmove, ymove, bitmap );
|
---|
90 |
|
---|
91 | INCR_VAR_PTR(pState);
|
---|
92 | }
|
---|
93 |
|
---|
94 | /*
|
---|
95 | * ZPixCR - compressed DrawPixels
|
---|
96 | */
|
---|
97 | void crUnpackExtendZPixCR(PCrUnpackerState pState)
|
---|
98 | {
|
---|
99 | CHECK_BUFFER_SIZE_STATIC_LAST(pState, 32, GLint);
|
---|
100 |
|
---|
101 | GLsizei width = READ_DATA(pState, 8, GLsizei );
|
---|
102 | GLsizei height = READ_DATA(pState, 12, GLsizei );
|
---|
103 | GLenum format = READ_DATA(pState, 16, GLenum );
|
---|
104 | GLenum type = READ_DATA(pState, 20, GLenum );
|
---|
105 | GLenum ztype = READ_DATA(pState, 24, GLenum );
|
---|
106 | GLint zparm = READ_DATA(pState, 28, GLuint );
|
---|
107 | GLint length = READ_DATA(pState, 32, GLint );
|
---|
108 | GLvoid *pixels = DATA_POINTER(pState, 36, GLvoid );
|
---|
109 |
|
---|
110 | pState->pDispatchTbl->PixelStorei( GL_UNPACK_ROW_LENGTH, 0 );
|
---|
111 | pState->pDispatchTbl->PixelStorei( GL_UNPACK_SKIP_PIXELS, 0 );
|
---|
112 | pState->pDispatchTbl->PixelStorei( GL_UNPACK_SKIP_ROWS, 0 );
|
---|
113 | pState->pDispatchTbl->PixelStorei( GL_UNPACK_ALIGNMENT, 1 );
|
---|
114 |
|
---|
115 | CHECK_ARRAY_SIZE_FROM_PTR_UPDATE_LAST(pState, pixels, length, GLubyte);
|
---|
116 | pState->pDispatchTbl->ZPixCR( width, height, format, type, ztype, zparm, length, pixels );
|
---|
117 |
|
---|
118 | /* Don't call INCR_VAR_PTR(); - it's done in crUnpackExtend() */
|
---|
119 | }
|
---|