cbs_jpeg_syntax_template.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*
  2. * This file is part of FFmpeg.
  3. *
  4. * FFmpeg is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * FFmpeg is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with FFmpeg; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. static int FUNC(frame_header)(CodedBitstreamContext *ctx, RWContext *rw,
  19. JPEGRawFrameHeader *current)
  20. {
  21. int err, i;
  22. HEADER("Frame Header");
  23. u(16, Lf, 8, 8 + 3 * JPEG_MAX_COMPONENTS);
  24. u(8, P, 2, 16);
  25. u(16, Y, 0, JPEG_MAX_HEIGHT);
  26. u(16, X, 1, JPEG_MAX_WIDTH);
  27. u(8, Nf, 1, JPEG_MAX_COMPONENTS);
  28. for (i = 0; i < current->Nf; i++) {
  29. us(8, C[i], i, 0, JPEG_MAX_COMPONENTS);
  30. us(4, H[i], i, 1, 4);
  31. us(4, V[i], i, 1, 4);
  32. us(8, Tq[i], i, 0, 3);
  33. }
  34. return 0;
  35. }
  36. static int FUNC(quantisation_table)(CodedBitstreamContext *ctx, RWContext *rw,
  37. JPEGRawQuantisationTable *current)
  38. {
  39. int err, i;
  40. u(4, Pq, 0, 1);
  41. u(4, Tq, 0, 3);
  42. if (current->Pq) {
  43. for (i = 0; i < 64; i++)
  44. us(16, Q[i], i, 1, 255);
  45. } else {
  46. for (i = 0; i < 64; i++)
  47. us(8, Q[i], i, 1, 255);
  48. }
  49. return 0;
  50. }
  51. static int FUNC(dqt)(CodedBitstreamContext *ctx, RWContext *rw,
  52. JPEGRawQuantisationTableSpecification *current)
  53. {
  54. int err, i, n;
  55. HEADER("Quantisation Tables");
  56. u(16, Lq, 2, 2 + 4 * 65);
  57. n = current->Lq / 65;
  58. for (i = 0; i < n; i++)
  59. CHECK(FUNC(quantisation_table)(ctx, rw, &current->table[i]));
  60. return 0;
  61. }
  62. static int FUNC(huffman_table)(CodedBitstreamContext *ctx, RWContext *rw,
  63. JPEGRawHuffmanTable *current)
  64. {
  65. int err, i, j, ij;
  66. u(4, Tc, 0, 1);
  67. u(4, Th, 0, 3);
  68. for (i = 0; i < 16; i++)
  69. us(8, L[i], i, 0, 224);
  70. ij = 0;
  71. for (i = 0; i < 16; i++) {
  72. for (j = 0; j < current->L[i]; j++) {
  73. us(8, V[ij], ij, 0, 255);
  74. ++ij;
  75. }
  76. }
  77. return 0;
  78. }
  79. static int FUNC(dht)(CodedBitstreamContext *ctx, RWContext *rw,
  80. JPEGRawHuffmanTableSpecification *current)
  81. {
  82. int err, i, j, n;
  83. HEADER("Huffman Tables");
  84. u(16, Lh, 2, 2 + 8 * (1 + 16 + 256));
  85. n = 2;
  86. for (i = 0; n < current->Lh; i++) {
  87. CHECK(FUNC(huffman_table)(ctx, rw, &current->table[i]));
  88. ++n;
  89. for (j = 0; j < 16; j++)
  90. n += 1 + current->table[i].L[j];
  91. }
  92. return 0;
  93. }
  94. static int FUNC(scan_header)(CodedBitstreamContext *ctx, RWContext *rw,
  95. JPEGRawScanHeader *current)
  96. {
  97. int err, j;
  98. HEADER("Scan");
  99. u(16, Ls, 6, 6 + 2 * JPEG_MAX_COMPONENTS);
  100. u(8, Ns, 1, 4);
  101. for (j = 0; j < current->Ns; j++) {
  102. us(8, Cs[j], j, 0, JPEG_MAX_COMPONENTS);
  103. us(4, Td[j], j, 0, 3);
  104. us(4, Ta[j], j, 0, 3);
  105. }
  106. u(8, Ss, 0, 63);
  107. u(8, Se, 0, 63);
  108. u(4, Ah, 0, 13);
  109. u(4, Al, 0, 15);
  110. return 0;
  111. }
  112. static int FUNC(application_data)(CodedBitstreamContext *ctx, RWContext *rw,
  113. JPEGRawApplicationData *current)
  114. {
  115. int err, i;
  116. HEADER("Application Data");
  117. u(16, Lp, 2, 65535);
  118. if (current->Lp > 2) {
  119. #ifdef READ
  120. current->Ap_ref = av_buffer_alloc(current->Lp - 2);
  121. if (!current->Ap_ref)
  122. return AVERROR(ENOMEM);
  123. current->Ap = current->Ap_ref->data;
  124. #endif
  125. for (i = 0; i < current->Lp - 2; i++)
  126. us(8, Ap[i], i, 0, 255);
  127. }
  128. return 0;
  129. }
  130. static int FUNC(comment)(CodedBitstreamContext *ctx, RWContext *rw,
  131. JPEGRawComment *current)
  132. {
  133. int err, i;
  134. HEADER("Comment");
  135. u(16, Lc, 2, 65535);
  136. if (current->Lc > 2) {
  137. #ifdef READ
  138. current->Cm_ref = av_buffer_alloc(current->Lc - 2);
  139. if (!current->Cm_ref)
  140. return AVERROR(ENOMEM);
  141. current->Cm = current->Cm_ref->data;
  142. #endif
  143. for (i = 0; i < current->Lc - 2; i++)
  144. us(8, Cm[i], i, 0, 255);
  145. }
  146. return 0;
  147. }