Mercurial > sdl-ios-xcode
comparison src/video/photon/SDL_ph_image.c @ 380:bce7171e7a85
Date: Wed, 22 May 2002 22:30:58 +0300
From: "Mike Gorchak" <mike@malva.com.ua>
Subject: One more QNX patch
Hi !
- Fixed graywin test application. Added properly support for
window size not equal to 640x480.
- Added support for not aligned pitch of image in SDL_SWSURFACE
and SDL_HWSURFACE. Using Photon builtin alignes.
- Added memory clear after each malloc to avoid problems in the
future :)
- Removed unused variables and static variables, fixed some warnings.
- Updated readme.QNX file.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 28 May 2002 19:31:32 +0000 |
parents | ba72f259bc88 |
children | 8e3ce997621c |
comparison
equal
deleted
inserted
replaced
379:11c8a7684f74 | 380:bce7171e7a85 |
---|---|
36 /* remove this line, if photon headers updates */ | 36 /* remove this line, if photon headers updates */ |
37 int PgWaitHWIdle(void); | 37 int PgWaitHWIdle(void); |
38 | 38 |
39 int ph_SetupImage(_THIS, SDL_Surface *screen) | 39 int ph_SetupImage(_THIS, SDL_Surface *screen) |
40 { | 40 { |
41 PgColor_t* palette=NULL; | |
41 int type=0; | 42 int type=0; |
42 PgColor_t* palette=NULL; | 43 int bpp; |
44 | |
45 bpp=screen->format->BitsPerPixel; | |
43 | 46 |
44 /* Determine image type */ | 47 /* Determine image type */ |
45 switch(screen->format->BitsPerPixel) | 48 switch(bpp) |
46 { | 49 { |
47 case 8:{ | 50 case 8:{ |
48 type = Pg_IMAGE_PALETTE_BYTE; | 51 type = Pg_IMAGE_PALETTE_BYTE; |
49 } | 52 } |
50 break; | 53 break; |
63 case 32:{ | 66 case 32:{ |
64 type = Pg_IMAGE_DIRECT_8888; | 67 type = Pg_IMAGE_DIRECT_8888; |
65 } | 68 } |
66 break; | 69 break; |
67 default:{ | 70 default:{ |
68 fprintf(stderr,"ph_SetupImage(): unsupported bbp = %d\n", screen->format->BitsPerPixel); | 71 fprintf(stderr,"ph_SetupImage(): unsupported bbp = %d\n", bpp); |
69 return -1; | 72 return -1; |
70 } | 73 } |
71 break; | 74 break; |
72 } | 75 } |
73 | 76 |
74 /* palette emulation code */ | 77 /* palette emulation code */ |
75 if ((screen->format->BitsPerPixel==8) && (desktoppal==SDLPH_PAL_EMULATE)) | 78 if ((bpp==8) && (desktoppal==SDLPH_PAL_EMULATE)) |
76 { | 79 { |
77 /* creating image palette */ | 80 /* creating image palette */ |
78 palette=malloc(_Pg_MAX_PALETTE*sizeof(PgColor_t)); | 81 palette=malloc(_Pg_MAX_PALETTE*sizeof(PgColor_t)); |
79 PgGetPalette(palette); | 82 PgGetPalette(palette); |
80 | 83 |
81 /* using shared memory for speed (set last param to 1) */ | 84 /* using shared memory for speed (set last param to 1) */ |
82 if ((SDL_Image = PhCreateImage(NULL, screen->w, screen->h, type, palette, _Pg_MAX_PALETTE, 1)) == NULL) | 85 if ((SDL_Image = PhCreateImage(NULL, screen->w, screen->h, type, palette, _Pg_MAX_PALETTE, 1)) == NULL) |
83 { | 86 { |
84 fprintf(stderr,"ph_SetupImage: PhCreateImage failed for bpp=8.\n"); | 87 fprintf(stderr,"ph_SetupImage(): PhCreateImage failed for bpp=8.\n"); |
85 return -1; | 88 return -1; |
86 } | 89 } |
87 } | 90 } |
88 else | 91 else |
89 { | 92 { |
92 { | 95 { |
93 fprintf(stderr,"ph_SetupImage: PhCreateImage failed.\n"); | 96 fprintf(stderr,"ph_SetupImage: PhCreateImage failed.\n"); |
94 return -1; | 97 return -1; |
95 } | 98 } |
96 } | 99 } |
97 | 100 |
98 screen->pixels = SDL_Image->image; | 101 screen->pixels = SDL_Image->image; |
102 screen->pitch = SDL_Image->bpl; /* Recalculated pitch, created by PhCreateImage */ | |
99 | 103 |
100 this->UpdateRects = ph_NormalUpdate; | 104 this->UpdateRects = ph_NormalUpdate; |
101 | 105 |
102 return 0; | 106 return 0; |
103 } | 107 } |
104 | 108 |
105 int ph_SetupOCImage(_THIS, SDL_Surface *screen) | 109 int ph_SetupOCImage(_THIS, SDL_Surface *screen) |
106 { | 110 { |
107 int type = 0; | 111 int type = 0; |
112 int bpp; | |
113 | |
114 bpp=screen->format->BitsPerPixel; | |
108 | 115 |
109 /* Determine image type */ | 116 /* Determine image type */ |
110 switch(screen->format->BitsPerPixel) | 117 switch(bpp) |
111 { | 118 { |
112 case 8: { | 119 case 8: { |
113 type = Pg_IMAGE_PALETTE_BYTE; | 120 type = Pg_IMAGE_PALETTE_BYTE; |
114 } | 121 } |
115 break; | 122 break; |
128 case 32:{ | 135 case 32:{ |
129 type = Pg_IMAGE_DIRECT_8888; | 136 type = Pg_IMAGE_DIRECT_8888; |
130 } | 137 } |
131 break; | 138 break; |
132 default:{ | 139 default:{ |
133 fprintf(stderr,"ph_SetupOCImage(): unsupported bpp = %d\n", screen->format->BitsPerPixel); | 140 fprintf(stderr,"ph_SetupOCImage(): unsupported bpp = %d\n", bpp); |
134 return -1; | 141 return -1; |
135 } | 142 } |
136 break; | 143 break; |
137 } | 144 } |
138 | 145 |
139 OCImage.FrameData0 = (FRAMEDATA *) malloc((size_t)(sizeof(FRAMEDATA))); | 146 OCImage.FrameData0 = (FRAMEDATA *) malloc((size_t)(sizeof(FRAMEDATA))); |
140 OCImage.FrameData1 = (FRAMEDATA *) malloc((size_t)(sizeof(FRAMEDATA))); | 147 OCImage.FrameData1 = (FRAMEDATA *) malloc((size_t)(sizeof(FRAMEDATA))); |
148 memset(OCImage.FrameData0, 0x00, (size_t)(sizeof(FRAMEDATA))); | |
149 memset(OCImage.FrameData1, 0x00, (size_t)(sizeof(FRAMEDATA))); | |
141 | 150 |
142 if(OCImage.direct_context == NULL) | 151 if(OCImage.direct_context == NULL) |
143 { | 152 { |
144 OCImage.direct_context = PdCreateDirectContext(); | 153 OCImage.direct_context = PdCreateDirectContext(); |
145 } | 154 } |
150 { | 159 { |
151 fprintf(stderr, "ph_SetupOCImage(): PdCreateOffscreenContext failed !\n"); | 160 fprintf(stderr, "ph_SetupOCImage(): PdCreateOffscreenContext failed !\n"); |
152 return -1; | 161 return -1; |
153 } | 162 } |
154 | 163 |
155 OCImage.Stride = OCImage.offscreen_context->pitch; | 164 screen->pitch = OCImage.offscreen_context->pitch; /* Recalculated pitch */ |
156 | 165 |
157 if (OCImage.flags & SDL_DOUBLEBUF) | 166 if (OCImage.flags & SDL_DOUBLEBUF) |
158 { | 167 { |
159 fprintf(stderr, "ph_SetupOCImage(): Hardware flag for doublebuf offscreen context\n"); | 168 fprintf(stderr, "ph_SetupOCImage(): Hardware flag for doublebuf offscreen context\n"); |
160 } | 169 } |
267 void ph_UnlockHWSurface(_THIS, SDL_Surface *surface) | 276 void ph_UnlockHWSurface(_THIS, SDL_Surface *surface) |
268 { | 277 { |
269 return; | 278 return; |
270 } | 279 } |
271 | 280 |
272 static PhPoint_t ph_pos; | |
273 static PhRect_t ph_rect; | |
274 static int i; | |
275 | |
276 void ph_OpenGLUpdate(_THIS, int numrects, SDL_Rect* rects) | 281 void ph_OpenGLUpdate(_THIS, int numrects, SDL_Rect* rects) |
277 { | 282 { |
278 this->GL_SwapBuffers(this); | 283 this->GL_SwapBuffers(this); |
279 | 284 |
280 return; | 285 return; |
281 } | 286 } |
282 | 287 |
283 void ph_NormalUpdate(_THIS, int numrects, SDL_Rect *rects) | 288 void ph_NormalUpdate(_THIS, int numrects, SDL_Rect *rects) |
284 { | 289 { |
285 for ( i=0; i<numrects; ++i ) | 290 PhPoint_t ph_pos; |
291 PhRect_t ph_rect; | |
292 int i; | |
293 | |
294 for (i=0; i<numrects; ++i) | |
286 { | 295 { |
287 if (rects[i].w==0) /* Clipped? */ | 296 if (rects[i].w==0) /* Clipped? */ |
288 { | 297 { |
289 continue; | 298 continue; |
290 } | 299 } |
308 } | 317 } |
309 } | 318 } |
310 | 319 |
311 void ph_OCUpdate(_THIS, int numrects, SDL_Rect *rects) | 320 void ph_OCUpdate(_THIS, int numrects, SDL_Rect *rects) |
312 { | 321 { |
322 int i; | |
323 | |
313 PhPoint_t zero = {0}; | 324 PhPoint_t zero = {0}; |
314 PhArea_t src_rect; | 325 PhArea_t src_rect; |
315 PhArea_t dest_rect; | 326 PhArea_t dest_rect; |
316 | 327 |
317 if(OCImage.direct_context == NULL) | 328 if(OCImage.direct_context == NULL) |