Skip to content
Snippets Groups Projects
Select Git revision
  • 3ebbb919eac479825c19bcc62c91c078bc27c5f2
  • main default protected
  • 39-retour-utilisateur-sur-le-compteur
3 results

Attack.java

Blame
  • WinWindow.cpp 4.49 KiB
    /***************************************************************************
     *  MacWindow.cpp
     *  Part of 
     *  2016-  Florent Berthaut
     *  hitmuri.net
     ****************************************************************************/
    /*
     *  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 2 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, write to the Free Software
     *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
     */
    
    #include "MacWindow.hpp"
    #include <iostream>
    
    using namespace std;
    
    MacWindow::MacWindow(OvWindowsManager* man, CGWindowID id): OvWindow(man) { 
        CGRect rect = CGRectMake(0, 0, 100, 100);
        m_idCArray[0] = id;
        m_idArray = CFArrayCreate(NULL, (const void **) m_idCArray, 1, NULL);
        CFArrayRef descArray = CGWindowListCreateDescriptionFromArray(m_idArray);
        if(CFArrayGetCount(descArray)>0) {
            CFDictionaryRef description = 
                (CFDictionaryRef) CFArrayGetValueAtIndex(descArray, 0);
            if (CFDictionaryContainsKey(description, kCGWindowBounds)) {
                CFDictionaryRef bounds = 
                        (CFDictionaryRef) CFDictionaryGetValue(description, 
                                                               kCGWindowBounds);
                if (bounds) {
                    CGRectMakeWithDictionaryRepresentation(bounds, &rect);
                }
            }
        }
        CFRelease(descArray);
    
        m_posX = rect.origin.x; 
        m_posY = rect.origin.y; 
        m_width = rect.size.width;
        m_height = rect.size.height;
        m_offsetX = m_posX;
        m_offsetY = m_posY;
        m_pixPerRow = m_width;
        m_isBGR=true;
        m_needsOffset=false;
        m_pixPerRow=m_width;
    }
    
    MacWindow::~MacWindow() {
        CFRelease(m_idArray);
    }
    
    int MacWindow::computeNbPixPerRow(const int& srcW, const int& srcH) {
        CGRect rect = CGRectMake(m_posX, m_posY, srcW, srcH);
        CGImageRef img = CGWindowListCreateImageFromArray(rect,
                                                 m_idArray,
                                                 kCGWindowImageBoundsIgnoreFraming);
        int nb = CGImageGetBytesPerRow(img)/4;
        CFRelease(img);
        return nb;
    }
    
    void MacWindow::getPixels(const int& srcX, const int& srcY, 
                              const int& srcW, const int& srcH, 
                              const vector<int>& srcIndices,
                              const vector<vector<int> >& srcCoords,
                              const vector<int>& destIndices,
                              const uchar& alpha,
                              const ZoneWidget::ZONE_COLOR& color,
                              uchar* destImg) {
        CGRect rect = CGRectMake(m_posX+srcX, m_posY+srcY, srcW, srcH);
        CGImageRef img = CGWindowListCreateImageFromArray(rect,
                                                 m_idArray,
                                                 kCGWindowImageBoundsIgnoreFraming);
        if(img!=NULL) {
            CFDataRef data = CGDataProviderCopyData(CGImageGetDataProvider(img));
            uchar* buf = (uchar*)CFDataGetBytePtr(data);
            vector<int>::const_iterator itId = srcIndices.begin();
            vector<vector<int> >::const_iterator itCo = srcCoords.begin();
            vector<int>::const_iterator itDe = destIndices.begin();
            for(; itCo!=srcCoords.end(); ++itCo) {
                if((*itCo)[0]>=0) { 
                    //copy rgb
                    for(int c=0; c<3; ++c) {
                        destImg[(*itDe)] = (color==ZoneWidget::NORMAL)
                                                ?buf[(*itId)]
                                                :255-buf[(*itId)];
                        ++itId;
                        ++itDe;
                    }
                    //copy alpha
                    destImg[(*itDe)] = alpha;
                    ++itId;
                    ++itDe;
                }
                else { //black
                    for(int c=0; c<4; ++c) {
                        destImg[(*itDe)] = 0;
                        ++itId;
                        ++itDe;
                    }
                }
            }
            //release CG stuff
            CFRelease(data);
            CFRelease(img);
        }
        else {
            cout<<"Error getting image of window "<<m_name<<endl;
        }
    }