Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
K

Kiran Satish

@Kiran Satish
About
Posts
255
Topics
88
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Using nlohmann JSON to insert more data
    K Kiran Satish

    I have a json file genrated in python from another system that needs to be read/updated in another MFC application. I can successfully read the existing data from the json file using nlohmann json add-in. For example, the file consists of two data fields with one field having any array of two subfields as below

    {
    "city_data":[
    {
    "t":"m",
    "l":[12.0,10.3,0.0,1.0]
    },
    {
    "t":"l",
    "l":[10.1,20.37,0.0,1.0]
    },
    {
    "t":"l",
    "l":[47.82,4.63,0.0,1.0]
    },
    {
    "t":"m",
    "l":[67.66,43.33,0.0,1.0]
    }
    ],
    "map_data":"JZDKZTCaTyWQymUwmk8lkMplMJpPJZDKZTCaTyWQymUwmk/8/+n8AVAZ1WCxk8rYAAAAASUVORK5CYII="
    }

    The "map_data" is basically base64 encoded png image. I would like to add more entries into "city_data" field as {"t":"x","l":[0.0,0.0,0.0,0.0]} while the "map_data" stays the same. Then I can write the json object into a new file with updates. To read the json file,

    std::ifstream f(file);
    json data = json::parse(f);

    To retreive "city_data" and then its type and location

    json& cityInfo = data["city_data"];
    for (unsigned int i = 0; i < cityInfo.size(); i++)
    {
    json& cityType = cityInfo[i];
    std::string ctyTyp = cityType["t"];
    json& cityLoc = cityType["l"];
    std::float_t x = cityLoc[0];
    std::float_t y = cityLoc[1];
    // do something with the retrieved values
    }
    //To retreive map data
    ofstream outfile;
    outfile.open(m_strFolderPath + m_strFileName + ".png", ofstream::binary);
    std::string mapFrame = data["map_data"];
    string temp = base64_decode(mapFrame );
    outfile.write(temp.c_str(), temp.size());
    outfile.close();
    f.close();

    Any suggestions on how to insert new city_data fields into the nlohmann JSON object? or a way to create a new json file like in above format? thanks

    PKNT

    C / C++ / MFC tutorial c++ python data-structures json

  • Application crashes on calling OnPaint() function!?
    K Kiran Satish

    Yes, that did the trick. I do that in couple of other child dialogs, but was not using it in this dialog. Well, looks like you overlook something that's fundamental. thanks David

    PKNT

    C / C++ / MFC c++ visual-studio question

  • Application crashes on calling OnPaint() function!?
    K Kiran Satish

    Thanks for your reply Richard. Could you suggest a better way to refresh my child dialog edit control where I draw these lines?

    PKNT

    C / C++ / MFC c++ visual-studio question

  • Application crashes on calling OnPaint() function!?
    K Kiran Satish

    I have a dialog based MFC application that I am rewriting in VS2010 from its original VC++ 6.0 source. Everything works fine in VC++ 6.0 The main dialog contains many child dialogs (not pop-ups) in which one child dialog is used to draw a plot based on the values sent from main dialog. The main dialog calls a function (Draw_Points) within the child dialog and the child dialog draws it and it does as long as the plot hits the edge and then it calls OnPaint message to refresh the dialog so that it can start afresh from left.

    void CPlotDlg::Draw_Points(double value1, double value2)
    {
    if(m_LastPoint1.x < (m_time_rect.right-2))
    {
    // Store the data for later retrieval
    m_CurrentPoint1.x = m_LastPoint1.x + 1;
    m_CurrentPoint2.x = m_LastPoint2.x + 1;
    // Do some calculations
    m_Data1[m_DataCounter] = value1;
    m_Data2[m_DataCounter++] = value2;
    CWnd *Ctrl = GetDlgItem(IDE_PLOTS);
    CDC *cdc = Ctrl->GetDC();
    HGDIOBJ original = NULL;
    original = cdc->SelectObject(GetStockObject(DC_PEN));
    cdc->SelectObject(pen1);
    cdc->MoveTo(m_LastPoint1);
    cdc->LineTo(m_CurrentPoint1);
    cdc->SelectObject(pen2);
    cdc->MoveTo(m_LastPoint2);
    cdc->LineTo(m_CurrentPoint2);
    cdc->SelectObject(original);
    Ctrl->ReleaseDC(cdc);
    m_LastPoint1 = m_CurrentPoint1;
    m_LastPoint2 = m_CurrentPoint2;
    }
    else
    {
    OnPaint();
    Reset_PlotData();
    }
    }

    void CPlotDlg::OnPaint()
    {
    CPaintDC dc(this); // device context for painting
    // TODO: Add your message handler code here
    if(m_BUpdate)
    {
    CDialogEx::OnPaint();
    CWnd *Ctrl = GetDlgItem(IDE_PLOTS);
    Ctrl->InvalidateRect(NULL,true);
    Ctrl->UpdateWindow();
    }
    // Do not call CDialogEx::OnPaint() for painting messages
    }

    It crashes when the Draw_points function calls OnPaint function in its else section, and when OnPaint() function executes CPaintDC dc(this); Any suggestions? thanks

    PKNT

    C / C++ / MFC c++ visual-studio question

  • How to effectively wait for a thread to complete in a dialog class?
    K Kiran Satish

    I have a MFC dialog application with multiple child dialogs inside a main dialog and then a few normal classes controlling a camera and other hardware. I have a thread in camera class that is always active and waits for couple of events to do further processing within the thread. One of the events is a manual event and the other one auto event. The manual event keeps running as soon as the application is launched. But when the user pressed a button on one of the child dialogs, I would like to Set the auto event, for this within the button even handler of the child dialog, I call ResetEvent() on the camera thread manual event, wait for sometime using ::WaitForSingleObject command and then call SetEvent() on the camera thread auto event. But not matter how much time I wait in the even thandler, the SetEvent executes only when I am out of the button's event handler. Ideally I would like to wait for another event (using WaitForSingleObject) that is Set by the camera thread after its done with the autoevent process.

    // All events are global handles
    //Camera class
    //thread function
    {
    event[1] = manual event;
    event[2] = auto event;
    event[3] = auto event done event;

    switch(Waitformultipleobject(event[3]))
    {
    case manual event:
    // keep doing some process until the manual event is reset
    break;
    case auto event:
    // perform the process
    Set (auto event done event);
    break;}
    }
    }

    //Child dialog class
    button event handler
    {
    Reset(manual event)
    Set(auto event)
    WaitForSingleObject(auto event done event, ms);
    }

    Any tips/suggestions on how to achieve this?

    PKNT

    C / C++ / MFC c++ hardware tutorial question

  • How to dynamically update gdiplus bitmap object in MFC?
    K Kiran Satish

    Thanks Chris, that solved my memory leak issue.

    PKNT

    C / C++ / MFC graphics question c++ performance tutorial

  • How to dynamically update gdiplus bitmap object in MFC?
    K Kiran Satish

    I have a MFC dialog application in which I have a gdiplus object that I use to draw images in real-time. Works fine if I don't want to do any changes to this object or its associated variables. But when I try to update them at runtime, it starts to increase my memory consumption. So, my question is, how to safely update a gdiplus object at runtime. Here is my code

    // Variables declaration in header file
    LONG Width;
    LONG Height;
    LONG bpp;
    LONG Stride;
    BITMAPINFO* bmi;
    BYTE* pDIBSectionBits;
    HBITMAP hbm;
    Graphics* imagedisp;
    Bitmap* offscreenBitmap;
    CWnd* Display;
    CStatic m_ImageDisp;

    // Source file
    OnInitDialog()
    {
    ......
    Width = 512;
    Height = 512;
    bpp = 8;
    Stride = ((Width * bpp + 31L) & (~31L)) / 8L;
    ......
    }

    InitParams()
    {
    SetImageColor();

    Display = GetDlgItem(IDH_IMAGE);
    this->GetClientRect(&m_disp_rect);
    Display->GetClientRect(&m_disp_rect);
    m_ImageDisp.GetClientRect(&m_disp_rect);
    imagedisp = new Graphics(m_ImageDisp.GetDC()->GetSafeHdc());
    }

    SetImageColor()
    {
    m_BUpdate = false;
    if (bmi != NULL)
    {
    delete bmi;
    bmi = NULL;
    }
    bmi = (BITMAPINFO *)new BYTE[sizeof(BITMAPINFO) + UCHAR_MAX * sizeof(RGBQUAD)];
    bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    bmi->bmiHeader.biWidth = Width;
    bmi->bmiHeader.biHeight = Height;
    bmi->bmiHeader.biPlanes = 1;
    bmi->bmiHeader.biBitCount = (WORD)bpp;
    bmi->bmiHeader.biCompression = BI_RGB;
    bmi->bmiHeader.biSizeImage = 0;//Stride * abs(Height);
    bmi->bmiHeader.biXPelsPerMeter = 0;
    bmi->bmiHeader.biYPelsPerMeter = 0;
    bmi->bmiHeader.biClrUsed = 0;
    bmi->bmiHeader.biClrImportant = 0;
    memcpy(bmi->bmiColors, USECOLORMAP?summercmap:greyscale, 256*sizeof(RGBQUAD));
    hbm = ::CreateDIBSection(NULL, bmi, DIB_RGB_COLORS, (void**)&pDIBSectionBits, NULL, 0);
    if (offscreenBitmap != NULL)
    {
    delete offscreenBitmap;
    offscreenBitmap = NULL;
    }
    offscreenBitmap = new Bitmap(bmi, pDIBSectionBits);
    m_BUpdate = true;
    }

    OnPaint()
    {
    CPaintDC dc(this); // device context for painting
    // TODO: Add your message handler code here
    if (m_BUpdate)
    {
    BYTE *pCurRowPixel = (BYTE *)(pDIBSectionBits);
    memcpy(pCurRowPixel, ImgBuff, Width*Height);

    imagedisp->DrawImage(offscreenBitmap, 0, 0, Width, Height);
    

    }
    }

    So whenever the user clicks a button to change between grayscale and color pallette, SetImageColor() is called. When I monitor the memory usage while clicking that button, I see its changing the way I ex

    C / C++ / MFC graphics question c++ performance tutorial

  • Calling GDI+ DrawImage function throws _BLOCK_TYPE_IS_VALID error
    K Kiran Satish

    I am trying to use GDI+ within my MFC dialog based application with multiple child dialogs. On one of the child dialogs, I am trying to draw an image from an array of 8 bit BYTE pixel data. Here is how my flow process is for this- Variables declared in my child dialog's header file.

    LONG DIBSecWidth;
    LONG DIBSecHeight;
    LONG BitsPerPixel;
    LONG Stride;
    BITMAPINFO* bmi;
    BYTE* pDIBSectionBits;
    HBITMAP hbm;
    Graphics* imagedisp;
    Bitmap* offscreenBitmap;
    RECT m_imagedisp_rect;
    BOOL m_BUpdate;

    Then in my OnInitDialog() function, I do the following

    DIBSecWidth = 512;
    DIBSecHeight = 512;
    BitsPerPixel = 8;

    Stride = ((DIBSecWidth* BitsPerPixel + 31L) & (~31L)) / 8L;

    bmi = (BITMAPINFO *)new BYTE[sizeof(BITMAPINFO) + UCHAR_MAX * sizeof(RGBQUAD)];
    bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    bmi->bmiHeader.biWidth = DIBSecWidth;
    bmi->bmiHeader.biHeight = DIBSecHeight;
    bmi->bmiHeader.biPlanes = 1;
    bmi->bmiHeader.biBitCount = (WORD)BitsPerPixel;
    bmi->bmiHeader.biCompression = BI_RGB;
    bmi->bmiHeader.biSizeImage = 0;
    bmi->bmiHeader.biXPelsPerMeter = 0;
    bmi->bmiHeader.biYPelsPerMeter = 0;
    bmi->bmiHeader.biClrUsed = 0;
    bmi->bmiHeader.biClrImportant = 0;
    memcpy(bmi->bmiColors, summercmap, 256*sizeof(RGBQUAD)); //summercmap is a color table of 256 RGB (COLORREF) values

    hbm = ::CreateDIBSection(NULL, bmi, DIB_RGB_COLORS, (void**)&pDIBSectionBits, NULL, 0);

    offscreenBitmap = new Bitmap(bmi, pDIBSectionBits);
    ImageDisplay.GetClientRect(&m_imagedisp_rect);
    imagedisp = new Graphics(ImageDisplay.GetDC()->GetSafeHdc());
    m_BUpdate = true;

    and in OnPaint() message handler I have the following

    CPaintDC dc(this); // device context for painting
    // TODO: Add your message handler code here
    if (m_BUpdate)
    {
    BYTE *pCurRowPixel = (BYTE *)(pDIBSectionBits);
    memcpy(pCurRowPixel, m_pImgBuffPrc, DIBSecWidth*DIBSecHeight);
    imagedisp->DrawImage(offscreenBitmap, 0, 0, DIBSecWidth, DIBSecWidth);
    m_BUpdate = false;
    delete pCurRowPixel;
    }

    Whenever I run my application, it throws an error at imagedisplay->DrawImage function, if I comment it out it doesn't throw the error. I am sure there is something simple that I am missing here or the way I am trying to draw is not right, any ideas/suggestions? thanks

    PKNT

    C / C++ / MFC graphics c++ winforms data-structures help

  • RAMDisk slower than Spinning drive!?!
    K Kiran Satish

    Sorry if I am not clear, but I am using 32 bit OS, so you can access only about 3GB of RAM for OS. Since I already have 16GB of memory installed which is not being utilized, I made a 8GB RAMDisk using the unutilized RAM which I use for paging file.

    PKNT

    Hardware & Devices performance question

  • RAMDisk slower than Spinning drive!?!
    K Kiran Satish

    I have a pretty much brand new system with 16GB DDR4 memory on which I have Win 7 32bit OS. I made a RAMDisk (using Dataram RAMDisk) of 8GB on which I keep windows paging file. I ran DiskBench tool and ran file creation with the following settings Create Two files Block Size - 256KB Number of blocks - 30 The above values replicate the writing that I usually do on this PC most of the time. Here are the results- RAMDisk - ~9MB/s Spinning drive - ~97MB/s SSD - ~441MB/s I am confused about the RAMDisk performance as I expect it to be the faster among the three by far. Any ideas? thanks

    PKNT

    Hardware & Devices performance question

  • Dialog controls not showing up on a child dialog
    K Kiran Satish

    Its a MFC dialog based application. Main dialog is created when the application is created using "New Project" wizard and the child dialog is created by inserting a "Insert Dialog" in resource view and then adding dialog controls to it.

    PKNT

    C / C++ / MFC c++ question

  • Dialog controls not showing up on a child dialog
    K Kiran Satish

    I am rewriting an old application in VS2010 that was developed in vc++6.0. I am trying to keep the basic structure of the GUI the same which consists of a main Dialog in which I have multiple child dialogs. All the child dialogs except one are simple with no border, title bar or system menu. This works fine in VC++6.0, but on VS2010, none of the controls that I have in those child dialogs show up when I run the program. Am I missing something simple here that I am not aware of? thanks

    PKNT

    C / C++ / MFC c++ question

  • Efficient way of converting an 8bit array of grayscale pixel data into 24bpp bitmap for GDI+?
    K Kiran Satish

    Hello, I have access to array of pixel data (size:512x512x8bpp) from a framegrabber which I currently assign to a 8bpp bitmap which is assigned to a GDI+ graphics object later on. Now, I would like to convert my array of 8bpp pixel data into 24bpp (BGRA, but I have no use for Alpha channel) and assign it to my bitmap and then modify individual pixel data to different colors depending on other conditions. When I say efficient, I want it to be done in real-time without much delay. Any suggestions? thanks

    PKNT

    C / C++ / MFC graphics winforms data-structures question

  • Reading uncompressed AVI file frame by frame into raw memory buffer?
    K Kiran Satish

    I guess I found the problem. It was the way Matlab is writing the avi files. By default, for uncompressed gray scale avi files it uses 64 level color map and indicies data to it. Now the problem is resolved.

    PKNT

    C / C++ / MFC c++ graphics performance question

  • Reading uncompressed AVI file frame by frame into raw memory buffer?
    K Kiran Satish

    For the file I attached in my first post, AVIFileInfo is returning the following data-

    avi_info {dwMaxBytesPerSec=0 dwFlags=0 dwCaps=3 ...} _AVIFILEINFOA
    dwMaxBytesPerSec 0 unsigned long
    dwFlags 0 unsigned long
    dwCaps 3 unsigned long
    dwStreams 1 unsigned long
    dwSuggestedBufferSize 2296 unsigned long
    dwWidth 26 unsigned long
    dwHeight 82 unsigned long
    dwScale 33333 unsigned long
    dwRate 1000000 unsigned long
    dwLength 30 unsigned long
    dwEditCount 0 unsigned long
    szFileType 0x0068e930 "AVI Default File Handler" char [64]

    When I write the frame to a text file after

    imgTemp = (BYTE*) AVIStreamGetFrame(pFrame, i);

    I see the correct header of 1064 bytes, but the image data doesn't have two black squares that I am supposed to see (for example from frame 3), but only one black square. Any ideas?

    PKNT

    C / C++ / MFC c++ graphics performance question

  • Reading uncompressed AVI file frame by frame into raw memory buffer?
    K Kiran Satish

    As the title states, I am having problems reading uncompressed avi files in MFC. It works fine on some files and reads different data on some avi files. Here is the code-

    pStream = g_GetAviStream(_T("D:\\Lab_Programs\\Matlab\\output.avi"), &frames, &fWidth, &fHeight, &iFirstFrame, &nPlanes, &fBufSize);
    fWidthOffs = fWidth%4;
    tempBuff = new BYTE[fWidth*fHeight*nPlanes];
    ZeroMemory(tempBuff, sizeof(BYTE)*fWidth*fHeight*nPlanes);

    pFrame = AVIStreamGetFrameOpen(pStream, NULL);

    bytBuff = new BYTE[fBufSize];//fWidth*fHeight*nPlanes];

    // read video stream to video buffer
    for (i = 0; i < frames; i ++)
    {
    // the returned is a packed DIB frame
    imgTemp = (BYTE*) AVIStreamGetFrame(pFrame, i);

    RtlMoveMemory(&bih.biSize, imgTemp, sizeof(BITMAPINFOHEADER));
    
    //now get the bitmap bits and get rid of the header information and retrieve the real image 
    RtlMoveMemory(bytBuff, imgTemp+sizeof(BITMAPINFOHEADER)+sizeof(RGBQUAD)\*256, bih.biSizeImage);
    ind = i\*fWidth\*fHeight\*nPlanes;
    for (j = 0; j < fHeight; j ++) {	
    	idxd1 = j\*nStimVideoNX;
    	idxs = (fHeight-1-j) \* (fWidth \* nPlanes + fWidthOffs);
    	for (k = 0; k < fWidth/\*nStimVideoNX\*/; k ++) {
    datain = bytBuff\[idxs + k\*nPlanes\];
    tempBuff\[idxd1+k\] = datain;
    						
    	}
    }
    

    }

    After doing this, I am writing tempBuff to a text file to view the contents in maltab and imshow it. If you play the video, you will see two black squares inside the frame, but when I check the text file for frame 3, I only see one black square. Here is the link[^] for a sample file that I am trying to read.

    PKNT

    C / C++ / MFC c++ graphics performance question

  • How to Convert 8bit image data into RGB based on color palette in Direct2D?
    K Kiran Satish

    Thanks for that suggestion Pallini, I guess I was not clear enough in my questions about how time critical this operation is. In my current application, I do similarly for not so time critical operation. I am looking for something that can do it automatically for me in Direct2D like in OpenCV using LUT & merge commands rather than going pixel by pixel.

    PKNT

    C / C++ / MFC question tutorial

  • How to Convert 8bit image data into RGB based on color palette in Direct2D?
    K Kiran Satish

    As the question states, how can I perform this in Direct2D? This needs to be done at real-time ~35fps. thanks

    PKNT

    C / C++ / MFC question tutorial

  • Suggestions on real-time video display with drawing
    K Kiran Satish

    Thanks for your reply Pallini, I need to interface external hardware in this application that come with C++ api than C#, so I am a bit stuckw ith C++/MFC combo I guess. Basically I get a 512x512 8bit pixel data from a framegrabber which I need to display in realtime and even draw some graphics on this image as needed (mostly squares, dots and lines) based on a colorbar.

    PKNT

    C / C++ / MFC c++ graphics asp-net help question

  • Suggestions on real-time video display with drawing
    K Kiran Satish

    I wrote a VC++ 6.0 application few years back that we still use. Its basically a Dialog based application with a parent dialog and few child dialogs. Most of the child dialogs have something to do with drawing upon requests from parent dialog. The application itself is multi- threaded. Most of the drawing on some dialogs is done using gdiplus and for a couple using just MFC drawing functions. The only issue is have with this is that it flickers a bit and that flicker rate is different on different systems. We are now thinking of redeveloping the application on VS2010 as support for XP which supports VC++ 6.0 has ended and its getting harder and harder to get PCs with XP on them or even to install XP. I am looking at some best options to choose from to implement in VS2010 for real-time drawing without flicker issues while the core structure will be the same for most part. We will be sticking with dialog based application again as we don't see any real use for SDI or MDI based application in our case. The core of the program is dependent on frames captured from a scientific camera and do some analysis on that frame and do the following Draw the captured frame on a dialog and draw some graphics (squares/lines) on the same frame based on analysis 4 more dialogs (in which one will have plots in it) will draw/refresh with new analysis data for that frame. I am looking at few options like OpenCV (which we already use in other applications) Direct2D (my application doesn't involve any 3D graphics) GdiPlus (not sure if this works better on VS2010) Any suggestions? thanks

    PKNT

    C / C++ / MFC c++ graphics asp-net help question
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups