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

Side by Side Diff: examples/analyzer.cc

Issue 1382: Motion Vector overlay in the Analyzer
Patch Set: Created 3 years, 9 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 {
negge 2016/06/24 15:02:59 Open bracket on previous line.
luc.trudeau 2016/07/01 19:45:03 Done.
118 int p0[2];
119 int p1[2];
120 int dx[2];
121 int step[2];
122 int steep;
123 int err;
124 int derr;
125
126 steep = abs(y) > abs(x);
127 p0[0] = 0;
128 p0[1] = 0;
129 p1[0] = x;
130 p1[1] = y;
131 dx[0] = abs(x);
132 dx[1] = abs(y);
133
134 err = 0;
135 derr = dx[1 - steep];
136 step[0] = ((p0[0] < x) << 1) - 1;
137 step[1] = ((p0[1] < y) << 1) - 1;
138
139 *channel = 1;
140 while (p0[steep] != p1[steep]) {
141 p0[steep] += step[steep];
142 err += derr;
143 if (err << 1 > dx[steep]) {
144 p0[1 - steep] += step[1 - steep];
145 err -= dx[steep];
146 }
147 *(channel + (channel_stride * p0[1] + p0[0])) = 1;
148 }
149 }
114 150
115 class DaalaDecoder { 151 class DaalaDecoder {
116 private: 152 private:
117 FILE *input; 153 FILE *input;
118 wxString path; 154 wxString path;
119 155
120 ogg_page page; 156 ogg_page page;
121 ogg_sync_state oy; 157 ogg_sync_state oy;
122 ogg_stream_state os; 158 ogg_stream_state os;
123 159
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 double *bpp_q3; 459 double *bpp_q3;
424 460
425 unsigned char *dering; 461 unsigned char *dering;
426 unsigned int dering_len; 462 unsigned int dering_len;
427 463
428 od_mv_grid_pt *mv; 464 od_mv_grid_pt *mv;
429 unsigned int mv_len; 465 unsigned int mv_len;
430 466
431 int plane_mask; 467 int plane_mask;
432 const wxString path; 468 const wxString path;
469
470 unsigned char *mv_mask;
433 471
434 // The decode size is the picture size or frame size. 472 // The decode size is the picture size or frame size.
435 int getDecodeWidth() const; 473 int getDecodeWidth() const;
436 int getDecodeHeight() const; 474 int getDecodeHeight() const;
437 475
438 // The display size is the decode size, scaled by the zoom. 476 // The display size is the decode size, scaled by the zoom.
439 int getDisplayWidth() const; 477 int getDisplayWidth() const;
440 int getDisplayHeight() const; 478 int getDisplayHeight() const;
441 479
442 bool updateDisplaySize(); 480 bool updateDisplaySize();
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 close(); 680 close();
643 return false; 681 return false;
644 } 682 }
645 mv_len = sizeof(od_mv_grid_pt)*(dd.getNHMVBS() + 1)*(dd.getNVMVBS() + 1); 683 mv_len = sizeof(od_mv_grid_pt)*(dd.getNHMVBS() + 1)*(dd.getNVMVBS() + 1);
646 mv = (od_mv_grid_pt *)malloc(mv_len); 684 mv = (od_mv_grid_pt *)malloc(mv_len);
647 if (!dd.setMVBuffer(mv, mv_len)) { 685 if (!dd.setMVBuffer(mv, mv_len)) {
648 fprintf(stderr, "Could not set mv buffer\n"); 686 fprintf(stderr, "Could not set mv buffer\n");
649 close(); 687 close();
650 return false; 688 return false;
651 } 689 }
690 mv_mask = (unsigned char *)malloc(sizeof(char)*dd.getFrameWidth()
691 * dd.getFrameHeight());
652 if (!nextFrame()) { 692 if (!nextFrame()) {
653 close(); 693 close();
654 return false; 694 return false;
655 } 695 }
656 SetFocus(); 696 SetFocus();
657 return true; 697 return true;
658 } 698 }
659 699
660 void TestPanel::close() { 700 void TestPanel::close() {
661 dd.close(); 701 dd.close();
662 free(pixels); 702 free(pixels);
663 pixels = NULL; 703 pixels = NULL;
664 free(bsize); 704 free(bsize);
665 bsize = NULL; 705 bsize = NULL;
666 free(flags); 706 free(flags);
667 flags = NULL; 707 flags = NULL;
668 free(bpp_q3); 708 free(bpp_q3);
669 bpp_q3 = NULL; 709 bpp_q3 = NULL;
670 free(dering); 710 free(dering);
671 dering = NULL; 711 dering = NULL;
672 free(mv); 712 free(mv);
713 mv = NULL;
714 free(mv_mask);
673 mv = NULL; 715 mv = NULL;
674 } 716 }
675 717
676 int TestPanel::getDecodeWidth() const { 718 int TestPanel::getDecodeWidth() const {
677 return show_padding ? dd.getFrameWidth() : dd.getWidth(); 719 return show_padding ? dd.getFrameWidth() : dd.getWidth();
678 } 720 }
679 721
680 int TestPanel::getDecodeHeight() const { 722 int TestPanel::getDecodeHeight() const {
681 return show_padding ? dd.getFrameHeight() : dd.getHeight(); 723 return show_padding ? dd.getFrameHeight() : dd.getHeight();
682 } 724 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 double norm; 768 double norm;
727 if (show_bits) { 769 if (show_bits) {
728 double maxval = 0; 770 double maxval = 0;
729 for (int j = 0; j < getDecodeHeight(); j++) { 771 for (int j = 0; j < getDecodeHeight(); j++) {
730 for (int i = 0; i < getDecodeWidth(); i++) { 772 for (int i = 0; i < getDecodeWidth(); i++) {
731 double bpp = bpp_q3[j*dd.getFrameWidth() + i]; 773 double bpp = bpp_q3[j*dd.getFrameWidth() + i];
732 if (bpp > maxval) maxval = bpp; 774 if (bpp > maxval) maxval = bpp;
733 } 775 }
734 } 776 }
735 norm = 1./(1e-4+maxval); 777 norm = 1./(1e-4+maxval);
778 }
779 if (show_motion) {
780 memset(mv_mask, 0, sizeof(char) * dd.getFrameWidth() * dd.getFrameHeight());
781 unsigned char *mv_pel = mv_mask;
782 for (int sby = 0; sby < dd.getNVMVBS() + 1; sby++) {
783 int y = sby << OD_LOG_MVBSIZE_MIN;
784 for (int sbx = 0; sbx < dd.getNHMVBS() + 1; sbx++) {
785 int x = sbx << OD_LOG_MVBSIZE_MIN;
786 if(x < getDecodeWidth() && y < getDecodeHeight()) {
787 od_mv_grid_pt cur = mv[sby * (dd.getNHMVBS()+1) + sbx];
788 int mv_x = cur.mv[0] >> OD_LOG_MVBSIZE_MIN;
789 int mv_y = cur.mv[1] >> OD_LOG_MVBSIZE_MIN;
790 int xx = x + mv_x;
791 int yy = y + mv_y;
792 if(xx < 0) {
793 mv_x += xx;
negge 2016/06/24 15:02:59 Tab on this line.
luc.trudeau 2016/07/01 19:45:03 Done.
794 }
795 else if(xx > getDecodeWidth()) {
796 mv_x += getDecodeWidth() - xx;
797 }
798 if(yy < 0) {
799 mv_y += yy;
800 }
801 else if(yy > getDecodeHeight()) {
802 mv_y += getDecodeHeight() - yy;
803 }
804 if(cur.valid) {
805 od_img_draw_line(mv_x, mv_y, mv_pel+(y * dd.getFrameWidth() + x),
806 dd.getFrameWidth());
807 }
808 }
809 }
810 }
736 } 811 }
737 812
738 for (int j = 0; j < getDecodeHeight(); j++) { 813 for (int j = 0; j < getDecodeHeight(); j++) {
739 unsigned char *y = y_row; 814 unsigned char *y = y_row;
740 unsigned char *cb = cb_row; 815 unsigned char *cb = cb_row;
741 unsigned char *cr = cr_row; 816 unsigned char *cr = cr_row;
742 unsigned char *p = p_row; 817 unsigned char *p = p_row;
743 for (int i = 0; i < getDecodeWidth(); i++) { 818 for (int i = 0; i < getDecodeWidth(); i++) {
744 ogg_int64_t yval; 819 ogg_int64_t yval;
745 ogg_int64_t cbval; 820 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); 905 unsigned char d = OD_BLOCK_SIZE4x4(bsize, bstride, i >> 2, j >> 2);
831 int mask = (1 << (d + OD_LOG_BSIZE0)) - 1; 906 int mask = (1 << (d + OD_LOG_BSIZE0)) - 1;
832 if (!(i & mask) || !(j & mask)) { 907 if (!(i & mask) || !(j & mask)) {
833 yval = block_edge_luma(yval); 908 yval = block_edge_luma(yval);
834 cbval = (cbval + 128) >> 1; 909 cbval = (cbval + 128) >> 1;
835 crval = (crval + 128) >> 1; 910 crval = (crval + 128) >> 1;
836 pmask = OD_ALL_MASK; 911 pmask = OD_ALL_MASK;
837 } 912 }
838 } 913 }
839 if (show_motion) { 914 if (show_motion) {
840 int mask = ~(OD_MVBSIZE_MIN - 1); 915 if (mv_mask[j * dd.getFrameWidth() + i] == 1) {
841 int b = OD_LOG_MVBSIZE_MIN; 916 cbval = 0;
842 while (i == (i & mask) || j == (j & mask)) { 917 crval = 255;
843 mask <<= 1; 918 yval = 0;
844 int mid_step = 1 << b++; 919 } else {
845 int row = ((i & mask) + mid_step) >> OD_LOG_MVBSIZE_MIN; 920 int mask = ~(OD_MVBSIZE_MIN - 1);
846 int col = ((j & mask) + mid_step) >> OD_LOG_MVBSIZE_MIN; 921 int b = OD_LOG_MVBSIZE_MIN;
847 int index = col * (dd.getNHMVBS() + 1) + row; 922 while (i == (i & mask) || j == (j & mask)) {
848 if (mv[index].valid) { 923 mask <<= 1;
849 yval = block_edge_luma(yval); 924 int mid_step = 1 << b++;
850 cbval = 255; 925 int row = ((i & mask) + mid_step) >> OD_LOG_MVBSIZE_MIN;
851 break; 926 int col = ((j & mask) + mid_step) >> OD_LOG_MVBSIZE_MIN;
852 } 927 int index = col * (dd.getNHMVBS() + 1) + row;
853 if (b > OD_LOG_MVBSIZE_MAX) { 928 if (mv[index].valid) {
854 break; 929 yval = block_edge_luma(yval);
930 cbval = 255;
931 break;
932 }
933 if (b > OD_LOG_MVBSIZE_MAX) {
934 break;
935 }
855 } 936 }
856 } 937 }
857 } 938 }
858 if (i == dd.getWidth() || j == dd.getHeight()) { 939 if (i == dd.getWidth() || j == dd.getHeight()) {
859 /* Display a checkerboard pattern at the padding edge */ 940 /* Display a checkerboard pattern at the padding edge */
860 yval = 255 * ((i + j) & 1); 941 yval = 255 * ((i + j) & 1);
861 pmask = OD_ALL_MASK; 942 pmask = OD_ALL_MASK;
862 } 943 }
863 if (pmask & OD_LUMA_MASK) { 944 if (pmask & OD_LUMA_MASK) {
864 yval -= 16; 945 yval -= 16;
(...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after
1547 bool TestApp::OnCmdLineParsed(wxCmdLineParser &parser) { 1628 bool TestApp::OnCmdLineParsed(wxCmdLineParser &parser) {
1548 frame = new TestFrame(parser.Found(_(OD_BIT_ACCOUNTING_SWITCH))); 1629 frame = new TestFrame(parser.Found(_(OD_BIT_ACCOUNTING_SWITCH)));
1549 frame->Show(); 1630 frame->Show();
1550 if (parser.GetParamCount() > 0) { 1631 if (parser.GetParamCount() > 0) {
1551 return frame->open(parser.GetParam(0)); 1632 return frame->open(parser.GetParam(0));
1552 } 1633 }
1553 return true; 1634 return true;
1554 } 1635 }
1555 1636
1556 IMPLEMENT_APP(TestApp) 1637 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