Ejemplo n.º 1
0
static void action(void)
{
    UBYTE *buf = AllocVec(SCREENWIDTH * SCREENHEIGHT * sizeof(ULONG), MEMF_PUBLIC);
    ULONG i;
    
    if (buf)
    {
    	ReadPixelArray(buf,
	    	       0,
		       0,
		       SCREENWIDTH * sizeof(ULONG),
		       win->RPort,
		       win->BorderLeft,
		       win->BorderTop,
		       SCREENWIDTH,
		       SCREENHEIGHT,
		       RECTFMT_ARGB);

    	for(i = 0; i < SCREENWIDTH * SCREENHEIGHT * 4; i += 4)
	{
	    buf[i + 1] /= 2;
	    buf[i + 2] /= 2;
	    buf[i + 3] /= 2;	    
	}
	
    	WritePixelArray(buf,
	    		0,
			0,
			SCREENWIDTH * sizeof(ULONG),
			win->RPort,
			win->BorderLeft,
			win->BorderTop,
			SCREENWIDTH,
			SCREENHEIGHT,
			RECTFMT_ARGB);
		       
    }
    
    while (!Keys[KC_ESC])
    {
    	WaitPort(win->UserPort);
        getevents();
	
    } /* while(!Keys[KC_ESC]) */

    if (buf)
	FreeVec(buf);
}
Ejemplo n.º 2
0
FUNC_HOOK(ULONG, readrgb, struct Hook *, hook, APTR, buffer, struct RND_LineMessage *, msg)
{
        struct readrgbdata *data = hook->h_Data;

        if (msg->RND_LMsg_type == LMSGTYPE_LINE_FETCH)
        {
                if (data->lastline != msg->RND_LMsg_row)
                {
                        data->lastline = msg->RND_LMsg_row;
                        ReadPixelArray(buffer, 0,0, data->sourcewidth * 4, data->rp,
                                data->sourcex, data->sourcey + msg->RND_LMsg_row, data->sourcewidth, 1, RECTFMT_ARGB);
                }
        }

        return TRUE;
}
Ejemplo n.º 3
0
APTR ReadBitMapA(struct BitMap *bm, UWORD displayID, PALETTE palette,
        int *ptr_pixelformat, int *ptr_width, int *ptr_height, TAGLIST tags)
{
        APTR array = NULL;

        if (bm)
        {
                BOOL success;
                
                int sourcex, sourcey, sourcewidth, sourceheight, destwidth, destheight; 
                int width, height, flags, depth, iscyber, bmapformat, pixelformat;
                int bufsize;
                APTR scaleengine = NULL;
                struct RastPort rp, temprp;
        
                sourcex = GetTagData(GGFX_SourceX, 0, tags);
                sourcey = GetTagData(GGFX_SourceY, 0, tags);

                GetBitMapInfo(bm, displayID,
                        BMAPATTR_Width, &width,
                        BMAPATTR_Height, &height,
                        BMAPATTR_Depth, &depth,
                        BMAPATTR_Flags, &flags,
                        BMAPATTR_CyberGFX, &iscyber,
                        BMAPATTR_BitMapFormat, &bmapformat,
                        BMAPATTR_PixelFormat, &pixelformat,
                        TAG_DONE);

                sourcewidth = GetTagData(GGFX_SourceWidth, width, tags);
                sourceheight = GetTagData(GGFX_SourceHeight, height, tags);
                destwidth = GetTagData(GGFX_DestWidth, width, tags);
                destheight = GetTagData(GGFX_DestHeight, height, tags);


                success = TRUE;


                //      insert bitmap into rastport, create temp rastport

                InitRastPort(&rp);
                rp.BitMap = bm;
                TurboCopyMem(&rp, &temprp, sizeof(struct RastPort));
                temprp.Layer = NULL;
                if (!(temprp.BitMap = AllocBitMap(width, 1, depth, flags, bm)))
                {
                        success = FALSE;
                }


                //      create scale engine

                if (success)
                {
                        if (sourcewidth != destwidth || sourceheight != destheight)
                        {
                                if (!(scaleengine = CreateScaleEngine(
                                        sourcewidth, sourceheight,
                                        destwidth, destheight,
                                        RND_RMHandler, MemHandler,
                                        RND_PixelFormat, pixelformat,
                                        TAG_DONE)))
                                {
                                        success = FALSE;
                                }
                        }
                }


                //      get buffer

                if (success)
                {
                        if (pixelformat == PIXFMT_0RGB_32)
                        {
                                bufsize = destwidth * destheight * PIXELSIZE(pixelformat);
                        }
                        else
                        {
                                bufsize = ((destwidth+15) & ~15) * destheight;
                        }

                        DB(kprintf("!readbitmap alloc\n"));

                        if (!(array = AllocRenderVec(MemHandler, bufsize)))
                        {
                                success = FALSE;
                        }
                }



                //      convert data
                
                if (success)
                {
                        success = FALSE;

                        if (scaleengine)
                        {

                                //      with scaling

                                switch (bmapformat)
                                {
                                        case PIXFMT_BITMAP_RGB:
                                        {
                                                ULONG *linebuffer;

                                                DB(kprintf("~reading/scaling RGB bitmap\n"));
                                                
                                                if (linebuffer = AllocRenderVec(MemHandler, sourcewidth * 4))
                                                {
                                                        struct Hook readhook;
                                                        struct readrgbdata hookdata;
                
                                                        hookdata.rp = &rp;
                                                        hookdata.sourcex = sourcex;
                                                        hookdata.sourcey = sourcey;
                                                        hookdata.sourcewidth = sourcewidth;
                                                        hookdata.lastline = -1;
        
                                                        readhook.h_Data = &hookdata;
                                                        readhook.h_Entry = HOOKENTRY(readrgb);

                                                        Scale(scaleengine, linebuffer, array,
                                                                RND_SourceWidth, 0,
                                                                RND_LineHook, &readhook,
                                                                TAG_DONE);

                                                        FreeRenderVec(linebuffer);
                                                        success = TRUE;
                                                }
                                                break;
                                        }
                                        case PIXFMT_BITMAP_CLUT:
                                        {
                                                UBYTE *linebuffer;

                                                DB(kprintf("~reading/scaling CLUT bitmap\n"));

                                                if (linebuffer = AllocRenderVec(MemHandler, ((sourcewidth+15) & ~15)))
                                                {
                                                        struct Hook readhook;
                                                        struct readclutdata hookdata;
                
                                                        hookdata.rp = &rp;
                                                        hookdata.temprp = &temprp;
                                                        hookdata.sourcex = sourcex;
                                                        hookdata.sourcey = sourcey;
                                                        hookdata.sourcewidth = sourcewidth;
                                                        hookdata.lastline = -1;
        
                                                        readhook.h_Data = &hookdata;
                                                        readhook.h_Entry = HOOKENTRY(readclut);

                                                        Scale(scaleengine, linebuffer, array,
                                                                RND_SourceWidth, 0,
                                                                RND_LineHook, &readhook,
                                                                TAG_DONE);

                                                        FreeRenderVec(linebuffer);
                                                        success = TRUE;
                                                }
                                                break;                                  
                                        }

                                        case PIXFMT_BITMAP_HAM6:
                                        case PIXFMT_BITMAP_HAM8:
                                        {
                                                UBYTE *linebuffer;
                                                ULONG *rgbbuffer;

                                                DB(kprintf("~reading/scaling HAM bitmap\n"));

                                                if (linebuffer = AllocRenderVec(MemHandler, ((sourcewidth + sourcex + 15) & ~15)))
                                                {
                                                        if (rgbbuffer = AllocRenderVec(MemHandler, sourcewidth * 4))
                                                        {
                                                                struct Hook readhook;
                                                                struct readhamdata hookdata;
                        
                                                                hookdata.rp = &rp;
                                                                hookdata.temprp = &temprp;
                                                                hookdata.sourcex = sourcex;
                                                                hookdata.sourcey = sourcey;
                                                                hookdata.sourcewidth = sourcewidth;
                                                                hookdata.linebuffer = linebuffer;
                                                                hookdata.palette = palette;
                                                                hookdata.colormode = (depth == 8) ? COLORMODE_HAM8 : COLORMODE_HAM6;
                                                                hookdata.lastline = -1;
                
                                                                readhook.h_Data = &hookdata;
                                                                readhook.h_Entry = HOOKENTRY(readham);
        
                                                                Scale(scaleengine, rgbbuffer, array,
                                                                        RND_SourceWidth, 0,
                                                                        RND_LineHook, &readhook,
                                                                        TAG_DONE);
        
                                                                FreeRenderVec(rgbbuffer);
                                                                success = TRUE;
                                                        }
                                                        FreeRenderVec(linebuffer);
                                                }
                                                break;                                  
                                        }
                                }
                        
                        }
                        else
                        {
                                //      no scaling
                                
                                switch (bmapformat)
                                {
                                        case PIXFMT_BITMAP_RGB:
                                        {
                                                DB(kprintf("~reading RGB bitmap\n"));
                                        
                                                ReadPixelArray(array, 0,0, destwidth * 4, &rp,
                                                        sourcex, sourcey, destwidth, destheight, RECTFMT_ARGB);
                                                success = TRUE;
                                                break;
                                        }

                                        case PIXFMT_BITMAP_CLUT:
                                        {
                                                int i;
                                                char *p = array;

                                                DB(kprintf("~reading CLUT bitmap\n"));

                                                for(i = 0; i < destheight; ++i)
                                                {
                                                        ReadPixelLine8(&rp, sourcex, sourcey + i, destwidth, p, &temprp);
                                                        p += destwidth;
                                                }
                                                success = TRUE;
                                                break;
                                        }
                                        
                                        case PIXFMT_BITMAP_HAM6:
                                        case PIXFMT_BITMAP_HAM8:
                                        {
                                                UBYTE *linebuffer;

                                                DB(kprintf("~reading HAM bitmap\n"));

                                                if (linebuffer = AllocRenderVec(MemHandler, ((destwidth+15) & ~15) ))
                                                {
                                                        int i;
                                                        ULONG *p = array;
                                                        for(i = 0; i < destheight; ++i)
                                                        {
                                                                ReadPixelLine8(&rp, sourcex, sourcey + i, destwidth, linebuffer, &temprp);

                                                                Chunky2RGB(linebuffer, destwidth, 1, p, palette,
                                                                        RND_ColorMode, ((depth == 8) ? COLORMODE_HAM8 : COLORMODE_HAM6),
                                                                        TAG_DONE);

                                                                p += destwidth;
                                                        }
                                                        FreeRenderVec(linebuffer);
                                                        success = TRUE;
                                                }
                                                break;
                                        }

                                }
                        }
                
                }
                
                
                        

                //      close down

                if (success)
                {
                        *ptr_pixelformat = pixelformat;
                        *ptr_width = destwidth;
                        *ptr_height = destheight;
                }
                else
                {
                        if (array)
                        {
                                FreeRenderVec(array);
                                array = NULL;
                        }
                }
                
                if (scaleengine)
                {
                        DeleteScaleEngine(scaleengine);
                }

                if (temprp.BitMap)
                {
                        FreeBitMap(temprp.BitMap);
                }

        }

        return array;
}