Exemplo n.º 1
0
/*********************************************************************
*
*       GUI_ALLOC_AllocZero
*/
GUI_HMEM GUI_ALLOC_AllocZero(GUI_ALLOC_DATATYPE Size) {
  GUI_HMEM hMem;
  GUI_LOCK();
  GUI_DEBUG_LOG2("\nGUI_ALLOC_Alloc... requesting %d, %d avail", Size, GUI_ALLOC_GetMaxSize());
  hMem = GUI_ALLOC_AllocNoInit(Size);
  if (hMem) {
    GUI_MEMSET((U8*)GUI_ALLOC_h2p(hMem), 0, Size);   /* Zeroinit ! */
  }
  GUI_UNLOCK();
  return hMem;
}
Exemplo n.º 2
0
/*********************************************************************
*
*       GUI_JPEG_Draw
*/
int GUI_JPEG_Draw(const void * pFileData, int DataSize, int x0, int y0) {
  #if (GUI_WINSUPPORT)
    GUI_RECT r;
  #endif
  int Ret = 0;
  GUI_HMEM hBuffer = 0;
	struct jpeg_decompress_struct cinfo;
	struct jpeg_error_mgr jerr;
  GUI_LOCK();
  _Init(&jerr, &cinfo, pFileData, DataSize);
  #if (GUI_WINSUPPORT)
    WM_ADDORG(x0,y0);
    r.x1 = (r.x0 = x0) + cinfo.image_width - 1;
    r.y1 = (r.y0 = y0) + cinfo.image_height - 1;
    WM_ITERATE_START(&r) {
  #endif
    if (hBuffer) {
      _Init(&jerr, &cinfo, pFileData, DataSize);
    }
    /* 4. Set up parameters for decompression (optional ...) */
    /* 5. jpeg_start_decompress(...); Should normally return quickly */
	  jpeg_start_decompress(&cinfo);
    /* 6. while (scan lines remain to be read) */
	  /*     jpeg_read_scanlines(...); */
    if (!hBuffer) {
      hBuffer = GUI_ALLOC_AllocNoInit(cinfo.image_width * 3);
    }
    while (cinfo.output_scanline < cinfo.output_height) {
      U8* p;
      p = (U8*)GUI_ALLOC_h2p(hBuffer);
      jpeg_read_scanlines(&cinfo, &p, 1);
      if (cinfo.jpeg_color_space == JCS_GRAYSCALE) {
        _WritePixelsGray(p, x0, y0 + cinfo.output_scanline, cinfo.image_width);
      } else {
        _WritePixelsRGB(p, x0, y0 + cinfo.output_scanline, cinfo.image_width);
      }
    }
    /* 7. jpeg_finish_decompress(...); */
    /*    Complete the decompression cycle.  This causes working memory associated */
    /*    with the JPEG object to be released. */
	  jpeg_finish_decompress(&cinfo);
    /* 8. Release the JPEG decompression object. */
    jpeg_destroy_decompress(&cinfo);
  #if (GUI_WINSUPPORT)
    } WM_ITERATE_END();
  #endif
  GUI_ALLOC_Free(hBuffer);
  GUI_UNLOCK();
  return Ret;
}
Exemplo n.º 3
0
int GUI__SetText(GUI_HMEM* phText, const char* s) {
  int r = 0;
  if (GUI__strcmp_hp(*phText, s) != 0) {            /* Make sure we have a quick out if nothing changes */
    GUI_HMEM hMem;
    hMem = GUI_ALLOC_AllocNoInit(GUI__strlen(s) + 1);
    if (hMem) {
      char* pMem;
      pMem = (char*) GUI_ALLOC_h2p(hMem);
      strcpy(pMem, s);
      GUI_ALLOC_FreePtr(phText);
      *phText = hMem;
      r = 1;
    }
  }
  return r;
}
Exemplo n.º 4
0
/*********************************************************************
*
*       GUI_ALLOC_Realloc
*
* Purpose:
*   Reallocate a memory block. This is typically used to grow memory
*   blocks. The contents of the old memory block are copied into the
*   new block (or as much as fits in case of shrinkage).
*   In case of error the old memory block (and its handle) remain
*   unchanged.
*
* Return value:
*   On success:    Handle of newly allocated memory block
*   On error:      0
*/
GUI_HMEM GUI_ALLOC_Realloc(GUI_HMEM hOld, int NewSize) {
  GUI_HMEM hNew;
  hNew = GUI_ALLOC_AllocNoInit(NewSize);
  if (hNew && hOld) {
    void *pNew, *pOld;
    int Size, OldSize;
    OldSize = GUI_ALLOC_GetSize(hOld);
    Size = (OldSize < NewSize) ? OldSize : NewSize;
    GUI_LOCK();
    pNew = GUI_ALLOC_h2p(hNew);
    pOld = GUI_ALLOC_h2p(hOld);
    memcpy(pNew, pOld, Size);
    GUI_UNLOCK();
    GUI_ALLOC_Free(hOld);
  }
  return hNew;
}
Exemplo n.º 5
0
/*********************************************************************
*
*       GUI_ALLOC_AllocInit
*
* Purpose:
*   Alloc memory block of the given size and initialize from the given pointer.
*   If the pointer is a NULL pointer, zeroinit
*/
GUI_HMEM GUI_ALLOC_AllocInit(const void *pInitData, GUI_ALLOC_DATATYPE Size) {
  GUI_HMEM hMem;
  GUI_LOCK();
  if (Size == 0) {
    return (GUI_HMEM)0;
  }
  hMem = GUI_ALLOC_AllocNoInit(Size);
  if (hMem) {
    void *pMem;
    pMem = GUI_ALLOC_h2p(hMem);
    if (pInitData) {
      memcpy(pMem, pInitData, Size);
    } else {
      GUI_MEMSET((U8*)pMem, 0, Size);
    }
  }
  GUI_UNLOCK();
  return hMem;
}