Skip to content

Commit 0db96a3

Browse files
authored
Merge pull request #137 from moradology/feature/multiband-color-encoding
Add support for RGB and RGBA tiffs
2 parents 42e760f + 465f900 commit 0db96a3

File tree

4 files changed

+39
-9
lines changed

4 files changed

+39
-9
lines changed

ogc-example/src/main/scala/geotrellis/server/ogc/wms/WmsView.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class WmsView(wmsModel: WmsModel, serviceUrl: URL) extends LazyLogging {
8888
Invalid(errs)
8989
}.attempt flatMap {
9090
case Right(Valid((mbtile, hists))) => // success
91-
val rendered = Render(mbtile, layer.style, wmsReq.format, hists)
91+
val rendered = Render.singleband(mbtile, layer.style, wmsReq.format, hists)
9292
Ok(rendered)
9393
case Right(Invalid(errs)) => // maml-specific errors
9494
logger.debug(errs.toList.toString)

ogc-example/src/main/scala/geotrellis/server/ogc/wmts/WmtsView.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class WmtsView(wmtsModel: WmtsModel, serviceUrl: URL) extends LazyLogging {
7373
Invalid(errs)
7474
}.attempt flatMap {
7575
case Right(Valid((mbtile, hists))) => // success
76-
val rendered = Render(mbtile, layer.style, wmtsReq.format, hists)
76+
val rendered = Render.singleband(mbtile, layer.style, wmtsReq.format, hists)
7777
Ok(rendered)
7878
case Right(Invalid(errs)) => // maml-specific errors
7979
logger.debug(errs.toList.toString)

ogc/src/main/scala/geotrellis/server/ogc/OutputFormat.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ object OutputFormat {
1414
object Png {
1515
final val PngEncodingRx = """image/png(?:;encoding=(\w+))?""".r
1616

17-
def encodoingToString(enc: PngColorEncoding): String = enc match {
17+
def encodingToString(enc: PngColorEncoding): String = enc match {
1818
case RgbaPngEncoding => "rgba"
1919
case GreyaPngEncoding => "greya"
2020
case _: RgbPngEncoding => "rgb"
@@ -34,7 +34,7 @@ object OutputFormat {
3434

3535
case class Png(encoding: Option[PngColorEncoding]) extends OutputFormat {
3636
override def toString = encoding match {
37-
case Some(e) => s"image/png;encoding=${Png.encodoingToString(e)}"
37+
case Some(e) => s"image/png;encoding=${Png.encodingToString(e)}"
3838
case None => "image/png"
3939
}
4040

ogc/src/main/scala/geotrellis/server/ogc/Render.scala

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,56 @@ package geotrellis.server.ogc
33
import geotrellis.raster._
44
import geotrellis.raster.render._
55
import geotrellis.raster.render.png._
6-
import geotrellis.raster.histogram._
76
import geotrellis.raster.render.png._
7+
import geotrellis.raster.render._
8+
import geotrellis.raster.histogram._
89

910
import scala.collection.mutable
1011
import scala.util.Try
1112

1213
object Render {
13-
def apply(mbtile: MultibandTile, maybeStyle: Option[OgcStyle], format: OutputFormat, hists: List[Histogram[Double]]): Array[Byte] =
14+
def rgb(mbtile: MultibandTile, maybeStyle: Option[OgcStyle], format: OutputFormat, hists: List[Histogram[Double]]): Array[Byte] =
1415
maybeStyle match {
1516
case Some(style) =>
1617
style.renderImage(mbtile, format, hists)
1718
case None =>
1819
format match {
1920
case format: OutputFormat.Png =>
20-
format.render(mbtile.band(bandIndex = 0))
21+
OutputFormat.Png(Some(RgbPngEncoding)).render(mbtile.color())
22+
case OutputFormat.Jpg =>
23+
mbtile.color().renderJpg.bytes
24+
case format =>
25+
throw new IllegalArgumentException(s"$format is not a valid output format")
26+
}
27+
}
2128

29+
def rgba(mbtile: MultibandTile, maybeStyle: Option[OgcStyle], format: OutputFormat, hists: List[Histogram[Double]]): Array[Byte] =
30+
maybeStyle match {
31+
case Some(style) =>
32+
style.renderImage(mbtile, format, hists)
33+
case None =>
34+
format match {
35+
case format: OutputFormat.Png =>
36+
OutputFormat.Png(Some(RgbaPngEncoding)).render(mbtile.color())
2237
case OutputFormat.Jpg =>
23-
mbtile.band(bandIndex = 0).renderJpg.bytes
38+
mbtile.color().renderJpg.bytes
39+
case format =>
40+
throw new IllegalArgumentException(s"$format is not a valid output format")
41+
}
42+
}
2443

25-
case OutputFormat.GeoTiff => ??? // Implementation necessary
44+
def singleband(mbtile: MultibandTile, maybeStyle: Option[OgcStyle], format: OutputFormat, hists: List[Histogram[Double]]): Array[Byte] =
45+
maybeStyle match {
46+
case Some(style) =>
47+
style.renderImage(mbtile, format, hists)
48+
case None =>
49+
format match {
50+
case format: OutputFormat.Png =>
51+
format.render(mbtile.band(bandIndex = 0))
52+
case OutputFormat.Jpg =>
53+
mbtile.band(bandIndex = 0).renderJpg.bytes
54+
case format =>
55+
throw new IllegalArgumentException(s"$format is not a valid output format")
2656
}
2757
}
2858

0 commit comments

Comments
 (0)