Subversion Repositories filter_foundry

Rev

Rev 198 | Rev 268 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. /*
  2.         This file is part of a common library for Adobe(R) Photoshop(R) plugins
  3.     Copyright (C) 2002-6 Toby Thain, toby@telegraphics.com.au
  4.  
  5.     This program is free software; you can redistribute it and/or modify
  6.     it under the terms of the GNU General Public License as published by  
  7.     the Free Software Foundation; either version 2 of the License, or
  8.     (at your option) any later version.
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License  
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18. */
  19.  
  20. #include <windows.h>
  21. #include <stdlib.h>
  22.  
  23. #include "ui_compat.h"
  24.  
  25. #include "str.h"
  26. #include "dbg.h"
  27.  
  28. /* see "DIBs and Their Use",
  29.    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dngdi/html/msdn_dibs2.asp */
  30.  
  31. Boolean newbitmap(BITMAPREF *ppb,int depth,UIRECT *bounds){
  32.         //char s[0x100];
  33.         if( (*ppb = (BITMAPREF)malloc(sizeof(**ppb))) ){
  34.                 BITMAPINFOHEADER *pbmih = &(*ppb)->bmi.bmiHeader;
  35.  
  36.         pbmih->biWidth = bounds->right - bounds->left;
  37.         pbmih->biHeight = bounds->top - bounds->bottom; // negative: top-down!
  38.                 pbmih->biSize = sizeof(BITMAPINFOHEADER);
  39.         pbmih->biPlanes = 1;
  40.         pbmih->biBitCount = depth; // blue,green,red; high byte not used
  41.         pbmih->biCompression = BI_RGB;
  42.         pbmih->biSizeImage = 0; //(*ppb)->rowbytes * -pbmih->biHeight;
  43.         pbmih->biXPelsPerMeter =
  44.         pbmih->biYPelsPerMeter = 0;
  45.         pbmih->biClrUsed =
  46.         pbmih->biClrImportant = 0;
  47.        
  48.         (*ppb)->hbmp = CreateDIBSection(NULL/*hDC*/,&(*ppb)->bmi,DIB_RGB_COLORS,(void**)&(*ppb)->pbits,NULL,0);
  49.  
  50.                 (*ppb)->rowbytes = ((depth * pbmih->biWidth + 31) >> 3) & -4;
  51.  
  52.                 if( (*ppb)->hbmp ){
  53.                
  54.                         /*long i,j,*p;
  55.                        
  56.                         char s[0x200];
  57.                 sprintf(s,"newbitmap: biWidth = %d,rowbytes = %d,biHeight = %d,biSize = %d,biBitCount = %d,result = %#x",
  58.                         pbmih->biWidth,(*ppb)->rowbytes,pbmih->biHeight,
  59.                         pbmih->biSize,pbmih->biBitCount,(*ppb)->hbmp );
  60.                 dbg(s);
  61.        
  62.                 // checkerboard test pattern
  63.                 for(j = -pbmih->biHeight,p=(long*)(*ppb)->pbits;j--;p+=(*ppb)->rowbytes/4)
  64.                         for(i=pbmih->biWidth;i--;)
  65.                                 p[i] = -( (i^j)&1 ) ;*/
  66.                
  67.                         return true;
  68.                 }else
  69.                         dbg("CreateDIBSection FAILED");
  70.         }
  71.         return false;
  72. }
  73.  
  74. void disposebitmap(BITMAPREF pb){
  75.         if(pb){
  76.                 DeleteObject(pb->hbmp);
  77.                 free(pb);
  78.         }
  79. }
  80.  
  81. void centre_window(HWND hwnd){
  82.         RECT rs, rd;
  83.         HWND hw = GetDesktopWindow();
  84.         if (GetWindowRect(hw, &rs) && GetWindowRect(hwnd, &rd))
  85.                 MoveWindow(hwnd,(rs.right + rs.left + rd.left - rd.right) / 2,
  86.                                                 (rs.bottom + rs.top + rd.top - rd.bottom) / 3,
  87.                                                 rd.right - rd.left, rd.bottom - rd.top, TRUE);
  88. }
  89.