#include <CGBuffer.h>
Collaboration diagram for CGBuffer:

Public Member Functions | |
| CGBuffer (const char *path) | |
| bool | LoadJPEG () |
| bool | Open (const char *path) |
| void | Release () |
| bool | Render () |
| void | Reset () |
| CGBuffer * | Retain () |
| ~CGBuffer () | |
Public Attributes | |
| MemoryBuffer * | buffer |
| size_t | image_depth |
| bool | image_finished |
| CGSize | image_size |
Private Member Functions | |
| bool | CreateCGContext () |
| void | Init () |
| void | RenderCGImage (const CGRect &dst_rect) |
Private Attributes | |
| CGContextRef | context_ref |
| Datafile | file |
| CGImageRef | image_ref |
| int | ref_count |
|
|
Definition at line 310 of file CGBuffer.h. References Init(), and Open().
|
|
|
Definition at line 316 of file CGBuffer.h. References Reset(). 00317 {
00318 Reset();
00319 }
|
|
|
Definition at line 249 of file CGBuffer.h. References buffer, context_ref, MemoryBuffer::Create(), MemoryBuffer::data, image_depth, image_size, and MemoryBuffer::Release(). Referenced by Render(). 00250 {
00251 if (context_ref)
00252 {
00253 CGContextRelease(context_ref);
00254 context_ref = NULL;
00255 }
00256
00257 if (buffer)
00258 {
00259 buffer->Release();
00260 buffer = NULL;
00261 }
00262
00263 size_t buffer_rowbytes = (size_t)(image_size.width * ((image_depth == 8) ? 1 : 4)); //CGImageGetBytesPerRow(image_ref);
00264
00265 buffer = MemoryBuffer::Create(buffer_rowbytes * (size_t)image_size.height);
00266
00267 if (!buffer)
00268 return false;
00269
00270 CGColorSpaceRef colorspace_ref = (image_depth == 8) ? CGColorSpaceCreateDeviceGray() : CGColorSpaceCreateDeviceRGB();
00271
00272 if (!colorspace_ref)
00273 return false;
00274
00275 CGImageAlphaInfo alpha_info = (image_depth == 8) ? kCGImageAlphaNone : kCGImageAlphaPremultipliedLast; //kCGImageAlphaLast; //RGBA format
00276
00277 context_ref = CGBitmapContextCreate(buffer->data, (size_t)image_size.width, (size_t)image_size.height, 8, buffer_rowbytes, colorspace_ref, alpha_info);
00278
00279 if (context_ref)
00280 {
00281 CGContextSetFillColorSpace(context_ref, colorspace_ref);
00282 CGContextSetStrokeColorSpace(context_ref, colorspace_ref);
00283 // move down, and flip vertically
00284 // to turn postscript style coordinates to "screen style"
00285 CGContextTranslateCTM(context_ref, 0.0, image_size.height);
00286 CGContextScaleCTM(context_ref, 1.0, -1.0);
00287 }
00288
00289 CGColorSpaceRelease(colorspace_ref);
00290 colorspace_ref = NULL;
00291
00292 return !!context_ref;
00293 }
|
|
|
Definition at line 240 of file CGBuffer.h. References buffer, context_ref, image_finished, image_ref, and ref_count. Referenced by CGBuffer(). 00241 {
00242 ref_count = 1;
00243 buffer = NULL;
00244 image_ref = NULL;
00245 context_ref = NULL;
00246 image_finished = false;
00247 }
|
|
|
Definition at line 339 of file CGBuffer.h. References Datafile::Close(), MemoryBuffer::data, Datafile::data_buffer, Datafile::data_size, file, image_depth, image_ref, image_size, and Datafile::Read(). Referenced by LoadJPEGImage(). 00340 {
00341 if (!file.Read())
00342 return false;
00343
00344 file.Close();
00345
00346 CGDataProviderRef src_provider_ref = CGDataProviderCreateWithData(this, file.data_buffer->data, file.data_size, NULL);
00347
00348 if (!src_provider_ref)
00349 return false;
00350
00351 image_ref = CGImageCreateWithJPEGDataProvider(src_provider_ref, NULL, true, kCGRenderingIntentDefault);
00352
00353 CGDataProviderRelease(src_provider_ref);
00354 src_provider_ref = NULL;
00355
00356 if (!image_ref)
00357 return false;
00358
00359 image_size = CGSizeMake(CGImageGetWidth(image_ref), CGImageGetHeight(image_ref));
00360 image_depth = CGImageGetBitsPerPixel(image_ref);
00361
00362 return !!image_ref;
00363 }
|
|
|
Definition at line 333 of file CGBuffer.h. References file, Datafile::Open(), and Datafile::Reset(). Referenced by CGBuffer().
|
|
|
Definition at line 327 of file CGBuffer.h. References ref_count. 00328 {
00329 if (--ref_count == 0)
00330 delete this;
00331 }
|
|
|
Definition at line 365 of file CGBuffer.h. References context_ref, CreateCGContext(), file, image_ref, image_size, RenderCGImage(), and Datafile::Reset(). Referenced by LoadJPEGImage(). 00366 {
00367 if (!image_ref)
00368 return false;
00369
00370 if (!CreateCGContext())
00371 return false;
00372
00373 RenderCGImage(CGFrame(image_size));
00374
00375 CGContextRelease(context_ref);
00376 context_ref = NULL;
00377
00378 CGImageRelease(image_ref);
00379 image_ref = NULL;
00380
00381 file.Reset();
00382
00383 return true;
00384 }
|
|
|
Definition at line 295 of file CGBuffer.h. References context_ref, and image_ref. Referenced by Render(). 00296 {
00297 if (!context_ref || !image_ref)
00298 return;
00299
00300 CGContextDrawImage(context_ref, dst_rect, image_ref);
00301 }
|
|
|
Definition at line 386 of file CGBuffer.h. References buffer, context_ref, image_ref, and MemoryBuffer::Release(). Referenced by ~CGBuffer(). 00387 {
00388 if (buffer)
00389 {
00390 buffer->Release();
00391 buffer = NULL;
00392 }
00393
00394 if (image_ref)
00395 {
00396 CGImageRelease(image_ref);
00397 image_ref = NULL;
00398 }
00399
00400 if (context_ref)
00401 {
00402 CGContextRelease(context_ref);
00403 context_ref = NULL;
00404 }
00405 }
|
|
|
Definition at line 321 of file CGBuffer.h. References ref_count. 00322 {
00323 ++ref_count;
00324 return this;
00325 }
|
|
|
Definition at line 305 of file CGBuffer.h. Referenced by CreateCGContext(), Init(), LoadJPEGImage(), and Reset(). |
|
|
Definition at line 236 of file CGBuffer.h. Referenced by CreateCGContext(), Init(), Render(), RenderCGImage(), and Reset(). |
|
|
Definition at line 234 of file CGBuffer.h. Referenced by LoadJPEG(), Open(), and Render(). |
|
|
Definition at line 307 of file CGBuffer.h. Referenced by CreateCGContext(), LoadJPEG(), and LoadJPEGImage(). |
|
|
Definition at line 308 of file CGBuffer.h. Referenced by Init(). |
|
|
Definition at line 235 of file CGBuffer.h. Referenced by Init(), LoadJPEG(), Render(), RenderCGImage(), and Reset(). |
|
|
Definition at line 306 of file CGBuffer.h. Referenced by CreateCGContext(), LoadJPEG(), LoadJPEGImage(), and Render(). |
|
|
Definition at line 238 of file CGBuffer.h. |
1.4.1