OpenTTD
8bpp_simple.cpp
Go to the documentation of this file.
1 /* $Id: 8bpp_simple.cpp 27837 2017-03-30 21:33:40Z peter1138 $ */
2 
3 /*
4  * This file is part of OpenTTD.
5  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6  * OpenTTD 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.
7  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8  */
9 
12 #include "../stdafx.h"
13 #include "../zoom_func.h"
14 #include "8bpp_simple.hpp"
15 
16 #include "../safeguards.h"
17 
20 
22 {
23  const uint8 *src, *src_line;
24  uint8 *dst, *dst_line;
25 
26  /* Find where to start reading in the source sprite */
27  src_line = (const uint8 *)bp->sprite + (bp->skip_top * bp->sprite_width + bp->skip_left) * ScaleByZoom(1, zoom);
28  dst_line = (uint8 *)bp->dst + bp->top * bp->pitch + bp->left;
29 
30  for (int y = 0; y < bp->height; y++) {
31  dst = dst_line;
32  dst_line += bp->pitch;
33 
34  src = src_line;
35  src_line += bp->sprite_width * ScaleByZoom(1, zoom);
36 
37  for (int x = 0; x < bp->width; x++) {
38  uint colour = 0;
39 
40  switch (mode) {
41  case BM_COLOUR_REMAP:
42  case BM_CRASH_REMAP:
43  colour = bp->remap[*src];
44  break;
45 
46  case BM_TRANSPARENT:
47  if (*src != 0) colour = bp->remap[*dst];
48  break;
49 
50  case BM_BLACK_REMAP:
51  if (*src != 0) *dst = 0;
52  break;
53 
54  default:
55  colour = *src;
56  break;
57  }
58  if (colour != 0) *dst = colour;
59  dst++;
60  src += ScaleByZoom(1, zoom);
61  }
62  }
63 }
64 
65 Sprite *Blitter_8bppSimple::Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator)
66 {
67  Sprite *dest_sprite;
68  dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite) + (size_t)sprite->height * (size_t)sprite->width);
69 
70  dest_sprite->height = sprite->height;
71  dest_sprite->width = sprite->width;
72  dest_sprite->x_offs = sprite->x_offs;
73  dest_sprite->y_offs = sprite->y_offs;
74 
75  /* Copy over only the 'remap' channel, as that is what we care about in 8bpp */
76  for (int i = 0; i < sprite->height * sprite->width; i++) {
77  dest_sprite->data[i] = sprite->data[i].m;
78  }
79 
80  return dest_sprite;
81 }
int left
The left offset in the &#39;dst&#39; in pixels to start drawing.
Definition: base.hpp:43
int sprite_width
Real width of the sprite.
Definition: base.hpp:41
int height
The height in pixels that needs to be drawn to dst.
Definition: base.hpp:40
Perform transparency colour remapping.
Definition: base.hpp:22
int skip_top
How much pixels of the source to skip on the top (based on zoom of dst)
Definition: base.hpp:38
Data structure describing a sprite.
Definition: spritecache.h:18
int width
The width in pixels that needs to be drawn to dst.
Definition: base.hpp:39
static int ScaleByZoom(int value, ZoomLevel zoom)
Scale by zoom level, usually shift left (when zoom > ZOOM_LVL_NORMAL) When shifting right...
Definition: zoom_func.h:24
Simple (and slow) 8 bpp blitter.
int skip_left
How much pixels of the source to skip on the left (based on zoom of dst)
Definition: base.hpp:37
int16 y_offs
Number of pixels to shift the sprite downwards.
Definition: spritecache.h:22
Parameters related to blitting.
Definition: base.hpp:33
int pitch
The pitch of the destination buffer.
Definition: base.hpp:47
int16 x_offs
The x-offset of where the sprite will be drawn.
SpriteLoader::CommonPixel * data
The sprite itself.
Perform a crash remapping.
Definition: base.hpp:23
byte data[]
Sprite data.
Definition: spritecache.h:23
Structure for passing information from the sprite loader to the blitter.
static FBlitter_8bppSimple iFBlitter_8bppSimple
Instantiation of the simple 8bpp blitter factory.
Definition: 8bpp_simple.cpp:19
Perform remapping to a completely blackened sprite.
Definition: base.hpp:24
Factory for the most trivial 8bpp blitter.
Definition: 8bpp_simple.hpp:28
uint16 height
Height of the sprite.
Definition: spritecache.h:19
uint8 m
Remap-channel.
uint16 width
Width of the sprite.
ZoomLevel
All zoom levels we know.
Definition: zoom_type.h:21
uint16 width
Width of the sprite.
Definition: spritecache.h:20
int top
The top offset in the &#39;dst&#39; in pixels to start drawing.
Definition: base.hpp:44
const byte * remap
XXX – Temporary storage for remap array.
Definition: base.hpp:35
const void * sprite
Pointer to the sprite how ever the encoder stored it.
Definition: base.hpp:34
void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)
Draw an image to the screen, given an amount of params defined above.
Definition: 8bpp_simple.cpp:21
Perform a colour remapping.
Definition: base.hpp:21
uint16 height
Height of the sprite.
int16 x_offs
Number of pixels to shift the sprite to the right.
Definition: spritecache.h:21
void * dst
Destination buffer.
Definition: base.hpp:46
int16 y_offs
The y-offset of where the sprite will be drawn.
BlitterMode
The modes of blitting we can do.
Definition: base.hpp:19
Sprite * Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator)
Convert a sprite from the loader to our own format.
Definition: 8bpp_simple.cpp:65