1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776
|
/*************************************************************************
This project implements a complete(!) JPEG (Recommendation ITU-T
T.81 | ISO/IEC 10918-1) codec, plus a library that can be used to
encode and decode JPEG streams.
It also implements ISO/IEC 18477 aka JPEG XT which is an extension
towards intermediate, high-dynamic-range lossy and lossless coding
of JPEG. In specific, it supports ISO/IEC 18477-3/-6/-7/-8 encoding.
Note that only Profiles C and D of ISO/IEC 18477-7 are supported
here. Check the JPEG XT reference software for a full implementation
of ISO/IEC 18477-7.
Copyright (C) 2012-2018 Thomas Richter, University of Stuttgart and
Accusoft. (C) 2019-2020 Thomas Richter, Fraunhofer IIS.
This program is available under two licenses, GPLv3 and the ITU
Software licence Annex A Option 2, RAND conditions.
For the full text of the GPU license option, see README.license.gpl.
For the full text of the ITU license option, see README.license.itu.
You may freely select between these two options.
For the GPL option, please note the following:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*************************************************************************/
/*
**
** Represents the scan including the scan header.
**
** $Id: acsequentialscan.cpp,v 1.52 2022/05/23 05:56:51 thor Exp $
**
*/
/// Includes
#include "codestream/acsequentialscan.hpp"
#include "codestream/tables.hpp"
#include "marker/frame.hpp"
#include "marker/scan.hpp"
#include "marker/component.hpp"
#include "coding/quantizedrow.hpp"
#include "codestream/rectanglerequest.hpp"
#include "dct/dct.hpp"
#include "std/assert.hpp"
#include "interface/bitmaphook.hpp"
#include "interface/imagebitmap.hpp"
#include "colortrafo/colortrafo.hpp"
#include "tools/traits.hpp"
#include "control/blockbitmaprequester.hpp"
#include "control/blockbuffer.hpp"
#include "control/blocklineadapter.hpp"
#include "coding/actemplate.hpp"
#include "marker/actable.hpp"
///
/// ACSequentialScan::ACSequentialScan
ACSequentialScan::ACSequentialScan(class Frame *frame,class Scan *scan,
UBYTE start,UBYTE stop,UBYTE lowbit,UBYTE,
bool differential,bool residual,bool large)
: EntropyParser(frame,scan)
#if ACCUSOFT_CODE
, m_pBlockCtrl(NULL),
m_ucScanStart(start), m_ucScanStop(stop), m_ucLowBit(lowbit),
m_bMeasure(false), m_bDifferential(differential), m_bResidual(residual), m_bLargeRange(large)
#endif
{
#if ACCUSOFT_CODE
m_ucCount = scan->ComponentsInScan();
for(UBYTE i = 0;i < m_ucCount;i++) {
m_ucSmall[i] = 0;
m_ucLarge[i] = 1;
m_ucBlockEnd[i] = 5;
}
#else
NOREF(start);
NOREF(stop);
NOREF(lowbit);
NOREF(differential);
NOREF(residual);
NOREF(large);
#endif
}
///
/// ACSequentialScan::~ACSequentialScan
ACSequentialScan::~ACSequentialScan(void)
{
}
///
/// ACSequentialScan::StartParseScan
void ACSequentialScan::StartParseScan(class ByteStream *io,class Checksum *chk,class BufferCtrl *ctrl)
{
#if ACCUSOFT_CODE
class ACTemplate *ac,*dc;
int i;
for(i = 0;i < m_ucCount;i++) {
dc = m_pScan->DCConditionerOf(i);
ac = m_pScan->ACConditionerOf(i);
m_ucDCContext[i] = m_pScan->DCTableIndexOf(i);
m_ucACContext[i] = m_pScan->ACTableIndexOf(i);
if (dc) {
m_ucSmall[i] = dc->LowerThresholdOf();
m_ucLarge[i] = dc->UpperThresholdOf();
} else {
m_ucSmall[i] = 0;
m_ucLarge[i] = 1;
}
if (ac) {
m_ucBlockEnd[i] = ac->BandDiscriminatorOf();
} else {
m_ucBlockEnd[i] = 5;
}
m_lDC[i] = 0;
m_lDiff[i] = 0;
m_ulX[i] = 0;
}
for(i = 0;i < 4;i++) {
m_Context[i].Init();
}
assert(!ctrl->isLineBased());
m_pBlockCtrl = dynamic_cast<BlockCtrl *>(ctrl);
m_pBlockCtrl->ResetToStartOfScan(m_pScan);
m_Coder.OpenForRead(io,chk);
#else
NOREF(io);
NOREF(chk);
NOREF(ctrl);
JPG_THROW(NOT_IMPLEMENTED,"ACSequentialScan::StartParseScan",
"Lossless JPEG not available in your code release, please contact Accusoft for a full version");
#endif
}
///
/// ACSequentialScan::StartWriteScan
void ACSequentialScan::StartWriteScan(class ByteStream *io,class Checksum *chk,class BufferCtrl *ctrl)
{
#if ACCUSOFT_CODE
class ACTemplate *ac,*dc;
int i;
for(i = 0;i < m_ucCount;i++) {
dc = m_pScan->DCConditionerOf(i);
ac = m_pScan->ACConditionerOf(i);
m_ucDCContext[i] = m_pScan->DCTableIndexOf(i);
m_ucACContext[i] = m_pScan->ACTableIndexOf(i);
if (dc) {
m_ucSmall[i] = dc->LowerThresholdOf();
m_ucLarge[i] = dc->UpperThresholdOf();
} else {
m_ucSmall[i] = 0;
m_ucLarge[i] = 1;
}
if (ac) {
m_ucBlockEnd[i] = ac->BandDiscriminatorOf();
} else {
m_ucBlockEnd[i] = 5;
}
m_lDC[i] = 0;
m_lDiff[i] = 0;
m_ulX[i] = 0;
}
for(i = 0;i < 4;i++) {
m_Context[i].Init();
}
assert(!ctrl->isLineBased());
m_pBlockCtrl = dynamic_cast<BlockCtrl *>(ctrl);
m_pBlockCtrl->ResetToStartOfScan(m_pScan);
EntropyParser::StartWriteScan(io,chk,ctrl);
m_pScan->WriteMarker(io);
m_Coder.OpenForWrite(io,chk);
#else
NOREF(io);
NOREF(chk);
NOREF(ctrl);
JPG_THROW(NOT_IMPLEMENTED,"ACSequentialScan::StartWriteScan",
"Lossless JPEG not available in your code release, please contact Accusoft for a full version");
#endif
}
///
/// ACSequentialScan::StartMeasureScan
// Measure scan statistics.
void ACSequentialScan::StartMeasureScan(class BufferCtrl *)
{
//
// This is not required.
JPG_THROW(NOT_IMPLEMENTED,"ACSequentialScan::StartMeasureScan",
"arithmetic coding is always adaptive and does not require "
"to measure the statistics");
}
///
/// ACSequentialScan::StartMCURow
// Start a MCU scan. Returns true if there are more rows.
bool ACSequentialScan::StartMCURow(void)
{
#if ACCUSOFT_CODE
bool more = m_pBlockCtrl->StartMCUQuantizerRow(m_pScan);
for(int i = 0;i < m_ucCount;i++) {
m_ulX[i] = 0;
}
return more;
#else
return false;
#endif
}
///
/// ACSequentialScan::WriteMCU
// Write a single MCU in this scan. Return true if there are more blocks in this row.
bool ACSequentialScan::WriteMCU(void)
{
#if ACCUSOFT_CODE
bool more = true;
int c;
assert(m_pBlockCtrl);
BeginWriteMCU(m_Coder.ByteStreamOf());
for(c = 0;c < m_ucCount;c++) {
class Component *comp = m_pComponent[c];
class QuantizedRow *q = m_pBlockCtrl->CurrentQuantizedRow(comp->IndexOf());
LONG &prevdc = m_lDC[c];
LONG &prevdiff = m_lDiff[c];
UBYTE l = m_ucSmall[c];
UBYTE u = m_ucLarge[c];
UBYTE kx = m_ucBlockEnd[c];
UBYTE mcux = (m_ucCount > 1)?(comp->MCUWidthOf() ):(1);
UBYTE mcuy = (m_ucCount > 1)?(comp->MCUHeightOf()):(1);
ULONG xmin = m_ulX[c];
ULONG xmax = xmin + mcux;
ULONG x,y;
if (xmax >= q->WidthOf()) {
more = false;
}
for(y = 0;y < mcuy;y++) {
for(x = xmin;x < xmax;x++) {
LONG *block,dummy[64];
if (q && x < q->WidthOf()) {
block = q->BlockAt(x)->m_Data;
} else {
block = dummy;
memset(dummy ,0,sizeof(dummy) );
block[0] = prevdc;
}
EncodeBlock(block,prevdc,prevdiff,l,u,kx,m_ucDCContext[c],m_ucACContext[c]);
}
if (q) q = q->NextOf();
}
// Done with this component, advance the block.
m_ulX[c] = xmax;
}
return more;
#else
return false;
#endif
}
///
/// ACSequentialScan::Restart
// Restart the parser at the next restart interval
void ACSequentialScan::Restart(void)
{
#if ACCUSOFT_CODE
int i;
for(i = 0;i < m_ucCount;i++) {
m_lDC[i] = 0;
m_lDiff[i] = 0;
}
for(i = 0;i < 4;i++) {
m_Context[i].Init();
}
m_Coder.OpenForRead(m_Coder.ByteStreamOf(),m_Coder.ChecksumOf());
#endif
}
///
/// ACSequentialScan::ParseMCU
// Parse a single MCU in this scan. Return true if there are more blocks in this row.
bool ACSequentialScan::ParseMCU(void)
{
#if ACCUSOFT_CODE
bool more = true;
int c;
assert(m_pBlockCtrl);
bool valid = BeginReadMCU(m_Coder.ByteStreamOf());
for(c = 0;c < m_ucCount;c++) {
class Component *comp = m_pComponent[c];
class QuantizedRow *q = m_pBlockCtrl->CurrentQuantizedRow(comp->IndexOf());
LONG &prevdc = m_lDC[c];
LONG &prevdiff = m_lDiff[c];
UBYTE l = m_ucSmall[c];
UBYTE u = m_ucLarge[c];
UBYTE kx = m_ucBlockEnd[c];
UBYTE mcux = (m_ucCount > 1)?(comp->MCUWidthOf() ):(1);
UBYTE mcuy = (m_ucCount > 1)?(comp->MCUHeightOf()):(1);
ULONG xmin = m_ulX[c];
ULONG xmax = xmin + mcux;
ULONG x,y;
if (xmax >= q->WidthOf()) {
more = false;
}
for(y = 0;y < mcuy;y++) {
for(x = xmin;x < xmax;x++) {
LONG *block,dummy[64];
if (q && x < q->WidthOf()) {
block = q->BlockAt(x)->m_Data;
} else {
block = dummy;
}
if (valid) {
DecodeBlock(block,prevdc,prevdiff,l,u,kx,m_ucDCContext[c],m_ucACContext[c]);
} else {
for(UBYTE i = m_ucScanStart;i <= m_ucScanStop;i++) {
block[i] = 0;
}
}
}
if (q) q = q->NextOf();
}
// Done with this component, advance the block.
m_ulX[c] = xmax;
}
return more;
#else
return false;
#endif
}
///
/// ACSequentialScan::Classify
// Find the DC context class depending on the previous DC and
// the values of L and U given in the conditioner.
#if ACCUSOFT_CODE
struct ACSequentialScan::QMContextSet::DCContextZeroSet &ACSequentialScan::QMContextSet::Classify(LONG diff,UBYTE l,UBYTE u)
{
LONG abs = (diff > 0)?(diff):(-diff);
if (abs <= ((1 << l) >> 1)) {
// the zero cathegory.
return DCZero;
}
if (abs <= (1 << u)) {
if (diff < 0) {
return DCSmallNegative;
} else {
return DCSmallPositive;
}
}
if (diff < 0) {
return DCLargeNegative;
} else {
return DCLargePositive;
}
}
#endif
///
/// ACSequentialScan::EncodeBlock
// Encode a single block
#if ACCUSOFT_CODE
void ACSequentialScan::EncodeBlock(const LONG *block,
LONG &prevdc,LONG &prevdiff,
UBYTE small,UBYTE large,UBYTE kx,UBYTE dc,UBYTE ac)
{
// DC coding
if (m_ucScanStart == 0 && m_bResidual == false) {
struct QMContextSet::DCContextZeroSet &cz = m_Context[dc].Classify(prevdiff,small,large);
LONG diff;
// DPCM coding of the DC coefficient.
diff = block[0] >> m_ucLowBit; // only correct for two's completement machines
diff -= prevdc;
if (m_bDifferential) {
prevdc = 0;
} else {
prevdc = block[0] >> m_ucLowBit;
}
if (diff) {
LONG sz;
//
// Nonzero, encode a one in context zero.
m_Coder.Put(cz.S0,true);
//
// Sign coding. Encode a zero for positive and a 1 for
// negative.
if (diff < 0) {
m_Coder.Put(cz.SS,true);
sz = -diff - 1;
} else {
m_Coder.Put(cz.SS,false);
sz = diff - 1;
}
//
// Code the magnitude.
if (sz >= 1) {
int i = 0;
LONG m = 2;
m_Coder.Put((diff > 0)?(cz.SP):(cz.SN),true);
//
// Magnitude category coding.
while(sz >= m) {
m_Coder.Put(m_Context[dc].DCMagnitude.X[i],true);
m <<= 1;
i++;
}
// Terminate magnitude cathegory coding.
m_Coder.Put(m_Context[dc].DCMagnitude.X[i],false);
//
// Get the MSB to code.
m >>= 1;
// Refinement bits: Depend on the magnitude category.
while((m >>= 1)) {
m_Coder.Put(m_Context[dc].DCMagnitude.M[i],(m & sz)?(true):(false));
}
} else {
m_Coder.Put((diff > 0)?(cz.SP):(cz.SN),false);
}
} else {
// Difference is zero. Encode a zero in context zero.
m_Coder.Put(cz.S0,false);
}
// Keep the difference for the next block.
prevdiff = diff;
}
if (m_ucScanStop) {
LONG data;
int eob,k;
// AC coding. Part one. Find the end of block.
// eob is the index of the first zero coefficient from
// which point on this, and all following coefficients
// up to coefficient with index 63 are zero.
eob = m_ucScanStop;
k = (m_ucScanStart)?(m_ucScanStart):((m_bResidual)?0:1);
//
while(eob >= k) {
data = block[DCT::ScanOrder[eob]];
if ((data >= 0)?(data >> m_ucLowBit):((-data) >> m_ucLowBit))
break;
eob--;
}
// The coefficient at eob is now nonzero, but eob+1 is
// a zero coefficient or beyond the block end.
eob++; // the first coefficient *not* to code.
do {
LONG data,sz;
//
if (k == eob) {
m_Coder.Put(m_Context[ac].ACZero[k-1].SE,true); // Code EOB.
break;
}
// Not EOB.
m_Coder.Put(m_Context[ac].ACZero[k-1].SE,false);
//
// Run coding in S0. Since k is not the eob, at least
// one non-zero coefficient must follow, so we cannot
// run over the end of the block.
do {
data = block[DCT::ScanOrder[k]];
data = (data >= 0)?(data >> m_ucLowBit):(-((-data) >> m_ucLowBit));
if (data == 0) {
m_Coder.Put(m_Context[ac].ACZero[k-1].S0,false);
k++;
}
} while(data == 0);
m_Coder.Put(m_Context[ac].ACZero[k-1].S0,true);
//
// The coefficient at k is now nonzero. First code
// the sign. This context is the uniform.
if (data < 0) {
m_Coder.Put(m_Context[ac].Uniform,true);
sz = -data - 1;
} else {
m_Coder.Put(m_Context[ac].Uniform,false);
sz = data - 1;
}
//
// Code the magnitude category.
if (sz >= 1) {
m_Coder.Put(m_Context[ac].ACZero[k-1].SP,true); // SP or SN coding.
if (sz >= 2) {
int i = 0;
LONG m = 4;
struct QMContextSet::ACContextMagnitudeSet &acm = (k > kx)?(m_Context[ac].ACMagnitudeHigh):(m_Context[ac].ACMagnitudeLow);
//
m_Coder.Put(m_Context[ac].ACZero[k-1].SP,true); // X1 coding, identical to SN and SP.
// Note that AC_SN,AC_SP and AC_X1 are all the same context
// all following decisions are not conditioned on k directly.
while(sz >= m) {
m_Coder.Put(acm.X[i],true);
m <<= 1;
i++;
}
m_Coder.Put(acm.X[i],false);
//
// Get the MSB to code.
m >>= 1;
//
// Magnitude refinement coding.
while((m >>= 1)) {
m_Coder.Put(acm.M[i],(m & sz)?true:false);
}
} else {
m_Coder.Put(m_Context[ac].ACZero[k-1].SP,false);
}
} else {
m_Coder.Put(m_Context[ac].ACZero[k-1].SP,false);
}
//
// Encode the next coefficient. Note that this bails out early without an
// S0 encoding if the end is reached.
} while(++k <= m_ucScanStop);
}
}
#endif
///
/// ACSequentialScan::DecodeBlock
// Decode a single block.
#if ACCUSOFT_CODE
void ACSequentialScan::DecodeBlock(LONG *block,
LONG &prevdc,LONG &prevdiff,
UBYTE small,UBYTE large,UBYTE kx,UBYTE dc,UBYTE ac)
{
// DC coding
if (m_ucScanStart == 0 && m_bResidual == false) {
LONG diff;
struct QMContextSet::DCContextZeroSet &cz = m_Context[dc].Classify(prevdiff,small,large);
// Check whether the difference is nonzero.
if (m_Coder.Get(cz.S0)) {
LONG sz;
bool sign = m_Coder.Get(cz.SS); // sign coding, is true for negative.
//
//
// Positive and negative are encoded in different contexts.
// Decode the magnitude cathegory.
if (m_Coder.Get((sign)?(cz.SN):(cz.SP))) {
int i = 0;
LONG m = 2;
while(m_Coder.Get(m_Context[dc].DCMagnitude.X[i])) {
m <<= 1;
if(++i >= QMContextSet::DCContextMagnitudeSet::MagnitudeContexts)
JPG_THROW(MALFORMED_STREAM,"ACSequentialScan::DecodeBlock",
"QMDecoder is out of sync");
}
//
// Get the MSB to decode.
m >>= 1;
sz = m;
//
// Refinement coding of remaining bits.
while((m >>= 1)) {
if (m_Coder.Get(m_Context[dc].DCMagnitude.M[i])) {
sz |= m;
}
}
} else {
sz = 0;
}
//
// Done, finally, include the sign and the offset.
if (sign) {
diff = -sz - 1;
} else {
diff = sz + 1;
}
} else {
// Difference is zero.
diff = 0;
}
prevdiff = diff;
if (m_bDifferential) {
prevdc = diff;
} else {
prevdc += diff;
}
block[0] = prevdc << m_ucLowBit; // point transformation
}
if (m_ucScanStop) {
// AC coding. No block skipping used here.
int k = (m_ucScanStart)?(m_ucScanStart):((m_bResidual)?0:1);
//
// EOB decoding.
while(k <= m_ucScanStop && !m_Coder.Get(m_Context[ac].ACZero[k-1].SE)) {
LONG sz;
bool sign;
//
// Not yet EOB. Run coding in S0: Skip over zeros.
while(!m_Coder.Get(m_Context[ac].ACZero[k-1].S0)) {
k++;
if (k > m_ucScanStop)
JPG_THROW(MALFORMED_STREAM,"ACSequentialScan::DecodeBlock",
"QMDecoder is out of sync");
}
//
// Now decode the sign of the coefficient.
// This happens in the uniform context.
sign = m_Coder.Get(m_Context[ac].Uniform);
//
// Decode the magnitude.
if (m_Coder.Get(m_Context[ac].ACZero[k-1].SP)) {
// X1 coding, identical to SN and SP.
if (m_Coder.Get(m_Context[ac].ACZero[k-1].SP)) {
int i = 0;
LONG m = 4;
struct QMContextSet::ACContextMagnitudeSet &acm = (k > kx)?(m_Context[ac].ACMagnitudeHigh):(m_Context[ac].ACMagnitudeLow);
while(m_Coder.Get(acm.X[i])) {
m <<= 1;
if(++i >= QMContextSet::ACContextMagnitudeSet::MagnitudeContexts)
JPG_THROW(MALFORMED_STREAM,"ACSequentialScan::DecodeBlock",
"QMDecoder is out of sync");
}
//
// Get the MSB to decode
m >>= 1;
sz = m;
//
// Proceed to refinement.
while((m >>= 1)) {
if (m_Coder.Get(acm.M[i])) {
sz |= m;
}
}
} else {
sz = 1;
}
} else {
sz = 0;
}
//
// Done. Finally, include sign and offset.
sz++;
if (sign)
sz = -sz;
block[DCT::ScanOrder[k]] = sz << m_ucLowBit;
//
// Proceed to the next block.
k++;
}
}
}
#endif
///
/// ACSequentialScan::WriteFrameType
// Write the marker that indicates the frame type fitting to this scan.
void ACSequentialScan::WriteFrameType(class ByteStream *io)
{
#if ACCUSOFT_CODE
UBYTE hidden = m_pFrame->TablesOf()->HiddenDCTBitsOf();
if (m_ucScanStart > 0 || m_ucScanStop < 63 || m_ucLowBit > hidden) {
// is progressive.
if (m_bResidual) {
io->PutWord(0xffba); // progressive sequential
} else {
if (m_bDifferential) {
io->PutWord(0xffce);
} else {
io->PutWord(0xffca);
}
}
} else {
if (m_bResidual) {
io->PutWord(0xffb9); // residual AC sequential
} else if (m_bDifferential) {
io->PutWord(0xffcd); // AC differential sequential
} else if (m_bLargeRange) {
io->PutWord(0xffbb);
} else {
io->PutWord(0xffc9); // AC sequential
}
}
#else
NOREF(io);
#endif
}
///
/// ACSequentialScan::Flush
// Flush the remaining bits out to the stream on writing.
void ACSequentialScan::Flush(bool)
{
#if ACCUSOFT_CODE
int i;
m_Coder.Flush();
for(i = 0;i < m_ucCount;i++) {
m_lDC[i] = 0;
m_lDiff[i] = 0;
}
for(i = 0;i < 4;i++) {
m_Context[i].Init();
}
m_Coder.OpenForWrite(m_Coder.ByteStreamOf(),m_Coder.ChecksumOf());
#endif
}
///
/// ACSequentialScan::OptimizeBlock
// Make an R/D optimization for the given scan by potentially pushing
// coefficients into other bins.
void ACSequentialScan::OptimizeBlock(LONG, LONG, UBYTE ,double ,
class DCT *,LONG [64])
{
JPG_THROW(NOT_IMPLEMENTED,"ACSequentialScan::OptimizeBlock",
"Rate-distortion optimization is not implemented for arithmetic coding");
}
///
/// ACSequentialScan::OptimizeDC
// Make an R/D optimization for the given scan by potentially pushing
// coefficients into other bins.
void ACSequentialScan::OptimizeDC(void)
{
JPG_THROW(NOT_IMPLEMENTED,"ACSequentialScan::OptimizeDC",
"Rate-distortion optimization is not implemented for arithmetic coding");
}
///
/// ACSequentialScan::StartOptimizeScan
// Start making an optimization run to adjust the coefficients.
void ACSequentialScan::StartOptimizeScan(class BufferCtrl *)
{
JPG_THROW(NOT_IMPLEMENTED,"ACSequentialScan::StartOptimizeScan",
"Rate-distortion optimization is not implemented for arithmetic coding");
}
///
|