Changeset 1391:e70d408b12e2
- Timestamp:
- 11/05/09 17:54:00 (2 years ago)
- Branch:
- default
- Location:
- src
- Files:
-
- 4 edited
-
examples/image/test.cc (modified) (8 diffs)
-
include/libdodo/graphicsImage.h (modified) (3 diffs)
-
src/graphicsImage.cc (modified) (4 diffs)
-
src/ioFileRegular.cc (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/examples/image/test.cc
r1386 r1391 7 7 8 8 #include <libdodo/dodo.h> 9 9 10 #include <math.h> 10 11 #include <iostream> … … 54 55 #endif 55 56 56 im.read File("test.png");57 im.read(file::regular("test.png", file::regular::OPEN_MODE_READ_ONLY)); 57 58 cout << im.compression() << " " << im.encoder() << " " << im.quality() << endl; 58 59 … … 62 63 draw::circle(im, point(300, 300), 50, color::blue, color::white, 5); 63 64 64 im.write File("test.jpg");65 im.write(file::regular("test-0.jpg", file::regular::OPEN_MODE_READ_WRITE_TRUNCATE)); 65 66 66 67 #ifndef GRAPHICS_WO_XEXEC … … 74 75 im.setQuality(4); 75 76 im.setColorSpecification(image::COLOR_SPECIFICATION_GRAYSCALE); 76 im.writeMemory(img); 77 78 file::regular io; 79 io.open("my.png", file::regular::OPEN_MODE_READ_WRITE_TRUNCATE); 80 io.blockSize = img.size(); 81 io.write(img); 82 83 cout << img.size() << endl; 77 im.write(file::regular("test-1.jpg", file::regular::OPEN_MODE_READ_WRITE_TRUNCATE)); 84 78 85 79 im.create(400, 400); … … 87 81 draw::circle(im, point(200, 200), 50, color::blue, color::white, 5); 88 82 draw::rectangle(im, point(200, 200), point(300, 300), color::green, color::red, 15); 89 im.write File("new.png");83 im.write(file::regular("new-0.png", file::regular::OPEN_MODE_READ_WRITE_TRUNCATE)); 90 84 91 im.read File("new.png");85 im.read(file::regular("new-0.png", file::regular::OPEN_MODE_READ_ONLY)); 92 86 im.removeAlpha(); 93 im.write File("new-1.png");87 im.write(file::regular("new-1.png", file::regular::OPEN_MODE_READ_WRITE_TRUNCATE)); 94 88 95 im.read File("new-1.png");89 im.read(file::regular("new-1.png", file::regular::OPEN_MODE_READ_ONLY)); 96 90 im.setBackgroundColor(color::transparent); 97 91 draw::circle(im, point(200, 200), 100, color::red, color::green, 5); … … 102 96 green.opacity = 65535 / 2; 103 97 draw::circle(im, point(250, 250), 50, green, color::white, 5); 104 im.write File("new-2.png");98 im.write(file::regular("new-2.png", file::regular::OPEN_MODE_READ_WRITE_TRUNCATE)); 105 99 106 100 im.create(400, 400); … … 114 108 for (int i = 0; i < 360; ++i) 115 109 draw::point(im, point((unsigned long)(cos(i) * 100 + 150), (unsigned long)(200 - sin(i) * 100)), color::black); 116 im.write File("new-3.png");110 im.write(file::regular("new-3.png", file::regular::OPEN_MODE_READ_WRITE_TRUNCATE)); 117 111 118 112 im.create(400, 400); … … 122 116 draw::text(im, point(150, 150), "libdodo", "Arial", 50, color::blue, color::green, 2, 180); 123 117 draw::text(im, point(150, 200), "libdodo", "Arial", 50, color::blue, color::green, 2, 90); 124 im.write File("new-4.png");118 im.write(file::regular("new-4.png", file::regular::OPEN_MODE_READ_WRITE_TRUNCATE)); 125 119 126 120 image wm; 127 wm.read File("new-4.png");121 wm.read(file::regular("new-4.png", file::regular::OPEN_MODE_READ_ONLY)); 128 122 129 123 im.create(600, 600); 130 124 draw::image(im, point(100, 100), wm, 45); 131 125 im.setOpacity(65535 / 2); 132 im.write File("new-5.png");126 im.write(file::regular("new-5.png", file::regular::OPEN_MODE_READ_WRITE_TRUNCATE)); 133 127 #endif 134 128 } catch (dodo::exception::basic &ex) { -
src/include/libdodo/graphicsImage.h
r1386 r1391 39 39 40 40 namespace dodo { 41 namespace io { 42 class channel; 43 }; 44 41 45 namespace graphics { 42 46 struct __image__; … … 126 130 127 131 COMPRESSION_ENUMSIZE 128 };129 130 /**131 * @struct __info__132 * @brief defines image information133 */134 struct __info__ {135 void *data; ///< 2D array of pixels136 unsigned long width; ///< width of the image137 unsigned long height; ///< height of the image138 short mapping; ///< type of mapping, @see image::mappingEnum139 short pixelSize; ///< type of pixel140 132 }; 141 133 … … 216 208 /** 217 209 * read image 218 * @param path defines path to image 219 */ 220 void readFile(const dodoString &path); 221 222 /** 223 * read image 224 * @param info defines image info 225 */ 226 void readMemory(const __info__ &info); 227 228 /** 229 * read image 230 * @param data defines image data 231 */ 232 void readMemory(const dodoString &data); 210 * @param img defines source for reading image 211 */ 212 void read(const io::channel &img); 233 213 234 214 /** 235 215 * write image 236 * @param path describes path to image 237 */ 238 void writeFile(const dodoString &path); 239 240 /** 241 * write image 242 * @param data defines image data 243 */ 244 void writeMemory(dodoString &data); 216 * @param img defines source for writing image 217 */ 218 void write(const io::channel &img); 245 219 246 220 /** -
src/src/graphicsImage.cc
r1386 r1391 46 46 #include <libdodo/graphicsImageEx.h> 47 47 #include <libdodo/xexec.h> 48 #include <libdodo/ioChannel.h> 48 49 49 50 namespace dodo { … … 252 253 253 254 void 254 image::read File(const dodoString &str)255 image::read(const io::channel &img) 255 256 { 256 257 #ifndef GRAPHICS_WO_XEXEC 257 258 performPreExec(OPERATION_READ); 258 259 #endif 259 260 unsigned long size = str.size() + 1;261 262 if (size >= MaxTextExtent)263 throw exception::basic(exception::MODULE_GRAPHICSIMAGE, IMAGEEX_READ, exception::ERRNO_LIBDODO, IMAGEEX_LONGPATH, GRAPHICSIMAGEEX_LONGPATH_STR, __LINE__, __FILE__);264 260 265 261 GetExceptionInfo((ExceptionInfo *)exInfo); 266 262 GetImageInfo(collectedData.handle->imInfo); 267 263 268 strncpy(collectedData.handle->imInfo->filename, str.data(), size);269 270 264 if (collectedData.handle->im != NULL) 271 265 DestroyImage(collectedData.handle->im); 272 266 273 collectedData.handle->im = ReadImage(collectedData.handle->imInfo, (ExceptionInfo *)exInfo); 274 if (collectedData.handle->im == NULL) 275 throw exception::basic(exception::MODULE_GRAPHICSIMAGE, IMAGEEX_READ, exception::ERRNO_IMAGEMAGICK, ((ExceptionInfo *)exInfo)->error_number, ((ExceptionInfo *)exInfo)->reason, __LINE__, __FILE__, ((ExceptionInfo *)exInfo)->description ? ((ExceptionInfo *)exInfo)->description : __dodostring__); 276 277 collectedData.handle->imInfo->compression = collectedData.handle->im->compression; 278 collectedData.handle->imInfo->quality = collectedData.handle->im->quality; 279 280 strcpy(collectedData.handle->imInfo->magick, collectedData.handle->im->magick); 281 282 #ifndef GRAPHICS_WO_XEXEC 283 performPostExec(OPERATION_READ); 284 #endif 285 } 286 287 //------------------------------------------------------------------- 288 289 void 290 image::readMemory(const dodoString &data) 291 { 292 #ifndef GRAPHICS_WO_XEXEC 293 performPreExec(OPERATION_READ); 294 #endif 295 296 GetExceptionInfo((ExceptionInfo *)exInfo); 297 GetImageInfo(collectedData.handle->imInfo); 298 299 if (collectedData.handle->im != NULL) 300 DestroyImage(collectedData.handle->im); 267 dodoString data, dataPart; 268 269 while (true) { 270 dataPart = img.read(); 271 if (dataPart.size() == 0) 272 break; 273 274 data.append(dataPart); 275 } 276 dataPart.clear(); 301 277 302 278 collectedData.handle->im = BlobToImage(collectedData.handle->imInfo, data.data(), data.size(), (ExceptionInfo *)exInfo); 303 if (collectedData.handle->im == NULL)304 throw exception::basic(exception::MODULE_GRAPHICSIMAGE, IMAGEEX_READ, exception::ERRNO_IMAGEMAGICK, ((ExceptionInfo *)exInfo)->error_number, ((ExceptionInfo *)exInfo)->reason, __LINE__, __FILE__, ((ExceptionInfo *)exInfo)->description ? ((ExceptionInfo *)exInfo)->description : __dodostring__);305 306 collectedData.handle->imInfo->compression = collectedData.handle->im->compression;307 collectedData.handle->imInfo->quality = collectedData.handle->im->quality;308 309 strcpy(collectedData.handle->imInfo->magick, collectedData.handle->im->magick);310 311 #ifndef GRAPHICS_WO_XEXEC312 performPostExec(OPERATION_READ);313 #endif314 }315 316 //-------------------------------------------------------------------317 318 void319 image::readMemory(const __info__ &info)320 {321 #ifndef GRAPHICS_WO_XEXEC322 performPreExec(OPERATION_READ);323 #endif324 325 if (info.mapping < 0 || info.mapping >= MAPPING_ENUMSIZE || info.pixelSize < 0 || info.pixelSize >= PIXEL_SIZE_ENUMSIZE)326 throw exception::basic(exception::MODULE_GRAPHICSIMAGE, IMAGEEX_READ, exception::ERRNO_LIBDODO, IMAGEEX_BADINFO, GRAPHICSIMAGEEX_BADINFO_STR, __LINE__, __FILE__);327 328 GetExceptionInfo((ExceptionInfo *)exInfo);329 GetImageInfo(collectedData.handle->imInfo);330 331 if (collectedData.handle->im != NULL)332 DestroyImage(collectedData.handle->im);333 334 collectedData.handle->im = ConstituteImage(info.width, info.height, mappingStatements[info.mapping], (StorageType)pixelSizeStatements[info.pixelSize], info.data, (ExceptionInfo *)exInfo);335 279 if (collectedData.handle->im == NULL) 336 280 throw exception::basic(exception::MODULE_GRAPHICSIMAGE, IMAGEEX_READ, exception::ERRNO_IMAGEMAGICK, ((ExceptionInfo *)exInfo)->error_number, ((ExceptionInfo *)exInfo)->reason, __LINE__, __FILE__, ((ExceptionInfo *)exInfo)->description ? ((ExceptionInfo *)exInfo)->description : __dodostring__); … … 470 414 471 415 void 472 image::writeFile(const dodoString &str) 473 { 474 #ifndef GRAPHICS_WO_XEXEC 475 performPreExec(OPERATION_WRITE); 476 #endif 477 478 if (collectedData.handle->im == NULL) 479 throw exception::basic(exception::MODULE_GRAPHICSIMAGE, IMAGEEX_WRITE, exception::ERRNO_IMAGEMAGICK, IMAGEEX_EMPTYIMAGE, GRAPHICSIMAGEEX_EMPTYIMAGE_STR, __LINE__, __FILE__); 480 481 unsigned long size = str.size() + 1; 482 483 if (size >= MaxTextExtent) 484 throw exception::basic(exception::MODULE_GRAPHICSIMAGE, IMAGEEX_WRITE, exception::ERRNO_LIBDODO, IMAGEEX_LONGPATH, GRAPHICSIMAGEEX_LONGPATH_STR, __LINE__, __FILE__); 485 486 strncpy(collectedData.handle->im->filename, str.data(), size); 487 488 GetExceptionInfo((ExceptionInfo *)exInfo); 489 490 if (WriteImage(collectedData.handle->imInfo, collectedData.handle->im) == MagickFalse) 491 throw exception::basic(exception::MODULE_GRAPHICSIMAGE, IMAGEEX_WRITE, exception::ERRNO_IMAGEMAGICK, collectedData.handle->im->exception.error_number, ((ExceptionInfo *)exInfo)->reason, __LINE__, __FILE__, ((ExceptionInfo *)exInfo)->description ? ((ExceptionInfo *)exInfo)->description : __dodostring__); 492 493 #ifndef GRAPHICS_WO_XEXEC 494 performPostExec(OPERATION_WRITE); 495 #endif 496 } 497 498 //------------------------------------------------------------------- 499 500 void 501 image::writeMemory(dodoString &data) 416 image::write(const io::channel &img) 502 417 { 503 418 #ifndef GRAPHICS_WO_XEXEC … … 515 430 throw exception::basic(exception::MODULE_GRAPHICSIMAGE, IMAGEEX_WRITE, exception::ERRNO_IMAGEMAGICK, ((ExceptionInfo *)exInfo)->error_number, ((ExceptionInfo *)exInfo)->reason, __LINE__, __FILE__, ((ExceptionInfo *)exInfo)->description ? ((ExceptionInfo *)exInfo)->description : __dodostring__); 516 431 517 data.assign((char *)imData, size); 432 img.blockSize = size; 433 img.write((char *)imData); 518 434 519 435 #ifndef GRAPHICS_WO_XEXEC -
src/src/ioFileRegular.cc
r1386 r1391 396 396 break; 397 397 } 398 399 this->pos += blockSize; 398 400 } 399 401 … … 430 432 break; 431 433 } 434 435 this->pos += blockSize; 432 436 } 433 437
Note: See TracChangeset
for help on using the changeset viewer.
