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

Side by Side Diff: examples/analyzer.cc

Issue 1050: Add image panning to the analyzer.
Patch Set: Rebase and fix default size. Created 4 years, 3 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 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 290
291 bool DaalaDecoder::setDeringFlagsBuffer(unsigned char *buf, size_t buf_sz) { 291 bool DaalaDecoder::setDeringFlagsBuffer(unsigned char *buf, size_t buf_sz) {
292 if (dctx == NULL) { 292 if (dctx == NULL) {
293 return false; 293 return false;
294 } 294 }
295 return daala_decode_ctl(dctx, OD_DECCTL_SET_DERING_BUFFER, buf, buf_sz) == 295 return daala_decode_ctl(dctx, OD_DECCTL_SET_DERING_BUFFER, buf, buf_sz) ==
296 OD_SUCCESS; 296 OD_SUCCESS;
297 } 297 }
298 298
299 #define MIN_ZOOM (1) 299 #define MIN_ZOOM (1)
300 #define MAX_ZOOM (4) 300 #define MAX_ZOOM (8)
301 301
302 enum { 302 enum {
303 OD_LUMA_MASK = 1 << 0, 303 OD_LUMA_MASK = 1 << 0,
304 OD_CB_MASK = 1 << 1, 304 OD_CB_MASK = 1 << 1,
305 OD_CR_MASK = 1 << 2, 305 OD_CR_MASK = 1 << 2,
306 OD_ALL_MASK = OD_LUMA_MASK | OD_CB_MASK | OD_CR_MASK 306 OD_ALL_MASK = OD_LUMA_MASK | OD_CB_MASK | OD_CR_MASK
307 }; 307 };
308 308
309 class TestPanel : public wxPanel { 309 class TestPanel : public wxScrolledWindow {
310 DECLARE_EVENT_TABLE() 310 DECLARE_EVENT_TABLE()
311 private: 311 private:
312 DaalaDecoder dd; 312 DaalaDecoder dd;
313 313
314 int zoom; 314 int zoom;
315 unsigned char *pixels; 315 unsigned char *pixels;
316 316
317 unsigned char *bsize; 317 unsigned char *bsize;
318 unsigned int bsize_len; 318 unsigned int bsize_len;
319 int bstride; 319 int bstride;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 bool open(const wxString &path); 356 bool open(const wxString &path);
357 void close(); 357 void close();
358 void render(); 358 void render();
359 bool nextFrame(); 359 bool nextFrame();
360 void refresh(); 360 void refresh();
361 bool gotoFrame(); 361 bool gotoFrame();
362 void restart(); 362 void restart();
363 363
364 int getZoom() const; 364 int getZoom() const;
365 bool setZoom(int zoom); 365 bool setZoom(int zoom);
366 int scrollUnit() const;
366 367
367 void setShowBlocks(bool show_blocks); 368 void setShowBlocks(bool show_blocks);
368 void setShowSkip(bool show_skip); 369 void setShowSkip(bool show_skip);
369 void setShowNoRef(bool show_noref); 370 void setShowNoRef(bool show_noref);
370 void setShowPadding(bool show_padding); 371 void setShowPadding(bool show_padding);
371 void setShowBits(bool show_bits); 372 void setShowBits(bool show_bits);
372 void setShowDering(bool show_dering); 373 void setShowDering(bool show_dering);
373 void setShowPlane(bool show_plane, int mask); 374 void setShowPlane(bool show_plane, int mask);
374 375
375 bool hasPadding(); 376 bool hasPadding();
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 EVT_MENU(wxID_SHOW_DERING, TestFrame::onFilter) 446 EVT_MENU(wxID_SHOW_DERING, TestFrame::onFilter)
446 EVT_MENU(wxID_SHOW_Y, TestFrame::onYChange) 447 EVT_MENU(wxID_SHOW_Y, TestFrame::onYChange)
447 EVT_MENU(wxID_SHOW_U, TestFrame::onUChange) 448 EVT_MENU(wxID_SHOW_U, TestFrame::onUChange)
448 EVT_MENU(wxID_SHOW_V, TestFrame::onVChange) 449 EVT_MENU(wxID_SHOW_V, TestFrame::onVChange)
449 EVT_MENU(wxID_NEXT_FRAME, TestFrame::onNextFrame) 450 EVT_MENU(wxID_NEXT_FRAME, TestFrame::onNextFrame)
450 EVT_MENU(wxID_GOTO_FRAME, TestFrame::onGotoFrame) 451 EVT_MENU(wxID_GOTO_FRAME, TestFrame::onGotoFrame)
451 EVT_MENU(wxID_RESTART, TestFrame::onRestart) 452 EVT_MENU(wxID_RESTART, TestFrame::onRestart)
452 EVT_MENU(wxID_ABOUT, TestFrame::onAbout) 453 EVT_MENU(wxID_ABOUT, TestFrame::onAbout)
453 END_EVENT_TABLE() 454 END_EVENT_TABLE()
454 455
455 TestPanel::TestPanel(wxWindow *parent, const wxString &path) : wxPanel(parent), 456 TestPanel::TestPanel(wxWindow *parent, const wxString &path) : wxScrolledWindow( parent),
456 pixels(NULL), zoom(0), bsize(NULL), bsize_len(0), show_blocks(false), 457 pixels(NULL), zoom(0), bsize(NULL), bsize_len(0), show_blocks(false),
457 flags(NULL), flags_len(0), show_skip(false), show_noref(false), 458 flags(NULL), flags_len(0), show_skip(false), show_noref(false),
458 show_padding(false), show_dering(false), acct(NULL), show_bits(false), 459 show_padding(false), show_dering(false), acct(NULL), show_bits(false),
459 bpp_q3(NULL), dering(NULL), dering_len(0), plane_mask(OD_ALL_MASK), 460 bpp_q3(NULL), dering(NULL), dering_len(0), plane_mask(OD_ALL_MASK),
460 path(path) { 461 path(path) {
461 } 462 }
462 463
463 TestPanel::~TestPanel() { 464 TestPanel::~TestPanel() {
464 close(); 465 close();
465 } 466 }
466 467
467 bool TestPanel::open(const wxString &path) { 468 bool TestPanel::open(const wxString &path) {
468 if (!dd.open(path)) { 469 if (!dd.open(path)) {
469 return false; 470 return false;
470 } 471 }
472 SetSize(dd.getWidth(), dd.getHeight());
471 if (!setZoom(MIN_ZOOM)) { 473 if (!setZoom(MIN_ZOOM)) {
472 return false; 474 return false;
473 } 475 }
474 int nhsb = dd.getFrameWidth() >> OD_LOG_BSIZE0 + OD_NBSIZES - 1; 476 int nhsb = dd.getFrameWidth() >> OD_LOG_BSIZE0 + OD_NBSIZES - 1;
475 int nvsb = dd.getFrameHeight() >> OD_LOG_BSIZE0 + OD_NBSIZES - 1; 477 int nvsb = dd.getFrameHeight() >> OD_LOG_BSIZE0 + OD_NBSIZES - 1;
476 bsize_len = sizeof(*bsize)*nhsb*4*nvsb*4; 478 bsize_len = sizeof(*bsize)*nhsb*4*nvsb*4;
477 bsize = (unsigned char *)malloc(bsize_len); 479 bsize = (unsigned char *)malloc(bsize_len);
478 if (bsize == NULL) { 480 if (bsize == NULL) {
479 bsize_len = 0; 481 bsize_len = 0;
480 close(); 482 close();
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 int dc = -((j & 1) | (1 - ydec)); 741 int dc = -((j & 1) | (1 - ydec));
740 y_row += y_stride; 742 y_row += y_stride;
741 cb_row += dc & cb_stride; 743 cb_row += dc & cb_stride;
742 cr_row += dc & cr_stride; 744 cr_row += dc & cr_stride;
743 p_row += zoom*p_stride; 745 p_row += zoom*p_stride;
744 } 746 }
745 } 747 }
746 748
747 int TestPanel::getZoom() const { 749 int TestPanel::getZoom() const {
748 return zoom; 750 return zoom;
751 }
752
753 int TestPanel::scrollUnit() const {
754 return zoom*8;
749 } 755 }
750 756
751 bool TestPanel::updateDisplaySize() { 757 bool TestPanel::updateDisplaySize() {
752 unsigned char *p = 758 unsigned char *p =
753 (unsigned char *)malloc(sizeof(*p)*3*getDisplayWidth()*getDisplayHeight()); 759 (unsigned char *)malloc(sizeof(*p)*3*getDisplayWidth()*getDisplayHeight());
754 if (p == NULL) { 760 if (p == NULL) {
755 return false; 761 return false;
756 } 762 }
757 free(pixels); 763 free(pixels);
758 pixels = p; 764 pixels = p;
759 SetSize(getDisplayWidth(), getDisplayHeight()); 765 int sx, sy;
766 GetViewStart(&sx, &sy);
767 SetScrollbars(scrollUnit(), scrollUnit(),
768 getDisplayWidth()/scrollUnit(), getDisplayHeight()/scrollUnit(), sx, sy);
760 return true; 769 return true;
761 } 770 }
762 771
763 bool TestPanel::setZoom(int z) { 772 bool TestPanel::setZoom(int z) {
764 if (z <= MAX_ZOOM && z >= MIN_ZOOM && zoom != z) { 773 if (z <= MAX_ZOOM && z >= MIN_ZOOM && zoom != z) {
765 int old_zoom = zoom; 774 int old_zoom = zoom;
766 zoom = z; 775 zoom = z;
767 if (!updateDisplaySize()) { 776 if (!updateDisplaySize()) {
768 zoom = old_zoom; 777 zoom = old_zoom;
769 return false; 778 return false;
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
966 dd.getAccountingStruct(&acct); 975 dd.getAccountingStruct(&acct);
967 dd.setDeringFlagsBuffer(dering, dering_len); 976 dd.setDeringFlagsBuffer(dering, dering_len);
968 nextFrame(); 977 nextFrame();
969 } 978 }
970 979
971 void TestPanel::onMouseMotion(wxMouseEvent& event) { 980 void TestPanel::onMouseMotion(wxMouseEvent& event) {
972 const wxPoint pt = wxGetMousePosition(); 981 const wxPoint pt = wxGetMousePosition();
973 int mouse_x = pt.x - this->GetScreenPosition().x; 982 int mouse_x = pt.x - this->GetScreenPosition().x;
974 int mouse_y = pt.y - this->GetScreenPosition().y; 983 int mouse_y = pt.y - this->GetScreenPosition().y;
975 TestFrame *parent = static_cast<TestFrame*>(GetParent()); 984 TestFrame *parent = static_cast<TestFrame*>(GetParent());
976 int row = mouse_y/zoom; 985 int sx, sy;
977 int col = mouse_x/zoom; 986 GetViewStart(&sx, &sy);
987 /* Offset row / col by scroll position. */
988 int col = (mouse_x + sx*scrollUnit())/zoom;
989 int row = (mouse_y + sy*scrollUnit())/zoom;
978 if (row >= 0 && col >= 0 && row < getDecodeHeight() 990 if (row >= 0 && col >= 0 && row < getDecodeHeight()
979 && col < getDecodeWidth()) { 991 && col < getDecodeWidth()) {
980 const od_img_plane *planes = dd.img.planes; 992 const od_img_plane *planes = dd.img.planes;
981 /* Assume both chroma planes are decimated the same */ 993 /* Assume both chroma planes are decimated the same */
982 int xdec = planes[1].xdec; 994 int xdec = planes[1].xdec;
983 int ydec = planes[1].ydec; 995 int ydec = planes[1].ydec;
984 int cb_stride = planes[1].ystride; 996 int cb_stride = planes[1].ystride;
985 int cr_stride = planes[2].ystride; 997 int cr_stride = planes[2].ystride;
986 ogg_int64_t y = planes[0].data[planes[0].ystride*row + col]; 998 ogg_int64_t y = planes[0].data[planes[0].ystride*row + col];
987 ogg_int64_t cb = planes[1].data[cb_stride*(row >> ydec) + (col >> xdec)]; 999 ogg_int64_t cb = planes[1].data[cb_stride*(row >> ydec) + (col >> xdec)];
988 ogg_int64_t cr = planes[2].data[cr_stride*(row >> ydec) + (col >> xdec)]; 1000 ogg_int64_t cr = planes[2].data[cr_stride*(row >> ydec) + (col >> xdec)];
989 parent->SetStatusText(wxString::Format(wxT("Y:%lld,U:%lld,V:%lld"), 1001 parent->SetStatusText(wxString::Format(wxT("Y:%lld,U:%lld,V:%lld"),
990 y, cb, cr), 1); 1002 y, cb, cr), 1);
991 } else { 1003 } else {
992 parent->SetStatusText(wxString::Format(wxT("")), 1); 1004 parent->SetStatusText(wxString::Format(wxT("")), 1);
993 } 1005 }
994 parent->SetStatusText(wxString::Format(wxT("X:%d,Y:%d"), 1006 parent->SetStatusText(wxString::Format(wxT("X:%d,Y:%d"),
995 col, row), 2); 1007 col, row), 2);
996 } 1008 }
997 1009
998 void TestPanel::onMouseLeaveWindow(wxMouseEvent& event) { 1010 void TestPanel::onMouseLeaveWindow(wxMouseEvent& event) {
999 TestFrame *parent = static_cast<TestFrame*>(GetParent()); 1011 TestFrame *parent = static_cast<TestFrame*>(GetParent());
1000 parent->SetStatusText(wxString::Format(wxT("")), 1); 1012 parent->SetStatusText(wxString::Format(wxT("")), 1);
1001 } 1013 }
1002 1014
1003 void TestPanel::onPaint(wxPaintEvent &) { 1015 void TestPanel::onPaint(wxPaintEvent &) {
1016 int sx, sy;
1017 GetViewStart(&sx, &sy);
1004 wxBitmap bmp(wxImage(getDisplayWidth(), getDisplayHeight(), pixels, true)); 1018 wxBitmap bmp(wxImage(getDisplayWidth(), getDisplayHeight(), pixels, true));
1005 wxBufferedPaintDC dc(this, bmp); 1019 wxBufferedPaintDC dc(this);
1020 dc.SetBackgroundMode(wxSOLID);
1021 dc.SetBackground(wxColor(0,0,0));
1022 dc.Clear();
1023 dc.DrawBitmap(bmp, -sx*scrollUnit(), -sy*scrollUnit());
1006 } 1024 }
1007 1025
1008 void TestPanel::onIdle(wxIdleEvent &) { 1026 void TestPanel::onIdle(wxIdleEvent &) {
1009 nextFrame(); 1027 nextFrame();
1010 Refresh(false); 1028 Refresh(false);
1011 /*wxMilliSleep(input.video_fps_n*1000/input.video_fps_n);*/ 1029 /*wxMilliSleep(input.video_fps_n*1000/input.video_fps_n);*/
1012 } 1030 }
1013 1031
1014 TestFrame::TestFrame() : wxFrame(NULL, wxID_ANY, _T("Daala Stream Analyzer"), 1032 TestFrame::TestFrame() : wxFrame(NULL, wxID_ANY, _T("Daala Stream Analyzer"),
1015 wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE), panel(NULL) { 1033 wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE), panel(NULL) {
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
1197 bool TestApp::OnInit() { 1215 bool TestApp::OnInit() {
1198 frame = new TestFrame(); 1216 frame = new TestFrame();
1199 frame->Show(); 1217 frame->Show();
1200 if (argc >= 2) { 1218 if (argc >= 2) {
1201 return frame->open(wxString(argv[1])); 1219 return frame->open(wxString(argv[1]));
1202 } 1220 }
1203 return true; 1221 return true;
1204 } 1222 }
1205 1223
1206 IMPLEMENT_APP(TestApp) 1224 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