<commit_before>/*
   (c) Copyright 2000-2002  convergence integrated media GmbH.
   (c) Copyright 2002       convergence GmbH.
   
   All rights reserved.

   Written by <NAME> <<EMAIL>>,
              <NAME> <<EMAIL>> and
              <NAME> <<EMAIL>>.

   Scaling routines ported from gdk_pixbuf by <NAME>
   <<EMAIL>>.

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library 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
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with this library; if not, write to the
   Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.
*/

#include <config.h>

#include <stdlib.h>
#include <stdio.h>

#include <pthread.h>

#include <directfb.h>

#include <core/core.h>
#include <core/coredefs.h>
#include <core/coretypes.h>

#include <core/palette.h>
#include <core/surfaces.h>

#include <misc/memcpy.h>
#include <misc/util.h>
#include <misc/mem.h>

#include <misc/gfx_util.h>

#include <gfx/convert.h>


#define SUBSAMPLE_BITS 4
#define SUBSAMPLE (1 << SUBSAMPLE_BITS)
#define SUBSAMPLE_MASK ((1 << SUBSAMPLE_BITS)-1)
#define SCALE_SHIFT 16


typedef struct _PixopsFilter PixopsFilter;

struct _PixopsFilter {
     int *weights;
     int n_x;
     int n_y;
     double x_offset;
     double y_offset;
};


static void rgba_to_dst_format (__u8 *dst,
                                __u32 r, __u32 g, __u32 b, __u32 a,
                                DFBSurfacePixelFormat dst_format,
                                CorePalette *palette)
{
     __u32 out_pixel;

     switch (dst_format) {

     case DSPF_RGB332:
          *((__u8*)dst) = PIXEL_RGB332( r, g, b );
          break;

     case DSPF_A8:
          *((__u8*)dst) = a;
          break;

     case DSPF_ARGB:
          *((__u32*)dst) = PIXEL_ARGB( a, r, g, b );
          break;

     case DSPF_ARGB1555:
          *((__u16*)dst) = PIXEL_ARGB1555( a, r, g, b );
          break;

     case DSPF_RGB32:
          *((__u32*)dst) = PIXEL_RGB32( r, g, b );
          break;

     case DSPF_RGB16:
          out_pixel  = b;
          out_pixel |= g << 8;
          out_pixel |= r << 16;
          *(__u16 *)dst = RGB32_TO_RGB16 (out_pixel);
          break;

     case DSPF_RGB24:
          *dst++ = b;
          *dst++ = g;
          *dst   = r;
          break;

     case DSPF_LUT8:
          if (palette)
               *dst++ = dfb_palette_search( palette, r, g, b, a );
          break;

     case DSPF_ALUT44:
          if (palette)
               *dst++ = (a & 0xF0) + dfb_palette_search( palette, r, g, b, 0x80 );
          break;

     default:
          ONCE( "unimplemented destination format" );
          break;
     }
}

#define LINE_PTR(dst,caps,y,h,pitch) \
     ((caps & DSCAPS_SEPARATED) \
          ? (((char*)dst) + y/2 * pitch + ((y%2) ? h/2 * pitch : 0)) \
          : (((char*)dst) + y * pitch))

void dfb_copy_buffer_32( void *dst, __u32 *src, int w, int h, int dpitch,
                         CoreSurface *dst_surface )
{
     int x, y;
     int dskip;
     __u32 /*rb,*/ a;
     int bpp = DFB_BYTES_PER_PIXEL( dst_surface->format );

     dskip = dpitch - DFB_BYTES_PER_LINE (dst_surface->format, w);

     switch (dst_surface->format) {
          case DSPF_A8:
               for (y = 0; y < h; y++) {
                    __u8 *d = LINE_PTR( dst, dst_surface->caps,
                                        y, dst_surface->height, dpitch );

                    for (x = 0; x < w; x++)
                         d[x] = src[x] >> 24;

                    src += w;
               }
               break;

          case DSPF_ARGB:
               for (y = 0; y < h; y++) {
                    void *d = LINE_PTR( dst, dst_surface->caps,
                                        y, dst_surface->height, dpitch );

                    dfb_memcpy (d, src, w * 4);

                    src += w;
               }
               break;

          default:
               for (y = 0; y < h; y++) {
                    void *d = LINE_PTR( dst, dst_surface->caps,
                                        y, dst_surface->height, dpitch );
                    
                    for (x = 0; x < w; x++) {
                         a = *src >> 24;

/*                         switch (a) {
                              case 0x0:
                                   memset ( (__u8*) d, 0, bpp );
                                   break;
                              case 0xFF:*/
                                   rgba_to_dst_format ((__u8 *)d,
                                                       (*src & 0x00FF0000) >> 16,
                                                       (*src & 0x0000FF00) >> 8,
                                                       (*src & 0x000000FF),
                                                       0xFF,
                                                       dst_surface->format,
                                                       dst_surface->palette);
/*                                   break;
                              default:
                                   rb = (*src & 0x00FF00FF) * (a+1);
                                   rgba_to_dst_format ((__u8 *)d,
                                                       rb >> 24,
                                                       ((*src & 0x0000FF00) * (a+1)) >> 16,
                                                       (rb & 0x0000FF00) >> 8,
                                                       a, dst_surface->format,
                                                       dst_surface->palette);
                                   break;
                         }*/

                         d += bpp;

                         src++;<commit_msg>Pass real alpha value to conversion routine.<commit_after>/*
   (c) Copyright 2000-2002  convergence integrated media GmbH.
   (c) Copyright 2002       convergence GmbH.
   
   All rights reserved.

   Written by <NAME> <<EMAIL>>,
              <NAME> <<EMAIL>> and
              <NAME> <<EMAIL>>.

   Scaling routines ported from gdk_pixbuf by <NAME>
   <<EMAIL>>.

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library 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
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with this library; if not, write to the
   Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.
*/

#include <config.h>

#include <stdlib.h>
#include <stdio.h>

#include <pthread.h>

#include <directfb.h>

#include <core/core.h>
#include <core/coredefs.h>
#include <core/coretypes.h>

#include <core/palette.h>
#include <core/surfaces.h>

#include <misc/memcpy.h>
#include <misc/util.h>
#include <misc/mem.h>

#include <misc/gfx_util.h>

#include <gfx/convert.h>


#define SUBSAMPLE_BITS 4
#define SUBSAMPLE (1 << SUBSAMPLE_BITS)
#define SUBSAMPLE_MASK ((1 << SUBSAMPLE_BITS)-1)
#define SCALE_SHIFT 16


typedef struct _PixopsFilter PixopsFilter;

struct _PixopsFilter {
     int *weights;
     int n_x;
     int n_y;
     double x_offset;
     double y_offset;
};


static void rgba_to_dst_format (__u8 *dst,
                                __u32 r, __u32 g, __u32 b, __u32 a,
                                DFBSurfacePixelFormat dst_format,
                                CorePalette *palette)
{
     __u32 out_pixel;

     switch (dst_format) {

     case DSPF_RGB332:
          *((__u8*)dst) = PIXEL_RGB332( r, g, b );
          break;

     case DSPF_A8:
          *((__u8*)dst) = a;
          break;

     case DSPF_ARGB:
          *((__u32*)dst) = PIXEL_ARGB( a, r, g, b );
          break;

     case DSPF_ARGB1555:
          *((__u16*)dst) = PIXEL_ARGB1555( a, r, g, b );
          break;

     case DSPF_RGB32:
          *((__u32*)dst) = PIXEL_RGB32( r, g, b );
          break;

     case DSPF_RGB16:
          out_pixel  = b;
          out_pixel |= g << 8;
          out_pixel |= r << 16;
          *(__u16 *)dst = RGB32_TO_RGB16 (out_pixel);
          break;

     case DSPF_RGB24:
          *dst++ = b;
          *dst++ = g;
          *dst   = r;
          break;

     case DSPF_LUT8:
          if (palette)
               *dst++ = dfb_palette_search( palette, r, g, b, a );
          break;

     case DSPF_ALUT44:
          if (palette)
               *dst++ = (a & 0xF0) + dfb_palette_search( palette, r, g, b, 0x80 );
          break;

     default:
          ONCE( "unimplemented destination format" );
          break;
     }
}

#define LINE_PTR(dst,caps,y,h,pitch) \
     ((caps & DSCAPS_SEPARATED) \
          ? (((char*)dst) + y/2 * pitch + ((y%2) ? h/2 * pitch : 0)) \
          : (((char*)dst) + y * pitch))

void dfb_copy_buffer_32( void *dst, __u32 *src, int w, int h, int dpitch,
                         CoreSurface *dst_surface )
{
     int x, y;
     int dskip;
     __u32 /*rb,*/ a;
     int bpp = DFB_BYTES_PER_PIXEL( dst_surface->format );

     dskip = dpitch - DFB_BYTES_PER_LINE (dst_surface->format, w);

     switch (dst_surface->format) {
          case DSPF_A8:
               for (y = 0; y < h; y++) {
                    __u8 *d = LINE_PTR( dst, dst_surface->caps,
                                        y, dst_surface->height, dpitch );

                    for (x = 0; x < w; x++)
                         d[x] = src[x] >> 24;

                    src += w;
               }
               break;

          case DSPF_ARGB:
               for (y = 0; y < h; y++) {
                    void *d = LINE_PTR( dst, dst_surface->caps,
                                        y, dst_surface->height, dpitch );

                    dfb_memcpy (d, src, w * 4);

                    src += w;
               }
               break;

          default:
               for (y = 0; y < h; y++) {
                    void *d = LINE_PTR( dst, dst_surface->caps,
                                        y, dst_surface->height, dpitch );
                    
                    for (x = 0; x < w; x++) {
                         a = *src >> 24;

/*                         switch (a) {
                              case 0x0:
                                   memset ( (__u8*) d, 0, bpp );
                                   break;
                              case 0xFF:*/
                                   rgba_to_dst_format ((__u8 *)d,
                                                       (*src & 0x00FF0000) >> 16,
                                                       (*src & 0x0000FF00) >> 8,
                                                       (*src & 0x000000FF),
                                                       a,
                                                       dst_surface->format,
                                                       dst_surface->palette);
/*                                   break;
                              default:
                                   rb = (*src & 0x00FF00FF) * (a+1);
                                   rgba_to_dst_format ((__u8 *)d,
                                                       rb >> 24,
                                                       ((*src & 0x0000FF00) * (a+1)) >> 16,
                                                       (rb & 0x0000FF00) >> 8,
                                                       a, dst_surface->format,
                                                       dst_surface->palette);
                                   break;
                         }*/

                         d += bpp;

                         src++;
{'fraction_non_alphanumeric': 0.10239987027728231, 'fraction_numerical': 0.027809307604994324, 'mean_word_length': 1.1363006581226187, 'pattern_counts': {'":': 0, '<': 83, '<?xml version=': 0, '>': 111, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 70, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1160206', 'n_tokens_mistral': 3873, 'n_tokens_neox': 3481, 'n_words': 1003}