Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(480069)

Side by Side Diff: examples/analyzer.cc

Issue 1382: Motion Vector overlay in the Analyzer
Patch Set: Motion Vector overlay in the Analyzer Created 2 years, 5 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /*Daala video codec 1 /*Daala video codec
2 Copyright (c) 2002-2015 Daala project contributors. All rights reserved. 2 Copyright (c) 2002-2015 Daala project contributors. All rights reserved.
3 3
4 Redistribution and use in source and binary forms, with or without 4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions are met: 5 modification, are permitted provided that the following conditions are met:
6 6
7 - Redistributions of source code must retain the above copyright notice, this 7 - Redistributions of source code must retain the above copyright notice, this
8 list of conditions and the following disclaimer. 8 list of conditions and the following disclaimer.
9 9
10 - Redistributions in binary form must reproduce the above copyright notice, 10 - Redistributions in binary form must reproduce the above copyright notice,
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 int mv[2]; 104 int mv[2];
105 /*The motion vector for backward prediction.*/ 105 /*The motion vector for backward prediction.*/
106 int mv1[2]; 106 int mv1[2];
107 /*Whether or not this MV actually has a valid value.*/ 107 /*Whether or not this MV actually has a valid value.*/
108 unsigned valid:1; 108 unsigned valid:1;
109 /*The ref image that this MV points into.*/ 109 /*The ref image that this MV points into.*/
110 /*For P frame, 0:golden frame, 1:previous frame. */ 110 /*For P frame, 0:golden frame, 1:previous frame. */
111 /*For B frame, 1:previous frame, 2:next frame, 3:both frames.*/ 111 /*For B frame, 1:previous frame, 2:next frame, 3:both frames.*/
112 unsigned ref:3; 112 unsigned ref:3;
113 }; 113 };
114
115 void od_img_draw_line(const int x, const int y,
116 unsigned char *channel, const int channel_stride) {
117 int p0[2];
118 int p1[2];
119 int dx[2];
120 int step[2];
121 int steep;
122 int err;
123 int derr;
124
125 steep = abs(y) > abs(x);
126 p0[0] = 0;
127 p0[1] = 0;
128 p1[0] = x;
129 p1[1] = y;
130 dx[0] = abs(x);
131 dx[1] = abs(y);
132
133 err = 0;
134 derr = dx[1 - steep];
135 step[0] = ((p0[0] < x) << 1) - 1;
136 step[1] = ((p0[1] < y) << 1) - 1;
137
138 *channel = 1;
139 while (p0[steep] != p1[steep]) {
140 p0[steep] += step[steep];
141 err += derr;
142 if (err << 1 > dx[steep]) {
143 p0[1 - steep] += step[1 - steep];
144 err -= dx[steep];
145 }
146 *(channel + (channel_stride * p0[1] + p0[0])) = 1;
147 }
148 }
114 149
115 class DaalaDecoder { 150 class DaalaDecoder {
116 private: 151 private:
117 FILE *input; 152 FILE *input;
118 wxString path; 153 wxString path;
119 154
120 ogg_page page; 155 ogg_page page;
121 ogg_sync_state oy; 156 ogg_sync_state oy;
122 ogg_stream_state os; 157 ogg_stream_state os;
123 158
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 double *bpp_q3; 458 double *bpp_q3;
424 459
425 unsigned char *dering; 460 unsigned char *dering;
426 unsigned int dering_len; 461 unsigned int dering_len;
427 462
428 od_mv_grid_pt *mv; 463 od_mv_grid_pt *mv;
429 unsigned int mv_len; 464 unsigned int mv_len;
430 465
431 int plane_mask; 466 int plane_mask;
432 const wxString path; 467 const wxString path;
468
469 unsigned char *mv_mask;
433 470
434 // The decode size is the picture size or frame size. 471 // The decode size is the picture size or frame size.
435 int getDecodeWidth() const; 472 int getDecodeWidth() const;
436 int getDecodeHeight() const; 473 int getDecodeHeight() const;
437 474
438 // The display size is the decode size, scaled by the zoom. 475 // The display size is the decode size, scaled by the zoom.
439 int getDisplayWidth() const; 476 int getDisplayWidth() const;
440 int getDisplayHeight() const; 477 int getDisplayHeight() const;
441 478
442 bool updateDisplaySize(); 479 bool updateDisplaySize();
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 close(); 679 close();
643 return false; 680 return false;
644 } 681 }
645 mv_len = sizeof(od_mv_grid_pt)*(dd.getNHMVBS() + 1)*(dd.getNVMVBS() + 1); 682 mv_len = sizeof(od_mv_grid_pt)*(dd.getNHMVBS() + 1)*(dd.getNVMVBS() + 1);
646 mv = (od_mv_grid_pt *)malloc(mv_len); 683 mv = (od_mv_grid_pt *)malloc(mv_len);
647 if (!dd.setMVBuffer(mv, mv_len)) { 684 if (!dd.setMVBuffer(mv, mv_len)) {
648 fprintf(stderr, "Could not set mv buffer\n"); 685 fprintf(stderr, "Could not set mv buffer\n");
649 close(); 686 close();
650 return false; 687 return false;
651 } 688 }
689 mv_mask = (unsigned char *)malloc(sizeof(char)*dd.getFrameWidth()
690 * dd.getFrameHeight());
652 if (!nextFrame()) { 691 if (!nextFrame()) {
653 close(); 692 close();
654 return false; 693 return false;
655 } 694 }
656 SetFocus(); 695 SetFocus();
657 return true; 696 return true;
658 } 697 }
659 698
660 void TestPanel::close() { 699 void TestPanel::close() {
661 dd.close(); 700 dd.close();
662 free(pixels); 701 free(pixels);
663 pixels = NULL; 702 pixels = NULL;
664 free(bsize); 703 free(bsize);
665 bsize = NULL; 704 bsize = NULL;
666 free(flags); 705 free(flags);
667 flags = NULL; 706 flags = NULL;
668 free(bpp_q3); 707 free(bpp_q3);
669 bpp_q3 = NULL; 708 bpp_q3 = NULL;
670 free(dering); 709 free(dering);
671 dering = NULL; 710 dering = NULL;
672 free(mv); 711 free(mv);
712 mv = NULL;
713 free(mv_mask);
673 mv = NULL; 714 mv = NULL;
674 } 715 }
675 716
676 int TestPanel::getDecodeWidth() const { 717 int TestPanel::getDecodeWidth() const {
677 return show_padding ? dd.getFrameWidth() : dd.getWidth(); 718 return show_padding ? dd.getFrameWidth() : dd.getWidth();
678 } 719 }
679 720
680 int TestPanel::getDecodeHeight() const { 721 int TestPanel::getDecodeHeight() const {
681 return show_padding ? dd.getFrameHeight() : dd.getHeight(); 722 return show_padding ? dd.getFrameHeight() : dd.getHeight();
682 } 723 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 double norm; 767 double norm;
727 if (show_bits) { 768 if (show_bits) {
728 double maxval = 0; 769 double maxval = 0;
729 for (int j = 0; j < getDecodeHeight(); j++) { 770 for (int j = 0; j < getDecodeHeight(); j++) {
730 for (int i = 0; i < getDecodeWidth(); i++) { 771 for (int i = 0; i < getDecodeWidth(); i++) {
731 double bpp = bpp_q3[j*dd.getFrameWidth() + i]; 772 double bpp = bpp_q3[j*dd.getFrameWidth() + i];
732 if (bpp > maxval) maxval = bpp; 773 if (bpp > maxval) maxval = bpp;
733 } 774 }
734 } 775 }
735 norm = 1./(1e-4+maxval); 776 norm = 1./(1e-4+maxval);
777 }
778 if (show_motion) {
779 memset(mv_mask, 0, sizeof(char) * dd.getFrameWidth() * dd.getFrameHeight());
780 unsigned char *mv_pel = mv_mask;
781 for (int sby = 0; sby < dd.getNVMVBS() + 1; sby++) {
782 int y = sby << OD_LOG_MVBSIZE_MIN;
783 for (int sbx = 0; sbx < dd.getNHMVBS() + 1; sbx++) {
784 int x = sbx << OD_LOG_MVBSIZE_MIN;
785 if(x < getDecodeWidth() && y < getDecodeHeight()) {
786 od_mv_grid_pt cur = mv[sby * (dd.getNHMVBS()+1) + sbx];
787 int mv_x = cur.mv[0] >> OD_LOG_MVBSIZE_MIN;
788 int mv_y = cur.mv[1] >> OD_LOG_MVBSIZE_MIN;
789 int xx = x + mv_x;
790 int yy = y + mv_y;
791 if(xx < 0) {
792 mv_x += xx;
793 }
794 else if(xx > getDecodeWidth()) {
795 mv_x += getDecodeWidth() - xx;
796 }
797 if(yy < 0) {
798 mv_y += yy;
799 }
800 else if(yy > getDecodeHeight()) {
801 mv_y += getDecodeHeight() - yy;
802 }
803 if(cur.valid) {
804 od_img_draw_line(mv_x, mv_y, mv_pel+(y * dd.getFrameWidth() + x),
805 dd.getFrameWidth());
806 }
807 }
808 }
809 }
736 } 810 }
737 811
738 for (int j = 0; j < getDecodeHeight(); j++) { 812 for (int j = 0; j < getDecodeHeight(); j++) {
739 unsigned char *y = y_row; 813 unsigned char *y = y_row;
740 unsigned char *cb = cb_row; 814 unsigned char *cb = cb_row;
741 unsigned char *cr = cr_row; 815 unsigned char *cr = cr_row;
742 unsigned char *p = p_row; 816 unsigned char *p = p_row;
743 for (int i = 0; i < getDecodeWidth(); i++) { 817 for (int i = 0; i < getDecodeWidth(); i++) {
744 ogg_int64_t yval; 818 ogg_int64_t yval;
745 ogg_int64_t cbval; 819 ogg_int64_t cbval;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 unsigned char d = OD_BLOCK_SIZE4x4(bsize, bstride, i >> 2, j >> 2); 904 unsigned char d = OD_BLOCK_SIZE4x4(bsize, bstride, i >> 2, j >> 2);
831 int mask = (1 << (d + OD_LOG_BSIZE0)) - 1; 905 int mask = (1 << (d + OD_LOG_BSIZE0)) - 1;
832 if (!(i & mask) || !(j & mask)) { 906 if (!(i & mask) || !(j & mask)) {
833 yval = block_edge_luma(yval); 907 yval = block_edge_luma(yval);
834 cbval = (cbval + 128) >> 1; 908 cbval = (cbval + 128) >> 1;
835 crval = (crval + 128) >> 1; 909 crval = (crval + 128) >> 1;
836 pmask = OD_ALL_MASK; 910 pmask = OD_ALL_MASK;
837 } 911 }
838 } 912 }
839 if (show_motion) { 913 if (show_motion) {
840 int mask = ~(OD_MVBSIZE_MIN - 1); 914 if (mv_mask[j * dd.getFrameWidth() + i] == 1) {
841 int b = OD_LOG_MVBSIZE_MIN; 915 cbval = 0;
842 while (i == (i & mask) || j == (j & mask)) { 916 crval = 255;
843 mask <<= 1; 917 yval = 0;
844 int mid_step = 1 << b++; 918 } else {
845 int row = ((i & mask) + mid_step) >> OD_LOG_MVBSIZE_MIN; 919 int mask = ~(OD_MVBSIZE_MIN - 1);
846 int col = ((j & mask) + mid_step) >> OD_LOG_MVBSIZE_MIN; 920 int b = OD_LOG_MVBSIZE_MIN;
847 int index = col * (dd.getNHMVBS() + 1) + row; 921 while (i == (i & mask) || j == (j & mask)) {
848 if (mv[index].valid) { 922 mask <<= 1;
849 yval = block_edge_luma(yval); 923 int mid_step = 1 << b++;
850 cbval = 255; 924 int row = ((i & mask) + mid_step) >> OD_LOG_MVBSIZE_MIN;
851 break; 925 int col = ((j & mask) + mid_step) >> OD_LOG_MVBSIZE_MIN;
852 } 926 int index = col * (dd.getNHMVBS() + 1) + row;
853 if (b > OD_LOG_MVBSIZE_MAX) { 927 if (mv[index].valid) {
854 break; 928 yval = block_edge_luma(yval);
929 cbval = 255;
930 break;
931 }
932 if (b > OD_LOG_MVBSIZE_MAX) {
933 break;
934 }
855 } 935 }
856 } 936 }
857 } 937 }
858 if (i == dd.getWidth() || j == dd.getHeight()) { 938 if (i == dd.getWidth() || j == dd.getHeight()) {
859 /* Display a checkerboard pattern at the padding edge */ 939 /* Display a checkerboard pattern at the padding edge */
860 yval = 255 * ((i + j) & 1); 940 yval = 255 * ((i + j) & 1);
861 pmask = OD_ALL_MASK; 941 pmask = OD_ALL_MASK;
862 } 942 }
863 if (pmask & OD_LUMA_MASK) { 943 if (pmask & OD_LUMA_MASK) {
864 yval -= 16; 944 yval -= 16;
(...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after
1549 bool TestApp::OnCmdLineParsed(wxCmdLineParser &parser) { 1629 bool TestApp::OnCmdLineParsed(wxCmdLineParser &parser) {
1550 frame = new TestFrame(parser.Found(_(OD_BIT_ACCOUNTING_SWITCH))); 1630 frame = new TestFrame(parser.Found(_(OD_BIT_ACCOUNTING_SWITCH)));
1551 frame->Show(); 1631 frame->Show();
1552 if (parser.GetParamCount() > 0) { 1632 if (parser.GetParamCount() > 0) {
1553 return frame->open(parser.GetParam(0)); 1633 return frame->open(parser.GetParam(0));
1554 } 1634 }
1555 return true; 1635 return true;
1556 } 1636 }
1557 1637
1558 IMPLEMENT_APP(TestApp) 1638 IMPLEMENT_APP(TestApp)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld