00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 INLINE PNMImageHeader::
00021 PNMImageHeader() {
00022 _x_size = 0;
00023 _y_size = 0;
00024 _num_channels = 0;
00025 _maxval = 255;
00026 _type = (PNMFileType *)NULL;
00027 }
00028
00029
00030
00031
00032
00033
00034 INLINE PNMImageHeader::
00035 PNMImageHeader(const PNMImageHeader ©) :
00036 _x_size(copy._x_size),
00037 _y_size(copy._y_size),
00038 _num_channels(copy._num_channels),
00039 _maxval(copy._maxval),
00040 _type(copy._type)
00041 {
00042 }
00043
00044
00045
00046
00047
00048
00049 INLINE void PNMImageHeader::
00050 operator = (const PNMImageHeader ©) {
00051 _x_size = copy._x_size;
00052 _y_size = copy._y_size;
00053 _num_channels = copy._num_channels;
00054 _maxval = copy._maxval;
00055 _comment = copy._comment;
00056 _type = copy._type;
00057 }
00058
00059
00060
00061
00062
00063
00064 INLINE PNMImageHeader::
00065 ~PNMImageHeader() {
00066 }
00067
00068
00069
00070
00071
00072
00073
00074
00075 INLINE PNMImageHeader::ColorType PNMImageHeader::
00076 get_color_type() const {
00077 nassertr(_num_channels >= 1 && _num_channels <= 4, CT_invalid);
00078 return (ColorType)_num_channels;
00079 }
00080
00081
00082
00083
00084
00085
00086 INLINE int PNMImageHeader::
00087 get_num_channels() const {
00088 nassertr(_num_channels >= 1 && _num_channels <= 4, 0);
00089 return _num_channels;
00090 }
00091
00092
00093
00094
00095
00096
00097
00098
00099 INLINE bool PNMImageHeader::
00100 is_grayscale(PNMImageHeader::ColorType color_type) {
00101 return (color_type == CT_grayscale || color_type == CT_two_channel);
00102 }
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113 INLINE bool PNMImageHeader::
00114 is_grayscale() const {
00115 return is_grayscale(get_color_type());
00116 }
00117
00118
00119
00120
00121
00122
00123
00124
00125 INLINE bool PNMImageHeader::
00126 has_alpha(PNMImageHeader::ColorType color_type) {
00127 return (color_type == CT_two_channel || color_type == CT_four_channel);
00128 }
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138 INLINE bool PNMImageHeader::
00139 has_alpha() const {
00140 return has_alpha(get_color_type());
00141 }
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151 INLINE xelval PNMImageHeader::
00152 get_maxval() const {
00153 return _maxval;
00154 }
00155
00156
00157
00158
00159
00160
00161
00162
00163 INLINE int PNMImageHeader::
00164 get_x_size() const {
00165 return _x_size;
00166 }
00167
00168
00169
00170
00171
00172
00173
00174
00175 INLINE int PNMImageHeader::
00176 get_y_size() const {
00177 return _y_size;
00178 }
00179
00180
00181
00182
00183
00184
00185 INLINE string PNMImageHeader::
00186 get_comment() const {
00187 return _comment;
00188 }
00189
00190
00191
00192
00193
00194
00195 INLINE void PNMImageHeader::
00196 set_comment(const string& comment) {
00197 _comment = comment;
00198 }
00199
00200
00201
00202
00203
00204
00205
00206 INLINE bool PNMImageHeader::
00207 has_type() const {
00208 return _type != (PNMFileType *)NULL;
00209 }
00210
00211
00212
00213
00214
00215
00216
00217
00218 INLINE PNMFileType *PNMImageHeader::
00219 get_type() const {
00220 return _type;
00221 }
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233 INLINE void PNMImageHeader::
00234 set_type(PNMFileType *type) {
00235 _type = type;
00236 }
00237
00238
00239
00240
00241
00242
00243 INLINE void PNMImageHeader::
00244 record_color(PNMImageHeader::HistMap &hist,
00245 const PNMImageHeader::PixelSpec &color) {
00246
00247
00248 HistMap::iterator hi = hist.insert(HistMap::value_type(color, 0)).first;
00249
00250
00251
00252
00253 (*hi).second++;
00254 }
00255
00256
00257
00258
00259
00260
00261 INLINE PNMImageHeader::PixelSpec::
00262 PixelSpec(xelval gray_value) :
00263 _red(gray_value),
00264 _green(gray_value),
00265 _blue(gray_value),
00266 _alpha(0)
00267 {
00268 }
00269
00270
00271
00272
00273
00274
00275 INLINE PNMImageHeader::PixelSpec::
00276 PixelSpec(xelval gray_value, xelval alpha) :
00277 _red(gray_value),
00278 _green(gray_value),
00279 _blue(gray_value),
00280 _alpha(alpha)
00281 {
00282 }
00283
00284
00285
00286
00287
00288
00289 INLINE PNMImageHeader::PixelSpec::
00290 PixelSpec(xelval red, xelval green, xelval blue) :
00291 _red(red),
00292 _green(green),
00293 _blue(blue),
00294 _alpha(0)
00295 {
00296 }
00297
00298
00299
00300
00301
00302
00303 INLINE PNMImageHeader::PixelSpec::
00304 PixelSpec(xelval red, xelval green, xelval blue, xelval alpha) :
00305 _red(red),
00306 _green(green),
00307 _blue(blue),
00308 _alpha(alpha)
00309 {
00310 }
00311
00312
00313
00314
00315
00316
00317 INLINE PNMImageHeader::PixelSpec::
00318 PixelSpec(const xel &rgb) :
00319 _red(PPM_GETR(rgb)),
00320 _green(PPM_GETG(rgb)),
00321 _blue(PPM_GETB(rgb)),
00322 _alpha(0)
00323 {
00324 }
00325
00326
00327
00328
00329
00330
00331 INLINE PNMImageHeader::PixelSpec::
00332 PixelSpec(const xel &rgb, xelval alpha) :
00333 _red(PPM_GETR(rgb)),
00334 _green(PPM_GETG(rgb)),
00335 _blue(PPM_GETB(rgb)),
00336 _alpha(alpha)
00337 {
00338 }
00339
00340
00341
00342
00343
00344
00345 INLINE PNMImageHeader::PixelSpec::
00346 PixelSpec(const PixelSpec ©) :
00347 _red(copy._red),
00348 _green(copy._green),
00349 _blue(copy._blue),
00350 _alpha(copy._alpha)
00351 {
00352 }
00353
00354
00355
00356
00357
00358
00359 INLINE void PNMImageHeader::PixelSpec::
00360 operator = (const PixelSpec ©) {
00361 _red = copy._red;
00362 _green = copy._green;
00363 _blue = copy._blue;
00364 _alpha = copy._alpha;
00365 }
00366
00367
00368
00369
00370
00371
00372 INLINE bool PNMImageHeader::PixelSpec::
00373 operator < (const PixelSpec &other) const {
00374 return compare_to(other) < 0;
00375 }
00376
00377
00378
00379
00380
00381
00382 INLINE bool PNMImageHeader::PixelSpec::
00383 operator == (const PixelSpec &other) const {
00384 return compare_to(other) == 0;
00385 }
00386
00387
00388
00389
00390
00391
00392 INLINE bool PNMImageHeader::PixelSpec::
00393 operator != (const PixelSpec &other) const {
00394 return compare_to(other) != 0;
00395 }
00396
00397
00398
00399
00400
00401
00402 INLINE int PNMImageHeader::PixelSpec::
00403 compare_to(const PixelSpec &other) const {
00404 if (_red != other._red) {
00405 return _red < other._red ? -1 : 1;
00406 }
00407 if (_green != other._green) {
00408 return _green < other._green ? -1 : 1;
00409 }
00410 if (_blue != other._blue) {
00411 return _blue < other._blue ? -1 : 1;
00412 }
00413 if (_alpha != other._alpha) {
00414 return _alpha < other._alpha ? -1 : 1;
00415 }
00416 return 0;
00417 }
00418
00419
00420
00421
00422
00423
00424 INLINE xelval PNMImageHeader::PixelSpec::
00425 get_red() const {
00426 return _red;
00427 }
00428
00429
00430
00431
00432
00433
00434 INLINE xelval PNMImageHeader::PixelSpec::
00435 get_green() const {
00436 return _green;
00437 }
00438
00439
00440
00441
00442
00443
00444 INLINE xelval PNMImageHeader::PixelSpec::
00445 get_blue() const {
00446 return _blue;
00447 }
00448
00449
00450
00451
00452
00453
00454 INLINE xelval PNMImageHeader::PixelSpec::
00455 get_alpha() const {
00456 return _alpha;
00457 }
00458
00459
00460
00461
00462
00463
00464 INLINE void PNMImageHeader::PixelSpec::
00465 set_red(xelval red) {
00466 _red = red;
00467 }
00468
00469
00470
00471
00472
00473
00474 INLINE void PNMImageHeader::PixelSpec::
00475 set_green(xelval green) {
00476 _green = green;
00477 }
00478
00479
00480
00481
00482
00483
00484 INLINE void PNMImageHeader::PixelSpec::
00485 set_blue(xelval blue) {
00486 _blue = blue;
00487 }
00488
00489
00490
00491
00492
00493
00494 INLINE void PNMImageHeader::PixelSpec::
00495 set_alpha(xelval alpha) {
00496 _alpha = alpha;
00497 }
00498
00499
00500
00501
00502
00503
00504
00505
00506 INLINE xelval PNMImageHeader::PixelSpec::
00507 operator [](int n) const {
00508 nassertr(n >= 0 && n < size(), 0);
00509 return (&_red)[n];
00510 }
00511
00512
00513
00514
00515
00516
00517
00518
00519 INLINE int PNMImageHeader::PixelSpec::
00520 size() {
00521 return 4;
00522 }
00523
00524
00525
00526 #ifndef CPPPARSER
00527
00528
00529
00530
00531
00532 INLINE PNMImageHeader::PixelSpecCount::
00533 PixelSpecCount(const PNMImageHeader::PixelSpec &pixel, int count) :
00534 _pixel(pixel),
00535 _count(count)
00536 {
00537 }
00538 #endif // CPPPARSER
00539
00540
00541
00542
00543
00544
00545
00546 INLINE bool PNMImageHeader::PixelSpecCount::
00547 operator < (const PNMImageHeader::PixelSpecCount &other) const {
00548 return _count > other._count;
00549 }
00550
00551
00552
00553
00554
00555
00556 INLINE PNMImageHeader::Histogram::
00557 Histogram() {
00558 }
00559
00560
00561
00562
00563
00564
00565
00566 INLINE int PNMImageHeader::Histogram::
00567 get_num_pixels() const {
00568 return _pixels.size();
00569 }
00570
00571
00572
00573
00574
00575
00576
00577
00578 INLINE const PNMImageHeader::PixelSpec &PNMImageHeader::Histogram::
00579 get_pixel(int n) const {
00580 nassertr(n >= 0 && n < (int)_pixels.size(), _pixels[0]._pixel);
00581 return _pixels[n]._pixel;
00582 }
00583
00584
00585
00586
00587
00588
00589
00590 INLINE int PNMImageHeader::Histogram::
00591 get_count(int n) const {
00592 nassertr(n >= 0 && n < (int)_pixels.size(), 0);
00593 return _pixels[n]._count;
00594 }
00595
00596
00597
00598
00599
00600
00601
00602 INLINE int PNMImageHeader::Histogram::
00603 get_count(const PNMImageHeader::PixelSpec &pixel) const {
00604 HistMap::const_iterator hi;
00605 hi = _hist_map.find(pixel);
00606 if (hi == _hist_map.end()) {
00607 return 0;
00608 }
00609 return (*hi).second;
00610 }
00611
00612
00613
00614
00615
00616
00617
00618
00619 INLINE void PNMImageHeader::Histogram::
00620 swap(PixelCount &pixels, HistMap &hist_map) {
00621 _pixels.swap(pixels);
00622 _hist_map.swap(hist_map);
00623 }